Chromium Code Reviews| Index: chrome/browser/ui/webui/policy_ui_handler.cc |
| diff --git a/chrome/browser/ui/webui/policy_ui.cc b/chrome/browser/ui/webui/policy_ui_handler.cc |
| similarity index 79% |
| copy from chrome/browser/ui/webui/policy_ui.cc |
| copy to chrome/browser/ui/webui/policy_ui_handler.cc |
| index 3f768e0f8bc8cbd8a015c0b5bad3589cbfce58d5..6086ba0924c681b3f5a99fd23a633c1227f81de1 100644 |
| --- a/chrome/browser/ui/webui/policy_ui.cc |
| +++ b/chrome/browser/ui/webui/policy_ui_handler.cc |
| @@ -2,9 +2,10 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/webui/policy_ui.h" |
| +#include "chrome/browser/ui/webui/policy_ui_handler.h" |
| #include <stddef.h> |
| +#include <string.h> |
|
Dan Beam
2015/11/03 18:34:11
just include <string> in policy_ui_handler.h and r
fhorschig
2015/11/04 18:51:18
Done.
|
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| @@ -23,32 +24,25 @@ |
| #include "chrome/browser/policy/schema_registry_service.h" |
| #include "chrome/browser/policy/schema_registry_service_factory.h" |
| #include "chrome/browser/profiles/profile.h" |
| -#include "chrome/common/url_constants.h" |
| #include "components/policy/core/browser/browser_policy_connector.h" |
| #include "components/policy/core/browser/cloud/message_util.h" |
| #include "components/policy/core/browser/configuration_policy_handler_list.h" |
| -#include "components/policy/core/browser/policy_error_map.h" |
| #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
| -#include "components/policy/core/common/policy_map.h" |
| -#include "components/policy/core/common/policy_namespace.h" |
| -#include "components/policy/core/common/policy_service.h" |
| +#include "components/policy/core/common/policy_details.h" |
| #include "components/policy/core/common/policy_types.h" |
| #include "components/policy/core/common/remote_commands/remote_commands_service.h" |
| #include "components/policy/core/common/schema.h" |
| #include "components/policy/core/common/schema_map.h" |
| -#include "components/policy/core/common/schema_registry.h" |
| #include "content/public/browser/web_contents.h" |
| -#include "content/public/browser/web_ui.h" |
| -#include "content/public/browser/web_ui_data_source.h" |
| -#include "content/public/browser/web_ui_message_handler.h" |
| #include "google_apis/gaia/gaia_auth_util.h" |
| -#include "grit/browser_resources.h" |
| #include "grit/components_strings.h" |
| +#include "grit/policy_resources.h" |
| +#include "grit/policy_resources_map.h" |
| #include "policy/policy_constants.h" |
| #include "policy/proto/device_management_backend.pb.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -69,7 +63,6 @@ |
| #if defined(ENABLE_EXTENSIONS) |
| #include "extensions/browser/extension_registry.h" |
| -#include "extensions/browser/extension_registry_observer.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/manifest.h" |
| #include "extensions/common/manifest_constants.h" |
| @@ -79,96 +72,15 @@ namespace em = enterprise_management; |
| namespace { |
| -struct PolicySourceMap { |
| - const char* key; |
| - int string_id; |
| -}; |
| - |
| // Strings that map from PolicySource enum to i18n string keys and their IDs. |
| -const PolicySourceMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { |
| +// Their order has to follow the order of the policy::PolicySource enum. |
| +const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { |
| {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, |
| {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, |
| {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, |
| - {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM} |
| + {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}, |
| }; |
| -void AddLocalizedPoilcySourceStrings(content::WebUIDataSource* source) { |
| - DCHECK_EQ(static_cast<size_t>(policy::POLICY_SOURCE_COUNT), |
| - arraysize(kPolicySources)); |
| - for (size_t i = 0; i < arraysize(kPolicySources); ++i) { |
| - source->AddLocalizedString(kPolicySources[i].key, |
| - kPolicySources[i].string_id); |
| - } |
| -} |
| - |
| -void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) { |
| - source->AddLocalizedString("title", IDS_POLICY_TITLE); |
| - source->AddLocalizedString("filterPlaceholder", |
| - IDS_POLICY_FILTER_PLACEHOLDER); |
| - source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); |
| - source->AddLocalizedString("status", IDS_POLICY_STATUS); |
| - source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE); |
| - source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER); |
| - source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN); |
| - source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME); |
| - source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID); |
| - source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID); |
| - source->AddLocalizedString("labelLocation", IDS_POLICY_LABEL_LOCATION); |
| - source->AddLocalizedString("labelDirectoryApiId", |
| - IDS_POLICY_LABEL_DIRECTORY_API_ID); |
| - source->AddLocalizedString("labelTimeSinceLastRefresh", |
| - IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH); |
| - source->AddLocalizedString("labelRefreshInterval", |
| - IDS_POLICY_LABEL_REFRESH_INTERVAL); |
| - source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); |
| - source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); |
| - source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); |
| - source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); |
| - source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); |
| - source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); |
| - source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); |
| - source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); |
| - source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); |
| - source->AddLocalizedString("showExpandedValue", |
| - IDS_POLICY_SHOW_EXPANDED_VALUE); |
| - source->AddLocalizedString("hideExpandedValue", |
| - IDS_POLICY_HIDE_EXPANDED_VALUE); |
| - source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); |
| - source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); |
| - source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); |
| - source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); |
| - source->AddLocalizedString("ok", IDS_POLICY_OK); |
| - source->AddLocalizedString("unset", IDS_POLICY_UNSET); |
| - source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); |
| - source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); |
| - AddLocalizedPoilcySourceStrings(source); |
| - |
| - source->SetJsonPath("strings.js"); |
| -} |
| - |
| -content::WebUIDataSource* CreatePolicyMaterialDesignUIHtmlSource() { |
| - content::WebUIDataSource* source = |
| - content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost); |
| - AddCommonLocalizedStringsToSource(source); |
| - source->SetDefaultResource(IDR_MD_POLICY_HTML); |
| - |
| - return source; |
| -} |
| - |
| - |
| -content::WebUIDataSource* CreatePolicyUIHtmlSource() { |
| - content::WebUIDataSource* source = |
| - content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost); |
| - AddCommonLocalizedStringsToSource(source); |
| - // Add required resources. |
| - source->AddResourcePath("policy.css", IDR_POLICY_CSS); |
| - source->AddResourcePath("policy.js", IDR_POLICY_JS); |
| - source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); |
| - source->SetDefaultResource(IDR_POLICY_HTML); |
| - |
| - return source; |
| -} |
| - |
| // Formats the association state indicated by |data|. If |data| is NULL, the |
| // state is considered to be UNMANAGED. |
| base::string16 FormatAssociationState(const em::PolicyData* data) { |
| @@ -387,80 +299,6 @@ class DeviceLocalAccountPolicyStatusProvider |
| }; |
| #endif |
| -// The JavaScript message handler for the chrome://policy page. |
| -class PolicyUIHandler : public content::WebUIMessageHandler, |
| -#if defined(ENABLE_EXTENSIONS) |
| - public extensions::ExtensionRegistryObserver, |
| -#endif |
| - public policy::PolicyService::Observer, |
| - public policy::SchemaRegistry::Observer { |
| - public: |
| - PolicyUIHandler(); |
| - ~PolicyUIHandler() override; |
| - |
| - // content::WebUIMessageHandler implementation. |
| - void RegisterMessages() override; |
| - |
| -#if defined(ENABLE_EXTENSIONS) |
| - // extensions::ExtensionRegistryObserver implementation. |
| - void OnExtensionLoaded(content::BrowserContext* browser_context, |
| - const extensions::Extension* extension) override; |
| - void OnExtensionUnloaded( |
| - content::BrowserContext* browser_context, |
| - const extensions::Extension* extension, |
| - extensions::UnloadedExtensionInfo::Reason reason) override; |
| -#endif |
| - |
| - // policy::PolicyService::Observer implementation. |
| - void OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| - const policy::PolicyMap& previous, |
| - const policy::PolicyMap& current) override; |
| - |
| - // policy::SchemaRegistry::Observer implementation. |
| - void OnSchemaRegistryUpdated(bool has_new_schemas) override; |
| - |
| - private: |
| - // Send a dictionary containing the names of all known policies to the UI. |
| - void SendPolicyNames() const; |
| - |
| - // Send information about the current policy values to the UI. For each policy |
| - // whose value has been set, a dictionary containing the value and additional |
| - // metadata is sent. |
| - void SendPolicyValues() const; |
| - |
| - // 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 is sent. |
| - void SendStatus() const; |
| - |
| - // Inserts a description of each policy in |policy_map| into |values|, using |
| - // the optional errors in |errors| to determine the status of each policy. |
| - void GetPolicyValues(const policy::PolicyMap& policy_map, |
| - policy::PolicyErrorMap* errors, |
| - base::DictionaryValue* values) const; |
| - |
| - void GetChromePolicyValues(base::DictionaryValue* values) const; |
| - |
| - void HandleInitialized(const base::ListValue* args); |
| - void HandleReloadPolicies(const base::ListValue* args); |
| - |
| - void OnRefreshPoliciesDone() const; |
| - |
| - policy::PolicyService* GetPolicyService() const; |
| - |
| - std::string device_domain_; |
| - |
| - // Providers that supply status dictionaries for user and device policy, |
| - // respectively. These are created on initialization time as appropriate for |
| - // the platform (Chrome OS / desktop) and type of policy that is in effect. |
| - scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; |
| - scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; |
| - |
| - base::WeakPtrFactory<PolicyUIHandler> weak_factory_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); |
| -}; |
| - |
| CloudPolicyStatusProvider::CloudPolicyStatusProvider() { |
| } |
| @@ -592,6 +430,36 @@ PolicyUIHandler::~PolicyUIHandler() { |
| #endif |
| } |
| +void PolicyUIHandler::AddLocalizedPolicyStrings( |
| + content::WebUIDataSource* source, |
| + const PolicyStringMap* strings, |
| + size_t count) { |
| + for (size_t i = 0; i < count; ++i) |
| + source->AddLocalizedString(strings[i].key, strings[i].string_id); |
| +} |
| + |
| +void PolicyUIHandler::AddCommonLocalizedStringsToSource( |
| + content::WebUIDataSource* source) { |
| + AddLocalizedPolicyStrings(source, kPolicySources, |
| + static_cast<size_t>(policy::POLICY_SOURCE_COUNT)); |
| + source->AddLocalizedString("title", IDS_POLICY_TITLE); |
| + source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); |
| + source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); |
| + source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); |
| + source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); |
| + source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); |
| + source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); |
| + source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); |
| + source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); |
| + source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); |
| + source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); |
| + source->AddLocalizedString("ok", IDS_POLICY_OK); |
| + source->AddLocalizedString("unset", IDS_POLICY_UNSET); |
| + source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); |
| + source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); |
| + source->SetJsonPath("strings.js"); |
| +} |
| + |
| void PolicyUIHandler::RegisterMessages() { |
| #if defined(OS_CHROMEOS) |
| policy::BrowserPolicyConnectorChromeOS* connector = |
| @@ -689,6 +557,11 @@ void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| SendPolicyValues(); |
| } |
| +void PolicyUIHandler::AddPolicyName(const std::string& name, |
| + base::DictionaryValue* names) const { |
| + names->SetBoolean(name, true); |
| +} |
| + |
| void PolicyUIHandler::SendPolicyNames() const { |
| base::DictionaryValue names; |
| @@ -704,7 +577,7 @@ void PolicyUIHandler::SendPolicyNames() const { |
| const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); |
| for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| !it.IsAtEnd(); it.Advance()) { |
| - chrome_policy_names->SetBoolean(it.key(), true); |
| + AddPolicyName(it.key(), chrome_policy_names); |
| } |
| names.Set("chromePolicyNames", chrome_policy_names); |
| @@ -873,22 +746,3 @@ policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| } |
| - |
| -PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| - web_ui->AddMessageHandler(new PolicyUIHandler); |
| - content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| - CreatePolicyUIHtmlSource()); |
| -} |
| - |
| -PolicyUI::~PolicyUI() { |
| -} |
| - |
| -PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) : |
| - WebUIController(web_ui) { |
| - web_ui->AddMessageHandler(new PolicyUIHandler); |
| - content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| - CreatePolicyMaterialDesignUIHtmlSource()); |
| -} |
| - |
| -PolicyMaterialDesignUI::~PolicyMaterialDesignUI() { |
| -} |