browser_options_handler.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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 <vector>
9
10#include "base/memory/ref_counted.h"
11#include "base/memory/scoped_ptr.h"
12#include "base/memory/weak_ptr.h"
13#include "base/prefs/pref_change_registrar.h"
14#include "base/prefs/pref_member.h"
15#include "chrome/browser/profiles/profile.h"
16#include "chrome/browser/search_engines/template_url_service_observer.h"
17#include "chrome/browser/shell_integration.h"
18#include "chrome/browser/sync/profile_sync_service_observer.h"
19#include "chrome/browser/ui/host_desktop.h"
20#include "chrome/browser/ui/webui/options/options_ui.h"
21#include "google_apis/gaia/google_service_auth_error.h"
22#include "ui/base/models/table_model_observer.h"
23#include "ui/shell_dialogs/select_file_dialog.h"
24
25#if defined(OS_CHROMEOS)
26#include "chrome/browser/chromeos/system/pointer_device_observer.h"
27#endif  // defined(OS_CHROMEOS)
28
29class AutocompleteController;
30class CloudPrintSetupHandler;
31class CustomHomePagesTableModel;
32class TemplateURLService;
33
34namespace options {
35
36// Chrome browser options page UI handler.
37class BrowserOptionsHandler
38    : public OptionsPageUIHandler,
39      public ProfileSyncServiceObserver,
40      public ui::SelectFileDialog::Listener,
41      public ShellIntegration::DefaultWebClientObserver,
42#if defined(OS_CHROMEOS)
43      public chromeos::system::PointerDeviceObserver::Observer,
44#endif
45      public TemplateURLServiceObserver {
46 public:
47  BrowserOptionsHandler();
48  virtual ~BrowserOptionsHandler();
49
50  // OptionsPageUIHandler implementation.
51  virtual void GetLocalizedValues(DictionaryValue* values) OVERRIDE;
52  virtual void PageLoadStarted() OVERRIDE;
53  virtual void InitializeHandler() OVERRIDE;
54  virtual void InitializePage() OVERRIDE;
55  virtual void RegisterMessages() OVERRIDE;
56
57  // ProfileSyncServiceObserver implementation.
58  virtual void OnStateChanged() OVERRIDE;
59
60  // ShellIntegration::DefaultWebClientObserver implementation.
61  virtual void SetDefaultWebClientUIState(
62      ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
63  virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
64
65  // TemplateURLServiceObserver implementation.
66  virtual void OnTemplateURLServiceChanged() OVERRIDE;
67
68 private:
69  // content::NotificationObserver implementation.
70  virtual void Observe(int type,
71                       const content::NotificationSource& source,
72                       const content::NotificationDetails& details) OVERRIDE;
73
74#if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
75  void OnCloudPrintPrefsChanged();
76#endif
77
78  // SelectFileDialog::Listener implementation
79  virtual void FileSelected(const base::FilePath& path,
80                            int index,
81                            void* params) OVERRIDE;
82
83#if defined(OS_CHROMEOS)
84  // PointerDeviceObserver::Observer implementation.
85  virtual void TouchpadExists(bool exists) OVERRIDE;
86  virtual void MouseExists(bool exists) OVERRIDE;
87#endif
88
89  void UpdateSyncState();
90
91  // Will be called when the kSigninAllowed pref has changed.
92  void OnSigninAllowedPrefChange();
93
94  // Makes this the default browser. Called from WebUI.
95  void BecomeDefaultBrowser(const base::ListValue* args);
96
97  // Sets the search engine at the given index to be default. Called from WebUI.
98  void SetDefaultSearchEngine(const base::ListValue* args);
99
100  // Enables/disables auto-launching of Chrome on computer startup.
101  void ToggleAutoLaunch(const base::ListValue* args);
102
103  // Checks (on the file thread) whether the user is in the auto-launch trial
104  // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
105  // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
106  // as a parameter to avoid the need to lock between this function and the
107  // destructor. |profile_path| is the full path to the current profile.
108  static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
109                              const base::FilePath& profile_path);
110
111  // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
112  // (if the user is part of the auto-launch and makes sure the HTML UI knows
113  // whether Chrome will auto-launch at login.
114  void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
115                               bool will_launch_at_login);
116
117  // Returns the string ID for the given default browser state.
118  int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
119
120  // Gets the current default browser state, and asynchronously reports it to
121  // the WebUI page.
122  void UpdateDefaultBrowserState();
123
124  // Updates the UI with the given state for the default browser.
125  void SetDefaultBrowserUIString(int status_string_id);
126
127  // Loads the possible default search engine list and reports it to the WebUI.
128  void AddTemplateUrlServiceObserver();
129
130  // Creates a list of dictionaries where each dictionary is of the form:
131  //   profileInfo = {
132  //     name: "Profile Name",
133  //     iconURL: "chrome://path/to/icon/image",
134  //     filePath: "/path/to/profile/data/on/disk",
135  //     isCurrentProfile: false
136  //   };
137  scoped_ptr<ListValue> GetProfilesInfoList();
138
139  // Sends an array of Profile objects to javascript.
140  void SendProfilesInfo();
141
142  // Deletes the given profile. Expects one argument:
143  //   0: profile file path (string)
144  void DeleteProfile(const base::ListValue* args);
145
146  void ObserveThemeChanged();
147  void ThemesReset(const base::ListValue* args);
148#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
149  void ThemesSetNative(const base::ListValue* args);
150#endif
151
152#if defined(OS_CHROMEOS)
153  void UpdateAccountPicture();
154#endif
155
156  // Callback for the "selectDownloadLocation" message. This will prompt the
157  // user for a destination folder using platform-specific APIs.
158  void HandleSelectDownloadLocation(const ListValue* args);
159
160  // Callback for the "autoOpenFileTypesResetToDefault" message. This will
161  // remove all auto-open file-type settings.
162  void HandleAutoOpenButton(const ListValue* args);
163
164  // Callback for the "defaultFontSizeAction" message. This is called if the
165  // user changes the default font size. |args| is an array that contains
166  // one item, the font size as a numeric value.
167  void HandleDefaultFontSize(const ListValue* args);
168
169  // Callback for the "defaultZoomFactorAction" message. This is called if the
170  // user changes the default zoom factor. |args| is an array that contains
171  // one item, the zoom factor as a numeric value.
172  void HandleDefaultZoomFactor(const ListValue* args);
173
174  // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
175  // the "Use SSL 3.0" checkbox.
176  void HandleUseSSL3Checkbox(const ListValue* args);
177
178  // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
179  // the "Use TLS 1.0" checkbox.
180  void HandleUseTLS1Checkbox(const ListValue* args);
181
182  // Callback for the "restartBrowser" message. Restores all tabs on restart.
183  void HandleRestartBrowser(const ListValue* args);
184
185  // Callback for "requestProfilesInfo" message.
186  void HandleRequestProfilesInfo(const ListValue* args);
187
188#if !defined(OS_CHROMEOS)
189  // Callback for the "showNetworkProxySettings" message. This will invoke
190  // an appropriate dialog for configuring proxy settings.
191  void ShowNetworkProxySettings(const ListValue* args);
192#endif
193
194#if !defined(USE_NSS)
195  // Callback for the "showManageSSLCertificates" message. This will invoke
196  // an appropriate certificate management action based on the platform.
197  void ShowManageSSLCertificates(const ListValue* args);
198#endif
199
200#if defined(ENABLE_MDNS)
201  void ShowCloudPrintDevicesPage(const ListValue* args);
202#endif
203
204#if defined(ENABLE_FULL_PRINTING)
205  // Callback for the Cloud Print manage button. This will open a new
206  // tab pointed at the management URL.
207  void ShowCloudPrintManagePage(const ListValue* args);
208
209  // Register localized values used by Cloud Print
210  void RegisterCloudPrintValues(DictionaryValue* values);
211
212#if !defined(OS_CHROMEOS)
213  // Callback for the Sign in to Cloud Print button. This will start
214  // the authentication process.
215  void ShowCloudPrintSetupDialog(const ListValue* args);
216
217  // Callback for the Disable Cloud Print button. This will sign out
218  // of cloud print.
219  void HandleDisableCloudPrintConnector(const ListValue* args);
220
221  // Pings the service to send us it's current notion of the enabled state.
222  void RefreshCloudPrintStatusFromService();
223
224  // Setup the enabled or disabled state of the cloud print connector
225  // management UI.
226  void SetupCloudPrintConnectorSection();
227
228  // Remove cloud print connector section if cloud print connector management
229  //  UI is disabled.
230  void RemoveCloudPrintConnectorSection();
231#endif  // defined(OS_CHROMEOS)
232#endif  // defined(ENABLE_FULL_PRINTING)
233
234#if defined(OS_CHROMEOS)
235  // Opens the wallpaper manager component extension.
236  void HandleOpenWallpaperManager(const base::ListValue* args);
237
238  // Called when the accessibility checkbox values are changed.
239  // |args| will contain the checkbox checked state as a string
240  // ("true" or "false").
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(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
290  StringPrefMember cloud_print_connector_email_;
291  BooleanPrefMember cloud_print_connector_enabled_;
292  bool cloud_print_connector_ui_enabled_;
293#endif
294
295  StringPrefMember auto_open_files_;
296  DoublePrefMember default_zoom_level_;
297
298  PrefChangeRegistrar profile_pref_registrar_;
299
300  DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
301};
302
303}  // namespace options
304
305#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
306