browser_options_handler.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/memory/weak_ptr.h"
11#include "base/prefs/pref_member.h"
12#include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h"
13#include "chrome/browser/profiles/profile.h"
14#include "chrome/browser/search_engines/template_url_service_observer.h"
15#include "chrome/browser/shell_integration.h"
16#include "chrome/browser/sync/profile_sync_service_observer.h"
17#include "chrome/browser/ui/webui/options/options_ui.h"
18#include "ui/base/models/table_model_observer.h"
19#include "ui/shell_dialogs/select_file_dialog.h"
20
21#if defined(OS_CHROMEOS)
22#include "chrome/browser/chromeos/system/pointer_device_observer.h"
23#else
24#include "base/prefs/pref_change_registrar.h"
25#endif  // defined(OS_CHROMEOS)
26
27class AutocompleteController;
28class CloudPrintSetupHandler;
29class CustomHomePagesTableModel;
30class TemplateURLService;
31
32namespace options {
33
34// Chrome browser options page UI handler.
35class BrowserOptionsHandler
36    : public OptionsPageUIHandler,
37      public CloudPrintSetupHandlerDelegate,
38      public ProfileSyncServiceObserver,
39      public ui::SelectFileDialog::Listener,
40      public ShellIntegration::DefaultWebClientObserver,
41#if defined(OS_CHROMEOS)
42      public chromeos::system::PointerDeviceObserver::Observer,
43#endif
44      public TemplateURLServiceObserver {
45 public:
46  BrowserOptionsHandler();
47  virtual ~BrowserOptionsHandler();
48
49  // OptionsPageUIHandler implementation.
50  virtual void GetLocalizedValues(DictionaryValue* values) OVERRIDE;
51  virtual void PageLoadStarted() OVERRIDE;
52  virtual void InitializeHandler() OVERRIDE;
53  virtual void InitializePage() OVERRIDE;
54  virtual void RegisterMessages() OVERRIDE;
55
56  // ProfileSyncServiceObserver implementation.
57  virtual void OnStateChanged() OVERRIDE;
58
59  // Will be called when the kSigninAllowed pref has changed.
60  void OnSigninAllowedPrefChange();
61
62  // Called whenever prefs::kSearchSuggestEnabled or the default search engine
63  // changes, so that we can update the state of the Instant pref checkbox.
64  void UpdateInstantCheckboxState();
65
66  // ShellIntegration::DefaultWebClientObserver implementation.
67  virtual void SetDefaultWebClientUIState(
68      ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
69  virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
70
71  // TemplateURLServiceObserver implementation.
72  virtual void OnTemplateURLServiceChanged() OVERRIDE;
73
74 private:
75  // content::NotificationObserver implementation.
76  virtual void Observe(int type,
77                       const content::NotificationSource& source,
78                       const content::NotificationDetails& details) OVERRIDE;
79
80  void OnCloudPrintPrefsChanged();
81
82  // SelectFileDialog::Listener implementation
83  virtual void FileSelected(const base::FilePath& path,
84                            int index,
85                            void* params) OVERRIDE;
86
87  // CloudPrintSetupHandler::Delegate implementation.
88  virtual void OnCloudPrintSetupClosed() OVERRIDE;
89
90#if defined(OS_CHROMEOS)
91  // PointerDeviceObserver::Observer implementation.
92  virtual void TouchpadExists(bool exists) OVERRIDE;
93  virtual void MouseExists(bool exists) OVERRIDE;
94#endif
95
96  // Makes this the default browser. Called from WebUI.
97  void BecomeDefaultBrowser(const base::ListValue* args);
98
99  // Sets the search engine at the given index to be default. Called from WebUI.
100  void SetDefaultSearchEngine(const base::ListValue* args);
101
102  // Enables/disables auto-launching of Chrome on computer startup.
103  void ToggleAutoLaunch(const base::ListValue* args);
104
105  // Checks (on the file thread) whether the user is in the auto-launch trial
106  // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
107  // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
108  // as a parameter to avoid the need to lock between this function and the
109  // destructor. |profile_path| is the full path to the current profile.
110  static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
111                              const base::FilePath& profile_path);
112
113  // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
114  // (if the user is part of the auto-launch and makes sure the HTML UI knows
115  // whether Chrome will auto-launch at login.
116  void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
117                               bool will_launch_at_login);
118
119  // Returns the string ID for the given default browser state.
120  int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
121
122  // Gets the current default browser state, and asynchronously reports it to
123  // the WebUI page.
124  void UpdateDefaultBrowserState();
125
126  // Updates the UI with the given state for the default browser.
127  void SetDefaultBrowserUIString(int status_string_id);
128
129  // Loads the possible default search engine list and reports it to the WebUI.
130  void AddTemplateUrlServiceObserver();
131
132  // Creates a list of dictionaries where each dictionary is of the form:
133  //   profileInfo = {
134  //     name: "Profile Name",
135  //     iconURL: "chrome://path/to/icon/image",
136  //     filePath: "/path/to/profile/data/on/disk",
137  //     isCurrentProfile: false
138  //   };
139  scoped_ptr<ListValue> GetProfilesInfoList();
140
141  // Sends an array of Profile objects to javascript.
142  void SendProfilesInfo();
143
144  // Asynchronously opens a new browser window to create a new profile.
145  // The arguments are as follows:
146  //   0: name (string)
147  //   1: icon (string)
148  //   2: a flag stating whether we should create a profile desktop shortcut
149  //      (optional, boolean)
150  //   3: a flag stating whether the user should be managed (optional, boolean)
151  void CreateProfile(const base::ListValue* args);
152
153  void ObserveThemeChanged();
154  void ThemesReset(const base::ListValue* args);
155#if defined(TOOLKIT_GTK)
156  void ThemesSetGTK(const base::ListValue* args);
157#endif
158
159#if defined(OS_CHROMEOS)
160  void UpdateAccountPicture();
161#endif
162
163  // Callback for the "selectDownloadLocation" message. This will prompt the
164  // user for a destination folder using platform-specific APIs.
165  void HandleSelectDownloadLocation(const ListValue* args);
166
167  // Callback for the "autoOpenFileTypesResetToDefault" message. This will
168  // remove all auto-open file-type settings.
169  void HandleAutoOpenButton(const ListValue* args);
170
171  // Callback for the "defaultFontSizeAction" message. This is called if the
172  // user changes the default font size. |args| is an array that contains
173  // one item, the font size as a numeric value.
174  void HandleDefaultFontSize(const ListValue* args);
175
176  // Callback for the "defaultZoomFactorAction" message. This is called if the
177  // user changes the default zoom factor. |args| is an array that contains
178  // one item, the zoom factor as a numeric value.
179  void HandleDefaultZoomFactor(const ListValue* args);
180
181  // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
182  // the "Use SSL 3.0" checkbox.
183  void HandleUseSSL3Checkbox(const ListValue* args);
184
185  // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
186  // the "Use TLS 1.0" checkbox.
187  void HandleUseTLS1Checkbox(const ListValue* args);
188
189  // Callback for the "restartBrowser" message. Restores all tabs on restart.
190  void HandleRestartBrowser(const ListValue* args);
191
192#if !defined(OS_CHROMEOS)
193  // Callback for the "showNetworkProxySettings" message. This will invoke
194  // an appropriate dialog for configuring proxy settings.
195  void ShowNetworkProxySettings(const ListValue* args);
196#endif
197
198#if !defined(USE_NSS)
199  // Callback for the "showManageSSLCertificates" message. This will invoke
200  // an appropriate certificate management action based on the platform.
201  void ShowManageSSLCertificates(const ListValue* args);
202#endif
203
204  // Callback for the Cloud Print manage button. This will open a new
205  // tab pointed at the management URL.
206  void ShowCloudPrintManagePage(const ListValue* args);
207
208  // Register localized values used by Cloud Print
209  void RegisterCloudPrintValues(DictionaryValue* values);
210
211#if !defined(OS_CHROMEOS)
212  // Callback for the Sign in to Cloud Print button. This will start
213  // the authentication process.
214  void ShowCloudPrintSetupDialog(const ListValue* args);
215
216  // Callback for the Disable Cloud Print button. This will sign out
217  // of cloud print.
218  void HandleDisableCloudPrintConnector(const ListValue* args);
219
220  // Pings the service to send us it's current notion of the enabled state.
221  void RefreshCloudPrintStatusFromService();
222
223  // Setup the enabled or disabled state of the cloud print connector
224  // management UI.
225  void SetupCloudPrintConnectorSection();
226
227  // Remove cloud print connector section if cloud print connector management
228  //  UI is disabled.
229  void RemoveCloudPrintConnectorSection();
230#endif
231
232#if defined(OS_CHROMEOS)
233  // Opens the wallpaper manager component extension.
234  void HandleOpenWallpaperManager(const base::ListValue* args);
235
236  // Called when the accessibility checkbox values are changed.
237  // |args| will contain the checkbox checked state as a string
238  // ("true" or "false").
239  void SpokenFeedbackChangeCallback(const base::ListValue* args);
240  void HighContrastChangeCallback(const base::ListValue* args);
241  void VirtualKeyboardChangeCallback(const base::ListValue* args);
242
243  // Called when the user confirmed factory reset. Chrome will
244  // initiate asynchronous file operation and then log out.
245  void PerformFactoryResetRestart(const base::ListValue* args);
246#endif
247
248  // Setup the visibility for the metrics reporting setting.
249  void SetupMetricsReportingSettingVisibility();
250
251  // Setup the visibility for the password generation setting.
252  void SetupPasswordGenerationSettingVisibility();
253
254  // Setup the font size selector control.
255  void SetupFontSizeSelector();
256
257  // Setup the page zoom selector control.
258  void SetupPageZoomSelector();
259
260  // Setup the visibility of the reset button.
261  void SetupAutoOpenFileTypes();
262
263  // Setup the proxy settings section UI.
264  void SetupProxySettingsSection();
265
266#if defined(OS_CHROMEOS)
267  // Setup the accessibility features for ChromeOS.
268  void SetupAccessibilityFeatures();
269#endif
270
271  // Returns a newly created dictionary with a number of properties that
272  // correspond to the status of sync.
273  scoped_ptr<DictionaryValue> GetSyncStateDictionary();
274
275  scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
276
277  bool page_initialized_;
278
279  StringPrefMember homepage_;
280  BooleanPrefMember default_browser_policy_;
281
282  TemplateURLService* template_url_service_;  // Weak.
283
284  // Used to get WeakPtr to self for use on the UI thread.
285  base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
286
287  scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
288
289#if !defined(OS_CHROMEOS)
290  StringPrefMember cloud_print_connector_email_;
291  BooleanPrefMember cloud_print_connector_enabled_;
292  bool cloud_print_connector_ui_enabled_;
293  scoped_ptr<CloudPrintSetupHandler> cloud_print_setup_handler_;
294#endif
295
296  StringPrefMember auto_open_files_;
297  DoublePrefMember default_zoom_level_;
298
299  PrefChangeRegistrar profile_pref_registrar_;
300
301  DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
302};
303
304}  // namespace options
305
306#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
307