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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
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"
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
27 #endif // defined(OS_CHROMEOS)
29 class AutocompleteController;
30 class CloudPrintSetupHandler;
31 class CustomHomePagesTableModel;
32 class TemplateURLService;
36 // Chrome browser options page UI handler.
37 class 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,
45 public TemplateURLServiceObserver {
47 BrowserOptionsHandler();
48 virtual ~BrowserOptionsHandler();
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 virtual void Uninitialize() OVERRIDE;
58 // ProfileSyncServiceObserver implementation.
59 virtual void OnStateChanged() OVERRIDE;
61 // ShellIntegration::DefaultWebClientObserver implementation.
62 virtual void SetDefaultWebClientUIState(
63 ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
64 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
66 // TemplateURLServiceObserver implementation.
67 virtual void OnTemplateURLServiceChanged() OVERRIDE;
70 // content::NotificationObserver implementation.
71 virtual void Observe(int type,
72 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE;
75 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
76 void OnCloudPrintPrefsChanged();
79 // SelectFileDialog::Listener implementation
80 virtual void FileSelected(const base::FilePath& path,
82 void* params) OVERRIDE;
84 #if defined(OS_CHROMEOS)
85 // PointerDeviceObserver::Observer implementation.
86 virtual void TouchpadExists(bool exists) OVERRIDE;
87 virtual void MouseExists(bool exists) OVERRIDE;
90 void UpdateSyncState();
92 // Will be called when the kSigninAllowed pref has changed.
93 void OnSigninAllowedPrefChange();
95 // Makes this the default browser. Called from WebUI.
96 void BecomeDefaultBrowser(const base::ListValue* args);
98 // Sets the search engine at the given index to be default. Called from WebUI.
99 void SetDefaultSearchEngine(const base::ListValue* args);
101 // Enables/disables auto-launching of Chrome on computer startup.
102 void ToggleAutoLaunch(const base::ListValue* args);
104 // Checks (on the file thread) whether the user is in the auto-launch trial
105 // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
106 // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
107 // as a parameter to avoid the need to lock between this function and the
108 // destructor. |profile_path| is the full path to the current profile.
109 static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
110 const base::FilePath& profile_path);
112 // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
113 // (if the user is part of the auto-launch and makes sure the HTML UI knows
114 // whether Chrome will auto-launch at login.
115 void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
116 bool will_launch_at_login);
118 // Returns the string ID for the given default browser state.
119 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
121 // Gets the current default browser state, and asynchronously reports it to
123 void UpdateDefaultBrowserState();
125 // Updates the UI with the given state for the default browser.
126 void SetDefaultBrowserUIString(int status_string_id);
128 // Loads the possible default search engine list and reports it to the WebUI.
129 void AddTemplateUrlServiceObserver();
131 // Creates a list of dictionaries where each dictionary is of the form:
133 // name: "Profile Name",
134 // iconURL: "chrome://path/to/icon/image",
135 // filePath: "/path/to/profile/data/on/disk",
136 // isCurrentProfile: false
138 scoped_ptr<ListValue> GetProfilesInfoList();
140 // Sends an array of Profile objects to javascript.
141 void SendProfilesInfo();
143 // Deletes the given profile. Expects one argument:
144 // 0: profile file path (string)
145 void DeleteProfile(const base::ListValue* args);
147 void ObserveThemeChanged();
148 void ThemesReset(const base::ListValue* args);
149 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
150 void ThemesSetNative(const base::ListValue* args);
153 #if defined(OS_CHROMEOS)
154 void UpdateAccountPicture();
157 // Callback for the "selectDownloadLocation" message. This will prompt the
158 // user for a destination folder using platform-specific APIs.
159 void HandleSelectDownloadLocation(const ListValue* args);
161 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
162 // remove all auto-open file-type settings.
163 void HandleAutoOpenButton(const ListValue* args);
165 // Callback for the "defaultFontSizeAction" message. This is called if the
166 // user changes the default font size. |args| is an array that contains
167 // one item, the font size as a numeric value.
168 void HandleDefaultFontSize(const ListValue* args);
170 // Callback for the "defaultZoomFactorAction" message. This is called if the
171 // user changes the default zoom factor. |args| is an array that contains
172 // one item, the zoom factor as a numeric value.
173 void HandleDefaultZoomFactor(const ListValue* args);
175 // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
176 // the "Use SSL 3.0" checkbox.
177 void HandleUseSSL3Checkbox(const ListValue* args);
179 // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
180 // the "Use TLS 1.0" checkbox.
181 void HandleUseTLS1Checkbox(const ListValue* args);
183 // Callback for the "restartBrowser" message. Restores all tabs on restart.
184 void HandleRestartBrowser(const ListValue* args);
186 // Callback for "requestProfilesInfo" message.
187 void HandleRequestProfilesInfo(const ListValue* args);
189 #if !defined(OS_CHROMEOS)
190 // Callback for the "showNetworkProxySettings" message. This will invoke
191 // an appropriate dialog for configuring proxy settings.
192 void ShowNetworkProxySettings(const ListValue* args);
195 #if !defined(USE_NSS)
196 // Callback for the "showManageSSLCertificates" message. This will invoke
197 // an appropriate certificate management action based on the platform.
198 void ShowManageSSLCertificates(const ListValue* args);
201 #if defined(ENABLE_MDNS)
202 void ShowCloudPrintDevicesPage(const ListValue* args);
205 #if defined(ENABLE_FULL_PRINTING)
206 // Callback for the Cloud Print manage button. This will open a new
207 // tab pointed at the management URL.
208 void ShowCloudPrintManagePage(const ListValue* args);
210 // Register localized values used by Cloud Print
211 void RegisterCloudPrintValues(DictionaryValue* values);
213 #if !defined(OS_CHROMEOS)
214 // Callback for the Sign in to Cloud Print button. This will start
215 // the authentication process.
216 void ShowCloudPrintSetupDialog(const ListValue* args);
218 // Callback for the Disable Cloud Print button. This will sign out
220 void HandleDisableCloudPrintConnector(const ListValue* args);
222 // Pings the service to send us it's current notion of the enabled state.
223 void RefreshCloudPrintStatusFromService();
225 // Setup the enabled or disabled state of the cloud print connector
227 void SetupCloudPrintConnectorSection();
229 // Remove cloud print connector section if cloud print connector management
231 void RemoveCloudPrintConnectorSection();
232 #endif // defined(OS_CHROMEOS)
233 #endif // defined(ENABLE_FULL_PRINTING)
235 #if defined(OS_CHROMEOS)
236 // Opens the wallpaper manager component extension.
237 void HandleOpenWallpaperManager(const base::ListValue* args);
239 // Called when the accessibility checkbox values are changed.
240 // |args| will contain the checkbox checked state as a string
241 // ("true" or "false").
242 void VirtualKeyboardChangeCallback(const base::ListValue* args);
244 // Called when the user confirmed factory reset. Chrome will
245 // initiate asynchronous file operation and then log out.
246 void PerformFactoryResetRestart(const base::ListValue* args);
249 // Setup the visibility for the metrics reporting setting.
250 void SetupMetricsReportingSettingVisibility();
252 // Setup the visibility for the password generation setting.
253 void SetupPasswordGenerationSettingVisibility();
255 // Setup the font size selector control.
256 void SetupFontSizeSelector();
258 // Setup the page zoom selector control.
259 void SetupPageZoomSelector();
261 // Setup the visibility of the reset button.
262 void SetupAutoOpenFileTypes();
264 // Setup the proxy settings section UI.
265 void SetupProxySettingsSection();
267 // Setup the UI specific to managing supervised users.
268 void SetupManagingSupervisedUsers();
270 #if defined(OS_CHROMEOS)
271 // Setup the accessibility features for ChromeOS.
272 void SetupAccessibilityFeatures();
275 // Returns a newly created dictionary with a number of properties that
276 // correspond to the status of sync.
277 scoped_ptr<DictionaryValue> GetSyncStateDictionary();
279 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
281 bool page_initialized_;
283 StringPrefMember homepage_;
284 BooleanPrefMember default_browser_policy_;
286 TemplateURLService* template_url_service_; // Weak.
288 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
290 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
291 StringPrefMember cloud_print_connector_email_;
292 BooleanPrefMember cloud_print_connector_enabled_;
293 bool cloud_print_connector_ui_enabled_;
296 bool cloud_print_mdns_ui_enabled_;
298 StringPrefMember auto_open_files_;
299 DoublePrefMember default_zoom_level_;
301 PrefChangeRegistrar profile_pref_registrar_;
303 // Used to get WeakPtr to self for use on the UI thread.
304 base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
306 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
309 } // namespace options
311 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_