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