browser_options_handler.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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. 4 5#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_ 6#define CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_ 7 8#include <vector> 9 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" 29 30#if defined(OS_CHROMEOS) 31#include "chrome/browser/chromeos/system/pointer_device_observer.h" 32#endif // defined(OS_CHROMEOS) 33 34class AutocompleteController; 35class CloudPrintSetupHandler; 36class CustomHomePagesTableModel; 37class TemplateURLService; 38 39namespace base { 40class Value; 41} 42 43namespace policy { 44class PolicyChangeRegistrar; 45} 46 47namespace options { 48 49// Chrome browser options page UI handler. 50class 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, 58#endif 59 public TemplateURLServiceObserver, 60 public content::NotificationObserver { 61 public: 62 BrowserOptionsHandler(); 63 virtual ~BrowserOptionsHandler(); 64 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; 72 73 // ProfileSyncServiceObserver implementation. 74 virtual void OnStateChanged() OVERRIDE; 75 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; 80 81 // ShellIntegration::DefaultWebClientObserver implementation. 82 virtual void SetDefaultWebClientUIState( 83 ShellIntegration::DefaultWebClientUIState state) OVERRIDE; 84 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; 85 86 // TemplateURLServiceObserver implementation. 87 virtual void OnTemplateURLServiceChanged() OVERRIDE; 88 89 private: 90 // content::NotificationObserver implementation. 91 virtual void Observe(int type, 92 const content::NotificationSource& source, 93 const content::NotificationDetails& details) OVERRIDE; 94 95#if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) 96 void OnCloudPrintPrefsChanged(); 97#endif 98 99 // SelectFileDialog::Listener implementation 100 virtual void FileSelected(const base::FilePath& path, 101 int index, 102 void* params) OVERRIDE; 103 104#if defined(OS_CHROMEOS) 105 // PointerDeviceObserver::Observer implementation. 106 virtual void TouchpadExists(bool exists) OVERRIDE; 107 virtual void MouseExists(bool exists) OVERRIDE; 108 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); 112 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); 116 117 // Will be called when powerwash dialog is shown. 118 void OnPowerwashDialogShow(const base::ListValue* args); 119#endif 120 121 void UpdateSyncState(); 122 123 // Will be called when the kSigninAllowed pref has changed. 124 void OnSigninAllowedPrefChange(); 125 126 // Makes this the default browser. Called from WebUI. 127 void BecomeDefaultBrowser(const base::ListValue* args); 128 129 // Sets the search engine at the given index to be default. Called from WebUI. 130 void SetDefaultSearchEngine(const base::ListValue* args); 131 132 // Enables/disables auto-launching of Chrome on computer startup. 133 void ToggleAutoLaunch(const base::ListValue* args); 134 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); 142 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); 148 149 // Returns the string ID for the given default browser state. 150 int StatusStringIdForState(ShellIntegration::DefaultWebClientState state); 151 152 // Returns if the "make Chrome default browser" button should be shown. 153 bool ShouldShowSetDefaultBrowser(); 154 155 // Returns if profiles list should be shown on settings page. 156 bool ShouldShowMultiProfilesUserList(); 157 158 // Gets the current default browser state, and asynchronously reports it to 159 // the WebUI page. 160 void UpdateDefaultBrowserState(); 161 162 // Updates the UI with the given state for the default browser. 163 void SetDefaultBrowserUIString(int status_string_id); 164 165 // Loads the possible default search engine list and reports it to the WebUI. 166 void AddTemplateUrlServiceObserver(); 167 168 // Creates a list of dictionaries where each dictionary is of the form: 169 // profileInfo = { 170 // name: "Profile Name", 171 // iconURL: "chrome://path/to/icon/image", 172 // filePath: "/path/to/profile/data/on/disk", 173 // isCurrentProfile: false 174 // }; 175 scoped_ptr<base::ListValue> GetProfilesInfoList(); 176 177 // Sends an array of Profile objects to javascript. 178 void SendProfilesInfo(); 179 180 // Deletes the given profile. Expects one argument: 181 // 0: profile file path (string) 182 void DeleteProfile(const base::ListValue* args); 183 184 void ObserveThemeChanged(); 185 void ThemesReset(const base::ListValue* args); 186#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 187 void ThemesSetNative(const base::ListValue* args); 188#endif 189 190#if defined(OS_CHROMEOS) 191 void UpdateAccountPicture(); 192 193 // Updates the UI, allowing the user to change the avatar image if |managed| 194 // is |false| and preventing the user from changing the avatar image if 195 // |managed| is |true|. 196 void OnAccountPictureManagedChanged(bool managed); 197 198 // Updates the UI, allowing the user to change the wallpaper if |managed| is 199 // |false| and preventing the user from changing the wallpaper if |managed| is 200 // |true|. 201 void OnWallpaperManagedChanged(bool managed); 202#endif 203 204 // Callback for the "selectDownloadLocation" message. This will prompt the 205 // user for a destination folder using platform-specific APIs. 206 void HandleSelectDownloadLocation(const base::ListValue* args); 207 208 // Callback for the "autoOpenFileTypesResetToDefault" message. This will 209 // remove all auto-open file-type settings. 210 void HandleAutoOpenButton(const base::ListValue* args); 211 212 // Callback for the "defaultFontSizeAction" message. This is called if the 213 // user changes the default font size. |args| is an array that contains 214 // one item, the font size as a numeric value. 215 void HandleDefaultFontSize(const base::ListValue* args); 216 217 // Callback for the "defaultZoomFactorAction" message. This is called if the 218 // user changes the default zoom factor. |args| is an array that contains 219 // one item, the zoom factor as a numeric value. 220 void HandleDefaultZoomFactor(const base::ListValue* args); 221 222 // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles 223 // the "Use SSL 3.0" checkbox. 224 void HandleUseSSL3Checkbox(const base::ListValue* args); 225 226 // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles 227 // the "Use TLS 1.0" checkbox. 228 void HandleUseTLS1Checkbox(const base::ListValue* args); 229 230 // Callback for the "restartBrowser" message. Restores all tabs on restart. 231 void HandleRestartBrowser(const base::ListValue* args); 232 233 // Callback for "requestProfilesInfo" message. 234 void HandleRequestProfilesInfo(const base::ListValue* args); 235 236#if !defined(OS_CHROMEOS) 237 // Callback for the "showNetworkProxySettings" message. This will invoke 238 // an appropriate dialog for configuring proxy settings. 239 void ShowNetworkProxySettings(const base::ListValue* args); 240#endif 241 242#if !defined(USE_NSS) 243 // Callback for the "showManageSSLCertificates" message. This will invoke 244 // an appropriate certificate management action based on the platform. 245 void ShowManageSSLCertificates(const base::ListValue* args); 246#endif 247 248#if defined(ENABLE_SERVICE_DISCOVERY) 249 void ShowCloudPrintDevicesPage(const base::ListValue* args); 250#endif 251 252#if defined(ENABLE_FULL_PRINTING) 253 // Callback for the Cloud Print manage button. This will open a new 254 // tab pointed at the management URL. 255 void ShowCloudPrintManagePage(const base::ListValue* args); 256 257 // Register localized values used by Cloud Print 258 void RegisterCloudPrintValues(base::DictionaryValue* values); 259 260#if !defined(OS_CHROMEOS) 261 // Callback for the Sign in to Cloud Print button. This will start 262 // the authentication process. 263 void ShowCloudPrintSetupDialog(const base::ListValue* args); 264 265 // Callback for the Disable Cloud Print button. This will sign out 266 // of cloud print. 267 void HandleDisableCloudPrintConnector(const base::ListValue* args); 268 269 // Pings the service to send us it's current notion of the enabled state. 270 void RefreshCloudPrintStatusFromService(); 271 272 // Setup the enabled or disabled state of the cloud print connector 273 // management UI. 274 void SetupCloudPrintConnectorSection(); 275 276 // Remove cloud print connector section if cloud print connector management 277 // UI is disabled. 278 void RemoveCloudPrintConnectorSection(); 279#endif // defined(OS_CHROMEOS) 280#endif // defined(ENABLE_FULL_PRINTING) 281 282 // Check if hotword is available. If it is, tell the javascript to show 283 // the hotword section of the settings page. 284 void SendHotwordAvailable(); 285 286 // Callback for "requestHotwordAvailable" message. 287 void HandleRequestHotwordAvailable(const base::ListValue* args); 288 289 // Callback for "requestHotwordSetupRetry" message. 290 void HandleRequestHotwordSetupRetry(const base::ListValue* args); 291 292 // Callback for "launchEasyUnlockSetup" message. 293 void HandleLaunchEasyUnlockSetup(const base::ListValue* args); 294 295#if defined(OS_CHROMEOS) 296 // Opens the wallpaper manager component extension. 297 void HandleOpenWallpaperManager(const base::ListValue* args); 298 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); 303 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 308 309 // Setup the visibility for the metrics reporting setting. 310 void SetupMetricsReportingSettingVisibility(); 311 312 // Setup the font size selector control. 313 void SetupFontSizeSelector(); 314 315 // Setup the page zoom selector control. 316 void SetupPageZoomSelector(); 317 318 // Setup the visibility of the reset button. 319 void SetupAutoOpenFileTypes(); 320 321 // Setup the proxy settings section UI. 322 void SetupProxySettingsSection(); 323 324 // Setup the manage certificates section UI. 325 void SetupManageCertificatesSection(); 326 327 // Setup the UI specific to managing supervised users. 328 void SetupManagingSupervisedUsers(); 329 330 // Setup the UI for Easy Unlock. 331 void SetupEasyUnlock(); 332 333#if defined(OS_CHROMEOS) 334 // Setup the accessibility features for ChromeOS. 335 void SetupAccessibilityFeatures(); 336#endif 337 338 // Returns a newly created dictionary with a number of properties that 339 // correspond to the status of sync. 340 scoped_ptr<base::DictionaryValue> GetSyncStateDictionary(); 341 342 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; 343 344 bool page_initialized_; 345 346 StringPrefMember homepage_; 347 BooleanPrefMember default_browser_policy_; 348 349 TemplateURLService* template_url_service_; // Weak. 350 351 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; 352 353#if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS) 354 StringPrefMember cloud_print_connector_email_; 355 BooleanPrefMember cloud_print_connector_enabled_; 356 bool cloud_print_connector_ui_enabled_; 357#endif 358 359 bool cloud_print_mdns_ui_enabled_; 360 361 StringPrefMember auto_open_files_; 362 DoublePrefMember default_zoom_level_; 363 364 PrefChangeRegistrar profile_pref_registrar_; 365#if defined(OS_CHROMEOS) 366 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_; 367#endif 368 369 ScopedObserver<SigninManagerBase, SigninManagerBase::Observer> 370 signin_observer_; 371 372 // Used to get WeakPtr to self for use on the UI thread. 373 base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_; 374 375 DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler); 376}; 377 378} // namespace options 379 380#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_ 381