Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / core_options_handler.h
blob28045903ec1c1695e43053257db78d89b380895d
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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_
8 #include <map>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/values.h"
15 #include "chrome/browser/plugins/plugin_status_pref_setter.h"
16 #include "chrome/browser/ui/webui/options/options_ui.h"
18 namespace options {
20 // Core options UI handler.
21 // Handles resource and JS calls common to all options sub-pages.
22 class CoreOptionsHandler : public OptionsPageUIHandler {
23 public:
24 CoreOptionsHandler();
25 virtual ~CoreOptionsHandler();
27 // OptionsPageUIHandler implementation.
28 virtual void GetLocalizedValues(
29 base::DictionaryValue* localized_strings) OVERRIDE;
30 virtual void InitializeHandler() OVERRIDE;
31 virtual void InitializePage() OVERRIDE;
32 virtual void Uninitialize() OVERRIDE;
34 // WebUIMessageHandler implementation.
35 virtual void RegisterMessages() OVERRIDE;
37 void set_handlers_host(OptionsPageUIHandlerHost* handlers_host) {
38 handlers_host_ = handlers_host;
41 // Adds localized strings to |localized_strings|.
42 static void GetStaticLocalizedValues(
43 base::DictionaryValue* localized_strings);
45 protected:
46 // Fetches a pref value of given |pref_name|.
47 // Note that caller owns the returned Value.
48 virtual base::Value* FetchPref(const std::string& pref_name);
50 // Observes a pref of given |pref_name|.
51 virtual void ObservePref(const std::string& pref_name);
53 // Stops observing given preference identified by |pref_name|.
54 virtual void StopObservingPref(const std::string& pref_name);
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);
61 // Clears pref value for given |pref_name|.
62 void ClearPref(const std::string& pref_name, const std::string& metric);
64 // Records a user metric action for the given value.
65 void ProcessUserMetric(const base::Value* value,
66 const std::string& metric);
68 // Virtual dispatch is needed as handling of some prefs may be
69 // finessed in subclasses. The PrefService pointer is included
70 // so that subclasses can know whether the observed pref is from the
71 // local state or not.
72 virtual void OnPreferenceChanged(PrefService* service,
73 const std::string& pref_name);
75 // Notifies registered JS callbacks on change in |pref_name| preference.
76 // |controlling_pref_name| controls if |pref_name| is managed by
77 // policy/extension; empty |controlling_pref_name| indicates no other pref is
78 // controlling |pref_name|.
79 void NotifyPrefChanged(const std::string& pref_name,
80 const std::string& controlling_pref_name);
82 // Calls JS callbacks to report a change in the value of the |name|
83 // preference. |value| is the new value for |name|. Called from
84 // Notify*Changed methods to fire off the notifications.
85 void DispatchPrefChangeNotification(const std::string& name,
86 scoped_ptr<base::Value> value);
88 // Creates dictionary value for the pref described by |pref_name|.
89 // If |controlling_pref| is not empty, it describes the pref that manages
90 // |pref| via policy or extension.
91 base::Value* CreateValueForPref(const std::string& pref_name,
92 const std::string& controlling_pref_name);
94 typedef std::multimap<std::string, std::string> PreferenceCallbackMap;
95 PreferenceCallbackMap pref_callback_map_;
97 private:
98 // Type of preference value received from the page. This doesn't map 1:1 to
99 // Value::Type, since a TYPE_STRING can require custom processing.
100 enum PrefType {
101 TYPE_BOOLEAN = 0,
102 TYPE_INTEGER,
103 TYPE_DOUBLE,
104 TYPE_STRING,
105 TYPE_URL,
106 TYPE_LIST,
109 // Finds the pref service that holds the given pref. If the pref is not found,
110 // it will return user prefs.
111 PrefService* FindServiceForPref(const std::string& pref_name);
113 // Callback for the "coreOptionsInitialize" message. This message will
114 // trigger the Initialize() method of all other handlers so that final
115 // setup can be performed before the page is shown.
116 void HandleInitialize(const base::ListValue* args);
118 // Callback for the "fetchPrefs" message. This message accepts the list of
119 // preference names passed as the |args| parameter (ListValue). It passes
120 // results dictionary of preference values by calling prefsFetched() JS method
121 // on the page.
122 void HandleFetchPrefs(const base::ListValue* args);
124 // Callback for the "observePrefs" message. This message initiates
125 // notification observing for given array of preference names.
126 void HandleObservePrefs(const base::ListValue* args);
128 // Callbacks for the "set<type>Pref" message. This message saves the new
129 // preference value. |args| is an array of parameters as follows:
130 // item 0 - name of the preference.
131 // item 1 - the value of the preference in string form.
132 // item 2 - name of the metric identifier (optional).
133 void HandleSetBooleanPref(const base::ListValue* args);
134 void HandleSetIntegerPref(const base::ListValue* args);
135 void HandleSetDoublePref(const base::ListValue* args);
136 void HandleSetStringPref(const base::ListValue* args);
137 void HandleSetURLPref(const base::ListValue* args);
138 void HandleSetListPref(const base::ListValue* args);
140 void HandleSetPref(const base::ListValue* args, PrefType type);
142 // Callback for the "clearPref" message. This message clears a preference
143 // value. |args| is an array of parameters as follows:
144 // item 0 - name of the preference.
145 // item 1 - name of the metric identifier (optional).
146 void HandleClearPref(const base::ListValue* args);
148 // Callback for the "coreOptionsUserMetricsAction" message. This records
149 // an action that should be tracked if metrics recording is enabled. |args|
150 // is an array that contains a single item, the name of the metric identifier.
151 void HandleUserMetricsAction(const base::ListValue* args);
153 // Callback for the "disableExtension" message. The extension ID string is the
154 // only argument in the |args| list.
155 void HandleDisableExtension(const base::ListValue* args);
157 void UpdateClearPluginLSOData();
158 void UpdatePepperFlashSettingsEnabled();
160 OptionsPageUIHandlerHost* handlers_host_;
161 // This registrar keeps track of user prefs.
162 PrefChangeRegistrar registrar_;
163 // This registrar keeps track of local state.
164 PrefChangeRegistrar local_state_registrar_;
166 PluginStatusPrefSetter plugin_status_pref_setter_;
168 // This maps pref names to filter functions. The callbacks should take the
169 // value that the user has attempted to set for the pref, and should return
170 // true if that value may be applied. If the return value is false, the
171 // change will be ignored.
172 typedef std::map<std::string, base::Callback<bool(const base::Value*)> >
173 PrefChangeFilterMap;
174 PrefChangeFilterMap pref_change_filters_;
176 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler);
179 } // namespace options
181 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_