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/profiles/profile_info_cache_observer.h"
20 #include "chrome/browser/shell_integration.h"
21 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/browser/ui/webui/options/options_ui.h"
23 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
24 #include "components/policy/core/common/policy_service.h"
25 #include "components/search_engines/template_url_service_observer.h"
26 #include "components/signin/core/browser/signin_manager_base.h"
27 #include "components/sync_driver/sync_service_observer.h"
28 #include "content/public/browser/notification_observer.h"
29 #include "extensions/browser/extension_registry_observer.h"
30 #include "google_apis/gaia/google_service_auth_error.h"
31 #include "ui/base/models/table_model_observer.h"
32 #include "ui/shell_dialogs/select_file_dialog.h"
34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
36 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
37 #endif // defined(OS_CHROMEOS)
39 class AutocompleteController
;
40 class CloudPrintSetupHandler
;
41 class CustomHomePagesTableModel
;
42 class TemplateURLService
;
49 class PolicyChangeRegistrar
;
54 // Chrome browser options page UI handler.
55 class BrowserOptionsHandler
56 : public OptionsPageUIHandler
,
57 public ProfileInfoCacheObserver
,
58 public sync_driver::SyncServiceObserver
,
59 public SigninManagerBase::Observer
,
60 public ui::SelectFileDialog::Listener
,
61 public ShellIntegration::DefaultWebClientObserver
,
62 #if defined(OS_CHROMEOS)
63 public chromeos::system::PointerDeviceObserver::Observer
,
64 public policy::ConsumerManagementService::Observer
,
66 public TemplateURLServiceObserver
,
67 public extensions::ExtensionRegistryObserver
,
68 public content::NotificationObserver
,
69 public policy::PolicyService::Observer
{
71 BrowserOptionsHandler();
72 ~BrowserOptionsHandler() override
;
74 // OptionsPageUIHandler implementation.
75 void GetLocalizedValues(base::DictionaryValue
* values
) override
;
76 void PageLoadStarted() override
;
77 void InitializeHandler() override
;
78 void InitializePage() override
;
79 void RegisterMessages() override
;
80 void Uninitialize() override
;
82 // sync_driver::SyncServiceObserver implementation.
83 void OnStateChanged() override
;
85 // SigninManagerBase::Observer implementation.
86 void GoogleSigninSucceeded(const std::string
& account_id
,
87 const std::string
& username
,
88 const std::string
& password
) override
;
89 void GoogleSignedOut(const std::string
& account_id
,
90 const std::string
& username
) override
;
92 // ShellIntegration::DefaultWebClientObserver implementation.
93 void SetDefaultWebClientUIState(
94 ShellIntegration::DefaultWebClientUIState state
) override
;
95 bool IsInteractiveSetDefaultPermitted() override
;
97 // TemplateURLServiceObserver implementation.
98 void OnTemplateURLServiceChanged() override
;
100 // extensions::ExtensionRegistryObserver:
101 void OnExtensionLoaded(content::BrowserContext
* browser_context
,
102 const extensions::Extension
* extension
) override
;
103 void OnExtensionUnloaded(
104 content::BrowserContext
* browser_context
,
105 const extensions::Extension
* extension
,
106 extensions::UnloadedExtensionInfo::Reason reason
) override
;
108 // policy::PolicyService::Observer:
109 void OnPolicyUpdated(const policy::PolicyNamespace
& ns
,
110 const policy::PolicyMap
& previous
,
111 const policy::PolicyMap
& current
) override
;
113 // content::NotificationObserver implementation.
114 void Observe(int type
,
115 const content::NotificationSource
& source
,
116 const content::NotificationDetails
& details
) override
;
118 // ProfileInfoCacheObserver implementation.
119 void OnProfileAdded(const base::FilePath
& profile_path
) override
;
120 void OnProfileWasRemoved(const base::FilePath
& profile_path
,
121 const base::string16
& profile_name
) override
;
122 void OnProfileNameChanged(const base::FilePath
& profile_path
,
123 const base::string16
& old_profile_name
) override
;
124 void OnProfileAvatarChanged(const base::FilePath
& profile_path
) override
;
126 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
127 void OnCloudPrintPrefsChanged();
130 // SelectFileDialog::Listener implementation
131 void FileSelected(const base::FilePath
& path
,
133 void* params
) override
;
135 #if defined(OS_CHROMEOS)
136 // PointerDeviceObserver::Observer implementation.
137 void TouchpadExists(bool exists
) override
;
138 void MouseExists(bool exists
) override
;
140 // Will be called when the policy::key::kUserAvatarImage policy changes.
141 void OnUserImagePolicyChanged(const base::Value
* previous_policy
,
142 const base::Value
* current_policy
);
144 // Will be called when the policy::key::kWallpaperImage policy changes.
145 void OnWallpaperPolicyChanged(const base::Value
* previous_policy
,
146 const base::Value
* current_policy
);
148 // Will be called when powerwash dialog is shown.
149 void OnPowerwashDialogShow(const base::ListValue
* args
);
151 // ConsumerManagementService::Observer:
152 void OnConsumerManagementStatusChanged() override
;
155 void UpdateSyncState();
157 // Will be called when the kSigninAllowed pref has changed.
158 void OnSigninAllowedPrefChange();
160 // Makes this the default browser. Called from WebUI.
161 void BecomeDefaultBrowser(const base::ListValue
* args
);
163 // Sets the search engine at the given index to be default. Called from WebUI.
164 void SetDefaultSearchEngine(const base::ListValue
* args
);
166 // Enables/disables auto-launching of Chrome on computer startup.
167 void ToggleAutoLaunch(const base::ListValue
* args
);
169 // Checks (on the file thread) whether the user is in the auto-launch trial
170 // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
171 // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
172 // as a parameter to avoid the need to lock between this function and the
173 // destructor. |profile_path| is the full path to the current profile.
174 static void CheckAutoLaunch(base::WeakPtr
<BrowserOptionsHandler
> weak_this
,
175 const base::FilePath
& profile_path
);
177 // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
178 // (if the user is part of the auto-launch and makes sure the HTML UI knows
179 // whether Chrome will auto-launch at login.
180 void CheckAutoLaunchCallback(bool is_in_auto_launch_group
,
181 bool will_launch_at_login
);
183 // Returns the string ID for the given default browser state.
184 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state
);
186 // Returns if the "make Chrome default browser" button should be shown.
187 bool ShouldShowSetDefaultBrowser();
189 // Returns if profiles list should be shown on settings page.
190 bool ShouldShowMultiProfilesUserList();
192 // Returns if access to advanced settings should be allowed.
193 bool ShouldAllowAdvancedSettings();
195 // Gets the current default browser state, and asynchronously reports it to
197 void UpdateDefaultBrowserState();
199 // Updates the UI with the given state for the default browser.
200 void SetDefaultBrowserUIString(int status_string_id
);
202 // Loads the possible default search engine list and reports it to the WebUI.
203 void AddTemplateUrlServiceObserver();
205 // Creates a list of dictionaries where each dictionary is of the form:
207 // name: "Profile Name",
208 // iconURL: "chrome://path/to/icon/image",
209 // filePath: "/path/to/profile/data/on/disk",
210 // isCurrentProfile: false
212 scoped_ptr
<base::ListValue
> GetProfilesInfoList();
214 // Sends an array of Profile objects to javascript.
215 void SendProfilesInfo();
217 // Deletes the given profile. Expects one argument:
218 // 0: profile file path (string)
219 void DeleteProfile(const base::ListValue
* args
);
221 void ObserveThemeChanged();
222 void ThemesReset(const base::ListValue
* args
);
223 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
224 void ThemesSetNative(const base::ListValue
* args
);
227 #if defined(OS_CHROMEOS)
228 void UpdateAccountPicture();
230 // Updates the UI, allowing the user to change the avatar image if |managed|
231 // is |false| and preventing the user from changing the avatar image if
232 // |managed| is |true|.
233 void OnAccountPictureManagedChanged(bool managed
);
235 // Updates the UI, allowing the user to change the wallpaper if |managed| is
236 // |false| and preventing the user from changing the wallpaper if |managed| is
238 void OnWallpaperManagedChanged(bool managed
);
240 // Updates the UI, allowing the user to change the system time zone if
241 // kSystemTimezonePolicy is set, and preventing the user from changing the
242 // system time zone if kSystemTimezonePolicy is not set.
243 void OnSystemTimezonePolicyChanged();
246 // Callback for the "selectDownloadLocation" message. This will prompt the
247 // user for a destination folder using platform-specific APIs.
248 void HandleSelectDownloadLocation(const base::ListValue
* args
);
250 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
251 // remove all auto-open file-type settings.
252 void HandleAutoOpenButton(const base::ListValue
* args
);
254 // Callback for the "defaultFontSizeAction" message. This is called if the
255 // user changes the default font size. |args| is an array that contains
256 // one item, the font size as a numeric value.
257 void HandleDefaultFontSize(const base::ListValue
* args
);
259 // Callback for the "defaultZoomFactorAction" message. This is called if the
260 // user changes the default zoom factor. |args| is an array that contains
261 // one item, the zoom factor as a numeric value.
262 void HandleDefaultZoomFactor(const base::ListValue
* args
);
264 // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
265 // the "Use SSL 3.0" checkbox.
266 void HandleUseSSL3Checkbox(const base::ListValue
* args
);
268 // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
269 // the "Use TLS 1.0" checkbox.
270 void HandleUseTLS1Checkbox(const base::ListValue
* args
);
272 // Callback for the "restartBrowser" message. Restores all tabs on restart.
273 void HandleRestartBrowser(const base::ListValue
* args
);
275 // Callback for "requestProfilesInfo" message.
276 void HandleRequestProfilesInfo(const base::ListValue
* args
);
278 #if !defined(OS_CHROMEOS)
279 // Callback for the "showNetworkProxySettings" message. This will invoke
280 // an appropriate dialog for configuring proxy settings.
281 void ShowNetworkProxySettings(const base::ListValue
* args
);
284 #if !defined(USE_NSS_CERTS)
285 // Callback for the "showManageSSLCertificates" message. This will invoke
286 // an appropriate certificate management action based on the platform.
287 void ShowManageSSLCertificates(const base::ListValue
* args
);
290 #if defined(ENABLE_SERVICE_DISCOVERY)
291 void ShowCloudPrintDevicesPage(const base::ListValue
* args
);
294 #if defined(ENABLE_PRINT_PREVIEW)
295 // Register localized values used by Cloud Print
296 void RegisterCloudPrintValues(base::DictionaryValue
* values
);
299 // Check if hotword is available. If it is, tell the javascript to show
300 // the hotword section of the settings page.
301 void SendHotwordAvailable();
303 // Callback that updates the visibility of the audio history upon completion
304 // of a call to the server to the get the current value.
305 void SetHotwordAudioHistorySectionVisible(
306 const base::string16
& audio_history_state
,
308 bool logging_enabled
);
310 // Callback for "requestHotwordAvailable" message.
311 void HandleRequestHotwordAvailable(const base::ListValue
* args
);
313 // Callback for "launchHotwordAudioVerificationApp" message.
314 void HandleLaunchHotwordAudioVerificationApp(const base::ListValue
* args
);
316 // Callback for "requestGoogleNowAvailable" message.
317 void HandleRequestGoogleNowAvailable(const base::ListValue
* args
);
319 // Callback for "launchEasyUnlockSetup" message.
320 void HandleLaunchEasyUnlockSetup(const base::ListValue
* args
);
322 // Callback for "refreshExtensionControlIndicators" message.
323 void HandleRefreshExtensionControlIndicators(const base::ListValue
* args
);
325 #if defined(OS_CHROMEOS)
326 // Opens the wallpaper manager component extension.
327 void HandleOpenWallpaperManager(const base::ListValue
* args
);
329 // Called when the accessibility checkbox values are changed.
330 // |args| will contain the checkbox checked state as a string
331 // ("true" or "false").
332 void VirtualKeyboardChangeCallback(const base::ListValue
* args
);
334 // Called when the user confirmed factory reset. Chrome will
335 // initiate asynchronous file operation and then log out.
336 void PerformFactoryResetRestart(const base::ListValue
* args
);
339 // Setup the visibility for the metrics reporting setting.
340 void SetupMetricsReportingSettingVisibility();
342 // Update value of predictive network actions UI element.
343 void SetupNetworkPredictionControl();
345 // Setup the font size selector control.
346 void SetupFontSizeSelector();
348 // Setup the page zoom selector control.
349 void SetupPageZoomSelector();
351 // Setup the visibility of the reset button.
352 void SetupAutoOpenFileTypes();
354 // Setup the proxy settings section UI.
355 void SetupProxySettingsSection();
357 // Setup the manage certificates section UI.
358 void SetupManageCertificatesSection();
360 // Setup the UI specific to managing supervised users.
361 void SetupManagingSupervisedUsers();
363 // Setup the UI for Easy Unlock.
364 void SetupEasyUnlock();
366 // Setup the UI for showing which settings are extension controlled.
367 void SetupExtensionControlledIndicators();
369 // Setup the value and the disabled property for metrics reporting for (except
370 // CrOS and Android).
371 void SetupMetricsReportingCheckbox();
373 // Called when the MetricsReportingEnabled checkbox values are changed.
374 // |args| will contain the checkbox checked state as a boolean.
375 void HandleMetricsReportingChange(const base::ListValue
* args
);
377 // Notifies the result of MetricsReportingEnabled change to Javascript layer.
378 void MetricsReportingChangeCallback(bool enabled
);
380 // Calls a Javascript function to set the state of MetricsReporting checkbox.
381 void SetMetricsReportingCheckbox(bool checked
, bool disabled
);
383 #if defined(OS_CHROMEOS)
384 // Setup the accessibility features for ChromeOS.
385 void SetupAccessibilityFeatures();
388 // Returns a newly created dictionary with a number of properties that
389 // correspond to the status of sync.
390 scoped_ptr
<base::DictionaryValue
> GetSyncStateDictionary();
392 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
394 bool page_initialized_
;
396 StringPrefMember homepage_
;
397 BooleanPrefMember default_browser_policy_
;
399 TemplateURLService
* template_url_service_
; // Weak.
401 scoped_refptr
<ui::SelectFileDialog
> select_folder_dialog_
;
403 bool cloud_print_mdns_ui_enabled_
;
405 StringPrefMember auto_open_files_
;
407 scoped_ptr
<chrome::ChromeZoomLevelPrefs::DefaultZoomLevelSubscription
>
408 default_zoom_level_subscription_
;
410 PrefChangeRegistrar profile_pref_registrar_
;
411 #if defined(OS_CHROMEOS)
412 scoped_ptr
<policy::PolicyChangeRegistrar
> policy_registrar_
;
415 ScopedObserver
<SigninManagerBase
, SigninManagerBase::Observer
>
418 // Used to get WeakPtr to self for use on the UI thread.
419 base::WeakPtrFactory
<BrowserOptionsHandler
> weak_ptr_factory_
;
421 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler
);
424 } // namespace options
426 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_