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> | 9 #include <utility> |
10 | 10 |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 !prop.IsAtEnd(); prop.Advance()) { | 607 !prop.IsAtEnd(); prop.Advance()) { |
608 policy_names->SetBoolean(prop.key(), true); | 608 policy_names->SetBoolean(prop.key(), true); |
609 } | 609 } |
610 } | 610 } |
611 extension_value->Set("policyNames", policy_names); | 611 extension_value->Set("policyNames", policy_names); |
612 extension_policy_names->Set(extension->id(), extension_value); | 612 extension_policy_names->Set(extension->id(), extension_value); |
613 } | 613 } |
614 names.Set("extensionPolicyNames", extension_policy_names); | 614 names.Set("extensionPolicyNames", extension_policy_names); |
615 #endif // defined(ENABLE_EXTENSIONS) | 615 #endif // defined(ENABLE_EXTENSIONS) |
616 | 616 |
617 web_ui()->CallJavascriptFunction("policy.Page.setPolicyNames", names); | 617 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyNames", names); |
618 } | 618 } |
619 | 619 |
620 void PolicyUIHandler::SendPolicyValues() const { | 620 void PolicyUIHandler::SendPolicyValues() const { |
621 base::DictionaryValue all_policies; | 621 base::DictionaryValue all_policies; |
622 | 622 |
623 // Add Chrome policy values. | 623 // Add Chrome policy values. |
624 base::DictionaryValue* chrome_policies = new base::DictionaryValue; | 624 base::DictionaryValue* chrome_policies = new base::DictionaryValue; |
625 GetChromePolicyValues(chrome_policies); | 625 GetChromePolicyValues(chrome_policies); |
626 all_policies.Set("chromePolicies", chrome_policies); | 626 all_policies.Set("chromePolicies", chrome_policies); |
627 | 627 |
(...skipping 12 matching lines...) Expand all Loading... |
640 base::DictionaryValue* extension_policies = new base::DictionaryValue; | 640 base::DictionaryValue* extension_policies = new base::DictionaryValue; |
641 policy::PolicyNamespace policy_namespace = policy::PolicyNamespace( | 641 policy::PolicyNamespace policy_namespace = policy::PolicyNamespace( |
642 policy::POLICY_DOMAIN_EXTENSIONS, extension->id()); | 642 policy::POLICY_DOMAIN_EXTENSIONS, extension->id()); |
643 policy::PolicyErrorMap empty_error_map; | 643 policy::PolicyErrorMap empty_error_map; |
644 GetPolicyValues(GetPolicyService()->GetPolicies(policy_namespace), | 644 GetPolicyValues(GetPolicyService()->GetPolicies(policy_namespace), |
645 &empty_error_map, extension_policies); | 645 &empty_error_map, extension_policies); |
646 extension_values->Set(extension->id(), extension_policies); | 646 extension_values->Set(extension->id(), extension_policies); |
647 } | 647 } |
648 all_policies.Set("extensionPolicies", extension_values); | 648 all_policies.Set("extensionPolicies", extension_values); |
649 #endif | 649 #endif |
650 web_ui()->CallJavascriptFunction("policy.Page.setPolicyValues", all_policies); | 650 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyValues", |
| 651 all_policies); |
651 } | 652 } |
652 | 653 |
653 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map, | 654 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map, |
654 policy::PolicyErrorMap* errors, | 655 policy::PolicyErrorMap* errors, |
655 base::DictionaryValue* values) const { | 656 base::DictionaryValue* values) const { |
656 for (const auto& entry : map) { | 657 for (const auto& entry : map) { |
657 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 658 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
658 value->Set("value", CopyAndConvert(entry.second.value.get())); | 659 value->Set("value", CopyAndConvert(entry.second.value.get())); |
659 if (entry.second.scope == policy::POLICY_SCOPE_USER) | 660 if (entry.second.scope == policy::POLICY_SCOPE_USER) |
660 value->SetString("scope", "user"); | 661 value->SetString("scope", "user"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 user_status->GetString("username", &username); | 707 user_status->GetString("username", &username); |
707 if (!username.empty()) | 708 if (!username.empty()) |
708 user_status->SetString("domain", gaia::ExtractDomainName(username)); | 709 user_status->SetString("domain", gaia::ExtractDomainName(username)); |
709 | 710 |
710 base::DictionaryValue status; | 711 base::DictionaryValue status; |
711 if (!device_status->empty()) | 712 if (!device_status->empty()) |
712 status.Set("device", device_status.release()); | 713 status.Set("device", device_status.release()); |
713 if (!user_status->empty()) | 714 if (!user_status->empty()) |
714 status.Set("user", user_status.release()); | 715 status.Set("user", user_status.release()); |
715 | 716 |
716 web_ui()->CallJavascriptFunction("policy.Page.setStatus", status); | 717 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setStatus", status); |
717 } | 718 } |
718 | 719 |
719 void PolicyUIHandler::HandleInitialized(const base::ListValue* args) { | 720 void PolicyUIHandler::HandleInitialized(const base::ListValue* args) { |
720 SendPolicyNames(); | 721 SendPolicyNames(); |
721 SendPolicyValues(); | 722 SendPolicyValues(); |
722 SendStatus(); | 723 SendStatus(); |
723 } | 724 } |
724 | 725 |
725 void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) { | 726 void PolicyUIHandler::HandleReloadPolicies(const base::ListValue* args) { |
726 #if defined(OS_CHROMEOS) | 727 #if defined(OS_CHROMEOS) |
727 // Allow user to manually fetch remote commands, in case invalidation | 728 // Allow user to manually fetch remote commands, in case invalidation |
728 // service is not working properly. | 729 // service is not working properly. |
729 // TODO(binjin): evaluate and possibly remove this after invalidation | 730 // TODO(binjin): evaluate and possibly remove this after invalidation |
730 // service is landed and tested. http://crbug.com/480982 | 731 // service is landed and tested. http://crbug.com/480982 |
731 policy::BrowserPolicyConnectorChromeOS* connector = | 732 policy::BrowserPolicyConnectorChromeOS* connector = |
732 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 733 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
733 policy::RemoteCommandsService* remote_commands_service = | 734 policy::RemoteCommandsService* remote_commands_service = |
734 connector->GetDeviceCloudPolicyManager() | 735 connector->GetDeviceCloudPolicyManager() |
735 ->core() | 736 ->core() |
736 ->remote_commands_service(); | 737 ->remote_commands_service(); |
737 if (remote_commands_service) | 738 if (remote_commands_service) |
738 remote_commands_service->FetchRemoteCommands(); | 739 remote_commands_service->FetchRemoteCommands(); |
739 #endif | 740 #endif |
740 GetPolicyService()->RefreshPolicies(base::Bind( | 741 GetPolicyService()->RefreshPolicies(base::Bind( |
741 &PolicyUIHandler::OnRefreshPoliciesDone, weak_factory_.GetWeakPtr())); | 742 &PolicyUIHandler::OnRefreshPoliciesDone, weak_factory_.GetWeakPtr())); |
742 } | 743 } |
743 | 744 |
744 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 745 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
745 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); | 746 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); |
746 } | 747 } |
747 | 748 |
748 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 749 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
749 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 750 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
750 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 751 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
751 } | 752 } |
OLD | NEW |