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 "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"
30 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
32 #endif // defined(OS_CHROMEOS)
34 class AutocompleteController
;
35 class CloudPrintSetupHandler
;
36 class CustomHomePagesTableModel
;
37 class TemplateURLService
;
44 class PolicyChangeRegistrar
;
49 // Chrome browser options page UI handler.
50 class 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
,
59 public TemplateURLServiceObserver
,
60 public content::NotificationObserver
{
62 BrowserOptionsHandler();
63 virtual ~BrowserOptionsHandler();
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
;
73 // ProfileSyncServiceObserver implementation.
74 virtual void OnStateChanged() OVERRIDE
;
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
;
81 // ShellIntegration::DefaultWebClientObserver implementation.
82 virtual void SetDefaultWebClientUIState(
83 ShellIntegration::DefaultWebClientUIState state
) OVERRIDE
;
84 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE
;
86 // TemplateURLServiceObserver implementation.
87 virtual void OnTemplateURLServiceChanged() OVERRIDE
;
90 // content::NotificationObserver implementation.
91 virtual void Observe(int type
,
92 const content::NotificationSource
& source
,
93 const content::NotificationDetails
& details
) OVERRIDE
;
95 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
96 void OnCloudPrintPrefsChanged();
99 // SelectFileDialog::Listener implementation
100 virtual void FileSelected(const base::FilePath
& path
,
102 void* params
) OVERRIDE
;
104 #if defined(OS_CHROMEOS)
105 // PointerDeviceObserver::Observer implementation.
106 virtual void TouchpadExists(bool exists
) OVERRIDE
;
107 virtual void MouseExists(bool exists
) OVERRIDE
;
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
);
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
);
117 // Will be called when powerwash dialog is shown.
118 void OnPowerwashDialogShow(const base::ListValue
* args
);
121 void UpdateSyncState();
123 // Will be called when the kSigninAllowed pref has changed.
124 void OnSigninAllowedPrefChange();
126 // Makes this the default browser. Called from WebUI.
127 void BecomeDefaultBrowser(const base::ListValue
* args
);
129 // Sets the search engine at the given index to be default. Called from WebUI.
130 void SetDefaultSearchEngine(const base::ListValue
* args
);
132 // Enables/disables auto-launching of Chrome on computer startup.
133 void ToggleAutoLaunch(const base::ListValue
* args
);
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
);
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
);
149 // Returns the string ID for the given default browser state.
150 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state
);
152 // Returns if the "make Chrome default browser" button should be shown.
153 bool ShouldShowSetDefaultBrowser();
155 // Returns if profiles list should be shown on settings page.
156 bool ShouldShowMultiProfilesUserList();
158 // Returns if access to advanced settings should be allowed.
159 bool ShouldAllowAdvancedSettings();
161 // Gets the current default browser state, and asynchronously reports it to
163 void UpdateDefaultBrowserState();
165 // Updates the UI with the given state for the default browser.
166 void SetDefaultBrowserUIString(int status_string_id
);
168 // Loads the possible default search engine list and reports it to the WebUI.
169 void AddTemplateUrlServiceObserver();
171 // Creates a list of dictionaries where each dictionary is of the form:
173 // name: "Profile Name",
174 // iconURL: "chrome://path/to/icon/image",
175 // filePath: "/path/to/profile/data/on/disk",
176 // isCurrentProfile: false
178 scoped_ptr
<base::ListValue
> GetProfilesInfoList();
180 // Sends an array of Profile objects to javascript.
181 void SendProfilesInfo();
183 // Deletes the given profile. Expects one argument:
184 // 0: profile file path (string)
185 void DeleteProfile(const base::ListValue
* args
);
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
);
193 #if defined(OS_CHROMEOS)
194 void UpdateAccountPicture();
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
);
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
204 void OnWallpaperManagedChanged(bool managed
);
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
);
211 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
212 // remove all auto-open file-type settings.
213 void HandleAutoOpenButton(const base::ListValue
* args
);
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
);
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
);
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
);
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
);
233 // Callback for the "restartBrowser" message. Restores all tabs on restart.
234 void HandleRestartBrowser(const base::ListValue
* args
);
236 // Callback for "requestProfilesInfo" message.
237 void HandleRequestProfilesInfo(const base::ListValue
* args
);
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
);
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
);
251 #if defined(ENABLE_SERVICE_DISCOVERY)
252 void ShowCloudPrintDevicesPage(const base::ListValue
* args
);
255 #if defined(ENABLE_FULL_PRINTING)
256 // Register localized values used by Cloud Print
257 void RegisterCloudPrintValues(base::DictionaryValue
* values
);
260 // Check if hotword is available. If it is, tell the javascript to show
261 // the hotword section of the settings page.
262 void SendHotwordAvailable();
264 // Callback for "requestHotwordAvailable" message.
265 void HandleRequestHotwordAvailable(const base::ListValue
* args
);
267 // Callback for "requestHotwordSetupRetry" message.
268 void HandleRequestHotwordSetupRetry(const base::ListValue
* args
);
270 // Callback for "launchEasyUnlockSetup" message.
271 void HandleLaunchEasyUnlockSetup(const base::ListValue
* args
);
273 #if defined(OS_CHROMEOS)
274 // Opens the wallpaper manager component extension.
275 void HandleOpenWallpaperManager(const base::ListValue
* args
);
277 // Called when the accessibility checkbox values are changed.
278 // |args| will contain the checkbox checked state as a string
279 // ("true" or "false").
280 void VirtualKeyboardChangeCallback(const base::ListValue
* args
);
282 // Called when the user confirmed factory reset. Chrome will
283 // initiate asynchronous file operation and then log out.
284 void PerformFactoryResetRestart(const base::ListValue
* args
);
287 // Setup the visibility for the metrics reporting setting.
288 void SetupMetricsReportingSettingVisibility();
290 // Setup the font size selector control.
291 void SetupFontSizeSelector();
293 // Setup the page zoom selector control.
294 void SetupPageZoomSelector();
296 // Setup the visibility of the reset button.
297 void SetupAutoOpenFileTypes();
299 // Setup the proxy settings section UI.
300 void SetupProxySettingsSection();
302 // Setup the manage certificates section UI.
303 void SetupManageCertificatesSection();
305 // Setup the UI specific to managing supervised users.
306 void SetupManagingSupervisedUsers();
308 // Setup the UI for Easy Unlock.
309 void SetupEasyUnlock();
312 // Setup the UI for showing which settings are extension controlled.
313 void SetupExtensionControlledIndicators(const base::ListValue
* args
);
316 #if defined(OS_CHROMEOS)
317 // Setup the accessibility features for ChromeOS.
318 void SetupAccessibilityFeatures();
321 // Returns a newly created dictionary with a number of properties that
322 // correspond to the status of sync.
323 scoped_ptr
<base::DictionaryValue
> GetSyncStateDictionary();
325 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
327 bool page_initialized_
;
329 StringPrefMember homepage_
;
330 BooleanPrefMember default_browser_policy_
;
332 TemplateURLService
* template_url_service_
; // Weak.
334 scoped_refptr
<ui::SelectFileDialog
> select_folder_dialog_
;
336 bool cloud_print_mdns_ui_enabled_
;
338 StringPrefMember auto_open_files_
;
339 DoublePrefMember default_zoom_level_
;
341 PrefChangeRegistrar profile_pref_registrar_
;
342 #if defined(OS_CHROMEOS)
343 scoped_ptr
<policy::PolicyChangeRegistrar
> policy_registrar_
;
346 ScopedObserver
<SigninManagerBase
, SigninManagerBase::Observer
>
349 // Used to get WeakPtr to self for use on the UI thread.
350 base::WeakPtrFactory
<BrowserOptionsHandler
> weak_ptr_factory_
;
352 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler
);
355 } // namespace options
357 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_