OLD | NEW |
---|---|
(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/common/notification_registrar.h" | |
14 #include "content/browser/tab_contents/tab_contents.h" | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
alphabetize
simo
2011/08/10 14:28:19
Done.
| |
15 #include "grit/browser_resources.h" | |
16 #include "grit/generated_resources.h" | |
17 | |
18 ChromeWebUIDataSource* CreatePolicyUIHTMLSource() { | |
19 ChromeWebUIDataSource* source = | |
20 new ChromeWebUIDataSource(chrome::kChromeUIPolicyHost); | |
21 | |
22 // Localized strings. | |
23 source->AddLocalizedString("policyTitle", IDS_POLICY_TITLE); | |
24 source->AddLocalizedString("aboutPolicyDescription", IDS_POLICY_DESCRIPTION); | |
25 source->AddLocalizedString("statusPaneTitle", IDS_POLICY_STATUS_TITLE); | |
26 source->AddLocalizedString("fetchPoliciesText", IDS_POLICY_FETCH); | |
27 source->AddLocalizedString("devicePoliciesBoxTitle", | |
28 IDS_POLICY_DEVICE_POLICIES); | |
29 source->AddLocalizedString("userPoliciesBoxTitle", | |
30 IDS_POLICY_USER_POLICIES); | |
31 source->AddLocalizedString("enrollmentDomainText", | |
32 IDS_POLICY_ENROLLMENT_DOMAIN); | |
33 source->AddLocalizedString("lastFetchedText", IDS_POLICY_LAST_FETCHED); | |
34 source->AddLocalizedString("fetchIntervalText", IDS_POLICY_FETCH_INTERVAL); | |
35 source->AddLocalizedString("serverStatusText", IDS_POLICY_SERVER_STATUS); | |
36 source->AddLocalizedString("showUnsentPoliciesText", | |
37 IDS_POLICY_SHOW_UNSENT); | |
38 source->AddLocalizedString("filterPoliciesText", IDS_POLICY_FILTER); | |
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 | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
only one newline
simo
2011/08/10 14:28:19
Done.
| |
62 PolicyUIHandler::PolicyUIHandler() { | |
63 policy_status_.reset(new policy::PolicyStatus()); | |
64 } | |
65 | |
66 PolicyUIHandler::~PolicyUIHandler() { | |
67 } | |
68 | |
69 WebUIMessageHandler* PolicyUIHandler::Attach(WebUI* web_ui) { | |
70 return WebUIMessageHandler::Attach(web_ui); | |
71 } | |
72 | |
73 void PolicyUIHandler::RegisterMessages() { | |
74 web_ui_->RegisterMessageCallback("requestPolicyData", | |
75 NewCallback(this, &PolicyUIHandler::HandleRequestPolicyData)); | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
4 spaces indentation.
simo
2011/08/10 14:28:19
Done.
| |
76 } | |
77 | |
78 void PolicyUIHandler::HandleRequestPolicyData(const ListValue* args) { | |
79 ListValue* list = new ListValue(); | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
You are creating a new ListValue object and leak i
simo
2011/08/10 14:28:19
Done.
| |
80 // policy::PolicyStatus* policy_status = new policy::PolicyStatus(); | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
indentation
simo
2011/08/10 14:28:19
Done.
| |
81 list = policy_status_->GetPolicyStatusList(); | |
82 DictionaryValue results; | |
83 results.Set("policies", list); | |
84 web_ui_->CallJavascriptFunction("returnPolicyData", results); | |
85 } | |
86 | |
87 void PolicyUIHandler::Observe(int type, | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
Since you have a reference to your PolicyStatus in
| |
88 const NotificationSource& source, | |
89 const NotificationDetails& details) { | |
90 // TODO(simo) set up PolicyStatus as a source and create notifications. | |
91 } | |
92 | |
93 //////////////////////////////////////////////////////////////////////////////// | |
94 // | |
95 // PolicyUI | |
96 // | |
97 //////////////////////////////////////////////////////////////////////////////// | |
98 | |
99 PolicyUI::PolicyUI(TabContents* contents) : ChromeWebUI(contents) { | |
100 AddMessageHandler((new PolicyUIHandler)->Attach(this)); | |
101 | |
102 // Set up the chrome://policy/ source. | |
103 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
104 profile->GetChromeURLDataManager()->AddDataSource(CreatePolicyUIHTMLSource()); | |
105 } | |
106 | |
107 PolicyUI::~PolicyUI() { | |
108 } | |
109 | |
Mattias Nissler (ping if slow)
2011/08/09 13:20:40
remove trailing whitespace.
simo
2011/08/10 14:28:19
Done.
| |
110 | |
111 | |
112 | |
OLD | NEW |