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