[email protected] | a8171203 | 2011-08-31 16:10:04 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/ui/webui/policy_ui.h" |
| 6 | |
| 7 | #include "chrome/browser/policy/policy_status_info.h" |
| 8 | #include "chrome/browser/profiles/profile.h" |
| 9 | #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 10 | #include "chrome/common/url_constants.h" |
| 11 | #include "content/browser/tab_contents/tab_contents.h" |
| 12 | #include "grit/browser_resources.h" |
| 13 | #include "grit/generated_resources.h" |
| 14 | |
| 15 | ChromeWebUIDataSource* CreatePolicyUIHTMLSource() { |
| 16 | ChromeWebUIDataSource* source = |
| 17 | new ChromeWebUIDataSource(chrome::kChromeUIPolicyHost); |
| 18 | |
| 19 | // Localized strings. |
| 20 | source->AddLocalizedString("policyTitle", IDS_POLICY_TITLE); |
| 21 | source->AddLocalizedString("statusPaneTitle", IDS_POLICY_STATUS_TITLE); |
| 22 | source->AddLocalizedString("fetchPoliciesText", IDS_POLICY_FETCH); |
| 23 | source->AddLocalizedString("devicePoliciesBoxTitle", |
| 24 | IDS_POLICY_DEVICE_POLICIES); |
| 25 | source->AddLocalizedString("userPoliciesBoxTitle", |
| 26 | IDS_POLICY_USER_POLICIES); |
| 27 | source->AddLocalizedString("enrollmentDomainText", |
| 28 | IDS_POLICY_ENROLLMENT_DOMAIN); |
| 29 | source->AddLocalizedString("lastFetchedText", IDS_POLICY_LAST_FETCHED); |
| 30 | source->AddLocalizedString("fetchIntervalText", IDS_POLICY_FETCH_INTERVAL); |
| 31 | source->AddLocalizedString("serverStatusText", IDS_POLICY_SERVER_STATUS); |
| 32 | source->AddLocalizedString("showUnsentPoliciesText", |
| 33 | IDS_POLICY_SHOW_UNSENT); |
| 34 | source->AddLocalizedString("filterPoliciesText", IDS_POLICY_FILTER); |
| 35 | source->AddLocalizedString("noPoliciesSet",IDS_POLICY_NO_POLICIES_SET); |
| 36 | source->AddLocalizedString("appliesToTableHeader", IDS_POLICY_APPLIES_TO); |
| 37 | source->AddLocalizedString("policyLevelTableHeader", IDS_POLICY_LEVEL); |
| 38 | source->AddLocalizedString("policyNameTableHeader", IDS_POLICY_ENTRY_NAME); |
| 39 | source->AddLocalizedString("policyValueTableHeader", IDS_POLICY_ENTRY_VALUE); |
| 40 | source->AddLocalizedString("policyStatusTableHeader", |
| 41 | IDS_POLICY_ENTRY_STATUS); |
| 42 | source->set_json_path("strings.js"); |
| 43 | |
| 44 | // Add required resources. |
| 45 | source->add_resource_path("policy.css", IDR_POLICY_CSS); |
| 46 | source->add_resource_path("policy.js", IDR_POLICY_JS); |
| 47 | source->set_default_resource(IDR_POLICY_HTML); |
| 48 | |
| 49 | return source; |
| 50 | } |
| 51 | |
| 52 | //////////////////////////////////////////////////////////////////////////////// |
| 53 | // |
| 54 | // PolicyUIHandler |
| 55 | // |
| 56 | //////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | PolicyUIHandler::PolicyUIHandler() { |
| 59 | policy::ConfigurationPolicyReader* managed_platform = |
| 60 | ConfigurationPolicyReader::CreateManagedPlatformPolicyReader(); |
| 61 | policy::ConfigurationPolicyReader* managed_cloud = |
| 62 | ConfigurationPolicyReader::CreateManagedCloudPolicyReader(); |
| 63 | policy::ConfigurationPolicyReader* recommended_platform = |
| 64 | ConfigurationPolicyReader::CreateRecommendedPlatformPolicyReader(); |
| 65 | policy::ConfigurationPolicyReader* recommended_cloud = |
| 66 | ConfigurationPolicyReader::CreateRecommendedCloudPolicyReader(); |
| 67 | policy_status_.reset(new policy::PolicyStatus(managed_platform, |
| 68 | managed_cloud, |
| 69 | recommended_platform, |
| 70 | recommended_cloud)); |
| 71 | } |
| 72 | |
| 73 | PolicyUIHandler::~PolicyUIHandler() { |
| 74 | } |
| 75 | |
| 76 | WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) { |
| 77 | return WebUIMessageHandler::Attach(web_ui); |
| 78 | } |
| 79 | |
| 80 | void PolicyUIHandler::RegisterMessages() { |
| 81 | web_ui_->RegisterMessageCallback("requestPolicyData", |
| 82 | NewCallback(this, &PolicyUIHandler::HandleRequestPolicyData)); |
| 83 | } |
| 84 | |
| 85 | void PolicyUIHandler::HandleRequestPolicyData(const ListValue* args) { |
| 86 | bool any_policies_sent; |
| 87 | ListValue* list = policy_status_->GetPolicyStatusList(&any_policies_sent); |
| 88 | DictionaryValue results; |
| 89 | results.Set("policies", list); |
| 90 | results.SetBoolean("anyPoliciesSet", any_policies_sent); |
| 91 | web_ui_->CallJavascriptFunction("Policy.returnPolicyData", results); |
| 92 | } |
| 93 | |
| 94 | //////////////////////////////////////////////////////////////////////////////// |
| 95 | // |
| 96 | // PolicyUI |
| 97 | // |
| 98 | //////////////////////////////////////////////////////////////////////////////// |
| 99 | |
| 100 | PolicyUI::PolicyUI(TabContents* contents) : ChromeWebUI(contents) { |
| 101 | AddMessageHandler((new PolicyUIHandler)->Attach(this)); |
| 102 | |
| 103 | // Set up the chrome://policy/ source. |
| 104 | Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 105 | profile->GetChromeURLDataManager()->AddDataSource(CreatePolicyUIHTMLSource()); |
| 106 | } |
| 107 | |
| 108 | PolicyUI::~PolicyUI() { |
| 109 | } |