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/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 "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 "content/public/browser/notification_observer.h"
28 #include "extensions/browser/extension_registry_observer.h"
29 #include "google_apis/gaia/google_service_auth_error.h"
30 #include "ui/base/models/table_model_observer.h"
31 #include "ui/shell_dialogs/select_file_dialog.h"
33 #if defined(OS_CHROMEOS)
34 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
35 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
36 #endif // defined(OS_CHROMEOS)
38 class AutocompleteController;
39 class CloudPrintSetupHandler;
40 class CustomHomePagesTableModel;
41 class TemplateURLService;
48 class PolicyChangeRegistrar;
53 // Chrome browser options page UI handler.
54 class BrowserOptionsHandler
55 : public OptionsPageUIHandler,
56 public ProfileSyncServiceObserver,
57 public SigninManagerBase::Observer,
58 public ui::SelectFileDialog::Listener,
59 public ShellIntegration::DefaultWebClientObserver,
60 #if defined(OS_CHROMEOS)
61 public chromeos::system::PointerDeviceObserver::Observer,
62 public policy::ConsumerManagementService::Observer,
64 public TemplateURLServiceObserver,
65 public extensions::ExtensionRegistryObserver,
66 public content::NotificationObserver,
67 public policy::PolicyService::Observer {
69 BrowserOptionsHandler();
70 ~BrowserOptionsHandler() override;
72 // OptionsPageUIHandler implementation.
73 void GetLocalizedValues(base::DictionaryValue* values) override;
74 void PageLoadStarted() override;
75 void InitializeHandler() override;
76 void InitializePage() override;
77 void RegisterMessages() override;
78 void Uninitialize() override;
80 // ProfileSyncServiceObserver implementation.
81 void OnStateChanged() override;
83 // SigninManagerBase::Observer implementation.
84 void GoogleSigninSucceeded(const std::string& account_id,
85 const std::string& username,
86 const std::string& password) override;
87 void GoogleSignedOut(const std::string& account_id,
88 const std::string& username) override;
90 // ShellIntegration::DefaultWebClientObserver implementation.
91 void SetDefaultWebClientUIState(
92 ShellIntegration::DefaultWebClientUIState state) override;
93 bool IsInteractiveSetDefaultPermitted() override;
95 // TemplateURLServiceObserver implementation.
96 void OnTemplateURLServiceChanged() override;
98 // extensions::ExtensionRegistryObserver:
99 void OnExtensionLoaded(content::BrowserContext* browser_context,
100 const extensions::Extension* extension) override;
101 void OnExtensionUnloaded(
102 content::BrowserContext* browser_context,
103 const extensions::Extension* extension,
104 extensions::UnloadedExtensionInfo::Reason reason) override;
106 // policy::PolicyService::Observer:
107 void OnPolicyUpdated(const policy::PolicyNamespace& ns,
108 const policy::PolicyMap& previous,
109 const policy::PolicyMap& current) override;
111 // content::NotificationObserver implementation.
112 void Observe(int type,
113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) override;
116 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
117 void OnCloudPrintPrefsChanged();
120 // SelectFileDialog::Listener implementation
121 void FileSelected(const base::FilePath& path,
123 void* params) override;
125 #if defined(OS_CHROMEOS)
126 // PointerDeviceObserver::Observer implementation.
127 virtual void TouchpadExists(bool exists) override;
128 virtual void MouseExists(bool exists) override;
130 // Will be called when the policy::key::kUserAvatarImage policy changes.
131 void OnUserImagePolicyChanged(const base::Value* previous_policy,
132 const base::Value* current_policy);
134 // Will be called when the policy::key::kWallpaperImage policy changes.
135 void OnWallpaperPolicyChanged(const base::Value* previous_policy,
136 const base::Value* current_policy);
138 // Will be called when powerwash dialog is shown.
139 void OnPowerwashDialogShow(const base::ListValue* args);
141 // ConsumerManagementService::Observer:
142 virtual void OnConsumerManagementStatusChanged() override;
145 void UpdateSyncState();
147 // Will be called when the kSigninAllowed pref has changed.
148 void OnSigninAllowedPrefChange();
150 // Makes this the default browser. Called from WebUI.
151 void BecomeDefaultBrowser(const base::ListValue* args);
153 // Sets the search engine at the given index to be default. Called from WebUI.
154 void SetDefaultSearchEngine(const base::ListValue* args);
156 // Enables/disables auto-launching of Chrome on computer startup.
157 void ToggleAutoLaunch(const base::ListValue* args);
159 // Checks (on the file thread) whether the user is in the auto-launch trial
160 // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
161 // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
162 // as a parameter to avoid the need to lock between this function and the
163 // destructor. |profile_path| is the full path to the current profile.
164 static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
165 const base::FilePath& profile_path);
167 // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
168 // (if the user is part of the auto-launch and makes sure the HTML UI knows
169 // whether Chrome will auto-launch at login.
170 void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
171 bool will_launch_at_login);
173 // Returns the string ID for the given default browser state.
174 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
176 // Returns if the "make Chrome default browser" button should be shown.
177 bool ShouldShowSetDefaultBrowser();
179 // Returns if profiles list should be shown on settings page.
180 bool ShouldShowMultiProfilesUserList();
182 // Returns if access to advanced settings should be allowed.
183 bool ShouldAllowAdvancedSettings();
185 // Gets the current default browser state, and asynchronously reports it to
187 void UpdateDefaultBrowserState();
189 // Updates the UI with the given state for the default browser.
190 void SetDefaultBrowserUIString(int status_string_id);
192 // Loads the possible default search engine list and reports it to the WebUI.
193 void AddTemplateUrlServiceObserver();
195 // Creates a list of dictionaries where each dictionary is of the form:
197 // name: "Profile Name",
198 // iconURL: "chrome://path/to/icon/image",
199 // filePath: "/path/to/profile/data/on/disk",
200 // isCurrentProfile: false
202 scoped_ptr<base::ListValue> GetProfilesInfoList();
204 // Sends an array of Profile objects to javascript.
205 void SendProfilesInfo();
207 // Deletes the given profile. Expects one argument:
208 // 0: profile file path (string)
209 void DeleteProfile(const base::ListValue* args);
211 void ObserveThemeChanged();
212 void ThemesReset(const base::ListValue* args);
213 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
214 void ThemesSetNative(const base::ListValue* args);
217 #if defined(OS_CHROMEOS)
218 void UpdateAccountPicture();
220 // Updates the UI, allowing the user to change the avatar image if |managed|
221 // is |false| and preventing the user from changing the avatar image if
222 // |managed| is |true|.
223 void OnAccountPictureManagedChanged(bool managed);
225 // Updates the UI, allowing the user to change the wallpaper if |managed| is
226 // |false| and preventing the user from changing the wallpaper if |managed| is
228 void OnWallpaperManagedChanged(bool managed);
231 // Callback for the "selectDownloadLocation" message. This will prompt the
232 // user for a destination folder using platform-specific APIs.
233 void HandleSelectDownloadLocation(const base::ListValue* args);
235 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
236 // remove all auto-open file-type settings.
237 void HandleAutoOpenButton(const base::ListValue* args);
239 // Callback for the "defaultFontSizeAction" message. This is called if the
240 // user changes the default font size. |args| is an array that contains
241 // one item, the font size as a numeric value.
242 void HandleDefaultFontSize(const base::ListValue* args);
244 // Callback for the "defaultZoomFactorAction" message. This is called if the
245 // user changes the default zoom factor. |args| is an array that contains
246 // one item, the zoom factor as a numeric value.
247 void HandleDefaultZoomFactor(const base::ListValue* args);
249 // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
250 // the "Use SSL 3.0" checkbox.
251 void HandleUseSSL3Checkbox(const base::ListValue* args);
253 // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
254 // the "Use TLS 1.0" checkbox.
255 void HandleUseTLS1Checkbox(const base::ListValue* args);
257 // Callback for the "restartBrowser" message. Restores all tabs on restart.
258 void HandleRestartBrowser(const base::ListValue* args);
260 // Callback for "requestProfilesInfo" message.
261 void HandleRequestProfilesInfo(const base::ListValue* args);
263 #if !defined(OS_CHROMEOS)
264 // Callback for the "showNetworkProxySettings" message. This will invoke
265 // an appropriate dialog for configuring proxy settings.
266 void ShowNetworkProxySettings(const base::ListValue* args);
269 #if !defined(USE_NSS)
270 // Callback for the "showManageSSLCertificates" message. This will invoke
271 // an appropriate certificate management action based on the platform.
272 void ShowManageSSLCertificates(const base::ListValue* args);
275 #if defined(ENABLE_SERVICE_DISCOVERY)
276 void ShowCloudPrintDevicesPage(const base::ListValue* args);
279 #if defined(ENABLE_PRINT_PREVIEW)
280 // Register localized values used by Cloud Print
281 void RegisterCloudPrintValues(base::DictionaryValue* values);
284 // Check if hotword is available. If it is, tell the javascript to show
285 // the hotword section of the settings page.
286 void SendHotwordAvailable();
288 // Callback for "requestHotwordAvailable" message.
289 void HandleRequestHotwordAvailable(const base::ListValue* args);
291 // Callback for "launchHotwordAudioVerificationApp" message.
292 void HandleLaunchHotwordAudioVerificationApp(const base::ListValue* args);
294 // Callback for "launchEasyUnlockSetup" message.
295 void HandleLaunchEasyUnlockSetup(const base::ListValue* args);
297 // Callback for "refreshExtensionControlIndicators" message.
298 void HandleRefreshExtensionControlIndicators(const base::ListValue* args);
300 #if defined(OS_CHROMEOS)
301 // Opens the wallpaper manager component extension.
302 void HandleOpenWallpaperManager(const base::ListValue* args);
304 // Called when the accessibility checkbox values are changed.
305 // |args| will contain the checkbox checked state as a string
306 // ("true" or "false").
307 void VirtualKeyboardChangeCallback(const base::ListValue* args);
309 // Called when the user confirmed factory reset. Chrome will
310 // initiate asynchronous file operation and then log out.
311 void PerformFactoryResetRestart(const base::ListValue* args);
314 // Setup the visibility for the metrics reporting setting.
315 void SetupMetricsReportingSettingVisibility();
317 // Update value of predictive network actions UI element.
318 void SetupNetworkPredictionControl();
320 // Setup the font size selector control.
321 void SetupFontSizeSelector();
323 // Setup the page zoom selector control.
324 void SetupPageZoomSelector();
326 // Setup the visibility of the reset button.
327 void SetupAutoOpenFileTypes();
329 // Setup the proxy settings section UI.
330 void SetupProxySettingsSection();
332 // Setup the manage certificates section UI.
333 void SetupManageCertificatesSection();
335 // Setup the UI specific to managing supervised users.
336 void SetupManagingSupervisedUsers();
338 // Setup the UI for Easy Unlock.
339 void SetupEasyUnlock();
341 // Setup the UI for showing which settings are extension controlled.
342 void SetupExtensionControlledIndicators();
344 // Setup the value and the disabled property for metrics reporting for (except
345 // CrOS and Android).
346 void SetupMetricsReportingCheckbox();
348 // Called when the MetricsReportingEnabled checkbox values are changed.
349 // |args| will contain the checkbox checked state as a boolean.
350 void HandleMetricsReportingChange(const base::ListValue* args);
352 // Notifies the result of MetricsReportingEnabled change to Javascript layer.
353 void MetricsReportingChangeCallback(bool enabled);
355 // Calls a Javascript function to set the state of MetricsReporting checkbox.
356 void SetMetricsReportingCheckbox(bool checked, bool disabled);
358 #if defined(OS_CHROMEOS)
359 // Setup the accessibility features for ChromeOS.
360 void SetupAccessibilityFeatures();
363 // Returns a newly created dictionary with a number of properties that
364 // correspond to the status of sync.
365 scoped_ptr<base::DictionaryValue> GetSyncStateDictionary();
367 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
369 bool page_initialized_;
371 StringPrefMember homepage_;
372 BooleanPrefMember default_browser_policy_;
374 TemplateURLService* template_url_service_; // Weak.
376 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
378 bool cloud_print_mdns_ui_enabled_;
380 StringPrefMember auto_open_files_;
382 scoped_ptr<chrome::ChromeZoomLevelPrefs::DefaultZoomLevelSubscription>
383 default_zoom_level_subscription_;
385 PrefChangeRegistrar profile_pref_registrar_;
386 #if defined(OS_CHROMEOS)
387 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
390 ScopedObserver<SigninManagerBase, SigninManagerBase::Observer>
393 // Used to get WeakPtr to self for use on the UI thread.
394 base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
396 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
399 } // namespace options
401 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_