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