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/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"
27 #if defined(OS_CHROMEOS)
28 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
29 #endif // defined(OS_CHROMEOS)
31 class AutocompleteController
;
32 class CloudPrintSetupHandler
;
33 class CustomHomePagesTableModel
;
34 class TemplateURLService
;
41 class PolicyChangeRegistrar
;
46 // Chrome browser options page UI handler.
47 class 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
,
55 public TemplateURLServiceObserver
{
57 BrowserOptionsHandler();
58 virtual ~BrowserOptionsHandler();
60 // OptionsPageUIHandler implementation.
61 virtual void GetLocalizedValues(base::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
;
68 // ProfileSyncServiceObserver implementation.
69 virtual void OnStateChanged() OVERRIDE
;
71 // ShellIntegration::DefaultWebClientObserver implementation.
72 virtual void SetDefaultWebClientUIState(
73 ShellIntegration::DefaultWebClientUIState state
) OVERRIDE
;
74 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE
;
76 // TemplateURLServiceObserver implementation.
77 virtual void OnTemplateURLServiceChanged() OVERRIDE
;
80 // content::NotificationObserver implementation.
81 virtual void Observe(int type
,
82 const content::NotificationSource
& source
,
83 const content::NotificationDetails
& details
) OVERRIDE
;
85 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
86 void OnCloudPrintPrefsChanged();
89 // SelectFileDialog::Listener implementation
90 virtual void FileSelected(const base::FilePath
& path
,
92 void* params
) OVERRIDE
;
94 #if defined(OS_CHROMEOS)
95 // PointerDeviceObserver::Observer implementation.
96 virtual void TouchpadExists(bool exists
) OVERRIDE
;
97 virtual void MouseExists(bool exists
) OVERRIDE
;
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
);
104 void UpdateSyncState();
106 // Will be called when the kSigninAllowed pref has changed.
107 void OnSigninAllowedPrefChange();
109 // Makes this the default browser. Called from WebUI.
110 void BecomeDefaultBrowser(const base::ListValue
* args
);
112 // Sets the search engine at the given index to be default. Called from WebUI.
113 void SetDefaultSearchEngine(const base::ListValue
* args
);
115 // Enables/disables auto-launching of Chrome on computer startup.
116 void ToggleAutoLaunch(const base::ListValue
* args
);
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
);
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
);
132 // Returns the string ID for the given default browser state.
133 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state
);
135 // Gets the current default browser state, and asynchronously reports it to
137 void UpdateDefaultBrowserState();
139 // Updates the UI with the given state for the default browser.
140 void SetDefaultBrowserUIString(int status_string_id
);
142 // Loads the possible default search engine list and reports it to the WebUI.
143 void AddTemplateUrlServiceObserver();
145 // Creates a list of dictionaries where each dictionary is of the form:
147 // name: "Profile Name",
148 // iconURL: "chrome://path/to/icon/image",
149 // filePath: "/path/to/profile/data/on/disk",
150 // isCurrentProfile: false
152 scoped_ptr
<base::ListValue
> GetProfilesInfoList();
154 // Sends an array of Profile objects to javascript.
155 void SendProfilesInfo();
157 // Deletes the given profile. Expects one argument:
158 // 0: profile file path (string)
159 void DeleteProfile(const base::ListValue
* args
);
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
);
167 #if defined(OS_CHROMEOS)
168 void UpdateAccountPicture();
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
);
176 // Callback for the "selectDownloadLocation" message. This will prompt the
177 // user for a destination folder using platform-specific APIs.
178 void HandleSelectDownloadLocation(const base::ListValue
* args
);
180 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
181 // remove all auto-open file-type settings.
182 void HandleAutoOpenButton(const base::ListValue
* args
);
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 base::ListValue
* args
);
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 base::ListValue
* args
);
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 base::ListValue
* args
);
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 base::ListValue
* args
);
202 // Callback for the "restartBrowser" message. Restores all tabs on restart.
203 void HandleRestartBrowser(const base::ListValue
* args
);
205 // Callback for "requestProfilesInfo" message.
206 void HandleRequestProfilesInfo(const base::ListValue
* args
);
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 base::ListValue
* args
);
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 base::ListValue
* args
);
220 #if defined(ENABLE_MDNS)
221 void ShowCloudPrintDevicesPage(const base::ListValue
* args
);
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 base::ListValue
* args
);
229 // Register localized values used by Cloud Print
230 void RegisterCloudPrintValues(base::DictionaryValue
* values
);
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 base::ListValue
* args
);
237 // Callback for the Disable Cloud Print button. This will sign out
239 void HandleDisableCloudPrintConnector(const base::ListValue
* args
);
241 // Pings the service to send us it's current notion of the enabled state.
242 void RefreshCloudPrintStatusFromService();
244 // Setup the enabled or disabled state of the cloud print connector
246 void SetupCloudPrintConnectorSection();
248 // Remove cloud print connector section if cloud print connector management
250 void RemoveCloudPrintConnectorSection();
251 #endif // defined(OS_CHROMEOS)
252 #endif // defined(ENABLE_FULL_PRINTING)
254 #if defined(OS_CHROMEOS)
255 // Opens the wallpaper manager component extension.
256 void HandleOpenWallpaperManager(const base::ListValue
* args
);
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
);
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
);
268 // Setup the visibility for the metrics reporting setting.
269 void SetupMetricsReportingSettingVisibility();
271 // Setup the visibility for the password generation setting.
272 void SetupPasswordGenerationSettingVisibility();
274 // Setup the font size selector control.
275 void SetupFontSizeSelector();
277 // Setup the page zoom selector control.
278 void SetupPageZoomSelector();
280 // Setup the visibility of the reset button.
281 void SetupAutoOpenFileTypes();
283 // Setup the proxy settings section UI.
284 void SetupProxySettingsSection();
286 // Setup the manage certificates section UI.
287 void SetupManageCertificatesSection();
289 // Setup the UI specific to managing supervised users.
290 void SetupManagingSupervisedUsers();
292 #if defined(OS_CHROMEOS)
293 // Setup the accessibility features for ChromeOS.
294 void SetupAccessibilityFeatures();
297 // Returns a newly created dictionary with a number of properties that
298 // correspond to the status of sync.
299 scoped_ptr
<base::DictionaryValue
> GetSyncStateDictionary();
301 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
303 bool page_initialized_
;
305 StringPrefMember homepage_
;
306 BooleanPrefMember default_browser_policy_
;
308 TemplateURLService
* template_url_service_
; // Weak.
310 scoped_refptr
<ui::SelectFileDialog
> select_folder_dialog_
;
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_
;
318 bool cloud_print_mdns_ui_enabled_
;
320 StringPrefMember auto_open_files_
;
321 DoublePrefMember default_zoom_level_
;
323 PrefChangeRegistrar profile_pref_registrar_
;
324 #if defined(OS_CHROMEOS)
325 scoped_ptr
<policy::PolicyChangeRegistrar
> policy_registrar_
;
328 // Used to get WeakPtr to self for use on the UI thread.
329 base::WeakPtrFactory
<BrowserOptionsHandler
> weak_ptr_factory_
;
331 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler
);
334 } // namespace options
336 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_