Chromium Code Reviews| 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.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | |
|
Dan Beam
2015/10/14 21:00:40
#include <string> (drop the .h)
fhorschig
2015/10/15 14:45:38
Done.
| |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector.h" | 22 #include "chrome/browser/policy/profile_policy_connector.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 23 #include "chrome/browser/policy/schema_registry_service.h" | 24 #include "chrome/browser/policy/schema_registry_service.h" |
| 24 #include "chrome/browser/policy/schema_registry_service_factory.h" | 25 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "components/policy/core/browser/browser_policy_connector.h" | 28 #include "components/policy/core/browser/browser_policy_connector.h" |
| 28 #include "components/policy/core/browser/cloud/message_util.h" | 29 #include "components/policy/core/browser/cloud/message_util.h" |
| 29 #include "components/policy/core/browser/configuration_policy_handler_list.h" | 30 #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/browser/policy_error_map.h" |
| 31 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 32 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 32 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 33 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 33 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 34 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| 34 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 35 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 35 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 36 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 36 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 37 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
| 38 #include "components/policy/core/common/policy_details.h" | |
| 37 #include "components/policy/core/common/policy_map.h" | 39 #include "components/policy/core/common/policy_map.h" |
| 38 #include "components/policy/core/common/policy_namespace.h" | 40 #include "components/policy/core/common/policy_namespace.h" |
| 39 #include "components/policy/core/common/policy_service.h" | 41 #include "components/policy/core/common/policy_service.h" |
| 40 #include "components/policy/core/common/policy_types.h" | 42 #include "components/policy/core/common/policy_types.h" |
| 41 #include "components/policy/core/common/remote_commands/remote_commands_service. h" | 43 #include "components/policy/core/common/remote_commands/remote_commands_service. h" |
| 42 #include "components/policy/core/common/schema.h" | 44 #include "components/policy/core/common/schema.h" |
| 43 #include "components/policy/core/common/schema_map.h" | 45 #include "components/policy/core/common/schema_map.h" |
| 44 #include "components/policy/core/common/schema_registry.h" | 46 #include "components/policy/core/common/schema_registry.h" |
| 45 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/web_ui.h" | 48 #include "content/public/browser/web_ui.h" |
| 47 #include "content/public/browser/web_ui_data_source.h" | 49 #include "content/public/browser/web_ui_data_source.h" |
| 48 #include "content/public/browser/web_ui_message_handler.h" | 50 #include "content/public/browser/web_ui_message_handler.h" |
| 49 #include "google_apis/gaia/gaia_auth_util.h" | 51 #include "google_apis/gaia/gaia_auth_util.h" |
| 50 #include "grit/browser_resources.h" | 52 #include "grit/browser_resources.h" |
| 51 #include "grit/components_strings.h" | 53 #include "grit/components_strings.h" |
| 54 #include "grit/policy_resources.h" | |
| 55 #include "grit/policy_resources_map.h" | |
| 52 #include "policy/policy_constants.h" | 56 #include "policy/policy_constants.h" |
| 53 #include "policy/proto/device_management_backend.pb.h" | 57 #include "policy/proto/device_management_backend.pb.h" |
| 58 #include "policy/risk_tag.h" | |
| 54 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
| 55 #include "ui/base/l10n/time_format.h" | 60 #include "ui/base/l10n/time_format.h" |
| 56 | 61 |
| 57 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
| 58 #include "chrome/browser/browser_process_platform_part.h" | 63 #include "chrome/browser/browser_process_platform_part.h" |
| 59 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 64 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 60 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 65 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 61 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 66 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 62 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 67 #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" | 68 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" |
| 64 #include "components/user_manager/user_manager.h" | 69 #include "components/user_manager/user_manager.h" |
| 65 #else | 70 #else |
| 66 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 71 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 67 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 72 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| 68 #endif | 73 #endif |
| 69 | 74 |
| 70 #if defined(ENABLE_EXTENSIONS) | 75 #if defined(ENABLE_EXTENSIONS) |
| 71 #include "extensions/browser/extension_registry.h" | 76 #include "extensions/browser/extension_registry.h" |
| 72 #include "extensions/browser/extension_registry_observer.h" | 77 #include "extensions/browser/extension_registry_observer.h" |
| 73 #include "extensions/common/extension.h" | 78 #include "extensions/common/extension.h" |
| 74 #include "extensions/common/manifest.h" | 79 #include "extensions/common/manifest.h" |
| 75 #include "extensions/common/manifest_constants.h" | 80 #include "extensions/common/manifest_constants.h" |
| 76 #endif | 81 #endif |
| 77 | 82 |
| 78 namespace em = enterprise_management; | 83 namespace em = enterprise_management; |
| 79 | 84 |
| 80 namespace { | 85 namespace { |
| 81 | 86 |
| 82 struct PolicySourceMap { | 87 struct PolicyStringMap { |
| 83 const char* key; | 88 const char* key; |
| 84 int string_id; | 89 int string_id; |
| 85 }; | 90 }; |
| 86 | 91 |
| 87 // Strings that map from PolicySource enum to i18n string keys and their IDs. | 92 // Strings that map from PolicySource enum to i18n string keys and their IDs. |
| 88 const PolicySourceMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { | 93 const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT] = { |
| 89 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, | 94 {"sourceEnterpriseDefault", IDS_POLICY_SOURCE_ENTERPRISE_DEFAULT}, |
| 90 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, | 95 {"sourceCloud", IDS_POLICY_SOURCE_CLOUD}, |
| 91 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, | 96 {"sourcePublicSessionOverride", IDS_POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE}, |
| 92 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM} | 97 {"sourcePlatform", IDS_POLICY_SOURCE_PLATFORM} |
| 93 }; | 98 }; |
| 94 | 99 |
| 95 void AddLocalizedPoilcySourceStrings(content::WebUIDataSource* source) { | 100 // Strings that map from policy::RiskTag enum to i18n string keys and their IDs. |
| 96 DCHECK_EQ(static_cast<size_t>(policy::POLICY_SOURCE_COUNT), | 101 const PolicyStringMap kPolicyRiskTags[policy::RISK_TAG_COUNT] = { |
| 97 arraysize(kPolicySources)); | 102 {"fullAdminAccess", IDS_POLICY_RISK_TAG_FULL_ADMIN_ACCESS}, |
| 98 for (size_t i = 0; i < arraysize(kPolicySources); ++i) { | 103 {"systemSecurity", IDS_POLICY_RISK_TAG_SYSTEM_SECURITY}, |
| 99 source->AddLocalizedString(kPolicySources[i].key, | 104 {"websiteSharing", IDS_POLICY_RISK_TAG_WEBSITE_SHARING}, |
| 100 kPolicySources[i].string_id); | 105 {"adminSharing", IDS_POLICY_RISK_TAG_ADMIN_SHARING}, |
| 101 } | 106 {"filtering", IDS_POLICY_RISK_TAG_FILTERING}, |
| 107 {"localDataAccess", IDS_POLICY_RISK_TAG_LOCAL_DATA_ACCESS}, | |
| 108 {"googleSharing", IDS_POLICY_RISK_TAG_GOOGLE_SHARING} | |
|
Dan Beam
2015/10/14 21:00:40
nit: alphabetize these, also don't omit trailing c
fhorschig
2015/10/15 14:45:38
Trailing comma added. Added a comment that the ord
| |
| 109 }; | |
| 110 | |
| 111 void AddLocalizedPolicyStrings(content::WebUIDataSource* source, | |
| 112 const PolicyStringMap* strings, | |
| 113 size_t count) { | |
| 114 for (size_t i = 0; i < count; ++i) | |
| 115 source->AddLocalizedString(strings[i].key, strings[i].string_id); | |
| 102 } | 116 } |
| 103 | 117 |
| 104 void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) { | 118 void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) { |
| 119 AddLocalizedPolicyStrings(source, kPolicySources, | |
| 120 static_cast<size_t>(policy::POLICY_SOURCE_COUNT)); | |
| 105 source->AddLocalizedString("title", IDS_POLICY_TITLE); | 121 source->AddLocalizedString("title", IDS_POLICY_TITLE); |
| 122 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); | |
| 123 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); | |
| 124 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); | |
| 125 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); | |
| 126 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); | |
| 127 source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); | |
| 128 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); | |
| 129 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); | |
| 130 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); | |
| 131 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); | |
| 132 source->AddLocalizedString("ok", IDS_POLICY_OK); | |
| 133 source->AddLocalizedString("unset", IDS_POLICY_UNSET); | |
| 134 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); | |
| 135 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); | |
| 136 source->SetJsonPath("strings.js"); | |
| 137 } | |
| 138 | |
| 139 content::WebUIDataSource* CreatePolicyUIHtmlSource() { | |
| 140 content::WebUIDataSource* source = | |
| 141 content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost); | |
| 142 AddCommonLocalizedStringsToSource(source); | |
| 106 source->AddLocalizedString("filterPlaceholder", | 143 source->AddLocalizedString("filterPlaceholder", |
| 107 IDS_POLICY_FILTER_PLACEHOLDER); | 144 IDS_POLICY_FILTER_PLACEHOLDER); |
| 108 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); | 145 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); |
| 109 source->AddLocalizedString("status", IDS_POLICY_STATUS); | 146 source->AddLocalizedString("status", IDS_POLICY_STATUS); |
| 110 source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE); | 147 source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE); |
| 111 source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER); | 148 source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER); |
| 112 source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN); | 149 source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN); |
| 113 source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME); | 150 source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME); |
| 114 source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID); | 151 source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID); |
| 115 source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID); | 152 source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID); |
| 116 source->AddLocalizedString("labelLocation", IDS_POLICY_LABEL_LOCATION); | 153 source->AddLocalizedString("labelLocation", IDS_POLICY_LABEL_LOCATION); |
| 117 source->AddLocalizedString("labelDirectoryApiId", | 154 source->AddLocalizedString("labelDirectoryApiId", |
| 118 IDS_POLICY_LABEL_DIRECTORY_API_ID); | 155 IDS_POLICY_LABEL_DIRECTORY_API_ID); |
| 119 source->AddLocalizedString("labelTimeSinceLastRefresh", | 156 source->AddLocalizedString("labelTimeSinceLastRefresh", |
| 120 IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH); | 157 IDS_POLICY_LABEL_TIME_SINCE_LAST_REFRESH); |
| 121 source->AddLocalizedString("labelRefreshInterval", | 158 source->AddLocalizedString("labelRefreshInterval", |
| 122 IDS_POLICY_LABEL_REFRESH_INTERVAL); | 159 IDS_POLICY_LABEL_REFRESH_INTERVAL); |
| 123 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); | 160 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); |
| 124 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); | 161 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); |
| 125 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); | 162 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", | 163 source->AddLocalizedString("showExpandedValue", |
| 133 IDS_POLICY_SHOW_EXPANDED_VALUE); | 164 IDS_POLICY_SHOW_EXPANDED_VALUE); |
| 134 source->AddLocalizedString("hideExpandedValue", | 165 source->AddLocalizedString("hideExpandedValue", |
| 135 IDS_POLICY_HIDE_EXPANDED_VALUE); | 166 IDS_POLICY_HIDE_EXPANDED_VALUE); |
| 136 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); | 167 // Add required resources. |
| 137 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); | 168 source->AddResourcePath("policy.css", IDR_POLICY_CSS); |
| 138 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); | 169 source->AddResourcePath("policy.js", IDR_POLICY_JS); |
| 139 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); | 170 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS); |
| 140 source->AddLocalizedString("ok", IDS_POLICY_OK); | 171 source->SetDefaultResource(IDR_POLICY_HTML); |
| 141 source->AddLocalizedString("unset", IDS_POLICY_UNSET); | 172 return source; |
| 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 } | 173 } |
| 148 | 174 |
| 149 content::WebUIDataSource* CreatePolicyMaterialDesignUIHtmlSource() { | 175 content::WebUIDataSource* CreatePolicyMaterialDesignUIHtmlSource() { |
| 150 content::WebUIDataSource* source = | 176 content::WebUIDataSource* source = |
| 151 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost); | 177 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost); |
| 152 AddCommonLocalizedStringsToSource(source); | 178 AddCommonLocalizedStringsToSource(source); |
| 179 AddLocalizedPolicyStrings(source, kPolicyRiskTags, | |
| 180 static_cast<size_t>(policy::RISK_TAG_COUNT)); | |
| 181 for (size_t i = 0; i < kPolicyResourcesSize; ++i) { | |
| 182 source->AddResourcePath(kPolicyResources[i].name, | |
| 183 kPolicyResources[i].value); | |
| 184 } | |
| 153 source->SetDefaultResource(IDR_MD_POLICY_HTML); | 185 source->SetDefaultResource(IDR_MD_POLICY_HTML); |
| 154 | |
| 155 return source; | 186 return source; |
| 156 } | 187 } |
| 157 | 188 |
| 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 | 189 // Formats the association state indicated by |data|. If |data| is NULL, the |
| 173 // state is considered to be UNMANAGED. | 190 // state is considered to be UNMANAGED. |
| 174 base::string16 FormatAssociationState(const em::PolicyData* data) { | 191 base::string16 FormatAssociationState(const em::PolicyData* data) { |
| 175 if (data) { | 192 if (data) { |
| 176 switch (data->state()) { | 193 switch (data->state()) { |
| 177 case em::PolicyData::ACTIVE: | 194 case em::PolicyData::ACTIVE: |
| 178 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); | 195 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); |
| 179 case em::PolicyData::UNMANAGED: | 196 case em::PolicyData::UNMANAGED: |
| 180 return l10n_util::GetStringUTF16( | 197 return l10n_util::GetStringUTF16( |
| 181 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); | 198 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 #endif | 429 #endif |
| 413 | 430 |
| 414 // policy::PolicyService::Observer implementation. | 431 // policy::PolicyService::Observer implementation. |
| 415 void OnPolicyUpdated(const policy::PolicyNamespace& ns, | 432 void OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 416 const policy::PolicyMap& previous, | 433 const policy::PolicyMap& previous, |
| 417 const policy::PolicyMap& current) override; | 434 const policy::PolicyMap& current) override; |
| 418 | 435 |
| 419 // policy::SchemaRegistry::Observer implementation. | 436 // policy::SchemaRegistry::Observer implementation. |
| 420 void OnSchemaRegistryUpdated(bool has_new_schemas) override; | 437 void OnSchemaRegistryUpdated(bool has_new_schemas) override; |
| 421 | 438 |
| 439 protected: | |
| 440 virtual void AddPolicyName(const std::string& name, | |
| 441 base::DictionaryValue* names) const; | |
| 442 | |
| 443 // Send a dictionary containing the names of all known policies to the UI. | |
| 444 virtual void SendPolicyNames() const; | |
| 445 | |
| 422 private: | 446 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 | 447 // 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 | 448 // whose value has been set, a dictionary containing the value and additional |
| 428 // metadata is sent. | 449 // metadata is sent. |
| 429 void SendPolicyValues() const; | 450 void SendPolicyValues() const; |
| 430 | 451 |
| 431 // Send the status of cloud policy to the UI. For each scope that has cloud | 452 // 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 | 453 // policy enabled (device and/or user), a dictionary containing status |
| 433 // information is sent. | 454 // information is sent. |
| 434 void SendStatus() const; | 455 void SendStatus() const; |
| 435 | 456 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 454 // respectively. These are created on initialization time as appropriate for | 475 // respectively. These are created on initialization time as appropriate for |
| 455 // the platform (Chrome OS / desktop) and type of policy that is in effect. | 476 // the platform (Chrome OS / desktop) and type of policy that is in effect. |
| 456 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; | 477 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; |
| 457 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; | 478 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; |
| 458 | 479 |
| 459 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; | 480 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; |
| 460 | 481 |
| 461 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); | 482 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); |
| 462 }; | 483 }; |
| 463 | 484 |
| 485 // The JavaScript message handler for the chrome://md-policy page. | |
| 486 class PolicyMaterialDesignUIHandler : public PolicyUIHandler { | |
|
Dan Beam
2015/10/14 21:00:40
why is this class not in it's own file[s]?
fhorschig
2015/10/15 14:45:38
A justified question. It seems to be usual to have
Dan Beam
2015/10/15 16:55:03
it seems far more "usual" to have 1 class per file
fhorschig
2015/10/22 14:47:08
There is now a separate class for PolicyMaterialDe
| |
| 487 public: | |
| 488 PolicyMaterialDesignUIHandler(); | |
| 489 ~PolicyMaterialDesignUIHandler() override; | |
| 490 | |
| 491 protected: | |
| 492 // PolicyUIHandler: | |
| 493 void AddPolicyName(const std::string& name, | |
| 494 base::DictionaryValue* names) const override; | |
| 495 void SendPolicyNames() const override; | |
| 496 | |
| 497 private: | |
| 498 DISALLOW_COPY_AND_ASSIGN(PolicyMaterialDesignUIHandler); | |
| 499 }; | |
| 500 | |
| 464 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { | 501 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { |
| 465 } | 502 } |
| 466 | 503 |
| 467 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { | 504 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { |
| 468 } | 505 } |
| 469 | 506 |
| 470 void CloudPolicyStatusProvider::SetStatusChangeCallback( | 507 void CloudPolicyStatusProvider::SetStatusChangeCallback( |
| 471 const base::Closure& callback) { | 508 const base::Closure& callback) { |
| 472 callback_ = callback; | 509 callback_ = callback; |
| 473 } | 510 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 SendPolicyValues(); | 719 SendPolicyValues(); |
| 683 } | 720 } |
| 684 } | 721 } |
| 685 | 722 |
| 686 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, | 723 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 687 const policy::PolicyMap& previous, | 724 const policy::PolicyMap& previous, |
| 688 const policy::PolicyMap& current) { | 725 const policy::PolicyMap& current) { |
| 689 SendPolicyValues(); | 726 SendPolicyValues(); |
| 690 } | 727 } |
| 691 | 728 |
| 729 void PolicyUIHandler::AddPolicyName(const std::string& name, | |
| 730 base::DictionaryValue* names) const { | |
| 731 names->SetBoolean(name, true); | |
| 732 } | |
| 733 | |
| 692 void PolicyUIHandler::SendPolicyNames() const { | 734 void PolicyUIHandler::SendPolicyNames() const { |
| 693 base::DictionaryValue names; | 735 base::DictionaryValue names; |
| 694 | 736 |
| 695 Profile* profile = Profile::FromWebUI(web_ui()); | 737 Profile* profile = Profile::FromWebUI(web_ui()); |
| 696 policy::SchemaRegistry* registry = | 738 policy::SchemaRegistry* registry = |
| 697 policy::SchemaRegistryServiceFactory::GetForContext( | 739 policy::SchemaRegistryServiceFactory::GetForContext( |
| 698 profile->GetOriginalProfile())->registry(); | 740 profile->GetOriginalProfile())->registry(); |
| 699 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); | 741 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); |
| 700 | 742 |
| 701 // Add Chrome policy names. | 743 // Add Chrome policy names. |
| 702 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; | 744 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; |
| 703 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); | 745 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); |
| 704 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); | 746 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); |
| 705 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); | 747 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| 706 !it.IsAtEnd(); it.Advance()) { | 748 !it.IsAtEnd(); it.Advance()) { |
| 707 chrome_policy_names->SetBoolean(it.key(), true); | 749 AddPolicyName(it.key(), chrome_policy_names); |
| 708 } | 750 } |
| 709 names.Set("chromePolicyNames", chrome_policy_names); | 751 names.Set("chromePolicyNames", chrome_policy_names); |
| 710 | 752 |
| 711 #if defined(ENABLE_EXTENSIONS) | 753 #if defined(ENABLE_EXTENSIONS) |
| 712 // Add extension policy names. | 754 // Add extension policy names. |
| 713 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; | 755 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; |
| 714 | 756 |
| 715 for (const scoped_refptr<const extensions::Extension>& extension : | 757 for (const scoped_refptr<const extensions::Extension>& extension : |
| 716 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { | 758 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { |
| 717 // Skip this extension if it's not an enterprise extension. | 759 // Skip this extension if it's not an enterprise extension. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 | 909 |
| 868 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 910 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
| 869 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); | 911 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); |
| 870 } | 912 } |
| 871 | 913 |
| 872 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 914 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| 873 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 915 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 874 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 916 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| 875 } | 917 } |
| 876 | 918 |
| 919 PolicyMaterialDesignUIHandler::PolicyMaterialDesignUIHandler() { | |
| 920 } | |
| 921 | |
| 922 PolicyMaterialDesignUIHandler::~PolicyMaterialDesignUIHandler() { | |
| 923 } | |
| 924 | |
| 925 void PolicyMaterialDesignUIHandler::AddPolicyName( | |
| 926 const std::string& name, base::DictionaryValue* names) const { | |
| 927 scoped_ptr<base::ListValue> list(new base::ListValue()); | |
| 928 const policy::RiskTag* tags = policy::GetChromePolicyDetails(name)->risk_tags; | |
| 929 for (size_t i = 0; i < policy::kMaxRiskTagCount; ++i) { | |
| 930 if (tags[i] != policy::RISK_TAG_NONE) | |
| 931 list->AppendString(kPolicyRiskTags[tags[i]].key); | |
| 932 } | |
| 933 names->Set(name, list.Pass()); | |
| 934 } | |
| 935 | |
| 936 void PolicyMaterialDesignUIHandler::SendPolicyNames() const { | |
| 937 base::ListValue tags; | |
| 938 for (size_t tag = 0; tag < policy::RISK_TAG_COUNT; ++tag) | |
| 939 tags.AppendString(kPolicyRiskTags[tag].key); | |
| 940 | |
| 941 web_ui()->CallJavascriptFunction("policy.Page.setPolicyGroups", tags); | |
| 942 PolicyUIHandler::SendPolicyNames(); | |
| 943 } | |
| 944 | |
| 877 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 945 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 878 web_ui->AddMessageHandler(new PolicyUIHandler); | 946 web_ui->AddMessageHandler(new PolicyUIHandler); |
| 879 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 947 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 880 CreatePolicyUIHtmlSource()); | 948 CreatePolicyUIHtmlSource()); |
| 881 } | 949 } |
| 882 | 950 |
| 883 PolicyUI::~PolicyUI() { | 951 PolicyUI::~PolicyUI() { |
| 884 } | 952 } |
| 885 | 953 |
| 886 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) : | 954 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) : |
| 887 WebUIController(web_ui) { | 955 WebUIController(web_ui) { |
| 888 web_ui->AddMessageHandler(new PolicyUIHandler); | 956 web_ui->AddMessageHandler(new PolicyMaterialDesignUIHandler); |
| 889 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 957 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 890 CreatePolicyMaterialDesignUIHtmlSource()); | 958 CreatePolicyMaterialDesignUIHtmlSource()); |
| 891 } | 959 } |
| 892 | 960 |
| 893 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() { | 961 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() { |
| 894 } | 962 } |
| OLD | NEW |