| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/policy_ui.h" | 5 #include "chrome/browser/ui/webui/policy_ui_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector.h" | 21 #include "chrome/browser/policy/profile_policy_connector.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 23 #include "chrome/browser/policy/schema_registry_service.h" | 23 #include "chrome/browser/policy/schema_registry_service.h" |
| 24 #include "chrome/browser/policy/schema_registry_service_factory.h" | 24 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/common/url_constants.h" | |
| 27 #include "components/policy/core/browser/browser_policy_connector.h" | 26 #include "components/policy/core/browser/browser_policy_connector.h" |
| 28 #include "components/policy/core/browser/cloud/message_util.h" | 27 #include "components/policy/core/browser/cloud/message_util.h" |
| 29 #include "components/policy/core/browser/configuration_policy_handler_list.h" | 28 #include "components/policy/core/browser/configuration_policy_handler_list.h" |
| 30 #include "components/policy/core/browser/policy_error_map.h" | |
| 31 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 29 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 32 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 30 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 33 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 31 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| 34 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 32 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 35 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 33 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 36 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 34 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
| 37 #include "components/policy/core/common/policy_map.h" | 35 #include "components/policy/core/common/policy_details.h" |
| 38 #include "components/policy/core/common/policy_namespace.h" | |
| 39 #include "components/policy/core/common/policy_service.h" | |
| 40 #include "components/policy/core/common/policy_types.h" | 36 #include "components/policy/core/common/policy_types.h" |
| 41 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" | 37 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" |
| 42 #include "components/policy/core/common/schema.h" | 38 #include "components/policy/core/common/schema.h" |
| 43 #include "components/policy/core/common/schema_map.h" | 39 #include "components/policy/core/common/schema_map.h" |
| 44 #include "components/policy/core/common/schema_registry.h" | |
| 45 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/web_ui.h" | |
| 47 #include "content/public/browser/web_ui_data_source.h" | |
| 48 #include "content/public/browser/web_ui_message_handler.h" | |
| 49 #include "google_apis/gaia/gaia_auth_util.h" | 41 #include "google_apis/gaia/gaia_auth_util.h" |
| 50 #include "grit/browser_resources.h" | |
| 51 #include "grit/components_strings.h" | 42 #include "grit/components_strings.h" |
| 43 #include "grit/policy_resources.h" |
| 44 #include "grit/policy_resources_map.h" |
| 52 #include "policy/policy_constants.h" | 45 #include "policy/policy_constants.h" |
| 53 #include "policy/proto/device_management_backend.pb.h" | 46 #include "policy/proto/device_management_backend.pb.h" |
| 54 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 55 #include "ui/base/l10n/time_format.h" | 48 #include "ui/base/l10n/time_format.h" |
| 56 | 49 |
| 57 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 58 #include "chrome/browser/browser_process_platform_part.h" | 51 #include "chrome/browser/browser_process_platform_part.h" |
| 59 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 52 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 60 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 53 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 61 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 54 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 62 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 55 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 63 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 56 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 64 #include "components/user_manager/user_manager.h" | 57 #include "components/user_manager/user_manager.h" |
| 65 #else | 58 #else |
| 66 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 59 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 67 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 60 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 68 #endif | 61 #endif |
| 69 | 62 |
| 70 #if defined(ENABLE_EXTENSIONS) | 63 #if defined(ENABLE_EXTENSIONS) |
| 71 #include "extensions/browser/extension_registry.h" | 64 #include "extensions/browser/extension_registry.h" |
| 72 #include "extensions/browser/extension_registry_observer.h" | |
| 73 #include "extensions/common/extension.h" | 65 #include "extensions/common/extension.h" |
| 74 #include "extensions/common/manifest.h" | 66 #include "extensions/common/manifest.h" |
| 75 #include "extensions/common/manifest_constants.h" | 67 #include "extensions/common/manifest_constants.h" |
| 76 #endif | 68 #endif |
| 77 | 69 |
| 78 namespace em = enterprise_management; | 70 namespace em = enterprise_management; |
| 79 | 71 |
| 80 namespace { | 72 namespace { |
| 81 | 73 |
| 82 struct PolicySourceMap { | |
| 83 const char* key; | |
| 84 int string_id; | |
| 85 }; | |
| 86 | |
| 87 // Strings that map from PolicySource enum to i18n string keys and their IDs. | 74 // Strings that map from PolicySource enum to i18n string keys and their IDs. |
| 88 const PolicySourceMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { | 75 // Their order has to follow the order of the policy::PolicySource enum. |
| 76 const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { |
| 89 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, | 77 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, |
| 90 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, | 78 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, |
| 91 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, | 79 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, |
| 92 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM} | 80 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM}, |
| 93 }; | 81 }; |
| 94 | 82 |
| 95 void AddLocalizedPoilcySourceStrings(content::WebUIDataSource* source) { | |
| 96 DCHECK_EQ(static_cast<size_t>(policy::POLICY_SOURCE_COUNT), | |
| 97 arraysize(kPolicySources)); | |
| 98 for (size_t i = 0; i < arraysize(kPolicySources); ++i) { | |
| 99 source->AddLocalizedString(kPolicySources[i].key, | |
| 100 kPolicySources[i].string_id); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) { | |
| 105 source->AddLocalizedString("title", IDS_POLICY_TITLE); | |
| 106 source->AddLocalizedString("filterPlaceholder", | |
| 107 IDS_POLICY_FILTER_PLACEHOLDER); | |
| 108 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); | |
| 109 source->AddLocalizedString("status", IDS_POLICY_STATUS); | |
| 110 source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE); | |
| 111 source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER); | |
| 112 source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN); | |
| 113 source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME); | |
| 114 source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID); | |
| 115 source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID); | |
| 116 source->AddLocalizedString("labelLocation", IDS_POLICY_LABEL_LOCATION); | |
| 117 source->AddLocalizedString("labelDirectoryApiId", | |
| 118 IDS_POLICY_LABEL_DIRECTORY_API_ID); | |
| 119 source->AddLocalizedString("labelTimeSinceLastRefresh", | |
| 120 IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH); | |
| 121 source->AddLocalizedString("labelRefreshInterval", | |
| 122 IDS_POLICY_LABEL_REFRESH_INTERVAL); | |
| 123 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); | |
| 124 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); | |
| 125 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); | |
| 126 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); | |
| 127 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); | |
| 128 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); | |
| 129 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); | |
| 130 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); | |
| 131 source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); | |
| 132 source->AddLocalizedString("showExpandedValue", | |
| 133 IDS_POLICY_SHOW_EXPANDED_VALUE); | |
| 134 source->AddLocalizedString("hideExpandedValue", | |
| 135 IDS_POLICY_HIDE_EXPANDED_VALUE); | |
| 136 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); | |
| 137 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); | |
| 138 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); | |
| 139 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); | |
| 140 source->AddLocalizedString("ok", IDS_POLICY_OK); | |
| 141 source->AddLocalizedString("unset", IDS_POLICY_UNSET); | |
| 142 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); | |
| 143 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); | |
| 144 AddLocalizedPoilcySourceStrings(source); | |
| 145 | |
| 146 source->SetJsonPath("strings.js"); | |
| 147 } | |
| 148 | |
| 149 content::WebUIDataSource* CreatePolicyMaterialDesignUIHtmlSource() { | |
| 150 content::WebUIDataSource* source = | |
| 151 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost); | |
| 152 AddCommonLocalizedStringsToSource(source); | |
| 153 source->SetDefaultResource(IDR_MD_POLICY_HTML); | |
| 154 | |
| 155 return source; | |
| 156 } | |
| 157 | |
| 158 | |
| 159 content::WebUIDataSource* CreatePolicyUIHtmlSource() { | |
| 160 content::WebUIDataSource* source = | |
| 161 content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost); | |
| 162 AddCommonLocalizedStringsToSource(source); | |
| 163 // Add required resources. | |
| 164 source->AddResourcePath("policy.css", IDR_POLICY_CSS); | |
| 165 source->AddResourcePath("policy.js", IDR_POLICY_JS); | |
| 166 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); | |
| 167 source->SetDefaultResource(IDR_POLICY_HTML); | |
| 168 | |
| 169 return source; | |
| 170 } | |
| 171 | |
| 172 // Formats the association state indicated by |data|. If |data| is NULL, the | 83 // Formats the association state indicated by |data|. If |data| is NULL, the |
| 173 // state is considered to be UNMANAGED. | 84 // state is considered to be UNMANAGED. |
| 174 base::string16 FormatAssociationState(const em::PolicyData* data) { | 85 base::string16 FormatAssociationState(const em::PolicyData* data) { |
| 175 if (data) { | 86 if (data) { |
| 176 switch (data->state()) { | 87 switch (data->state()) { |
| 177 case em::PolicyData::ACTIVE: | 88 case em::PolicyData::ACTIVE: |
| 178 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); | 89 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); |
| 179 case em::PolicyData::UNMANAGED: | 90 case em::PolicyData::UNMANAGED: |
| 180 return l10n_util::GetStringUTF16( | 91 return l10n_util::GetStringUTF16( |
| 181 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); | 92 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 void OnDeviceLocalAccountsChanged() override; | 291 void OnDeviceLocalAccountsChanged() override; |
| 381 | 292 |
| 382 private: | 293 private: |
| 383 const std::string user_id_; | 294 const std::string user_id_; |
| 384 policy::DeviceLocalAccountPolicyService* service_; | 295 policy::DeviceLocalAccountPolicyService* service_; |
| 385 | 296 |
| 386 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider); | 297 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStatusProvider); |
| 387 }; | 298 }; |
| 388 #endif | 299 #endif |
| 389 | 300 |
| 390 // The JavaScript message handler for the chrome://policy page. | |
| 391 class PolicyUIHandler : public content::WebUIMessageHandler, | |
| 392 #if defined(ENABLE_EXTENSIONS) | |
| 393 public extensions::ExtensionRegistryObserver, | |
| 394 #endif | |
| 395 public policy::PolicyService::Observer, | |
| 396 public policy::SchemaRegistry::Observer { | |
| 397 public: | |
| 398 PolicyUIHandler(); | |
| 399 ~PolicyUIHandler() override; | |
| 400 | |
| 401 // content::WebUIMessageHandler implementation. | |
| 402 void RegisterMessages() override; | |
| 403 | |
| 404 #if defined(ENABLE_EXTENSIONS) | |
| 405 // extensions::ExtensionRegistryObserver implementation. | |
| 406 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
| 407 const extensions::Extension* extension) override; | |
| 408 void OnExtensionUnloaded( | |
| 409 content::BrowserContext* browser_context, | |
| 410 const extensions::Extension* extension, | |
| 411 extensions::UnloadedExtensionInfo::Reason reason) override; | |
| 412 #endif | |
| 413 | |
| 414 // policy::PolicyService::Observer implementation. | |
| 415 void OnPolicyUpdated(const policy::PolicyNamespace& ns, | |
| 416 const policy::PolicyMap& previous, | |
| 417 const policy::PolicyMap& current) override; | |
| 418 | |
| 419 // policy::SchemaRegistry::Observer implementation. | |
| 420 void OnSchemaRegistryUpdated(bool has_new_schemas) override; | |
| 421 | |
| 422 private: | |
| 423 // Send a dictionary containing the names of all known policies to the UI. | |
| 424 void SendPolicyNames() const; | |
| 425 | |
| 426 // Send information about the current policy values to the UI. For each policy | |
| 427 // whose value has been set, a dictionary containing the value and additional | |
| 428 // metadata is sent. | |
| 429 void SendPolicyValues() const; | |
| 430 | |
| 431 // Send the status of cloud policy to the UI. For each scope that has cloud | |
| 432 // policy enabled (device and/or user), a dictionary containing status | |
| 433 // information is sent. | |
| 434 void SendStatus() const; | |
| 435 | |
| 436 // Inserts a description of each policy in |policy_map| into |values|, using | |
| 437 // the optional errors in |errors| to determine the status of each policy. | |
| 438 void GetPolicyValues(const policy::PolicyMap& policy_map, | |
| 439 policy::PolicyErrorMap* errors, | |
| 440 base::DictionaryValue* values) const; | |
| 441 | |
| 442 void GetChromePolicyValues(base::DictionaryValue* values) const; | |
| 443 | |
| 444 void HandleInitialized(const base::ListValue* args); | |
| 445 void HandleReloadPolicies(const base::ListValue* args); | |
| 446 | |
| 447 void OnRefreshPoliciesDone() const; | |
| 448 | |
| 449 policy::PolicyService* GetPolicyService() const; | |
| 450 | |
| 451 std::string device_domain_; | |
| 452 | |
| 453 // Providers that supply status dictionaries for user and device policy, | |
| 454 // respectively. These are created on initialization time as appropriate for | |
| 455 // the platform (Chrome OS / desktop) and type of policy that is in effect. | |
| 456 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; | |
| 457 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; | |
| 458 | |
| 459 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; | |
| 460 | |
| 461 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); | |
| 462 }; | |
| 463 | |
| 464 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { | 301 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { |
| 465 } | 302 } |
| 466 | 303 |
| 467 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { | 304 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { |
| 468 } | 305 } |
| 469 | 306 |
| 470 void CloudPolicyStatusProvider::SetStatusChangeCallback( | 307 void CloudPolicyStatusProvider::SetStatusChangeCallback( |
| 471 const base::Closure& callback) { | 308 const base::Closure& callback) { |
| 472 callback_ = callback; | 309 callback_ = callback; |
| 473 } | 310 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 policy::SchemaRegistryServiceFactory::GetForContext( | 422 policy::SchemaRegistryServiceFactory::GetForContext( |
| 586 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); | 423 Profile::FromWebUI(web_ui())->GetOriginalProfile())->registry(); |
| 587 registry->RemoveObserver(this); | 424 registry->RemoveObserver(this); |
| 588 | 425 |
| 589 #if defined(ENABLE_EXTENSIONS) | 426 #if defined(ENABLE_EXTENSIONS) |
| 590 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) | 427 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) |
| 591 ->RemoveObserver(this); | 428 ->RemoveObserver(this); |
| 592 #endif | 429 #endif |
| 593 } | 430 } |
| 594 | 431 |
| 432 void PolicyUIHandler::AddLocalizedPolicyStrings( |
| 433 content::WebUIDataSource* source, |
| 434 const PolicyStringMap* strings, |
| 435 size_t count) { |
| 436 for (size_t i = 0; i < count; ++i) |
| 437 source->AddLocalizedString(strings[i].key, strings[i].string_id); |
| 438 } |
| 439 |
| 440 void PolicyUIHandler::AddCommonLocalizedStringsToSource( |
| 441 content::WebUIDataSource* source) { |
| 442 AddLocalizedPolicyStrings(source, kPolicySources, |
| 443 static_cast<size_t>(policy::POLICY_SOURCE_COUNT)); |
| 444 source->AddLocalizedString("title", IDS_POLICY_TITLE); |
| 445 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); |
| 446 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); |
| 447 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); |
| 448 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); |
| 449 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); |
| 450 source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); |
| 451 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); |
| 452 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); |
| 453 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); |
| 454 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); |
| 455 source->AddLocalizedString("ok", IDS_POLICY_OK); |
| 456 source->AddLocalizedString("unset", IDS_POLICY_UNSET); |
| 457 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); |
| 458 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); |
| 459 source->SetJsonPath("strings.js"); |
| 460 } |
| 461 |
| 595 void PolicyUIHandler::RegisterMessages() { | 462 void PolicyUIHandler::RegisterMessages() { |
| 596 #if defined(OS_CHROMEOS) | 463 #if defined(OS_CHROMEOS) |
| 597 policy::BrowserPolicyConnectorChromeOS* connector = | 464 policy::BrowserPolicyConnectorChromeOS* connector = |
| 598 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 465 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 599 if (connector->IsEnterpriseManaged()) | 466 if (connector->IsEnterpriseManaged()) |
| 600 device_status_provider_.reset(new DevicePolicyStatusProvider(connector)); | 467 device_status_provider_.reset(new DevicePolicyStatusProvider(connector)); |
| 601 | 468 |
| 602 const user_manager::UserManager* user_manager = | 469 const user_manager::UserManager* user_manager = |
| 603 user_manager::UserManager::Get(); | 470 user_manager::UserManager::Get(); |
| 604 if (user_manager->IsLoggedInAsPublicAccount()) { | 471 if (user_manager->IsLoggedInAsPublicAccount()) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 SendPolicyValues(); | 549 SendPolicyValues(); |
| 683 } | 550 } |
| 684 } | 551 } |
| 685 | 552 |
| 686 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, | 553 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 687 const policy::PolicyMap& previous, | 554 const policy::PolicyMap& previous, |
| 688 const policy::PolicyMap& current) { | 555 const policy::PolicyMap& current) { |
| 689 SendPolicyValues(); | 556 SendPolicyValues(); |
| 690 } | 557 } |
| 691 | 558 |
| 559 void PolicyUIHandler::AddPolicyName(const std::string& name, |
| 560 base::DictionaryValue* names) const { |
| 561 names->SetBoolean(name, true); |
| 562 } |
| 563 |
| 692 void PolicyUIHandler::SendPolicyNames() const { | 564 void PolicyUIHandler::SendPolicyNames() const { |
| 693 base::DictionaryValue names; | 565 base::DictionaryValue names; |
| 694 | 566 |
| 695 Profile* profile = Profile::FromWebUI(web_ui()); | 567 Profile* profile = Profile::FromWebUI(web_ui()); |
| 696 policy::SchemaRegistry* registry = | 568 policy::SchemaRegistry* registry = |
| 697 policy::SchemaRegistryServiceFactory::GetForContext( | 569 policy::SchemaRegistryServiceFactory::GetForContext( |
| 698 profile->GetOriginalProfile())->registry(); | 570 profile->GetOriginalProfile())->registry(); |
| 699 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); | 571 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); |
| 700 | 572 |
| 701 // Add Chrome policy names. | 573 // Add Chrome policy names. |
| 702 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; | 574 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; |
| 703 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); | 575 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); |
| 704 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); | 576 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); |
| 705 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); | 577 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| 706 !it.IsAtEnd(); it.Advance()) { | 578 !it.IsAtEnd(); it.Advance()) { |
| 707 chrome_policy_names->SetBoolean(it.key(), true); | 579 AddPolicyName(it.key(), chrome_policy_names); |
| 708 } | 580 } |
| 709 names.Set("chromePolicyNames", chrome_policy_names); | 581 names.Set("chromePolicyNames", chrome_policy_names); |
| 710 | 582 |
| 711 #if defined(ENABLE_EXTENSIONS) | 583 #if defined(ENABLE_EXTENSIONS) |
| 712 // Add extension policy names. | 584 // Add extension policy names. |
| 713 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; | 585 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; |
| 714 | 586 |
| 715 for (const scoped_refptr<const extensions::Extension>& extension : | 587 for (const scoped_refptr<const extensions::Extension>& extension : |
| 716 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { | 588 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { |
| 717 // Skip this extension if it's not an enterprise extension. | 589 // Skip this extension if it's not an enterprise extension. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 738 } |
| 867 | 739 |
| 868 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 740 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
| 869 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); | 741 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); |
| 870 } | 742 } |
| 871 | 743 |
| 872 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 744 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| 873 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 745 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 874 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 746 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| 875 } | 747 } |
| 876 | |
| 877 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | |
| 878 web_ui->AddMessageHandler(new PolicyUIHandler); | |
| 879 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | |
| 880 CreatePolicyUIHtmlSource()); | |
| 881 } | |
| 882 | |
| 883 PolicyUI::~PolicyUI() { | |
| 884 } | |
| 885 | |
| 886 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) : | |
| 887 WebUIController(web_ui) { | |
| 888 web_ui->AddMessageHandler(new PolicyUIHandler); | |
| 889 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | |
| 890 CreatePolicyMaterialDesignUIHtmlSource()); | |
| 891 } | |
| 892 | |
| 893 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() { | |
| 894 } | |
| OLD | NEW |