OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CORE_OPTIONS_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CORE_OPTIONS_HANDLER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/values.h" | |
12 #include "chrome/browser/plugin_status_pref_setter.h" | |
13 #include "chrome/browser/prefs/pref_change_registrar.h" | |
14 #include "chrome/browser/prefs/pref_service.h" | |
15 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
16 | |
17 namespace options { | |
18 | |
19 // Core options UI handler. | |
20 // Handles resource and JS calls common to all options sub-pages. | |
21 class CoreOptionsHandler : public OptionsPageUIHandler { | |
22 public: | |
23 CoreOptionsHandler(); | |
24 virtual ~CoreOptionsHandler(); | |
25 | |
26 // OptionsPageUIHandler implementation. | |
27 virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE; | |
28 virtual void InitializeHandler() OVERRIDE; | |
29 virtual void InitializePage() OVERRIDE; | |
30 virtual void Uninitialize() OVERRIDE; | |
31 | |
32 // content::NotificationObserver implementation. | |
33 virtual void Observe(int type, | |
34 const content::NotificationSource& source, | |
35 const content::NotificationDetails& details) OVERRIDE; | |
36 | |
37 // WebUIMessageHandler implementation. | |
38 virtual void RegisterMessages() OVERRIDE; | |
39 | |
40 void set_handlers_host(OptionsPageUIHandlerHost* handlers_host) { | |
41 handlers_host_ = handlers_host; | |
42 } | |
43 | |
44 // Adds localized strings to |localized_strings|. | |
45 static void GetStaticLocalizedValues( | |
46 base::DictionaryValue* localized_strings); | |
47 | |
48 protected: | |
49 // Fetches a pref value of given |pref_name|. | |
50 // Note that caller owns the returned Value. | |
51 virtual base::Value* FetchPref(const std::string& pref_name); | |
52 | |
53 // Observes a pref of given |pref_name|. | |
54 virtual void ObservePref(const std::string& pref_name); | |
55 | |
56 // Sets a pref |value| to given |pref_name|. | |
57 virtual void SetPref(const std::string& pref_name, | |
58 const base::Value* value, | |
59 const std::string& metric); | |
60 | |
61 // Clears pref value for given |pref_name|. | |
62 void ClearPref(const std::string& pref_name, const std::string& metric); | |
63 | |
64 // Stops observing given preference identified by |path|. | |
65 virtual void StopObservingPref(const std::string& path); | |
66 | |
67 // Records a user metric action for the given value. | |
68 void ProcessUserMetric(const base::Value* value, | |
69 const std::string& metric); | |
70 | |
71 // Notifies registered JS callbacks on change in |pref_name| preference. | |
72 // |controlling_pref_name| controls if |pref_name| is managed by | |
73 // policy/extension; empty |controlling_pref_name| indicates no other pref is | |
74 // controlling |pref_name|. | |
75 void NotifyPrefChanged(const std::string& pref_name, | |
76 const std::string& controlling_pref_name); | |
77 | |
78 // Calls JS callbacks to report a change in the value of the |name| | |
79 // preference. |value| is the new value for |name|. Called from | |
80 // Notify*Changed methods to fire off the notifications. | |
81 void DispatchPrefChangeNotification(const std::string& name, | |
82 scoped_ptr<base::Value> value); | |
83 | |
84 // Creates dictionary value for |pref|, |controlling_pref| controls if |pref| | |
85 // is managed by policy/extension; NULL indicates no other pref is controlling | |
86 // |pref|. | |
87 DictionaryValue* CreateValueForPref( | |
88 const PrefService::Preference* pref, | |
89 const PrefService::Preference* controlling_pref); | |
90 | |
91 typedef std::multimap<std::string, std::wstring> PreferenceCallbackMap; | |
92 PreferenceCallbackMap pref_callback_map_; | |
93 | |
94 private: | |
95 // Type of preference value received from the page. This doesn't map 1:1 to | |
96 // Value::Type, since a TYPE_STRING can require custom processing. | |
97 enum PrefType { | |
98 TYPE_BOOLEAN = 0, | |
99 TYPE_INTEGER, | |
100 TYPE_DOUBLE, | |
101 TYPE_STRING, | |
102 TYPE_URL, | |
103 TYPE_LIST, | |
104 }; | |
105 | |
106 // Callback for the "coreOptionsInitialize" message. This message will | |
107 // trigger the Initialize() method of all other handlers so that final | |
108 // setup can be performed before the page is shown. | |
109 void HandleInitialize(const ListValue* args); | |
110 | |
111 // Callback for the "fetchPrefs" message. This message accepts the list of | |
112 // preference names passed as the |args| parameter (ListValue). It passes | |
113 // results dictionary of preference values by calling prefsFetched() JS method | |
114 // on the page. | |
115 void HandleFetchPrefs(const ListValue* args); | |
116 | |
117 // Callback for the "observePrefs" message. This message initiates | |
118 // notification observing for given array of preference names. | |
119 void HandleObservePrefs(const ListValue* args); | |
120 | |
121 // Callbacks for the "set<type>Pref" message. This message saves the new | |
122 // preference value. |args| is an array of parameters as follows: | |
123 // item 0 - name of the preference. | |
124 // item 1 - the value of the preference in string form. | |
125 // item 2 - name of the metric identifier (optional). | |
126 void HandleSetBooleanPref(const ListValue* args); | |
127 void HandleSetIntegerPref(const ListValue* args); | |
128 void HandleSetDoublePref(const ListValue* args); | |
129 void HandleSetStringPref(const ListValue* args); | |
130 void HandleSetURLPref(const ListValue* args); | |
131 void HandleSetListPref(const ListValue* args); | |
132 | |
133 void HandleSetPref(const ListValue* args, PrefType type); | |
134 | |
135 // Callback for the "clearPref" message. This message clears a preference | |
136 // value. |args| is an array of parameters as follows: | |
137 // item 0 - name of the preference. | |
138 // item 1 - name of the metric identifier (optional). | |
139 void HandleClearPref(const ListValue* args); | |
140 | |
141 // Callback for the "coreOptionsUserMetricsAction" message. This records | |
142 // an action that should be tracked if metrics recording is enabled. |args| | |
143 // is an array that contains a single item, the name of the metric identifier. | |
144 void HandleUserMetricsAction(const ListValue* args); | |
145 | |
146 void UpdateClearPluginLSOData(); | |
147 void UpdatePepperFlashSettingsEnabled(); | |
148 | |
149 OptionsPageUIHandlerHost* handlers_host_; | |
150 PrefChangeRegistrar registrar_; | |
151 | |
152 PluginStatusPrefSetter plugin_status_pref_setter_; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); | |
155 }; | |
156 | |
157 } // namespace options | |
158 | |
159 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CORE_OPTIONS_HANDLER_H_ | |
OLD | NEW |