1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_POLICY_POLICY_UI_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_POLICY_POLICY_UI_HANDLER_H_
#include <stddef.h>
#include <string.h>
#include <memory>
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/policy/policy_value_and_status_aggregator.h"
#include "components/policy/core/common/schema_registry.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "extensions/buildflags/buildflags.h"
#if !BUILDFLAG(IS_ANDROID)
#include "components/enterprise/browser/promotion/promotion_eligibility_checker.h"
#endif // !BUILDFLAG(IS_ANDROID)
class PrefChangeRegistrar;
namespace features {
// If enabled, the banner on the chrome://policy page to be shown only to
// eligible users passing through the promotion eligibility checker.
BASE_DECLARE_FEATURE(kPolicyPagePromotionEligibilityCheckedBanner);
} // namespace features
namespace enterprise_management {
class GetUserEligiblePromotionsResponse;
} // namespace enterprise_management
// The JavaScript message handler for the chrome://policy page.
class PolicyUIHandler : public content::WebUIMessageHandler,
public policy::PolicyValueAndStatusAggregator::Observer,
public policy::SchemaRegistry::Observer {
public:
PolicyUIHandler();
PolicyUIHandler(const PolicyUIHandler&) = delete;
PolicyUIHandler& operator=(const PolicyUIHandler&) = delete;
~PolicyUIHandler() override;
static void AddCommonLocalizedStringsToSource(
content::WebUIDataSource* source);
// content::WebUIMessageHandler implementation.
void RegisterMessages() override;
// policy::PolicyValueAndStatusAggregator::Observer implementation.
void OnPolicyValueAndStatusChanged() override;
// policy::SchemaRegistry::Observer implementation.
void OnSchemaRegistryUpdated(bool has_new_schemas) override;
void set_web_ui_for_test(content::WebUI* web_ui) { set_web_ui(web_ui); }
private:
void HandleExportPoliciesJson(const base::Value::List& args);
void HandleListenPoliciesUpdates(const base::Value::List& args);
void HandleReloadPolicies(const base::Value::List& args);
void HandleCopyPoliciesJson(const base::Value::List& args);
void HandleSetLocalTestPolicies(const base::Value::List& args);
void HandleRevertLocalTestPolicies(const base::Value::List& args);
void HandleRestartBrowser(const base::Value::List& args);
void HandleSetUserAffiliated(const base::Value::List& args);
void HandleGetAppliedTestPolicies(const base::Value::List& args);
void HandleShouldShowPromotion(const base::Value::List& args);
void HandleSetBannerDismissed(const base::Value::List& args);
void HandleRecordBannerRedirected(const base::Value::List& args);
#if !BUILDFLAG(IS_CHROMEOS)
void HandleUploadReport(const base::Value::List& args);
#endif
// Handler functions for chrome://policy/logs.
void HandleGetPolicyLogs(const base::Value::List& args);
// Send information about the current policy values to the UI. Information is
// sent in two parts to the UI:
// - A dictionary containing all available policy names
// - A dictionary containing the value and additional metadata for each
// policy whose value has been set and the list of available policy IDs.
// Policy values and names are sent separately because the UI displays the
// policies that has their values set and the policies without value
// separately.
void SendPolicies();
// Send the current policy schema to the UI: the list of supported Chrome &
// extension policies, and their types.
void SendSchema();
// Send the status of cloud policy to the UI. For each scope that has cloud
// policy enabled (device and/or user), a dictionary containing status
// information.
void SendStatus();
#if !BUILDFLAG(IS_CHROMEOS)
// Called when report has been uploaded, successfully or not.
void OnReportUploaded(const std::string& callback_id);
#endif
#if !BUILDFLAG(IS_ANDROID)
void OnPromotionEligibilityFetched(
const std::string& callback_id,
enterprise_management::GetUserEligiblePromotionsResponse response);
std::unique_ptr<enterprise_promotion::PromotionEligibilityChecker>
promotion_eligibility_checker_;
#endif
// Build a JSON string of all the policies.
std::string GetPoliciesAsJson();
std::unique_ptr<policy::PolicyValueAndStatusAggregator>
policy_value_and_status_aggregator_;
base::ScopedObservation<policy::PolicyValueAndStatusAggregator,
policy::PolicyValueAndStatusAggregator::Observer>
policy_value_and_status_observation_{this};
base::ScopedObservation<policy::SchemaRegistry,
policy::SchemaRegistry::Observer>
schema_registry_observation_{this};
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
uint32_t reload_policies_count_ = 0;
uint32_t export_to_json_count_ = 0;
uint32_t copy_to_json_count_ = 0;
uint32_t upload_report_count_ = 0;
base::WeakPtrFactory<PolicyUIHandler> weak_factory_{this};
};
#endif // CHROME_BROWSER_UI_WEBUI_POLICY_POLICY_UI_HANDLER_H_
|