OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_POLICY_UI_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_POLICY_UI_HANDLER_H_ |
| 7 |
| 8 #include <string.h> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/policy/core/browser/policy_error_map.h" |
| 14 #include "components/policy/core/common/policy_map.h" |
| 15 #include "components/policy/core/common/policy_namespace.h" |
| 16 #include "components/policy/core/common/policy_service.h" |
| 17 #include "components/policy/core/common/schema_registry.h" |
| 18 #include "content/public/browser/web_ui.h" |
| 19 #include "content/public/browser/web_ui_data_source.h" |
| 20 #include "content/public/browser/web_ui_message_handler.h" |
| 21 |
| 22 #if defined(ENABLE_EXTENSIONS) |
| 23 #include "extensions/browser/extension_registry_observer.h" |
| 24 #endif |
| 25 |
| 26 struct PolicyStringMap { |
| 27 const char* key; |
| 28 int string_id; |
| 29 }; |
| 30 |
| 31 class CloudPolicyStatusProvider; |
| 32 |
| 33 // The JavaScript message handler for the chrome://policy page. |
| 34 class PolicyUIHandler : public content::WebUIMessageHandler, |
| 35 #if defined(ENABLE_EXTENSIONS) |
| 36 public extensions::ExtensionRegistryObserver, |
| 37 #endif |
| 38 public policy::PolicyService::Observer, |
| 39 public policy::SchemaRegistry::Observer { |
| 40 public: |
| 41 PolicyUIHandler(); |
| 42 ~PolicyUIHandler() override; |
| 43 |
| 44 |
| 45 static void AddLocalizedPolicyStrings(content::WebUIDataSource* source, |
| 46 const PolicyStringMap* strings, |
| 47 size_t count); |
| 48 |
| 49 static void AddCommonLocalizedStringsToSource( |
| 50 content::WebUIDataSource* source); |
| 51 |
| 52 // content::WebUIMessageHandler implementation. |
| 53 void RegisterMessages() override; |
| 54 |
| 55 #if defined(ENABLE_EXTENSIONS) |
| 56 // extensions::ExtensionRegistryObserver implementation. |
| 57 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 58 const extensions::Extension* extension) override; |
| 59 void OnExtensionUnloaded( |
| 60 content::BrowserContext* browser_context, |
| 61 const extensions::Extension* extension, |
| 62 extensions::UnloadedExtensionInfo::Reason reason) override; |
| 63 #endif |
| 64 |
| 65 // policy::PolicyService::Observer implementation. |
| 66 void OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 67 const policy::PolicyMap& previous, |
| 68 const policy::PolicyMap& current) override; |
| 69 |
| 70 // policy::SchemaRegistry::Observer implementation. |
| 71 void OnSchemaRegistryUpdated(bool has_new_schemas) override; |
| 72 |
| 73 protected: |
| 74 virtual void AddPolicyName(const std::string& name, |
| 75 base::DictionaryValue* names) const; |
| 76 |
| 77 // Send a dictionary containing the names of all known policies to the UI. |
| 78 virtual void SendPolicyNames() const; |
| 79 |
| 80 private: |
| 81 // Send information about the current policy values to the UI. For each policy |
| 82 // whose value has been set, a dictionary containing the value and additional |
| 83 // metadata is sent. |
| 84 void SendPolicyValues() const; |
| 85 |
| 86 // Send the status of cloud policy to the UI. For each scope that has cloud |
| 87 // policy enabled (device and/or user), a dictionary containing status |
| 88 // information is sent. |
| 89 void SendStatus() const; |
| 90 |
| 91 // Inserts a description of each policy in |policy_map| into |values|, using |
| 92 // the optional errors in |errors| to determine the status of each policy. |
| 93 void GetPolicyValues(const policy::PolicyMap& policy_map, |
| 94 policy::PolicyErrorMap* errors, |
| 95 base::DictionaryValue* values) const; |
| 96 |
| 97 void GetChromePolicyValues(base::DictionaryValue* values) const; |
| 98 |
| 99 void HandleInitialized(const base::ListValue* args); |
| 100 void HandleReloadPolicies(const base::ListValue* args); |
| 101 |
| 102 void OnRefreshPoliciesDone() const; |
| 103 |
| 104 policy::PolicyService* GetPolicyService() const; |
| 105 |
| 106 std::string device_domain_; |
| 107 |
| 108 // Providers that supply status dictionaries for user and device policy, |
| 109 // respectively. These are created on initialization time as appropriate for |
| 110 // the platform (Chrome OS / desktop) and type of policy that is in effect. |
| 111 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; |
| 112 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; |
| 113 |
| 114 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); |
| 117 }; |
| 118 |
| 119 #endif // CHROME_BROWSER_UI_WEBUI_POLICY_UI_HANDLER_H_ |
OLD | NEW |