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 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ 7 #pragma once 8 9 #include <map> 10 #include <string> 11 12 #include "base/values.h" 13 #include "chrome/browser/plugin_data_remover_helper.h" 14 #include "chrome/browser/prefs/pref_change_registrar.h" 15 #include "chrome/browser/ui/webui/options/options_ui.h" 16 17 // Core options UI handler. 18 // Handles resource and JS calls common to all options sub-pages. 19 class CoreOptionsHandler : public OptionsPageUIHandler { 20 public: 21 CoreOptionsHandler(); 22 virtual ~CoreOptionsHandler(); 23 24 // OptionsPageUIHandler implementation. 25 virtual void Initialize(); 26 virtual void GetLocalizedValues(DictionaryValue* localized_strings); 27 virtual void Uninitialize(); 28 29 // NotificationObserver implementation. 30 virtual void Observe(NotificationType type, 31 const NotificationSource& source, 32 const NotificationDetails& details); 33 34 // WebUIMessageHandler implementation. 35 virtual void RegisterMessages(); 36 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 37 38 void set_handlers_host(OptionsPageUIHandlerHost* handlers_host) { 39 handlers_host_ = handlers_host; 40 } 41 42 protected: 43 // Fetches a pref value of given |pref_name|. 44 // Note that caller owns the returned Value. 45 virtual Value* FetchPref(const std::string& pref_name); 46 47 // Observes a pref of given |pref_name|. 48 virtual void ObservePref(const std::string& pref_name); 49 50 // Sets a pref |value| to given |pref_name|. 51 virtual void SetPref(const std::string& pref_name, 52 const Value* value, 53 const std::string& metric); 54 55 // Clears pref value for given |pref_name|. 56 void ClearPref(const std::string& pref_name, const std::string& metric); 57 58 // Stops observing given preference identified by |path|. 59 virtual void StopObservingPref(const std::string& path); 60 61 // Records a user metric action for the given value. 62 void ProcessUserMetric(const Value* value, 63 const std::string& metric); 64 65 typedef std::multimap<std::string, std::wstring> PreferenceCallbackMap; 66 PreferenceCallbackMap pref_callback_map_; 67 private: 68 // Callback for the "coreOptionsInitialize" message. This message will 69 // trigger the Initialize() method of all other handlers so that final 70 // setup can be performed before the page is shown. 71 void HandleInitialize(const ListValue* args); 72 73 // Callback for the "fetchPrefs" message. This message accepts the list of 74 // preference names passed as the |args| parameter (ListValue). It passes 75 // results dictionary of preference values by calling prefsFetched() JS method 76 // on the page. 77 void HandleFetchPrefs(const ListValue* args); 78 79 // Callback for the "observePrefs" message. This message initiates 80 // notification observing for given array of preference names. 81 void HandleObservePrefs(const ListValue* args); 82 83 // Callbacks for the "set<type>Pref" message. This message saves the new 84 // preference value. |args| is an array of parameters as follows: 85 // item 0 - name of the preference. 86 // item 1 - the value of the preference in string form. 87 // item 2 - name of the metric identifier (optional). 88 void HandleSetBooleanPref(const ListValue* args); 89 void HandleSetIntegerPref(const ListValue* args); 90 void HandleSetDoublePref(const ListValue* args); 91 void HandleSetStringPref(const ListValue* args); 92 void HandleSetListPref(const ListValue* args); 93 94 void HandleSetPref(const ListValue* args, Value::ValueType type); 95 96 // Callback for the "clearPref" message. This message clears a preference 97 // value. |args| is an array of parameters as follows: 98 // item 0 - name of the preference. 99 // item 1 - name of the metric identifier (optional). 100 void HandleClearPref(const ListValue* args); 101 102 // Callback for the "coreOptionsUserMetricsAction" message. This records 103 // an action that should be tracked if metrics recording is enabled. |args| 104 // is an array that contains a single item, the name of the metric identifier. 105 void HandleUserMetricsAction(const ListValue* args); 106 107 void UpdateClearPluginLSOData(); 108 109 void NotifyPrefChanged(const std::string* pref_name); 110 111 OptionsPageUIHandlerHost* handlers_host_; 112 PrefChangeRegistrar registrar_; 113 114 // Used for asynchronously updating the preference stating whether clearing 115 // LSO data is supported. 116 PluginDataRemoverHelper clear_plugin_lso_data_enabled_; 117 118 DISALLOW_COPY_AND_ASSIGN(CoreOptionsHandler); 119 }; 120 121 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CORE_OPTIONS_HANDLER_H_ 122