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