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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/prefs/pref_service.h" | |
Thiemo Nagel
2015/09/01 17:40:36
What is this required for?
fhorschig
2015/09/04 06:53:53
Deprecated. Removed.
| |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/policy/profile_policy_connector.h" | 20 #include "chrome/browser/policy/profile_policy_connector.h" |
20 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 21 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
21 #include "chrome/browser/policy/schema_registry_service.h" | 22 #include "chrome/browser/policy/schema_registry_service.h" |
22 #include "chrome/browser/policy/schema_registry_service_factory.h" | 23 #include "chrome/browser/policy/schema_registry_service_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 source->AddLocalizedString("labelRefreshInterval", | 102 source->AddLocalizedString("labelRefreshInterval", |
102 IDS_POLICY_LABEL_REFRESH_INTERVAL); | 103 IDS_POLICY_LABEL_REFRESH_INTERVAL); |
103 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); | 104 source->AddLocalizedString("labelStatus", IDS_POLICY_LABEL_STATUS); |
104 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); | 105 source->AddLocalizedString("showUnset", IDS_POLICY_SHOW_UNSET); |
105 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); | 106 source->AddLocalizedString("noPoliciesSet", IDS_POLICY_NO_POLICIES_SET); |
106 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); | 107 source->AddLocalizedString("headerScope", IDS_POLICY_HEADER_SCOPE); |
107 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); | 108 source->AddLocalizedString("headerLevel", IDS_POLICY_HEADER_LEVEL); |
108 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); | 109 source->AddLocalizedString("headerName", IDS_POLICY_HEADER_NAME); |
109 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); | 110 source->AddLocalizedString("headerValue", IDS_POLICY_HEADER_VALUE); |
110 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); | 111 source->AddLocalizedString("headerStatus", IDS_POLICY_HEADER_STATUS); |
112 source->AddLocalizedString("headerSource", IDS_POLICY_HEADER_SOURCE); | |
111 source->AddLocalizedString("showExpandedValue", | 113 source->AddLocalizedString("showExpandedValue", |
112 IDS_POLICY_SHOW_EXPANDED_VALUE); | 114 IDS_POLICY_SHOW_EXPANDED_VALUE); |
113 source->AddLocalizedString("hideExpandedValue", | 115 source->AddLocalizedString("hideExpandedValue", |
114 IDS_POLICY_HIDE_EXPANDED_VALUE); | 116 IDS_POLICY_HIDE_EXPANDED_VALUE); |
115 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); | 117 source->AddLocalizedString("scopeUser", IDS_POLICY_SCOPE_USER); |
116 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); | 118 source->AddLocalizedString("scopeDevice", IDS_POLICY_SCOPE_DEVICE); |
117 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); | 119 source->AddLocalizedString("levelRecommended", IDS_POLICY_LEVEL_RECOMMENDED); |
118 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); | 120 source->AddLocalizedString("levelMandatory", IDS_POLICY_LEVEL_MANDATORY); |
121 source->AddLocalizedString("sourceEnterprise", IDS_POLICY_SOURCE_ENTERPRISE); | |
122 source->AddLocalizedString("sourcePlatform", IDS_POLICY_SOURCE_PLATFORM); | |
123 source->AddLocalizedString("sourceCloud", IDS_POLICY_SOURCE_CLOUD); | |
119 source->AddLocalizedString("ok", IDS_POLICY_OK); | 124 source->AddLocalizedString("ok", IDS_POLICY_OK); |
120 source->AddLocalizedString("unset", IDS_POLICY_UNSET); | 125 source->AddLocalizedString("unset", IDS_POLICY_UNSET); |
121 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); | 126 source->AddLocalizedString("unknown", IDS_POLICY_UNKNOWN); |
122 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); | 127 source->AddLocalizedString("notSpecified", IDS_POLICY_NOT_SPECIFIED); |
123 | 128 |
124 source->SetJsonPath("strings.js"); | 129 source->SetJsonPath("strings.js"); |
125 | 130 |
126 // Add required resources. | 131 // Add required resources. |
127 source->AddResourcePath("policy.css", IDR_POLICY_CSS); | 132 source->AddResourcePath("policy.css", IDR_POLICY_CSS); |
128 source->AddResourcePath("policy.js", IDR_POLICY_JS); | 133 source->AddResourcePath("policy.js", IDR_POLICY_JS); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // policy enabled (device and/or user), a dictionary containing status | 400 // policy enabled (device and/or user), a dictionary containing status |
396 // information is sent. | 401 // information is sent. |
397 void SendStatus() const; | 402 void SendStatus() const; |
398 | 403 |
399 // Inserts a description of each policy in |policy_map| into |values|, using | 404 // Inserts a description of each policy in |policy_map| into |values|, using |
400 // the optional errors in |errors| to determine the status of each policy. | 405 // the optional errors in |errors| to determine the status of each policy. |
401 void GetPolicyValues(const policy::PolicyMap& policy_map, | 406 void GetPolicyValues(const policy::PolicyMap& policy_map, |
402 policy::PolicyErrorMap* errors, | 407 policy::PolicyErrorMap* errors, |
403 base::DictionaryValue* values) const; | 408 base::DictionaryValue* values) const; |
404 | 409 |
410 // Asks the profile's Pref_Service for the store that finally set the policy. | |
411 std::string GetSourceName(const policy::PolicySource& source) const; | |
412 | |
405 void GetChromePolicyValues(base::DictionaryValue* values) const; | 413 void GetChromePolicyValues(base::DictionaryValue* values) const; |
406 | 414 |
407 void HandleInitialized(const base::ListValue* args); | 415 void HandleInitialized(const base::ListValue* args); |
408 void HandleReloadPolicies(const base::ListValue* args); | 416 void HandleReloadPolicies(const base::ListValue* args); |
409 | 417 |
410 void OnRefreshPoliciesDone() const; | 418 void OnRefreshPoliciesDone() const; |
411 | 419 |
412 policy::PolicyService* GetPolicyService() const; | 420 policy::PolicyService* GetPolicyService() const; |
413 | 421 |
414 std::string device_domain_; | 422 std::string device_domain_; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 base::DictionaryValue* value = new base::DictionaryValue; | 753 base::DictionaryValue* value = new base::DictionaryValue; |
746 value->Set("value", CopyAndConvert(entry->second.value).release()); | 754 value->Set("value", CopyAndConvert(entry->second.value).release()); |
747 if (entry->second.scope == policy::POLICY_SCOPE_USER) | 755 if (entry->second.scope == policy::POLICY_SCOPE_USER) |
748 value->SetString("scope", "user"); | 756 value->SetString("scope", "user"); |
749 else | 757 else |
750 value->SetString("scope", "machine"); | 758 value->SetString("scope", "machine"); |
751 if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED) | 759 if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED) |
752 value->SetString("level", "recommended"); | 760 value->SetString("level", "recommended"); |
753 else | 761 else |
754 value->SetString("level", "mandatory"); | 762 value->SetString("level", "mandatory"); |
763 value->SetString("source", GetSourceName(entry->second.source)); | |
755 base::string16 error = errors->GetErrors(entry->first); | 764 base::string16 error = errors->GetErrors(entry->first); |
756 if (!error.empty()) | 765 if (!error.empty()) |
757 value->SetString("error", error); | 766 value->SetString("error", error); |
758 values->Set(entry->first, value); | 767 values->Set(entry->first, value); |
759 } | 768 } |
760 } | 769 } |
761 | 770 |
771 std::string PolicyUIHandler::GetSourceName( | |
772 const policy::PolicySource& source) const { | |
773 switch (source) { | |
774 case policy::POLICY_SOURCE_ENTERPRISE_DEFAULT: | |
775 return "sourceEnterprise"; | |
776 case policy::POLICY_SOURCE_CLOUD: | |
777 return "sourceCloud"; | |
778 case policy::POLICY_SOURCE_PLATFORM: | |
779 return "sourcePlatform"; | |
780 default: | |
781 return ""; | |
782 } | |
783 } | |
784 | |
762 void PolicyUIHandler::GetChromePolicyValues( | 785 void PolicyUIHandler::GetChromePolicyValues( |
763 base::DictionaryValue* values) const { | 786 base::DictionaryValue* values) const { |
764 policy::PolicyService* policy_service = GetPolicyService(); | 787 policy::PolicyService* policy_service = GetPolicyService(); |
765 policy::PolicyMap map; | 788 policy::PolicyMap map; |
766 | 789 |
767 // Make a copy that can be modified, since some policy values are modified | 790 // Make a copy that can be modified, since some policy values are modified |
768 // before being displayed. | 791 // before being displayed. |
769 map.CopyFrom(policy_service->GetPolicies( | 792 map.CopyFrom(policy_service->GetPolicies( |
770 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()))); | 793 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()))); |
771 | 794 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 } | 860 } |
838 | 861 |
839 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 862 PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
840 web_ui->AddMessageHandler(new PolicyUIHandler); | 863 web_ui->AddMessageHandler(new PolicyUIHandler); |
841 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 864 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
842 CreatePolicyUIHTMLSource()); | 865 CreatePolicyUIHTMLSource()); |
843 } | 866 } |
844 | 867 |
845 PolicyUI::~PolicyUI() { | 868 PolicyUI::~PolicyUI() { |
846 } | 869 } |
OLD | NEW |