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

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

Issue 7585036: First CL for the about:policy page. This only implements the policy section of the page. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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/policy/configuration_policy_reader.h"
6
7 #include <string>
8
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/policy_ui.h"
11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/browser/tab_contents/tab_contents.h"
14 #include "grit/browser_resources.h"
15 #include "grit/generated_resources.h"
16
17 ChromeWebUIDataSource* CreatePolicyUIHTMLSource() {
18 ChromeWebUIDataSource* source =
19 new ChromeWebUIDataSource(chrome::kChromeUIPolicyHost);
20
21 // Localized strings.
22 source->AddLocalizedString("policyTitle", IDS_POLICY_TITLE);
23 source->AddLocalizedString("aboutPolicyDescription", IDS_POLICY_DESCRIPTION);
24 source->AddLocalizedString("statusPaneTitle", IDS_POLICY_STATUS_TITLE);
25 source->AddLocalizedString("fetchPoliciesText", IDS_POLICY_FETCH);
26 source->AddLocalizedString("devicePoliciesBoxTitle",
27 IDS_POLICY_DEVICE_POLICIES);
28 source->AddLocalizedString("userPoliciesBoxTitle",
29 IDS_POLICY_USER_POLICIES);
30 source->AddLocalizedString("enrollmentDomainText",
31 IDS_POLICY_ENROLLMENT_DOMAIN);
32 source->AddLocalizedString("lastFetchedText", IDS_POLICY_LAST_FETCHED);
33 source->AddLocalizedString("fetchIntervalText", IDS_POLICY_FETCH_INTERVAL);
34 source->AddLocalizedString("serverStatusText", IDS_POLICY_SERVER_STATUS);
35 source->AddLocalizedString("showUnsentPoliciesText",
36 IDS_POLICY_SHOW_UNSENT);
37 source->AddLocalizedString("filterPoliciesText", IDS_POLICY_FILTER);
38 source->AddLocalizedString("noPoliciesSet",IDS_POLICY_NO_POLICIES_SET);
39 source->AddLocalizedString("appliesToTableHeader", IDS_POLICY_APPLIES_TO);
40 source->AddLocalizedString("policyLevelTableHeader", IDS_POLICY_LEVEL);
41 source->AddLocalizedString("policyNameTableHeader", IDS_POLICY_ENTRY_NAME);
42 source->AddLocalizedString("policyValueTableHeader", IDS_POLICY_ENTRY_VALUE);
43 source->AddLocalizedString("policyStatusTableHeader",
44 IDS_POLICY_ENTRY_STATUS);
45 source->set_json_path("strings.js");
46
47 // Add required resources.
48 source->add_resource_path("policy.css", IDR_POLICY_CSS);
49 source->add_resource_path("policy.js", IDR_POLICY_JS);
50 source->set_default_resource(IDR_POLICY_HTML);
51
52 return source;
53 }
54
55 ////////////////////////////////////////////////////////////////////////////////
56 //
57 // PolicyUIHandler
58 //
59 ////////////////////////////////////////////////////////////////////////////////
60
61 PolicyUIHandler::PolicyUIHandler() {
62 policy_status_.reset(new policy::PolicyStatus());
63 }
64
65 PolicyUIHandler::~PolicyUIHandler() {
66 }
67
68 WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) {
69 return WebUIMessageHandler::Attach(web_ui);
70 }
71
72 void PolicyUIHandler::RegisterMessages() {
73 web_ui_->RegisterMessageCallback("requestPolicyData",
74 NewCallback(this, &PolicyUIHandler::HandleRequestPolicyData));
75 }
76
77 void PolicyUIHandler::HandleRequestPolicyData(const ListValue* args) {
78 bool any_policies_sent;
79 ListValue* list = policy_status_->GetPolicyStatusList(any_policies_sent);
80 DictionaryValue results;
81 results.Set("policies", list);
82 results.SetBoolean("any_policies_set", any_policies_sent);
83 web_ui_->CallJavascriptFunction("Policy.returnPolicyData", results);
84 }
85
86 ////////////////////////////////////////////////////////////////////////////////
87 //
88 // PolicyUI
89 //
90 ////////////////////////////////////////////////////////////////////////////////
91
92 PolicyUI::PolicyUI(TabContents* contents) : ChromeWebUI(contents) {
93 AddMessageHandler((new PolicyUIHandler)->Attach(this));
94
95 // Set up the chrome://policy/ source.
96 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
97 profile->GetChromeURLDataManager()->AddDataSource(CreatePolicyUIHTMLSource());
98 }
99
100 PolicyUI::~PolicyUI() {
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698