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 #ifndef CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/string16.h" | |
14 #include "base/values.h" | |
15 #include "chrome/browser/policy/policy_map.h" | |
16 #include "chrome/browser/policy/policy_service.h" | |
17 #include "content/public/browser/web_ui_controller.h" | 11 #include "content/public/browser/web_ui_controller.h" |
18 #include "content/public/browser/web_ui_message_handler.h" | |
19 #include "policy/policy_constants.h" | |
20 | 12 |
21 class CloudPolicyStatusProvider; | 13 namespace content { |
| 14 class WebUI; |
| 15 } |
22 | 16 |
23 // The base class handler of Javascript messages of the about:policy page. | 17 // The Web UI controller for the chrome://policy page. |
24 class PolicyUIHandler : public content::WebUIMessageHandler, | |
25 public policy::PolicyService::Observer { | |
26 public: | |
27 // Keys expected in a DictionaryValue representing the status of a policy. | |
28 // Public for testing. | |
29 static const char kLevel[]; | |
30 static const char kName[]; | |
31 static const char kScope[]; | |
32 static const char kSet[]; | |
33 static const char kStatus[]; | |
34 static const char kValue[]; | |
35 | |
36 PolicyUIHandler(); | |
37 virtual ~PolicyUIHandler(); | |
38 | |
39 // WebUIMessageHandler implementation. | |
40 virtual void RegisterMessages() OVERRIDE; | |
41 | |
42 // policy::PolicyService::Observer implementation. | |
43 virtual void OnPolicyUpdated(const policy::PolicyNamespace& ns, | |
44 const policy::PolicyMap& previous, | |
45 const policy::PolicyMap& current) OVERRIDE; | |
46 | |
47 // Returns a ListValue pointer containing the status information of all | |
48 // policies defined in |policies|. |any_policies_set| is set to true if | |
49 // there are policies in the list that were valid, otherwise it's false. | |
50 static scoped_ptr<base::ListValue> GetPolicyStatusList( | |
51 const policy::PolicyMap& policies, | |
52 bool* any_policies_set); | |
53 | |
54 private: | |
55 // Callback for the "requestData" message. The parameter |args| is unused. | |
56 void HandleRequestData(const base::ListValue* args); | |
57 | |
58 // Callback for the "fetchPolicy" message. The parameter |args| is unused. | |
59 void HandleFetchPolicy(const base::ListValue* args); | |
60 | |
61 // Callback for completion of a RefreshPolicies call. | |
62 void OnRefreshDone(); | |
63 | |
64 // Sends policy data to UI. | |
65 void SendDataToUI(); | |
66 | |
67 // Returns the policy service to use. | |
68 policy::PolicyService* GetPolicyService(); | |
69 | |
70 // Returns a DictionaryValue pointer containing information about the status | |
71 // of the policy system. The caller acquires ownership of the returned | |
72 // DictionaryValue pointer. | |
73 base::DictionaryValue* GetStatusData(); | |
74 | |
75 // Used to post a callback to RefreshPolicies with a WeakPtr to |this|. | |
76 base::WeakPtrFactory<PolicyUIHandler> weak_factory_; | |
77 | |
78 // Providers that supply status dictionaries for user and device policy, | |
79 // respectively. These are created on initialization time as appropriate for | |
80 // the platform (Chrome OS / desktop) and type of policy that is in effect. | |
81 scoped_ptr<CloudPolicyStatusProvider> user_status_provider_; | |
82 scoped_ptr<CloudPolicyStatusProvider> device_status_provider_; | |
83 | |
84 // The domain the device is enrolled to, if applicable. | |
85 string16 enterprise_domain_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(PolicyUIHandler); | |
88 }; | |
89 | |
90 // The Web UI handler for about:policy. | |
91 class PolicyUI : public content::WebUIController { | 18 class PolicyUI : public content::WebUIController { |
92 public: | 19 public: |
93 explicit PolicyUI(content::WebUI* web_ui); | 20 explicit PolicyUI(content::WebUI* web_ui); |
94 virtual ~PolicyUI(); | 21 virtual ~PolicyUI(); |
95 | 22 |
96 private: | 23 private: |
97 DISALLOW_COPY_AND_ASSIGN(PolicyUI); | 24 DISALLOW_COPY_AND_ASSIGN(PolicyUI); |
98 }; | 25 }; |
99 | 26 |
100 #endif // CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ | 27 #endif // CHROME_BROWSER_UI_WEBUI_POLICY_UI_H_ |
OLD | NEW |