browser_options_handler.h revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
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 "base/time/time.h"
16#include "chrome/browser/profiles/profile.h"
17#include "chrome/browser/profiles/profile_manager.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 "ui/base/models/table_model_observer.h"
24#include "ui/shell_dialogs/select_file_dialog.h"
25
26#if defined(OS_CHROMEOS)
27#include "chrome/browser/chromeos/system/pointer_device_observer.h"
28#endif  // defined(OS_CHROMEOS)
29
30class AutocompleteController;
31class CloudPrintSetupHandler;
32class CustomHomePagesTableModel;
33class ManagedUserRegistrationUtility;
34class TemplateURLService;
35
36namespace options {
37
38// Chrome browser options page UI handler.
39class BrowserOptionsHandler
40    : public OptionsPageUIHandler,
41      public ProfileSyncServiceObserver,
42      public ui::SelectFileDialog::Listener,
43      public ShellIntegration::DefaultWebClientObserver,
44#if defined(OS_CHROMEOS)
45      public chromeos::system::PointerDeviceObserver::Observer,
46#endif
47      public TemplateURLServiceObserver {
48 public:
49  BrowserOptionsHandler();
50  virtual ~BrowserOptionsHandler();
51
52  // OptionsPageUIHandler implementation.
53  virtual void GetLocalizedValues(DictionaryValue* values) OVERRIDE;
54  virtual void PageLoadStarted() OVERRIDE;
55  virtual void InitializeHandler() OVERRIDE;
56  virtual void InitializePage() OVERRIDE;
57  virtual void RegisterMessages() OVERRIDE;
58
59  // ProfileSyncServiceObserver implementation.
60  virtual void OnStateChanged() OVERRIDE;
61
62  // ShellIntegration::DefaultWebClientObserver implementation.
63  virtual void SetDefaultWebClientUIState(
64      ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
65  virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
66
67  // TemplateURLServiceObserver implementation.
68  virtual void OnTemplateURLServiceChanged() OVERRIDE;
69
70 private:
71  // content::NotificationObserver implementation.
72  virtual void Observe(int type,
73                       const content::NotificationSource& source,
74                       const content::NotificationDetails& details) OVERRIDE;
75
76  void OnCloudPrintPrefsChanged();
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  // Returns the current desktop type.
143  chrome::HostDesktopType GetDesktopType();
144
145  // Asynchronously creates and initializes a new profile.
146  // The arguments are as follows:
147  //   0: name (string)
148  //   1: icon (string)
149  //   2: a flag stating whether we should create a profile desktop shortcut
150  //      (optional, boolean)
151  //   3: a flag stating whether the user should be managed (optional, boolean)
152  void CreateProfile(const base::ListValue* args);
153
154  // After a new managed-user profile has been created, registers the user with
155  // the management server.
156  void RegisterManagedUser(const ProfileManager::CreateCallback& callback,
157                           const std::string& managed_user_id,
158                           Profile* new_profile,
159                           Profile::CreateStatus status);
160
161  // Records UMA histograms relevant to profile creation.
162  void RecordProfileCreationMetrics(Profile::CreateStatus status);
163
164  // Updates the UI as the final task after a new profile has been created.
165  void ShowProfileCreationFeedback(
166      chrome::HostDesktopType desktop_type,
167      bool is_managed,
168      Profile* profile,
169      Profile::CreateStatus status);
170
171  // Deletes the given profile. Expects one argument:
172  //   0: profile file path (string)
173  void DeleteProfile(const base::ListValue* args);
174
175  // Deletes the profile at the given |file_path|.
176  void DeleteProfileAtPath(base::FilePath file_path);
177
178  // Cancels creation of a managed-user profile currently in progress, as
179  // indicated by profile_path_being_created_, removing the object and files
180  // and canceling managed-user registration. This is the handler for the
181  // "cancelCreateProfile" message. |args| is not used.
182  // TODO(pamg): Move all the profile-handling methods into a more appropriate
183  // class.
184  void HandleCancelProfileCreation(const base::ListValue* args);
185
186  // Internal implementation. This may safely be called whether profile creation
187  // or registration is in progress or not. |user_initiated| should be true if
188  // the cancellation was deliberately requested by the user, and false if it
189  // was caused implicitly, e.g. by shutting down the browser.
190  void CancelProfileRegistration(bool user_initiated);
191
192  void ObserveThemeChanged();
193  void ThemesReset(const base::ListValue* args);
194#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
195  void ThemesSetNative(const base::ListValue* args);
196#endif
197
198#if defined(OS_CHROMEOS)
199  void UpdateAccountPicture();
200#endif
201
202  // Callback for the "selectDownloadLocation" message. This will prompt the
203  // user for a destination folder using platform-specific APIs.
204  void HandleSelectDownloadLocation(const ListValue* args);
205
206  // Callback for the "autoOpenFileTypesResetToDefault" message. This will
207  // remove all auto-open file-type settings.
208  void HandleAutoOpenButton(const ListValue* args);
209
210  // Callback for the "defaultFontSizeAction" message. This is called if the
211  // user changes the default font size. |args| is an array that contains
212  // one item, the font size as a numeric value.
213  void HandleDefaultFontSize(const ListValue* args);
214
215  // Callback for the "defaultZoomFactorAction" message. This is called if the
216  // user changes the default zoom factor. |args| is an array that contains
217  // one item, the zoom factor as a numeric value.
218  void HandleDefaultZoomFactor(const ListValue* args);
219
220  // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
221  // the "Use SSL 3.0" checkbox.
222  void HandleUseSSL3Checkbox(const ListValue* args);
223
224  // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
225  // the "Use TLS 1.0" checkbox.
226  void HandleUseTLS1Checkbox(const ListValue* args);
227
228  // Callback for the "restartBrowser" message. Restores all tabs on restart.
229  void HandleRestartBrowser(const ListValue* args);
230
231#if !defined(OS_CHROMEOS)
232  // Callback for the "showNetworkProxySettings" message. This will invoke
233  // an appropriate dialog for configuring proxy settings.
234  void ShowNetworkProxySettings(const ListValue* args);
235#endif
236
237#if !defined(USE_NSS)
238  // Callback for the "showManageSSLCertificates" message. This will invoke
239  // an appropriate certificate management action based on the platform.
240  void ShowManageSSLCertificates(const ListValue* args);
241#endif
242
243  // Callback for the Cloud Print manage button. This will open a new
244  // tab pointed at the management URL.
245  void ShowCloudPrintManagePage(const ListValue* args);
246
247  // Register localized values used by Cloud Print
248  void RegisterCloudPrintValues(DictionaryValue* values);
249
250#if !defined(OS_CHROMEOS)
251  // Callback for the Sign in to Cloud Print button. This will start
252  // the authentication process.
253  void ShowCloudPrintSetupDialog(const ListValue* args);
254
255  // Callback for the Disable Cloud Print button. This will sign out
256  // of cloud print.
257  void HandleDisableCloudPrintConnector(const ListValue* args);
258
259  // Pings the service to send us it's current notion of the enabled state.
260  void RefreshCloudPrintStatusFromService();
261
262  // Setup the enabled or disabled state of the cloud print connector
263  // management UI.
264  void SetupCloudPrintConnectorSection();
265
266  // Remove cloud print connector section if cloud print connector management
267  //  UI is disabled.
268  void RemoveCloudPrintConnectorSection();
269#endif
270
271#if defined(OS_CHROMEOS)
272  // Opens the wallpaper manager component extension.
273  void HandleOpenWallpaperManager(const base::ListValue* args);
274
275  // Called when the accessibility checkbox values are changed.
276  // |args| will contain the checkbox checked state as a string
277  // ("true" or "false").
278  void VirtualKeyboardChangeCallback(const base::ListValue* args);
279
280  // Called when the user confirmed factory reset. Chrome will
281  // initiate asynchronous file operation and then log out.
282  void PerformFactoryResetRestart(const base::ListValue* args);
283#endif
284
285  // Setup the visibility for the metrics reporting setting.
286  void SetupMetricsReportingSettingVisibility();
287
288  // Setup the visibility for the password generation setting.
289  void SetupPasswordGenerationSettingVisibility();
290
291  // Setup the font size selector control.
292  void SetupFontSizeSelector();
293
294  // Setup the page zoom selector control.
295  void SetupPageZoomSelector();
296
297  // Setup the visibility of the reset button.
298  void SetupAutoOpenFileTypes();
299
300  // Setup the proxy settings section UI.
301  void SetupProxySettingsSection();
302
303#if defined(OS_CHROMEOS)
304  // Setup the accessibility features for ChromeOS.
305  void SetupAccessibilityFeatures();
306#endif
307
308  bool IsValidExistingManagedUserId(
309      const std::string& existing_managed_user_id) const;
310
311  // Returns a newly created dictionary with a number of properties that
312  // correspond to the status of sync.
313  scoped_ptr<DictionaryValue> GetSyncStateDictionary();
314
315  scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
316
317  bool page_initialized_;
318
319  StringPrefMember homepage_;
320  BooleanPrefMember default_browser_policy_;
321
322  TemplateURLService* template_url_service_;  // Weak.
323
324  // Used to allow cancelling a profile creation (particularly a managed-user
325  // registration) in progress. Set when profile creation is begun, and
326  // cleared when all the callbacks have been run and creation is complete.
327  base::FilePath profile_path_being_created_;
328
329  // Used to track how long profile creation takes.
330  base::TimeTicks profile_creation_start_time_;
331
332  // Used to get WeakPtr to self for use on the UI thread.
333  base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
334
335  scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
336
337#if !defined(OS_CHROMEOS)
338  StringPrefMember cloud_print_connector_email_;
339  BooleanPrefMember cloud_print_connector_enabled_;
340  bool cloud_print_connector_ui_enabled_;
341#endif
342
343  StringPrefMember auto_open_files_;
344  DoublePrefMember default_zoom_level_;
345
346  PrefChangeRegistrar profile_pref_registrar_;
347
348  scoped_ptr<ManagedUserRegistrationUtility> managed_user_registration_utility_;
349
350  DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
351};
352
353}  // namespace options
354
355#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
356