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_handler.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 <utility> |
| 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 13 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
13 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
17 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
18 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return base::WrapUnique(new base::StringValue(json_string)); | 177 return base::WrapUnique(new base::StringValue(json_string)); |
176 } | 178 } |
177 | 179 |
178 // Returns a copy of |value| with some values converted to a representation that | 180 // Returns a copy of |value| with some values converted to a representation that |
179 // i18n_template.js will display in a nicer way. | 181 // i18n_template.js will display in a nicer way. |
180 std::unique_ptr<base::Value> CopyAndConvert(const base::Value* value) { | 182 std::unique_ptr<base::Value> CopyAndConvert(const base::Value* value) { |
181 const base::DictionaryValue* dict = NULL; | 183 const base::DictionaryValue* dict = NULL; |
182 if (value->GetAsDictionary(&dict)) | 184 if (value->GetAsDictionary(&dict)) |
183 return DictionaryToJSONString(*dict); | 185 return DictionaryToJSONString(*dict); |
184 | 186 |
185 std::unique_ptr<base::Value> copy(value->DeepCopy()); | 187 std::unique_ptr<base::Value> copy = value->CreateDeepCopy(); |
186 base::ListValue* list = NULL; | 188 base::ListValue* list = NULL; |
187 if (copy->GetAsList(&list)) { | 189 if (copy->GetAsList(&list)) { |
188 for (size_t i = 0; i < list->GetSize(); ++i) { | 190 for (size_t i = 0; i < list->GetSize(); ++i) { |
189 if (list->GetDictionary(i, &dict)) | 191 if (list->GetDictionary(i, &dict)) |
190 list->Set(i, DictionaryToJSONString(*dict).release()); | 192 list->Set(i, DictionaryToJSONString(*dict)); |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 return copy; | 196 return copy; |
195 } | 197 } |
196 | 198 |
197 } // namespace | 199 } // namespace |
198 | 200 |
199 // An interface for querying the status of cloud policy. | 201 // An interface for querying the status of cloud policy. |
200 class CloudPolicyStatusProvider { | 202 class CloudPolicyStatusProvider { |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 extension_values->Set(extension->id(), extension_policies); | 646 extension_values->Set(extension->id(), extension_policies); |
645 } | 647 } |
646 all_policies.Set("extensionPolicies", extension_values); | 648 all_policies.Set("extensionPolicies", extension_values); |
647 #endif | 649 #endif |
648 web_ui()->CallJavascriptFunction("policy.Page.setPolicyValues", all_policies); | 650 web_ui()->CallJavascriptFunction("policy.Page.setPolicyValues", all_policies); |
649 } | 651 } |
650 | 652 |
651 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map, | 653 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map, |
652 policy::PolicyErrorMap* errors, | 654 policy::PolicyErrorMap* errors, |
653 base::DictionaryValue* values) const { | 655 base::DictionaryValue* values) const { |
654 for (policy::PolicyMap::const_iterator entry = map.begin(); | 656 for (const auto& entry : map) { |
655 entry != map.end(); ++entry) { | 657 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
656 base::DictionaryValue* value = new base::DictionaryValue; | 658 value->Set("value", CopyAndConvert(entry.second.value.get())); |
657 value->Set("value", CopyAndConvert(entry->second.value).release()); | 659 if (entry.second.scope == policy::POLICY_SCOPE_USER) |
658 if (entry->second.scope == policy::POLICY_SCOPE_USER) | |
659 value->SetString("scope", "user"); | 660 value->SetString("scope", "user"); |
660 else | 661 else |
661 value->SetString("scope", "machine"); | 662 value->SetString("scope", "machine"); |
662 if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED) | 663 if (entry.second.level == policy::POLICY_LEVEL_RECOMMENDED) |
663 value->SetString("level", "recommended"); | 664 value->SetString("level", "recommended"); |
664 else | 665 else |
665 value->SetString("level", "mandatory"); | 666 value->SetString("level", "mandatory"); |
666 value->SetString("source", kPolicySources[entry->second.source].key); | 667 value->SetString("source", kPolicySources[entry.second.source].key); |
667 base::string16 error = errors->GetErrors(entry->first); | 668 base::string16 error = errors->GetErrors(entry.first); |
668 if (!error.empty()) | 669 if (!error.empty()) |
669 value->SetString("error", error); | 670 value->SetString("error", error); |
670 values->Set(entry->first, value); | 671 values->Set(entry.first, std::move(value)); |
671 } | 672 } |
672 } | 673 } |
673 | 674 |
674 void PolicyUIHandler::GetChromePolicyValues( | 675 void PolicyUIHandler::GetChromePolicyValues( |
675 base::DictionaryValue* values) const { | 676 base::DictionaryValue* values) const { |
676 policy::PolicyService* policy_service = GetPolicyService(); | 677 policy::PolicyService* policy_service = GetPolicyService(); |
677 policy::PolicyMap map; | 678 policy::PolicyMap map; |
678 | 679 |
679 // Make a copy that can be modified, since some policy values are modified | 680 // Make a copy that can be modified, since some policy values are modified |
680 // before being displayed. | 681 // before being displayed. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 } | 742 } |
742 | 743 |
743 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 744 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
744 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); | 745 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); |
745 } | 746 } |
746 | 747 |
747 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 748 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
748 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 749 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
749 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 750 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
750 } | 751 } |
OLD | NEW |