Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / browser_options_handler.h
blobfe9935e9e5f3397c88b322384f7c4f985f2bbd08
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_
8 #include <vector>
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/search_engines/template_url_service_observer.h"
25 #include "components/signin/core/browser/signin_manager_base.h"
26 #include "content/public/browser/notification_observer.h"
27 #include "extensions/browser/extension_registry_observer.h"
28 #include "google_apis/gaia/google_service_auth_error.h"
29 #include "ui/base/models/table_model_observer.h"
30 #include "ui/shell_dialogs/select_file_dialog.h"
32 #if defined(OS_CHROMEOS)
33 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
34 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
35 #endif // defined(OS_CHROMEOS)
37 class AutocompleteController;
38 class CloudPrintSetupHandler;
39 class CustomHomePagesTableModel;
40 class TemplateURLService;
42 namespace base {
43 class Value;
46 namespace policy {
47 class PolicyChangeRegistrar;
50 namespace options {
52 // Chrome browser options page UI handler.
53 class BrowserOptionsHandler
54 : public OptionsPageUIHandler,
55 public ProfileSyncServiceObserver,
56 public SigninManagerBase::Observer,
57 public ui::SelectFileDialog::Listener,
58 public ShellIntegration::DefaultWebClientObserver,
59 #if defined(OS_CHROMEOS)
60 public chromeos::system::PointerDeviceObserver::Observer,
61 public policy::ConsumerManagementService::Observer,
62 #endif
63 public TemplateURLServiceObserver,
64 public extensions::ExtensionRegistryObserver,
65 public content::NotificationObserver {
66 public:
67 BrowserOptionsHandler();
68 virtual ~BrowserOptionsHandler();
70 // OptionsPageUIHandler implementation.
71 virtual void GetLocalizedValues(base::DictionaryValue* values) override;
72 virtual void PageLoadStarted() override;
73 virtual void InitializeHandler() override;
74 virtual void InitializePage() override;
75 virtual void RegisterMessages() override;
76 virtual void Uninitialize() override;
78 // ProfileSyncServiceObserver implementation.
79 virtual void OnStateChanged() override;
81 // SigninManagerBase::Observer implementation.
82 virtual void GoogleSigninSucceeded(const std::string& account_id,
83 const std::string& username,
84 const std::string& password) override;
85 virtual void GoogleSignedOut(const std::string& account_id,
86 const std::string& username) override;
88 // ShellIntegration::DefaultWebClientObserver implementation.
89 virtual void SetDefaultWebClientUIState(
90 ShellIntegration::DefaultWebClientUIState state) override;
91 virtual bool IsInteractiveSetDefaultPermitted() override;
93 // TemplateURLServiceObserver implementation.
94 virtual void OnTemplateURLServiceChanged() override;
96 // extensions::ExtensionRegistryObserver:
97 virtual void OnExtensionLoaded(
98 content::BrowserContext* browser_context,
99 const extensions::Extension* extension) override;
100 virtual void OnExtensionUnloaded(
101 content::BrowserContext* browser_context,
102 const extensions::Extension* extension,
103 extensions::UnloadedExtensionInfo::Reason reason) override;
105 private:
106 // content::NotificationObserver implementation.
107 virtual void Observe(int type,
108 const content::NotificationSource& source,
109 const content::NotificationDetails& details) override;
111 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
112 void OnCloudPrintPrefsChanged();
113 #endif
115 // SelectFileDialog::Listener implementation
116 virtual void FileSelected(const base::FilePath& path,
117 int index,
118 void* params) override;
120 #if defined(OS_CHROMEOS)
121 // PointerDeviceObserver::Observer implementation.
122 virtual void TouchpadExists(bool exists) override;
123 virtual void MouseExists(bool exists) override;
125 // Will be called when the policy::key::kUserAvatarImage policy changes.
126 void OnUserImagePolicyChanged(const base::Value* previous_policy,
127 const base::Value* current_policy);
129 // Will be called when the policy::key::kWallpaperImage policy changes.
130 void OnWallpaperPolicyChanged(const base::Value* previous_policy,
131 const base::Value* current_policy);
133 // Will be called when powerwash dialog is shown.
134 void OnPowerwashDialogShow(const base::ListValue* args);
136 // ConsumerManagementService::Observer:
137 virtual void OnConsumerManagementStatusChanged() override;
138 #endif
140 void UpdateSyncState();
142 // Will be called when the kSigninAllowed pref has changed.
143 void OnSigninAllowedPrefChange();
145 // Makes this the default browser. Called from WebUI.
146 void BecomeDefaultBrowser(const base::ListValue* args);
148 // Sets the search engine at the given index to be default. Called from WebUI.
149 void SetDefaultSearchEngine(const base::ListValue* args);
151 // Enables/disables auto-launching of Chrome on computer startup.
152 void ToggleAutoLaunch(const base::ListValue* args);
154 // Checks (on the file thread) whether the user is in the auto-launch trial
155 // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
156 // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
157 // as a parameter to avoid the need to lock between this function and the
158 // destructor. |profile_path| is the full path to the current profile.
159 static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
160 const base::FilePath& profile_path);
162 // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
163 // (if the user is part of the auto-launch and makes sure the HTML UI knows
164 // whether Chrome will auto-launch at login.
165 void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
166 bool will_launch_at_login);
168 // Returns the string ID for the given default browser state.
169 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
171 // Returns if the "make Chrome default browser" button should be shown.
172 bool ShouldShowSetDefaultBrowser();
174 // Returns if profiles list should be shown on settings page.
175 bool ShouldShowMultiProfilesUserList();
177 // Returns if access to advanced settings should be allowed.
178 bool ShouldAllowAdvancedSettings();
180 // Gets the current default browser state, and asynchronously reports it to
181 // the WebUI page.
182 void UpdateDefaultBrowserState();
184 // Updates the UI with the given state for the default browser.
185 void SetDefaultBrowserUIString(int status_string_id);
187 // Loads the possible default search engine list and reports it to the WebUI.
188 void AddTemplateUrlServiceObserver();
190 // Creates a list of dictionaries where each dictionary is of the form:
191 // profileInfo = {
192 // name: "Profile Name",
193 // iconURL: "chrome://path/to/icon/image",
194 // filePath: "/path/to/profile/data/on/disk",
195 // isCurrentProfile: false
196 // };
197 scoped_ptr<base::ListValue> GetProfilesInfoList();
199 // Sends an array of Profile objects to javascript.
200 void SendProfilesInfo();
202 // Deletes the given profile. Expects one argument:
203 // 0: profile file path (string)
204 void DeleteProfile(const base::ListValue* args);
206 void ObserveThemeChanged();
207 void ThemesReset(const base::ListValue* args);
208 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
209 void ThemesSetNative(const base::ListValue* args);
210 #endif
212 #if defined(OS_CHROMEOS)
213 void UpdateAccountPicture();
215 // Updates the UI, allowing the user to change the avatar image if |managed|
216 // is |false| and preventing the user from changing the avatar image if
217 // |managed| is |true|.
218 void OnAccountPictureManagedChanged(bool managed);
220 // Updates the UI, allowing the user to change the wallpaper if |managed| is
221 // |false| and preventing the user from changing the wallpaper if |managed| is
222 // |true|.
223 void OnWallpaperManagedChanged(bool managed);
224 #endif
226 // Callback for the "selectDownloadLocation" message. This will prompt the
227 // user for a destination folder using platform-specific APIs.
228 void HandleSelectDownloadLocation(const base::ListValue* args);
230 // Callback for the "autoOpenFileTypesResetToDefault" message. This will
231 // remove all auto-open file-type settings.
232 void HandleAutoOpenButton(const base::ListValue* args);
234 // Callback for the "defaultFontSizeAction" message. This is called if the
235 // user changes the default font size. |args| is an array that contains
236 // one item, the font size as a numeric value.
237 void HandleDefaultFontSize(const base::ListValue* args);
239 // Callback for the "defaultZoomFactorAction" message. This is called if the
240 // user changes the default zoom factor. |args| is an array that contains
241 // one item, the zoom factor as a numeric value.
242 void HandleDefaultZoomFactor(const base::ListValue* args);
244 // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
245 // the "Use SSL 3.0" checkbox.
246 void HandleUseSSL3Checkbox(const base::ListValue* args);
248 // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
249 // the "Use TLS 1.0" checkbox.
250 void HandleUseTLS1Checkbox(const base::ListValue* args);
252 // Callback for the "restartBrowser" message. Restores all tabs on restart.
253 void HandleRestartBrowser(const base::ListValue* args);
255 // Callback for "requestProfilesInfo" message.
256 void HandleRequestProfilesInfo(const base::ListValue* args);
258 #if !defined(OS_CHROMEOS)
259 // Callback for the "showNetworkProxySettings" message. This will invoke
260 // an appropriate dialog for configuring proxy settings.
261 void ShowNetworkProxySettings(const base::ListValue* args);
262 #endif
264 #if !defined(USE_NSS)
265 // Callback for the "showManageSSLCertificates" message. This will invoke
266 // an appropriate certificate management action based on the platform.
267 void ShowManageSSLCertificates(const base::ListValue* args);
268 #endif
270 #if defined(ENABLE_SERVICE_DISCOVERY)
271 void ShowCloudPrintDevicesPage(const base::ListValue* args);
272 #endif
274 #if defined(ENABLE_FULL_PRINTING)
275 // Register localized values used by Cloud Print
276 void RegisterCloudPrintValues(base::DictionaryValue* values);
277 #endif
279 // Check if hotword is available. If it is, tell the javascript to show
280 // the hotword section of the settings page.
281 void SendHotwordAvailable();
283 // Callback for "requestHotwordAvailable" message.
284 void HandleRequestHotwordAvailable(const base::ListValue* args);
286 // Callback for "launchHotwordAudioVerificationApp" message.
287 void HandleLaunchHotwordAudioVerificationApp(const base::ListValue* args);
289 // Callback for "launchEasyUnlockSetup" message.
290 void HandleLaunchEasyUnlockSetup(const base::ListValue* args);
292 // Callback for "refreshExtensionControlIndicators" message.
293 void HandleRefreshExtensionControlIndicators(const base::ListValue* args);
295 #if defined(OS_CHROMEOS)
296 // Opens the wallpaper manager component extension.
297 void HandleOpenWallpaperManager(const base::ListValue* args);
299 // Called when the accessibility checkbox values are changed.
300 // |args| will contain the checkbox checked state as a string
301 // ("true" or "false").
302 void VirtualKeyboardChangeCallback(const base::ListValue* args);
304 // Called when the user confirmed factory reset. Chrome will
305 // initiate asynchronous file operation and then log out.
306 void PerformFactoryResetRestart(const base::ListValue* args);
307 #endif
309 // Setup the visibility for the metrics reporting setting.
310 void SetupMetricsReportingSettingVisibility();
312 // Update value of predictive network actions UI element.
313 void SetupNetworkPredictionControl();
315 // Setup the font size selector control.
316 void SetupFontSizeSelector();
318 // Setup the page zoom selector control.
319 void SetupPageZoomSelector();
321 // Setup the visibility of the reset button.
322 void SetupAutoOpenFileTypes();
324 // Setup the proxy settings section UI.
325 void SetupProxySettingsSection();
327 // Setup the manage certificates section UI.
328 void SetupManageCertificatesSection();
330 // Setup the UI specific to managing supervised users.
331 void SetupManagingSupervisedUsers();
333 // Setup the UI for Easy Unlock.
334 void SetupEasyUnlock();
336 // Setup the UI for showing which settings are extension controlled.
337 void SetupExtensionControlledIndicators();
339 // Setup the value and the disabled property for metrics reporting for (except
340 // CrOS and Android).
341 void SetupMetricsReportingCheckbox();
343 // Called when the MetricsReportingEnabled checkbox values are changed.
344 // |args| will contain the checkbox checked state as a boolean.
345 void HandleMetricsReportingChange(const base::ListValue* args);
347 // Notifies the result of MetricsReportingEnabled change to Javascript layer.
348 void MetricsReportingChangeCallback(bool enabled);
350 // Calls a Javascript function to set the state of MetricsReporting checkbox.
351 void SetMetricsReportingCheckbox(bool checked, bool disabled);
353 #if defined(OS_CHROMEOS)
354 // Setup the accessibility features for ChromeOS.
355 void SetupAccessibilityFeatures();
356 #endif
358 // Returns a newly created dictionary with a number of properties that
359 // correspond to the status of sync.
360 scoped_ptr<base::DictionaryValue> GetSyncStateDictionary();
362 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
364 bool page_initialized_;
366 StringPrefMember homepage_;
367 BooleanPrefMember default_browser_policy_;
369 TemplateURLService* template_url_service_; // Weak.
371 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
373 bool cloud_print_mdns_ui_enabled_;
375 StringPrefMember auto_open_files_;
377 scoped_ptr<chrome::ChromeZoomLevelPrefs::DefaultZoomLevelSubscription>
378 default_zoom_level_subscription_;
380 PrefChangeRegistrar profile_pref_registrar_;
381 #if defined(OS_CHROMEOS)
382 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
383 #endif
385 ScopedObserver<SigninManagerBase, SigninManagerBase::Observer>
386 signin_observer_;
388 // Used to get WeakPtr to self for use on the UI thread.
389 base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
391 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
394 } // namespace options
396 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_