Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: chrome/browser/ui/webui/policy_ui.cc

Issue 1371073003: Display material design policies grouped by tags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning and Refactoring. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
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 {"sourceEnterpriseOverride", IDS_POLICY_SOURCE_ENTERPRISE_OVERRIDE}, 96 {"sourceEnterpriseOverride", IDS_POLICY_SOURCE_ENTERPRISE_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}
109 };
110
111 void AddLocalizedPoilcyStrings(content::WebUIDataSource* source,
112 const PolicyStringMap* map,
113 size_t count) {
114 for (size_t i = 0; i < count; ++i)
115 source->AddLocalizedString(map[i].key, map[i].string_id);
102 } 116 }
103 117
104 void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) { 118 void AddCommonLocalizedStringsToSource(content::WebUIDataSource* source) {
119 AddLocalizedPoilcyStrings(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->SetJsonPath("strings.js");
123 }
124
125 content::WebUIDataSource* CreatePolicyUIHTMLSource() {
126 content::WebUIDataSource* source =
127 content::WebUIDataSource::Create(chrome::kChromeUIPolicyHost);
128 AddCommonLocalizedStringsToSource(source);
106 source->AddLocalizedString("filterPlaceholder", 129 source->AddLocalizedString("filterPlaceholder",
107 IDS_POLICY_FILTER_PLACEHOLDER); 130 IDS_POLICY_FILTER_PLACEHOLDER);
108 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES); 131 source->AddLocalizedString("reloadPolicies", IDS_POLICY_RELOAD_POLICIES);
109 source->AddLocalizedString("status", IDS_POLICY_STATUS); 132 source->AddLocalizedString("status", IDS_POLICY_STATUS);
110 source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE); 133 source->AddLocalizedString("statusDevice", IDS_POLICY_STATUS_DEVICE);
111 source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER); 134 source->AddLocalizedString("statusUser", IDS_POLICY_STATUS_USER);
112 source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN); 135 source->AddLocalizedString("labelDomain", IDS_POLICY_LABEL_DOMAIN);
113 source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME); 136 source->AddLocalizedString("labelUsername", IDS_POLICY_LABEL_USERNAME);
114 source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID); 137 source->AddLocalizedString("labelClientId", IDS_POLICY_LABEL_CLIENT_ID);
115 source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID); 138 source->AddLocalizedString("labelAssetId", IDS_POLICY_LABEL_ASSET_ID);
(...skipping 18 matching lines...) Expand all
134 source->AddLocalizedString("hideExpandedValue", 157 source->AddLocalizedString("hideExpandedValue",
135 IDS_POLICY_HIDE_EXPANDED_VALUE); 158 IDS_POLICY_HIDE_EXPANDED_VALUE);
136 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); 159 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER);
137 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); 160 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE);
138 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); 161 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED);
139 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); 162 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY);
140 source->AddLocalizedString("ok", IDS_POLICY_OK); 163 source->AddLocalizedString("ok", IDS_POLICY_OK);
141 source->AddLocalizedString("unset", IDS_POLICY_UNSET); 164 source->AddLocalizedString("unset", IDS_POLICY_UNSET);
142 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); 165 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN);
143 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); 166 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED);
144 AddLocalizedPoilcySourceStrings(source); 167 AddLocalizedPoilcyStrings(source, kPolicyRiskTags,
145 168 static_cast<size_t>(policy::RISK_TAG_COUNT));
146 source->SetJsonPath("strings.js"); 169 // Add required resources.
170 source->AddResourcePath("policy.css", IDR_POLICY_CSS);
171 source->AddResourcePath("policy.js", IDR_POLICY_JS);
172 source->AddResourcePath("uber_utils.js", IDR_UBER_UTILS_JS);
173 source->SetDefaultResource(IDR_POLICY_HTML);
174 return source;
147 } 175 }
148 176
149 content::WebUIDataSource* CreatePolicyMaterialDesignUIHTMLSource() { 177 content::WebUIDataSource* CreatePolicyMaterialDesignUIHTMLSource() {
150 content::WebUIDataSource* source = 178 content::WebUIDataSource* source =
151 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost); 179 content::WebUIDataSource::Create(chrome::kChromeUIMdPolicyHost);
152 AddCommonLocalizedStringsToSource(source); 180 AddCommonLocalizedStringsToSource(source);
181 AddLocalizedPoilcyStrings(source, kPolicyRiskTags,
182 static_cast<size_t>(policy::RISK_TAG_COUNT));
183 for (size_t i = 0; i < kPolicyResourcesSize; ++i) {
184 source->AddResourcePath(kPolicyResources[i].name,
185 kPolicyResources[i].value);
186 }
153 source->SetDefaultResource(IDR_MD_POLICY_HTML); 187 source->SetDefaultResource(IDR_MD_POLICY_HTML);
154
155 return source; 188 return source;
156 } 189 }
157 190
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 191 // Formats the association state indicated by |data|. If |data| is NULL, the
173 // state is considered to be UNMANAGED. 192 // state is considered to be UNMANAGED.
174 base::string16 FormatAssociationState(const em::PolicyData* data) { 193 base::string16 FormatAssociationState(const em::PolicyData* data) {
175 if (data) { 194 if (data) {
176 switch (data->state()) { 195 switch (data->state()) {
177 case em::PolicyData::ACTIVE: 196 case em::PolicyData::ACTIVE:
178 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE); 197 return l10n_util::GetStringUTF16(IDS_POLICY_ASSOCIATION_STATE_ACTIVE);
179 case em::PolicyData::UNMANAGED: 198 case em::PolicyData::UNMANAGED:
180 return l10n_util::GetStringUTF16( 199 return l10n_util::GetStringUTF16(
181 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED); 200 IDS_POLICY_ASSOCIATION_STATE_UNMANAGED);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 #endif 431 #endif
413 432
414 // policy::PolicyService::Observer implementation. 433 // policy::PolicyService::Observer implementation.
415 void OnPolicyUpdated(const policy::PolicyNamespace& ns, 434 void OnPolicyUpdated(const policy::PolicyNamespace& ns,
416 const policy::PolicyMap& previous, 435 const policy::PolicyMap& previous,
417 const policy::PolicyMap& current) override; 436 const policy::PolicyMap& current) override;
418 437
419 // policy::SchemaRegistry::Observer implementation. 438 // policy::SchemaRegistry::Observer implementation.
420 void OnSchemaRegistryUpdated(bool has_new_schemas) override; 439 void OnSchemaRegistryUpdated(bool has_new_schemas) override;
421 440
441 protected:
442 virtual void AddPolicyName(base::DictionaryValue* names,
443 const std::string& name) const;
444
445 // Send a dictionary containing the names of all known policies to the UI.
446 virtual void SendPolicyNames() const;
447
422 private: 448 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 449 // 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 450 // whose value has been set, a dictionary containing the value and additional
428 // metadata is sent. 451 // metadata is sent.
429 void SendPolicyValues() const; 452 void SendPolicyValues() const;
430 453
431 // Send the status of cloud policy to the UI. For each scope that has cloud 454 // 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 455 // policy enabled (device and/or user), a dictionary containing status
433 // information is sent. 456 // information is sent.
434 void SendStatus() const; 457 void SendStatus() const;
435 458
(...skipping 18 matching lines...) Expand all
454 // respectively. These are created on initialization time as appropriate for 477 // respectively. These are created on initialization time as appropriate for
455 // the platform (Chrome OS / desktop) and type of policy that is in effect. 478 // the platform (Chrome OS / desktop) and type of policy that is in effect.
456 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; 479 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_;
457 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; 480 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_;
458 481
459 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; 482 base::WeakPtrFactory<PolicyUIHandler> weak_factory_;
460 483
461 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); 484 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler);
462 }; 485 };
463 486
487 // The JavaScript message handler for the chrome://md-policy page.
488 class PolicyMaterialDesignUIHandler : public PolicyUIHandler {
489 public:
490 PolicyMaterialDesignUIHandler();
491 ~PolicyMaterialDesignUIHandler() override;
492
493 protected:
494 // PolicyUIHandler:
495 void AddPolicyName(base::DictionaryValue* names,
496 const std::string& name) const override;
497 void SendPolicyNames() const override;
498
499 private:
500 DISALLOW_COPY_AND_ASSIGN(PolicyMaterialDesignUIHandler);
501 };
502
464 CloudPolicyStatusProvider::CloudPolicyStatusProvider() { 503 CloudPolicyStatusProvider::CloudPolicyStatusProvider() {
465 } 504 }
466 505
467 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() { 506 CloudPolicyStatusProvider::~CloudPolicyStatusProvider() {
468 } 507 }
469 508
470 void CloudPolicyStatusProvider::SetStatusChangeCallback( 509 void CloudPolicyStatusProvider::SetStatusChangeCallback(
471 const base::Closure& callback) { 510 const base::Closure& callback) {
472 callback_ = callback; 511 callback_ = callback;
473 } 512 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 SendPolicyValues(); 721 SendPolicyValues();
683 } 722 }
684 } 723 }
685 724
686 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 725 void PolicyUIHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
687 const policy::PolicyMap& previous, 726 const policy::PolicyMap& previous,
688 const policy::PolicyMap& current) { 727 const policy::PolicyMap& current) {
689 SendPolicyValues(); 728 SendPolicyValues();
690 } 729 }
691 730
731 void PolicyUIHandler::AddPolicyName(base::DictionaryValue* names,
732 const std::string& name) const {
733 names->SetBoolean(name, true);
734 }
735
692 void PolicyUIHandler::SendPolicyNames() const { 736 void PolicyUIHandler::SendPolicyNames() const {
693 base::DictionaryValue names; 737 base::DictionaryValue names;
694 738
695 Profile* profile = Profile::FromWebUI(web_ui()); 739 Profile* profile = Profile::FromWebUI(web_ui());
696 policy::SchemaRegistry* registry = 740 policy::SchemaRegistry* registry =
697 policy::SchemaRegistryServiceFactory::GetForContext( 741 policy::SchemaRegistryServiceFactory::GetForContext(
698 profile->GetOriginalProfile())->registry(); 742 profile->GetOriginalProfile())->registry();
699 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); 743 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map();
700 744
701 // Add Chrome policy names. 745 // Add Chrome policy names.
702 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; 746 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue;
703 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); 747 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, "");
704 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); 748 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns);
705 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); 749 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator();
706 !it.IsAtEnd(); it.Advance()) { 750 !it.IsAtEnd(); it.Advance()) {
707 chrome_policy_names->SetBoolean(it.key(), true); 751 AddPolicyName(chrome_policy_names, it.key());
708 } 752 }
709 names.Set("chromePolicyNames", chrome_policy_names); 753 names.Set("chromePolicyNames", chrome_policy_names);
710 754
711 #if defined(ENABLE_EXTENSIONS) 755 #if defined(ENABLE_EXTENSIONS)
712 // Add extension policy names. 756 // Add extension policy names.
713 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; 757 base::DictionaryValue* extension_policy_names = new base::DictionaryValue;
714 758
715 for (const scoped_refptr<const extensions::Extension>& extension : 759 for (const scoped_refptr<const extensions::Extension>& extension :
716 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { 760 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
717 // Skip this extension if it's not an enterprise extension. 761 // Skip this extension if it's not an enterprise extension.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 911
868 void PolicyUIHandler::OnRefreshPoliciesDone() const { 912 void PolicyUIHandler::OnRefreshPoliciesDone() const {
869 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); 913 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone");
870 } 914 }
871 915
872 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { 916 policy::PolicyService* PolicyUIHandler::GetPolicyService() const {
873 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( 917 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
874 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); 918 web_ui()->GetWebContents()->GetBrowserContext())->policy_service();
875 } 919 }
876 920
921 PolicyMaterialDesignUIHandler::PolicyMaterialDesignUIHandler() {
922 }
923
924 PolicyMaterialDesignUIHandler::~PolicyMaterialDesignUIHandler() {
925 }
926
927 void PolicyMaterialDesignUIHandler::AddPolicyName(
928 base::DictionaryValue* names, const std::string& name) const {
929 scoped_ptr<base::ListValue> list = make_scoped_ptr(new base::ListValue());
930 const policy::RiskTag* tags = policy::GetChromePolicyDetails(name)->risk_tags;
931 for (size_t i = 0; i < policy::kMaxRiskTagCount; ++i)
932 if (tags[i] != policy::RISK_TAG_NONE)
933 list->AppendString(kPolicyRiskTags[tags[i]].key);
934 names->Set(name, list.Pass());
935 }
936
937 void PolicyMaterialDesignUIHandler::SendPolicyNames() const {
938 base::ListValue tags;
939 for (size_t tag = 0; tag < policy::RISK_TAG_COUNT; ++tag)
940 tags.AppendString(kPolicyRiskTags[tag].key);
941
942 web_ui()->CallJavascriptFunction("policy.Page.setPolicyGroups", tags);
943 PolicyUIHandler::SendPolicyNames();
944 }
945
877 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { 946 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
878 web_ui->AddMessageHandler(new PolicyUIHandler); 947 web_ui->AddMessageHandler(new PolicyUIHandler);
879 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), 948 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
880 CreatePolicyUIHTMLSource()); 949 CreatePolicyUIHTMLSource());
881 } 950 }
882 951
883 PolicyUI::~PolicyUI() { 952 PolicyUI::~PolicyUI() {
884 } 953 }
885 954
886 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) : 955 PolicyMaterialDesignUI::PolicyMaterialDesignUI(content::WebUI* web_ui) :
887 WebUIController(web_ui) { 956 WebUIController(web_ui) {
888 web_ui->AddMessageHandler(new PolicyUIHandler); 957 web_ui->AddMessageHandler(new PolicyMaterialDesignUIHandler);
889 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), 958 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
890 CreatePolicyMaterialDesignUIHTMLSource()); 959 CreatePolicyMaterialDesignUIHTMLSource());
891 } 960 }
892 961
893 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() { 962 PolicyMaterialDesignUI::~PolicyMaterialDesignUI() {
894 } 963 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698