browser_options_handler.cc revision a36e5920737c6adbddd3e43b760e5de8431db6e0
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#include "chrome/browser/ui/webui/options/browser_options_handler.h" 6 7#include <string> 8#include <vector> 9 10#include "base/basictypes.h" 11#include "base/bind.h" 12#include "base/bind_helpers.h" 13#include "base/command_line.h" 14#include "base/memory/singleton.h" 15#include "base/metrics/field_trial.h" 16#include "base/metrics/histogram.h" 17#include "base/path_service.h" 18#include "base/prefs/pref_service.h" 19#include "base/stl_util.h" 20#include "base/strings/string_number_conversions.h" 21#include "base/strings/utf_string_conversions.h" 22#include "base/value_conversions.h" 23#include "base/values.h" 24#include "chrome/browser/auto_launch_trial.h" 25#include "chrome/browser/browser_process.h" 26#include "chrome/browser/chrome_notification_types.h" 27#include "chrome/browser/chrome_page_zoom.h" 28#include "chrome/browser/custom_home_pages_table_model.h" 29#include "chrome/browser/download/download_prefs.h" 30#include "chrome/browser/gpu/gpu_mode_manager.h" 31#include "chrome/browser/lifetime/application_lifetime.h" 32#include "chrome/browser/prefs/session_startup_pref.h" 33#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 34#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" 35#include "chrome/browser/printing/cloud_print/cloud_print_url.h" 36#include "chrome/browser/profiles/profile.h" 37#include "chrome/browser/profiles/profile_info_cache.h" 38#include "chrome/browser/profiles/profile_info_util.h" 39#include "chrome/browser/profiles/profile_metrics.h" 40#include "chrome/browser/profiles/profile_shortcut_manager.h" 41#include "chrome/browser/profiles/profile_window.h" 42#include "chrome/browser/profiles/profiles_state.h" 43#include "chrome/browser/search/search.h" 44#include "chrome/browser/search_engines/template_url.h" 45#include "chrome/browser/search_engines/template_url_service.h" 46#include "chrome/browser/search_engines/template_url_service_factory.h" 47#include "chrome/browser/service/service_process_control.h" 48#include "chrome/browser/signin/signin_manager.h" 49#include "chrome/browser/signin/signin_manager_factory.h" 50#include "chrome/browser/sync/profile_sync_service.h" 51#include "chrome/browser/sync/profile_sync_service_factory.h" 52#include "chrome/browser/sync/sync_ui_util.h" 53#include "chrome/browser/themes/theme_service.h" 54#include "chrome/browser/themes/theme_service_factory.h" 55#include "chrome/browser/ui/browser_finder.h" 56#include "chrome/browser/ui/chrome_select_file_policy.h" 57#include "chrome/browser/ui/host_desktop.h" 58#include "chrome/browser/ui/options/options_util.h" 59#include "chrome/browser/ui/webui/favicon_source.h" 60#include "chrome/common/chrome_constants.h" 61#include "chrome/common/chrome_paths.h" 62#include "chrome/common/chrome_switches.h" 63#include "chrome/common/net/url_fixer_upper.h" 64#include "chrome/common/pref_names.h" 65#include "chrome/common/url_constants.h" 66#include "content/public/browser/browser_thread.h" 67#include "content/public/browser/download_manager.h" 68#include "content/public/browser/navigation_controller.h" 69#include "content/public/browser/notification_details.h" 70#include "content/public/browser/notification_service.h" 71#include "content/public/browser/notification_source.h" 72#include "content/public/browser/notification_types.h" 73#include "content/public/browser/url_data_source.h" 74#include "content/public/browser/user_metrics.h" 75#include "content/public/browser/web_contents.h" 76#include "content/public/browser/web_contents_view.h" 77#include "content/public/common/page_zoom.h" 78#include "google_apis/gaia/google_service_auth_error.h" 79#include "grit/chromium_strings.h" 80#include "grit/generated_resources.h" 81#include "grit/locale_settings.h" 82#include "grit/theme_resources.h" 83#include "third_party/skia/include/core/SkBitmap.h" 84#include "ui/base/l10n/l10n_util.h" 85#include "ui/webui/web_ui_util.h" 86 87#if defined(ENABLE_MANAGED_USERS) 88#include "chrome/browser/managed_mode/managed_user_registration_utility.h" 89#include "chrome/browser/managed_mode/managed_user_service.h" 90#include "chrome/browser/managed_mode/managed_user_service_factory.h" 91#endif 92 93#if !defined(OS_CHROMEOS) 94#include "chrome/browser/ui/webui/options/advanced_options_utils.h" 95#include "chromeos/chromeos_switches.h" 96#endif 97 98#if defined(OS_CHROMEOS) 99#include "ash/magnifier/magnifier_constants.h" 100#include "chrome/browser/chromeos/accessibility/accessibility_util.h" 101#include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" 102#include "chrome/browser/chromeos/login/user_manager.h" 103#include "chrome/browser/chromeos/settings/cros_settings.h" 104#include "chrome/browser/policy/browser_policy_connector.h" 105#include "chrome/browser/ui/browser_window.h" 106#include "chrome/browser/ui/webui/options/chromeos/timezone_options_util.h" 107#include "chromeos/chromeos_switches.h" 108#include "chromeos/dbus/dbus_thread_manager.h" 109#include "chromeos/dbus/power_manager_client.h" 110#include "ui/gfx/image/image_skia.h" 111#endif // defined(OS_CHROMEOS) 112 113#if defined(OS_WIN) 114#include "chrome/installer/util/auto_launch_util.h" 115#endif // defined(OS_WIN) 116 117using content::BrowserContext; 118using content::BrowserThread; 119using content::DownloadManager; 120using content::OpenURLParams; 121using content::Referrer; 122using content::UserMetricsAction; 123 124namespace options { 125 126namespace { 127 128// Constants for the new tab button field trial. 129 const char kProfileResetTrialName[] = "ManualResetProfile"; 130 const char kProfileResetTrialEnableGroupName[] = "Enable"; 131 132bool ShouldShowMultiProfilesUserList(chrome::HostDesktopType desktop_type) { 133#if defined(OS_CHROMEOS) 134 // On Chrome OS we use different UI for multi-profiles. 135 return false; 136#else 137 if (desktop_type != chrome::HOST_DESKTOP_TYPE_NATIVE) 138 return false; 139 return profiles::IsMultipleProfilesEnabled(); 140#endif 141} 142 143void CreateDesktopShortcutForProfile(Profile* profile, 144 Profile::CreateStatus status) { 145 ProfileShortcutManager* shortcut_manager = 146 g_browser_process->profile_manager()->profile_shortcut_manager(); 147 if (shortcut_manager) 148 shortcut_manager->CreateProfileShortcut(profile->GetPath()); 149} 150 151void RunProfileCreationCallbacks( 152 const std::vector<ProfileManager::CreateCallback>& callbacks, 153 Profile* profile, 154 Profile::CreateStatus status) { 155 std::vector<ProfileManager::CreateCallback>::const_iterator it; 156 for (it = callbacks.begin(); it != callbacks.end(); ++it) { 157 it->Run(profile, status); 158 } 159} 160 161void OpenNewWindowForProfile( 162 chrome::HostDesktopType desktop_type, 163 Profile* profile, 164 Profile::CreateStatus status) { 165 if (status != Profile::CREATE_STATUS_INITIALIZED) 166 return; 167 168 profiles::FindOrCreateNewWindowForProfile( 169 profile, 170 chrome::startup::IS_PROCESS_STARTUP, 171 chrome::startup::IS_FIRST_RUN, 172 desktop_type, 173 false); 174} 175 176} // namespace 177 178BrowserOptionsHandler::BrowserOptionsHandler() 179 : page_initialized_(false), 180 template_url_service_(NULL), 181 weak_ptr_factory_(this) { 182#if !defined(OS_MACOSX) 183 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); 184#endif 185#if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) 186 // On Windows, we need the PDF plugin which is only guaranteed to exist on 187 // Google Chrome builds. Use a command-line switch for Windows non-Google 188 // Chrome builds. 189 cloud_print_connector_ui_enabled_ = 190 CommandLine::ForCurrentProcess()->HasSwitch( 191 switches::kEnableCloudPrintProxy); 192#elif(!defined(OS_CHROMEOS)) 193 // Always enabled for Mac, Linux and Google Chrome Windows builds. 194 // Never enabled for Chrome OS, we don't even need to indicate it. 195 cloud_print_connector_ui_enabled_ = true; 196#endif 197} 198 199BrowserOptionsHandler::~BrowserOptionsHandler() { 200 CancelProfileRegistration(false); 201 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: 202 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); 203 if (sync_service) 204 sync_service->RemoveObserver(this); 205 206 if (default_browser_worker_.get()) 207 default_browser_worker_->ObserverDestroyed(); 208 if (template_url_service_) 209 template_url_service_->RemoveObserver(this); 210 // There may be pending file dialogs, we need to tell them that we've gone 211 // away so they don't try and call back to us. 212 if (select_folder_dialog_.get()) 213 select_folder_dialog_->ListenerDestroyed(); 214} 215 216void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) { 217 DCHECK(values); 218 219 static OptionsStringResource resources[] = { 220 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT }, 221 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY }, 222 { "advancedSectionTitleContent", 223 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, 224 { "advancedSectionTitleLanguages", 225 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES }, 226 { "advancedSectionTitleNetwork", 227 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, 228 { "advancedSectionTitlePrivacy", 229 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, 230 { "advancedSectionTitleSecurity", 231 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY }, 232 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE }, 233 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, 234 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, 235 { "autoOpenFileTypesResetToDefault", 236 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, 237 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, 238 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, 239 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL }, 240 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, 241 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, 242 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, 243#if defined(OS_CHROMEOS) 244 { "disableGData", IDS_OPTIONS_DISABLE_GDATA }, 245#endif 246 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES }, 247#if defined(OS_CHROMEOS) 248 { "displayOptions", 249 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL }, 250#endif 251 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK }, 252 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT }, 253 { "doNotTrackConfirmEnable", 254 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE }, 255 { "doNotTrackConfirmDisable", 256 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE }, 257 { "downloadLocationAskForSaveLocation", 258 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION }, 259 { "downloadLocationBrowseTitle", 260 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE }, 261 { "downloadLocationChangeButton", 262 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON }, 263 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME }, 264 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING }, 265 { "fontSettingsCustomizeFontsButton", 266 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON }, 267 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM }, 268 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE }, 269 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, 270 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, 271 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE }, 272 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, 273 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS }, 274 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP }, 275 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, 276 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, 277 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, 278 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, 279 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE }, 280 { "languageAndSpellCheckSettingsButton", 281 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS }, 282 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF }, 283 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK }, 284 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES }, 285 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK }, 286 { "networkPredictionEnabledDescription", 287 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, 288 { "passwordsAndAutofillGroupName", 289 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME }, 290 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE }, 291 { "passwordGenerationEnabledDescription", 292 IDS_OPTIONS_PASSWORD_GENERATION_ENABLED_LABEL }, 293 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, 294 { "privacyContentSettingsButton", 295 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON }, 296 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL }, 297 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL }, 298 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL }, 299 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT }, 300 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL }, 301#if defined(ENABLE_SETTINGS_APP) 302 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL }, 303#endif 304 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL }, 305 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL, 306 IDS_PRODUCT_NAME }, 307 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON }, 308 { "resetProfileSettingsDescription", 309 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION }, 310 { "resetProfileSettingsSectionTitle", 311 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE }, 312 { "safeBrowsingEnableProtection", 313 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION }, 314 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME }, 315 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME }, 316 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME }, 317 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME }, 318 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME }, 319 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME }, 320 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT }, 321 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE }, 322 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE }, 323 { "spellingPref", IDS_OPTIONS_SPELLING_PREF }, 324 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION }, 325 { "settingsTitle", IDS_SETTINGS_TITLE }, 326 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS }, 327 { "sslCheckRevocation", IDS_OPTIONS_SSL_CHECKREVOCATION }, 328 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES }, 329 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB }, 330 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES }, 331 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF }, 332 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS }, 333 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL }, 334 { "themesGallery", IDS_THEMES_GALLERY_BUTTON }, 335 { "themesGalleryURL", IDS_THEMES_GALLERY_URL }, 336 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF }, 337 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR }, 338 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, 339 { "translateEnableTranslate", 340 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, 341#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 342 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS }, 343 { "themesNativeButton", IDS_THEMES_GTK_BUTTON }, 344 { "themesSetClassic", IDS_THEMES_SET_CLASSIC }, 345#else 346 { "themes", IDS_THEMES_GROUP_NAME }, 347#endif 348 { "themesReset", IDS_THEMES_RESET_BUTTON }, 349#if defined(OS_CHROMEOS) 350 { "accessibilityExplanation", 351 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION }, 352 { "accessibilityHighContrast", 353 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION }, 354 { "accessibilityScreenMagnifier", 355 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION }, 356 { "accessibilityTapDragging", 357 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION }, 358 { "accessibilityScreenMagnifierOff", 359 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF }, 360 { "accessibilityScreenMagnifierFull", 361 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL }, 362 { "accessibilityScreenMagnifierPartial", 363 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL }, 364 { "accessibilityLargeCursor", 365 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION }, 366 { "accessibilityStickyKeys", 367 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION }, 368 { "accessibilitySpokenFeedback", 369 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION }, 370 { "accessibilityTitle", 371 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY }, 372 { "accessibilityVirtualKeyboard", 373 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION }, 374 { "accessibilityAlwaysShowMenu", 375 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU }, 376 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING }, 377 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET }, 378 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON }, 379 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON }, 380 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING }, 381 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL }, 382 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE_CAPTION }, 383 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME }, 384 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION }, 385 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION }, 386 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION }, 387 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION }, 388 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX }, 389 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE }, 390 { "keyboardSettingsButtonTitle", 391 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE }, 392 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE }, 393 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES }, 394 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME }, 395 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL }, 396 { "syncOverview", IDS_SYNC_OVERVIEW }, 397 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL }, 398 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION }, 399 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION }, 400#else 401 { "cloudPrintConnectorEnabledManageButton", 402 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON}, 403 { "cloudPrintConnectorEnablingButton", 404 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON }, 405 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON }, 406#endif 407#if defined(OS_CHROMEOS) && defined(USE_ASH) 408 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON }, 409#endif 410 { "advancedSectionTitleSystem", 411 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM }, 412#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) 413 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE }, 414#endif 415#if !defined(OS_CHROMEOS) 416 { "gpuModeCheckbox", 417 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE }, 418 { "gpuModeResetRestart", 419 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART }, 420 // Strings with product-name substitutions. 421 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME }, 422 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL }, 423#endif 424 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL, 425 IDS_SHORT_PRODUCT_NAME }, 426 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE, 427 IDS_PRODUCT_NAME }, 428 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, 429 IDS_PRODUCT_NAME }, 430 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, 431 IDS_PRODUCT_NAME }, 432 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT, IDS_PRODUCT_NAME }, 433#if defined(OS_CHROMEOS) 434 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION, 435 IDS_SHORT_PRODUCT_NAME }, 436#endif 437 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, 438 IDS_SHORT_PRODUCT_NAME }, 439 }; 440 441#if defined(ENABLE_SETTINGS_APP) 442 static OptionsStringResource app_resources[] = { 443 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW }, 444 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL, 445 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 446 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE, 447 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 448 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, 449 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 450 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL, 451 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 452 }; 453 DictionaryValue* app_values = NULL; 454 CHECK(values->GetDictionary(kSettingsAppKey, &app_values)); 455 RegisterStrings(app_values, app_resources, arraysize(app_resources)); 456#endif 457 458 RegisterStrings(values, resources, arraysize(resources)); 459 RegisterTitle(values, "doNotTrackConfirmOverlay", 460 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE); 461 RegisterTitle(values, "spellingConfirmOverlay", 462 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE); 463 RegisterCloudPrintValues(values); 464 465 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL); 466 string16 omnibox_url = ASCIIToUTF16(chrome::kOmniboxLearnMoreURL); 467 values->SetString( 468 "defaultSearchGroupLabel", 469 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url)); 470 471#if defined(OS_CHROMEOS) 472 const chromeos::User* user = chromeos::UserManager::Get()->GetLoggedInUser(); 473 values->SetString("username", user ? user->email() : std::string()); 474#endif 475 476 // Pass along sync status early so it will be available during page init. 477 values->Set("syncData", GetSyncStateDictionary().release()); 478 479 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 480 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 481 482#if defined(OS_CHROMEOS) 483 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); 484 485 // TODO(pastarmovj): replace this with a call to the CrosSettings list 486 // handling functionality to come. 487 values->Set("timezoneList", GetTimezoneList().release()); 488 489 values->SetString("accessibilityLearnMoreURL", 490 chrome::kChromeAccessibilityHelpURL); 491 492 // Creates magnifierList. 493 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue); 494 495 scoped_ptr<base::ListValue> option_full(new base::ListValue); 496 option_full->AppendInteger(ash::MAGNIFIER_FULL); 497 option_full->AppendString(l10n_util::GetStringUTF16( 498 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL)); 499 magnifier_list->Append(option_full.release()); 500 501 scoped_ptr<base::ListValue> option_partial(new base::ListValue); 502 option_partial->AppendInteger(ash::MAGNIFIER_PARTIAL); 503 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16( 504 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL))); 505 magnifier_list->Append(option_partial.release()); 506 507 values->Set("magnifierList", magnifier_list.release()); 508 509 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 510 values->SetBoolean("enableStickyKeys", 511 !command_line.HasSwitch(switches::kDisableStickyKeys)); 512#endif 513 514#if defined(OS_MACOSX) 515 values->SetString("macPasswordsWarning", 516 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); 517 values->SetBoolean("multiple_profiles", 518 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); 519#endif 520 521 if (ShouldShowMultiProfilesUserList(GetDesktopType())) 522 values->Set("profilesInfo", GetProfilesInfoList().release()); 523 524 values->SetBoolean("profileIsManaged", 525 Profile::FromWebUI(web_ui())->IsManaged()); 526 527#if !defined(OS_CHROMEOS) 528 values->SetBoolean( 529 "gpuEnabledAtStart", 530 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref()); 531#endif 532 533 bool finch_allows_button = 534 base::FieldTrialList::FindFullName(kProfileResetTrialName) == 535 kProfileResetTrialEnableGroupName; 536 values->SetBoolean("enableResetProfileSettingsSection", 537 finch_allows_button || 538 CommandLine::ForCurrentProcess()->HasSwitch( 539 switches::kEnableResetProfileSettings)); 540} 541 542void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) { 543#if defined(OS_CHROMEOS) 544 values->SetString("cloudPrintChromeosOptionLabel", 545 l10n_util::GetStringFUTF16( 546 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, 547 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 548 values->SetString("cloudPrintChromeosOptionButton", 549 l10n_util::GetStringFUTF16( 550 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON, 551 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 552#else 553 values->SetString("cloudPrintConnectorDisabledLabel", 554 l10n_util::GetStringFUTF16( 555 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, 556 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 557 values->SetString("cloudPrintConnectorDisabledButton", 558 l10n_util::GetStringUTF16( 559 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON)); 560 values->SetString("cloudPrintConnectorEnabledButton", 561 l10n_util::GetStringUTF16( 562 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON)); 563#endif 564} 565 566void BrowserOptionsHandler::RegisterMessages() { 567 web_ui()->RegisterMessageCallback( 568 "becomeDefaultBrowser", 569 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, 570 base::Unretained(this))); 571 web_ui()->RegisterMessageCallback( 572 "setDefaultSearchEngine", 573 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, 574 base::Unretained(this))); 575 web_ui()->RegisterMessageCallback( 576 "createProfile", 577 base::Bind(&BrowserOptionsHandler::CreateProfile, 578 base::Unretained(this))); 579 web_ui()->RegisterMessageCallback( 580 "deleteProfile", 581 base::Bind(&BrowserOptionsHandler::DeleteProfile, 582 base::Unretained(this))); 583 web_ui()->RegisterMessageCallback( 584 "cancelCreateProfile", 585 base::Bind(&BrowserOptionsHandler::HandleCancelProfileCreation, 586 base::Unretained(this))); 587 web_ui()->RegisterMessageCallback( 588 "themesReset", 589 base::Bind(&BrowserOptionsHandler::ThemesReset, 590 base::Unretained(this))); 591#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 592 web_ui()->RegisterMessageCallback( 593 "themesSetNative", 594 base::Bind(&BrowserOptionsHandler::ThemesSetNative, 595 base::Unretained(this))); 596#endif 597 web_ui()->RegisterMessageCallback( 598 "selectDownloadLocation", 599 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation, 600 base::Unretained(this))); 601 web_ui()->RegisterMessageCallback( 602 "autoOpenFileTypesAction", 603 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton, 604 base::Unretained(this))); 605 web_ui()->RegisterMessageCallback( 606 "defaultFontSizeAction", 607 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize, 608 base::Unretained(this))); 609 web_ui()->RegisterMessageCallback( 610 "defaultZoomFactorAction", 611 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor, 612 base::Unretained(this))); 613#if !defined(USE_NSS) && !defined(USE_OPENSSL) 614 web_ui()->RegisterMessageCallback( 615 "showManageSSLCertificates", 616 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates, 617 base::Unretained(this))); 618#endif 619 web_ui()->RegisterMessageCallback( 620 "showCloudPrintManagePage", 621 base::Bind(&BrowserOptionsHandler::ShowCloudPrintManagePage, 622 base::Unretained(this))); 623#if !defined(OS_CHROMEOS) 624 if (cloud_print_connector_ui_enabled_) { 625 web_ui()->RegisterMessageCallback( 626 "showCloudPrintSetupDialog", 627 base::Bind(&BrowserOptionsHandler::ShowCloudPrintSetupDialog, 628 base::Unretained(this))); 629 web_ui()->RegisterMessageCallback( 630 "disableCloudPrintConnector", 631 base::Bind(&BrowserOptionsHandler::HandleDisableCloudPrintConnector, 632 base::Unretained(this))); 633 } 634 web_ui()->RegisterMessageCallback( 635 "showNetworkProxySettings", 636 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings, 637 base::Unretained(this))); 638#endif 639#if defined(OS_CHROMEOS) 640 web_ui()->RegisterMessageCallback( 641 "openWallpaperManager", 642 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager, 643 base::Unretained(this))); 644 web_ui()->RegisterMessageCallback( 645 "virtualKeyboardChange", 646 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback, 647 base::Unretained(this))); 648 web_ui()->RegisterMessageCallback( 649 "performFactoryResetRestart", 650 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart, 651 base::Unretained(this))); 652#else 653 web_ui()->RegisterMessageCallback( 654 "restartBrowser", 655 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser, 656 base::Unretained(this))); 657#endif 658} 659 660void BrowserOptionsHandler::OnStateChanged() { 661 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 662 *GetSyncStateDictionary()); 663 664 SendProfilesInfo(); 665} 666 667void BrowserOptionsHandler::OnSigninAllowedPrefChange() { 668 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 669 *GetSyncStateDictionary()); 670 671 SendProfilesInfo(); 672} 673 674void BrowserOptionsHandler::PageLoadStarted() { 675 page_initialized_ = false; 676} 677 678void BrowserOptionsHandler::InitializeHandler() { 679 Profile* profile = Profile::FromWebUI(web_ui()); 680 PrefService* prefs = profile->GetPrefs(); 681 682 ProfileSyncService* sync_service( 683 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); 684 if (sync_service) 685 sync_service->AddObserver(this); 686 687 // Create our favicon data source. 688 content::URLDataSource::Add( 689 profile, new FaviconSource(profile, FaviconSource::FAVICON)); 690 691 default_browser_policy_.Init( 692 prefs::kDefaultBrowserSettingEnabled, 693 g_browser_process->local_state(), 694 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState, 695 base::Unretained(this))); 696 697 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 698 content::NotificationService::AllSources()); 699#if defined(OS_CHROMEOS) 700 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 701 content::NotificationService::AllSources()); 702#endif 703 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 704 content::Source<ThemeService>( 705 ThemeServiceFactory::GetForProfile(profile))); 706 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 707 content::Source<Profile>(profile)); 708 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 709 content::Source<Profile>(profile)); 710 AddTemplateUrlServiceObserver(); 711 712#if defined(OS_WIN) 713 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 714 if (!command_line.HasSwitch(switches::kChromeFrame) && 715 !command_line.HasSwitch(switches::kUserDataDir)) { 716 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 717 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, 718 weak_ptr_factory_.GetWeakPtr(), 719 profile->GetPath())); 720 } 721#endif 722 723#if !defined(OS_CHROMEOS) 724 base::Closure cloud_print_callback = base::Bind( 725 &BrowserOptionsHandler::OnCloudPrintPrefsChanged, base::Unretained(this)); 726 cloud_print_connector_email_.Init( 727 prefs::kCloudPrintEmail, prefs, cloud_print_callback); 728 cloud_print_connector_enabled_.Init( 729 prefs::kCloudPrintProxyEnabled, prefs, cloud_print_callback); 730#endif 731 732 auto_open_files_.Init( 733 prefs::kDownloadExtensionsToOpen, prefs, 734 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, 735 base::Unretained(this))); 736 default_zoom_level_.Init( 737 prefs::kDefaultZoomLevel, prefs, 738 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, 739 base::Unretained(this))); 740 profile_pref_registrar_.Init(prefs); 741 profile_pref_registrar_.Add( 742 prefs::kWebKitDefaultFontSize, 743 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, 744 base::Unretained(this))); 745 profile_pref_registrar_.Add( 746 prefs::kWebKitDefaultFixedFontSize, 747 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, 748 base::Unretained(this))); 749 profile_pref_registrar_.Add( 750 prefs::kSigninAllowed, 751 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange, 752 base::Unretained(this))); 753 754#if !defined(OS_CHROMEOS) 755 profile_pref_registrar_.Add( 756 prefs::kProxy, 757 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection, 758 base::Unretained(this))); 759#endif // !defined(OS_CHROMEOS) 760} 761 762void BrowserOptionsHandler::InitializePage() { 763 page_initialized_ = true; 764 765 OnTemplateURLServiceChanged(); 766 767 ObserveThemeChanged(); 768 OnStateChanged(); 769 UpdateDefaultBrowserState(); 770 771 SetupMetricsReportingSettingVisibility(); 772 SetupPasswordGenerationSettingVisibility(); 773 SetupFontSizeSelector(); 774 SetupPageZoomSelector(); 775 SetupAutoOpenFileTypes(); 776 SetupProxySettingsSection(); 777#if !defined(OS_CHROMEOS) 778 if (cloud_print_connector_ui_enabled_) { 779 SetupCloudPrintConnectorSection(); 780 RefreshCloudPrintStatusFromService(); 781 } else { 782 RemoveCloudPrintConnectorSection(); 783 } 784#endif 785#if defined(OS_CHROMEOS) 786 SetupAccessibilityFeatures(); 787 if (!g_browser_process->browser_policy_connector()->IsEnterpriseManaged() && 788 !chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 789 web_ui()->CallJavascriptFunction( 790 "BrowserOptions.enableFactoryResetSection"); 791 } 792#endif 793} 794 795// static 796void BrowserOptionsHandler::CheckAutoLaunch( 797 base::WeakPtr<BrowserOptionsHandler> weak_this, 798 const base::FilePath& profile_path) { 799#if defined(OS_WIN) 800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 801 802 // Auto-launch is not supported for secondary profiles yet. 803 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile)) 804 return; 805 806 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is 807 // deleted. 808 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 809 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, 810 weak_this, 811 auto_launch_trial::IsInAutoLaunchGroup(), 812 auto_launch_util::AutoStartRequested( 813 profile_path.BaseName().value(), 814 true, // Window requested. 815 base::FilePath()))); 816#endif 817} 818 819void BrowserOptionsHandler::CheckAutoLaunchCallback( 820 bool is_in_auto_launch_group, 821 bool will_launch_at_login) { 822#if defined(OS_WIN) 823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 824 825 if (is_in_auto_launch_group) { 826 web_ui()->RegisterMessageCallback("toggleAutoLaunch", 827 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, 828 base::Unretained(this))); 829 830 base::FundamentalValue enabled(will_launch_at_login); 831 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", 832 enabled); 833 } 834#endif 835} 836 837void BrowserOptionsHandler::UpdateDefaultBrowserState() { 838 // Check for side-by-side first. 839 if (ShellIntegration::CanSetAsDefaultBrowser() == 840 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { 841 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); 842 return; 843 } 844 845#if defined(OS_MACOSX) 846 ShellIntegration::DefaultWebClientState state = 847 ShellIntegration::GetDefaultBrowser(); 848 int status_string_id; 849 if (state == ShellIntegration::IS_DEFAULT) 850 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; 851 else if (state == ShellIntegration::NOT_DEFAULT) 852 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; 853 else 854 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; 855 856 SetDefaultBrowserUIString(status_string_id); 857#else 858 default_browser_worker_->StartCheckIsDefault(); 859#endif 860} 861 862void BrowserOptionsHandler::BecomeDefaultBrowser(const ListValue* args) { 863 // If the default browser setting is managed then we should not be able to 864 // call this function. 865 if (default_browser_policy_.IsManaged()) 866 return; 867 868 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser")); 869#if defined(OS_MACOSX) 870 if (ShellIntegration::SetAsDefaultBrowser()) 871 UpdateDefaultBrowserState(); 872#else 873 default_browser_worker_->StartSetAsDefault(); 874 // Callback takes care of updating UI. 875#endif 876 877 // If the user attempted to make Chrome the default browser, then he/she 878 // arguably wants to be notified when that changes. 879 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 880 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); 881} 882 883int BrowserOptionsHandler::StatusStringIdForState( 884 ShellIntegration::DefaultWebClientState state) { 885 if (state == ShellIntegration::IS_DEFAULT) 886 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; 887 if (state == ShellIntegration::NOT_DEFAULT) 888 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; 889 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; 890} 891 892void BrowserOptionsHandler::SetDefaultWebClientUIState( 893 ShellIntegration::DefaultWebClientUIState state) { 894 int status_string_id; 895 if (state == ShellIntegration::STATE_IS_DEFAULT) 896 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; 897 else if (state == ShellIntegration::STATE_NOT_DEFAULT) 898 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; 899 else if (state == ShellIntegration::STATE_UNKNOWN) 900 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; 901 else 902 return; // Still processing. 903 904 SetDefaultBrowserUIString(status_string_id); 905} 906 907bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() { 908 return true; // This is UI so we can allow it. 909} 910 911void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) { 912 base::StringValue status_string( 913 l10n_util::GetStringFUTF16(status_string_id, 914 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 915 916 base::FundamentalValue is_default( 917 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT); 918 919 base::FundamentalValue can_be_default( 920 !default_browser_policy_.IsManaged() && 921 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT || 922 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT)); 923 924 web_ui()->CallJavascriptFunction( 925 "BrowserOptions.updateDefaultBrowserState", 926 status_string, is_default, can_be_default); 927} 928 929void BrowserOptionsHandler::OnTemplateURLServiceChanged() { 930 if (!template_url_service_ || !template_url_service_->loaded()) 931 return; 932 933 const TemplateURL* default_url = 934 template_url_service_->GetDefaultSearchProvider(); 935 936 int default_index = -1; 937 ListValue search_engines; 938 TemplateURLService::TemplateURLVector model_urls( 939 template_url_service_->GetTemplateURLs()); 940 for (size_t i = 0; i < model_urls.size(); ++i) { 941 if (!model_urls[i]->ShowInDefaultList()) 942 continue; 943 944 DictionaryValue* entry = new DictionaryValue(); 945 entry->SetString("name", model_urls[i]->short_name()); 946 entry->SetInteger("index", i); 947 search_engines.Append(entry); 948 if (model_urls[i] == default_url) 949 default_index = i; 950 } 951 952 web_ui()->CallJavascriptFunction( 953 "BrowserOptions.updateSearchEngines", 954 search_engines, 955 base::FundamentalValue(default_index), 956 base::FundamentalValue( 957 template_url_service_->is_default_search_managed())); 958} 959 960void BrowserOptionsHandler::SetDefaultSearchEngine(const ListValue* args) { 961 int selected_index = -1; 962 if (!ExtractIntegerValue(args, &selected_index)) { 963 NOTREACHED(); 964 return; 965 } 966 967 TemplateURLService::TemplateURLVector model_urls( 968 template_url_service_->GetTemplateURLs()); 969 if (selected_index >= 0 && 970 selected_index < static_cast<int>(model_urls.size())) 971 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); 972 973 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); 974} 975 976void BrowserOptionsHandler::AddTemplateUrlServiceObserver() { 977 template_url_service_ = 978 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 979 if (template_url_service_) { 980 template_url_service_->Load(); 981 template_url_service_->AddObserver(this); 982 } 983} 984 985void BrowserOptionsHandler::Observe( 986 int type, 987 const content::NotificationSource& source, 988 const content::NotificationDetails& details) { 989 // Notifications are used to update the UI dynamically when settings change in 990 // the background. If the UI is currently being loaded, no dynamic updates are 991 // possible (as the DOM and JS are not fully loaded) or necessary (as 992 // InitializePage() will update the UI at the end of the load). 993 if (!page_initialized_) 994 return; 995 996 switch (type) { 997 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 998 ObserveThemeChanged(); 999 break; 1000#if defined(OS_CHROMEOS) 1001 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: 1002 UpdateAccountPicture(); 1003 break; 1004#endif 1005 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: 1006 // If the browser shuts down during supervised-profile creation, deleting 1007 // the unregistered supervised-user profile triggers this notification, 1008 // but the RenderViewHost the profile info would be sent to has already 1009 // been destroyed. 1010 if (!web_ui()->GetWebContents()->GetRenderViewHost()) 1011 return; 1012 SendProfilesInfo(); 1013 break; 1014 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: 1015 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: 1016 // Update our sync/signin status display. 1017 OnStateChanged(); 1018 break; 1019 default: 1020 NOTREACHED(); 1021 } 1022} 1023 1024void BrowserOptionsHandler::OnCloudPrintPrefsChanged() { 1025#if !defined(OS_CHROMEOS) 1026 if (cloud_print_connector_ui_enabled_) 1027 SetupCloudPrintConnectorSection(); 1028#endif 1029} 1030 1031void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { 1032#if defined(OS_WIN) 1033 if (!auto_launch_trial::IsInAutoLaunchGroup()) 1034 return; 1035 1036 bool enable; 1037 CHECK_EQ(args->GetSize(), 1U); 1038 CHECK(args->GetBoolean(0, &enable)); 1039 1040 Profile* profile = Profile::FromWebUI(web_ui()); 1041 content::BrowserThread::PostTask( 1042 content::BrowserThread::FILE, FROM_HERE, 1043 enable ? 1044 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin, 1045 profile->GetPath().BaseName().value(), base::FilePath()) : 1046 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin, 1047 profile->GetPath().BaseName().value())); 1048#endif // OS_WIN 1049} 1050 1051scoped_ptr<ListValue> BrowserOptionsHandler::GetProfilesInfoList() { 1052 ProfileInfoCache& cache = 1053 g_browser_process->profile_manager()->GetProfileInfoCache(); 1054 scoped_ptr<ListValue> profile_info_list(new ListValue); 1055 base::FilePath current_profile_path = 1056 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); 1057 1058 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { 1059 DictionaryValue* profile_value = new DictionaryValue(); 1060 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); 1061 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i); 1062 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); 1063 profile_value->SetBoolean("isCurrentProfile", 1064 profile_path == current_profile_path); 1065 profile_value->SetBoolean("isManaged", cache.ProfileIsManagedAtIndex(i)); 1066 1067 bool is_gaia_picture = 1068 cache.IsUsingGAIAPictureOfProfileAtIndex(i) && 1069 cache.GetGAIAPictureOfProfileAtIndex(i); 1070 if (is_gaia_picture) { 1071 gfx::Image icon = profiles::GetAvatarIconForWebUI( 1072 cache.GetAvatarIconOfProfileAtIndex(i), true); 1073 profile_value->SetString("iconURL", 1074 webui::GetBitmapDataUrl(icon.AsBitmap())); 1075 } else { 1076 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); 1077 profile_value->SetString("iconURL", 1078 cache.GetDefaultAvatarIconUrl(icon_index)); 1079 } 1080 1081 profile_info_list->Append(profile_value); 1082 } 1083 1084 return profile_info_list.Pass(); 1085} 1086 1087void BrowserOptionsHandler::SendProfilesInfo() { 1088 if (!ShouldShowMultiProfilesUserList(GetDesktopType())) 1089 return; 1090 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo", 1091 *GetProfilesInfoList()); 1092} 1093 1094chrome::HostDesktopType BrowserOptionsHandler::GetDesktopType() { 1095 Browser* browser = 1096 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); 1097 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; 1098 if (browser) 1099 desktop_type = browser->host_desktop_type(); 1100 return desktop_type; 1101} 1102 1103void BrowserOptionsHandler::CreateProfile(const ListValue* args) { 1104 // This handler could have been called in managed mode, for example because 1105 // the user fiddled with the web inspector. Silently return in this case. 1106 Profile* current_profile = Profile::FromWebUI(web_ui()); 1107 if (current_profile->IsManaged()) 1108 return; 1109 1110 if (!profiles::IsMultipleProfilesEnabled()) 1111 return; 1112 1113 DCHECK(profile_path_being_created_.empty()); 1114 profile_creation_start_time_ = base::TimeTicks::Now(); 1115 1116 string16 name; 1117 string16 icon; 1118 bool create_shortcut = false; 1119 bool managed_user = false; 1120 if (args->GetString(0, &name) && args->GetString(1, &icon)) { 1121 if (args->GetBoolean(2, &create_shortcut)) { 1122 bool success = args->GetBoolean(3, &managed_user); 1123 DCHECK(success); 1124 } 1125 } 1126 1127 std::vector<ProfileManager::CreateCallback> callbacks; 1128 if (create_shortcut) 1129 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile)); 1130 1131 ProfileManager::CreateCallback show_user_feedback = 1132 base::Bind(&BrowserOptionsHandler::ShowProfileCreationFeedback, 1133 weak_ptr_factory_.GetWeakPtr(), GetDesktopType(), 1134 managed_user); 1135 1136 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) { 1137 callbacks.push_back( 1138 base::Bind(&BrowserOptionsHandler::RegisterNewManagedUser, 1139 weak_ptr_factory_.GetWeakPtr(), show_user_feedback)); 1140 } else { 1141 callbacks.push_back(show_user_feedback); 1142 } 1143 1144 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); 1145 1146 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( 1147 name, icon, base::Bind(&RunProfileCreationCallbacks, callbacks), 1148 managed_user); 1149} 1150 1151void BrowserOptionsHandler::RegisterNewManagedUser( 1152 const ProfileManager::CreateCallback& callback, 1153 Profile* new_profile, 1154 Profile::CreateStatus status) { 1155 DCHECK(profile_path_being_created_ == new_profile->GetPath()); 1156 if (status != Profile::CREATE_STATUS_INITIALIZED) 1157 return; 1158 1159 ManagedUserService* managed_user_service = 1160 ManagedUserServiceFactory::GetForProfile(new_profile); 1161 1162 // Register the managed user using the profile of the custodian. 1163 managed_user_registration_utility_ = 1164 ManagedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); 1165 managed_user_service->RegisterAndInitSync( 1166 managed_user_registration_utility_.get(), 1167 Profile::FromWebUI(web_ui()), 1168 callback); 1169} 1170 1171void BrowserOptionsHandler::RecordProfileCreationMetrics( 1172 Profile::CreateStatus status) { 1173 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", 1174 status, 1175 Profile::MAX_CREATE_STATUS); 1176 UMA_HISTOGRAM_CUSTOM_TIMES("Profile.CreateTime", 1177 base::TimeTicks::Now() - profile_creation_start_time_, 1178 base::TimeDelta::FromMilliseconds(1), 1179 base::TimeDelta::FromSeconds(30), // From kRegistrationTimeoutMS. 1180 100); 1181} 1182 1183void BrowserOptionsHandler::ShowProfileCreationFeedback( 1184 chrome::HostDesktopType desktop_type, 1185 bool is_managed, 1186 Profile* profile, 1187 Profile::CreateStatus status) { 1188 DCHECK(profile_path_being_created_ == profile->GetPath()); 1189 if (status != Profile::CREATE_STATUS_CREATED) 1190 RecordProfileCreationMetrics(status); 1191 1192 switch (status) { 1193 case Profile::CREATE_STATUS_LOCAL_FAIL: { 1194 profile_path_being_created_.clear(); 1195 web_ui()->CallJavascriptFunction( 1196 "BrowserOptions.showCreateProfileLocalError"); 1197 DeleteProfileAtPath(profile->GetPath()); 1198 break; 1199 } 1200 case Profile::CREATE_STATUS_REMOTE_FAIL: { 1201 profile_path_being_created_.clear(); 1202 web_ui()->CallJavascriptFunction( 1203 "BrowserOptions.showCreateProfileRemoteError"); 1204 DeleteProfileAtPath(profile->GetPath()); 1205 break; 1206 } 1207 case Profile::CREATE_STATUS_CREATED: { 1208 // Do nothing for an intermediate status. 1209 break; 1210 } 1211 case Profile::CREATE_STATUS_INITIALIZED: { 1212 profile_path_being_created_.clear(); 1213 DictionaryValue dict; 1214 dict.SetString("name", 1215 profile->GetPrefs()->GetString(prefs::kProfileName)); 1216 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); 1217 dict.SetBoolean("isManaged", is_managed); 1218 web_ui()->CallJavascriptFunction( 1219 "BrowserOptions.showCreateProfileSuccess", dict); 1220 1221 // If the new profile is a managed user, instead of opening a new window 1222 // right away, a confirmation overlay will be shown from the creation 1223 // dialog. 1224 if (!is_managed) { 1225 // Opening the new window must be the last action, after all callbacks 1226 // have been run, to give them a chance to initialize the profile. 1227 OpenNewWindowForProfile(desktop_type, 1228 profile, 1229 Profile::CREATE_STATUS_INITIALIZED); 1230 } 1231 break; 1232 } 1233 // User-initiated cancellation is handled in CancelProfileRegistration and 1234 // does not call this callback. 1235 case Profile::CREATE_STATUS_CANCELED: 1236 case Profile::MAX_CREATE_STATUS: { 1237 NOTREACHED(); 1238 break; 1239 } 1240 } 1241} 1242 1243void BrowserOptionsHandler::DeleteProfile(const ListValue* args) { 1244 DCHECK(args); 1245 const Value* file_path_value; 1246 if (!args->Get(0, &file_path_value)) 1247 return; 1248 1249 base::FilePath file_path; 1250 if (!base::GetValueAsFilePath(*file_path_value, &file_path)) 1251 return; 1252 DeleteProfileAtPath(file_path); 1253} 1254 1255void BrowserOptionsHandler::DeleteProfileAtPath(base::FilePath file_path) { 1256 // This handler could have been called in managed mode, for example because 1257 // the user fiddled with the web inspector. Silently return in this case. 1258 if (Profile::FromWebUI(web_ui())->IsManaged()) 1259 return; 1260 1261 if (!profiles::IsMultipleProfilesEnabled()) 1262 return; 1263 1264 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); 1265 1266 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 1267 file_path, 1268 base::Bind(&OpenNewWindowForProfile, GetDesktopType())); 1269} 1270 1271void BrowserOptionsHandler::HandleCancelProfileCreation(const ListValue* args) { 1272 CancelProfileRegistration(true); 1273} 1274 1275void BrowserOptionsHandler::CancelProfileRegistration(bool user_initiated) { 1276 if (profile_path_being_created_.empty()) 1277 return; 1278 1279 ProfileManager* manager = g_browser_process->profile_manager(); 1280 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); 1281 if (!new_profile) 1282 return; 1283 1284 // Non-managed user creation cannot be canceled. (Creating a non-managed 1285 // profile shouldn't take significant time, and it can easily be deleted 1286 // afterward.) 1287 if (!new_profile->IsManaged()) 1288 return; 1289 1290 if (user_initiated) { 1291 UMA_HISTOGRAM_CUSTOM_TIMES("Profile.CreateTimeCanceled", 1292 base::TimeTicks::Now() - profile_creation_start_time_, 1293 base::TimeDelta::FromMilliseconds(1), 1294 base::TimeDelta::FromSeconds(30), // From kRegistrationTimeoutMS. 1295 100); 1296 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); 1297 } 1298 1299 DCHECK(managed_user_registration_utility_.get()); 1300 managed_user_registration_utility_.reset(); 1301 1302 // Cancelling registration means the callback passed into 1303 // RegisterAndInitSync() won't be called, so the cleanup must be done here. 1304 profile_path_being_created_.clear(); 1305 DeleteProfileAtPath(new_profile->GetPath()); 1306} 1307 1308void BrowserOptionsHandler::ObserveThemeChanged() { 1309 Profile* profile = Profile::FromWebUI(web_ui()); 1310 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); 1311 bool is_native_theme = false; 1312 1313#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1314 bool profile_is_managed = profile->IsManaged(); 1315 is_native_theme = theme_service->UsingNativeTheme(); 1316 base::FundamentalValue native_theme_enabled(!is_native_theme && 1317 !profile_is_managed); 1318 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled", 1319 native_theme_enabled); 1320#endif 1321 1322 bool is_classic_theme = !is_native_theme && 1323 theme_service->UsingDefaultTheme(); 1324 base::FundamentalValue enabled(!is_classic_theme); 1325 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled", 1326 enabled); 1327} 1328 1329void BrowserOptionsHandler::ThemesReset(const ListValue* args) { 1330 Profile* profile = Profile::FromWebUI(web_ui()); 1331 content::RecordAction(UserMetricsAction("Options_ThemesReset")); 1332 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); 1333} 1334 1335#if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1336void BrowserOptionsHandler::ThemesSetNative(const ListValue* args) { 1337 content::RecordAction(UserMetricsAction("Options_GtkThemeSet")); 1338 Profile* profile = Profile::FromWebUI(web_ui()); 1339 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); 1340} 1341#endif 1342 1343#if defined(OS_CHROMEOS) 1344void BrowserOptionsHandler::UpdateAccountPicture() { 1345 std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email(); 1346 if (!email.empty()) { 1347 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture"); 1348 base::StringValue email_value(email); 1349 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", 1350 email_value); 1351 } 1352} 1353#endif 1354 1355scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { 1356 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); 1357 Profile* profile = Profile::FromWebUI(web_ui()); 1358 if (profile->IsManaged()) { 1359 sync_status->SetBoolean("supervisedUser", true); 1360 sync_status->SetBoolean("signinAllowed", false); 1361 return sync_status.Pass(); 1362 } 1363 if (profile->IsGuestSession()) { 1364 // Cannot display signin status when running in guest mode on chromeos 1365 // because there is no SigninManager. 1366 sync_status->SetBoolean("signinAllowed", false); 1367 return sync_status.Pass(); 1368 } 1369 sync_status->SetBoolean("supervisedUser", false); 1370 1371 bool signout_prohibited = false; 1372#if !defined(OS_CHROMEOS) 1373 // Signout is not allowed if the user has policy (crbug.com/172204). 1374 signout_prohibited = 1375 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited(); 1376#endif 1377 1378 ProfileSyncService* service = 1379 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 1380 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); 1381 DCHECK(signin); 1382 sync_status->SetBoolean("signoutAllowed", !signout_prohibited); 1383 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed()); 1384 sync_status->SetBoolean("syncSystemEnabled", !!service); 1385 sync_status->SetBoolean("setupCompleted", 1386 service && service->HasSyncSetupCompleted()); 1387 sync_status->SetBoolean("setupInProgress", 1388 service && !service->IsManaged() && service->FirstSetupInProgress()); 1389 1390 string16 status_label; 1391 string16 link_label; 1392 bool status_has_error = sync_ui_util::GetStatusLabels( 1393 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == 1394 sync_ui_util::SYNC_ERROR; 1395 sync_status->SetString("statusText", status_label); 1396 sync_status->SetString("actionLinkText", link_label); 1397 sync_status->SetBoolean("hasError", status_has_error); 1398 1399 sync_status->SetBoolean("managed", service && service->IsManaged()); 1400 sync_status->SetBoolean("signedIn", 1401 !signin->GetAuthenticatedUsername().empty()); 1402 sync_status->SetBoolean("hasUnrecoverableError", 1403 service && service->HasUnrecoverableError()); 1404 sync_status->SetBoolean( 1405 "autoLoginVisible", 1406 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) && 1407 service && service->IsSyncEnabledAndLoggedIn() && 1408 service->IsOAuthRefreshTokenAvailable()); 1409 1410 return sync_status.Pass(); 1411} 1412 1413void BrowserOptionsHandler::HandleSelectDownloadLocation( 1414 const ListValue* args) { 1415 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1416 select_folder_dialog_ = ui::SelectFileDialog::Create( 1417 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); 1418 ui::SelectFileDialog::FileTypeInfo info; 1419 info.support_drive = true; 1420 select_folder_dialog_->SelectFile( 1421 ui::SelectFileDialog::SELECT_FOLDER, 1422 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), 1423 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), 1424 &info, 1425 0, 1426 base::FilePath::StringType(), 1427 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), 1428 NULL); 1429} 1430 1431void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index, 1432 void* params) { 1433 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); 1434 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1435 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); 1436 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path); 1437} 1438 1439#if defined(OS_CHROMEOS) 1440void BrowserOptionsHandler::TouchpadExists(bool exists) { 1441 base::FundamentalValue val(exists); 1442 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val); 1443} 1444 1445void BrowserOptionsHandler::MouseExists(bool exists) { 1446 base::FundamentalValue val(exists); 1447 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val); 1448} 1449#endif 1450 1451void BrowserOptionsHandler::HandleAutoOpenButton(const ListValue* args) { 1452 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); 1453 DownloadManager* manager = BrowserContext::GetDownloadManager( 1454 web_ui()->GetWebContents()->GetBrowserContext()); 1455 if (manager) 1456 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); 1457} 1458 1459void BrowserOptionsHandler::HandleDefaultFontSize(const ListValue* args) { 1460 int font_size; 1461 if (ExtractIntegerValue(args, &font_size)) { 1462 if (font_size > 0) { 1463 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1464 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size); 1465 SetupFontSizeSelector(); 1466 } 1467 } 1468} 1469 1470void BrowserOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { 1471 double zoom_factor; 1472 if (ExtractDoubleValue(args, &zoom_factor)) { 1473 default_zoom_level_.SetValue(content::ZoomFactorToZoomLevel(zoom_factor)); 1474 } 1475} 1476 1477void BrowserOptionsHandler::HandleRestartBrowser(const ListValue* args) { 1478 chrome::AttemptRestart(); 1479} 1480 1481#if !defined(OS_CHROMEOS) 1482void BrowserOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { 1483 content::RecordAction(UserMetricsAction("Options_ShowProxySettings")); 1484 AdvancedOptionsUtilities::ShowNetworkProxySettings( 1485 web_ui()->GetWebContents()); 1486} 1487#endif 1488 1489#if !defined(USE_NSS) && !defined(USE_OPENSSL) 1490void BrowserOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { 1491 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); 1492 AdvancedOptionsUtilities::ShowManageSSLCertificates( 1493 web_ui()->GetWebContents()); 1494} 1495#endif 1496 1497void BrowserOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { 1498 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); 1499 // Open a new tab in the current window for the management page. 1500 Profile* profile = Profile::FromWebUI(web_ui()); 1501 OpenURLParams params( 1502 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), Referrer(), 1503 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); 1504 web_ui()->GetWebContents()->OpenURL(params); 1505} 1506 1507#if !defined(OS_CHROMEOS) 1508void BrowserOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { 1509 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); 1510 // Open the connector enable page in the current tab. 1511 Profile* profile = Profile::FromWebUI(web_ui()); 1512 OpenURLParams params( 1513 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( 1514 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), 1515 Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 1516 web_ui()->GetWebContents()->OpenURL(params); 1517} 1518 1519void BrowserOptionsHandler::HandleDisableCloudPrintConnector( 1520 const ListValue* args) { 1521 content::RecordAction( 1522 UserMetricsAction("Options_DisableCloudPrintProxy")); 1523 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 1524 DisableForUser(); 1525} 1526 1527void BrowserOptionsHandler::RefreshCloudPrintStatusFromService() { 1528 if (cloud_print_connector_ui_enabled_) 1529 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 1530 RefreshStatusFromService(); 1531} 1532 1533void BrowserOptionsHandler::SetupCloudPrintConnectorSection() { 1534 Profile* profile = Profile::FromWebUI(web_ui()); 1535 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { 1536 cloud_print_connector_ui_enabled_ = false; 1537 RemoveCloudPrintConnectorSection(); 1538 return; 1539 } 1540 1541 bool cloud_print_connector_allowed = 1542 !cloud_print_connector_enabled_.IsManaged() || 1543 cloud_print_connector_enabled_.GetValue(); 1544 base::FundamentalValue allowed(cloud_print_connector_allowed); 1545 1546 std::string email; 1547 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && 1548 cloud_print_connector_allowed) { 1549 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); 1550 } 1551 base::FundamentalValue disabled(email.empty()); 1552 1553 string16 label_str; 1554 if (email.empty()) { 1555 label_str = l10n_util::GetStringFUTF16( 1556 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, 1557 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); 1558 } else { 1559 label_str = l10n_util::GetStringFUTF16( 1560 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, 1561 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), 1562 UTF8ToUTF16(email)); 1563 } 1564 StringValue label(label_str); 1565 1566 web_ui()->CallJavascriptFunction( 1567 "BrowserOptions.setupCloudPrintConnectorSection", disabled, label, 1568 allowed); 1569} 1570 1571void BrowserOptionsHandler::RemoveCloudPrintConnectorSection() { 1572 web_ui()->CallJavascriptFunction( 1573 "BrowserOptions.removeCloudPrintConnectorSection"); 1574} 1575#endif 1576 1577#if defined(OS_CHROMEOS) 1578void BrowserOptionsHandler::HandleOpenWallpaperManager( 1579 const ListValue* args) { 1580 wallpaper_manager_util::OpenWallpaperManager(); 1581} 1582 1583void BrowserOptionsHandler::VirtualKeyboardChangeCallback( 1584 const ListValue* args) { 1585 bool enabled = false; 1586 args->GetBoolean(0, &enabled); 1587 1588 chromeos::accessibility::EnableVirtualKeyboard(enabled); 1589} 1590 1591#if defined(OS_CHROMEOS) 1592 1593void BrowserOptionsHandler::PerformFactoryResetRestart(const ListValue* args) { 1594 if (g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) 1595 return; 1596 1597 PrefService* prefs = g_browser_process->local_state(); 1598 prefs->SetBoolean(prefs::kFactoryResetRequested, true); 1599 prefs->CommitPendingWrite(); 1600 1601 // Perform sign out. Current chrome process will then terminate, new one will 1602 // be launched (as if it was a restart). 1603 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 1604} 1605 1606#endif 1607 1608void BrowserOptionsHandler::SetupAccessibilityFeatures() { 1609 PrefService* pref_service = g_browser_process->local_state(); 1610 base::FundamentalValue virtual_keyboard_enabled( 1611 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled)); 1612 web_ui()->CallJavascriptFunction( 1613 "BrowserOptions.setVirtualKeyboardCheckboxState", 1614 virtual_keyboard_enabled); 1615} 1616#endif 1617 1618void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() { 1619#if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) 1620 // Don't show the reporting setting if we are in the guest mode. 1621 if (CommandLine::ForCurrentProcess()->HasSwitch( 1622 chromeos::switches::kGuestSession)) { 1623 base::FundamentalValue visible(false); 1624 web_ui()->CallJavascriptFunction( 1625 "BrowserOptions.setMetricsReportingSettingVisibility", visible); 1626 } 1627#endif 1628} 1629 1630void BrowserOptionsHandler::SetupPasswordGenerationSettingVisibility() { 1631 base::FundamentalValue visible( 1632 CommandLine::ForCurrentProcess()->HasSwitch( 1633 switches::kEnablePasswordGeneration)); 1634 web_ui()->CallJavascriptFunction( 1635 "BrowserOptions.setPasswordGenerationSettingVisibility", visible); 1636} 1637 1638void BrowserOptionsHandler::SetupFontSizeSelector() { 1639 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1640 const PrefService::Preference* default_font_size = 1641 pref_service->FindPreference(prefs::kWebKitDefaultFontSize); 1642 const PrefService::Preference* default_fixed_font_size = 1643 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize); 1644 1645 DictionaryValue dict; 1646 dict.SetInteger("value", 1647 pref_service->GetInteger(prefs::kWebKitDefaultFontSize)); 1648 1649 // The font size control displays the value of the default font size, but 1650 // setting it alters both the default font size and the default fixed font 1651 // size. So it must be disabled when either of those prefs is not user 1652 // modifiable. 1653 dict.SetBoolean("disabled", 1654 !default_font_size->IsUserModifiable() || 1655 !default_fixed_font_size->IsUserModifiable()); 1656 1657 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref, 1658 // adapted to consider two prefs. It may be better to refactor 1659 // CreateValueForPref so it can be called from here. 1660 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) { 1661 dict.SetString("controlledBy", "policy"); 1662 } else if (default_font_size->IsExtensionControlled() || 1663 default_fixed_font_size->IsExtensionControlled()) { 1664 dict.SetString("controlledBy", "extension"); 1665 } 1666 1667 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict); 1668} 1669 1670void BrowserOptionsHandler::SetupPageZoomSelector() { 1671 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1672 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); 1673 double default_zoom_factor = 1674 content::ZoomLevelToZoomFactor(default_zoom_level); 1675 1676 // Generate a vector of zoom factors from an array of known presets along with 1677 // the default factor added if necessary. 1678 std::vector<double> zoom_factors = 1679 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); 1680 1681 // Iterate through the zoom factors and and build the contents of the 1682 // selector that will be sent to the javascript handler. 1683 // Each item in the list has the following parameters: 1684 // 1. Title (string). 1685 // 2. Value (double). 1686 // 3. Is selected? (bool). 1687 ListValue zoom_factors_value; 1688 for (std::vector<double>::const_iterator i = zoom_factors.begin(); 1689 i != zoom_factors.end(); ++i) { 1690 ListValue* option = new ListValue(); 1691 double factor = *i; 1692 int percent = static_cast<int>(factor * 100 + 0.5); 1693 option->Append(new base::StringValue( 1694 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); 1695 option->Append(new base::FundamentalValue(factor)); 1696 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); 1697 option->Append(new base::FundamentalValue(selected)); 1698 zoom_factors_value.Append(option); 1699 } 1700 1701 web_ui()->CallJavascriptFunction( 1702 "BrowserOptions.setupPageZoomSelector", zoom_factors_value); 1703} 1704 1705void BrowserOptionsHandler::SetupAutoOpenFileTypes() { 1706 // Set the hidden state for the AutoOpenFileTypesResetToDefault button. 1707 // We show the button if the user has any auto-open file types registered. 1708 DownloadManager* manager = BrowserContext::GetDownloadManager( 1709 web_ui()->GetWebContents()->GetBrowserContext()); 1710 bool display = manager && 1711 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); 1712 base::FundamentalValue value(display); 1713 web_ui()->CallJavascriptFunction( 1714 "BrowserOptions.setAutoOpenFileTypesDisplayed", value); 1715} 1716 1717void BrowserOptionsHandler::SetupProxySettingsSection() { 1718#if !defined(OS_CHROMEOS) 1719 // Disable the button if proxy settings are managed by a sysadmin or 1720 // overridden by an extension. 1721 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1722 const PrefService::Preference* proxy_config = 1723 pref_service->FindPreference(prefs::kProxy); 1724 bool is_extension_controlled = (proxy_config && 1725 proxy_config->IsExtensionControlled()); 1726 1727 base::FundamentalValue disabled(proxy_config && 1728 !proxy_config->IsUserModifiable()); 1729 base::FundamentalValue extension_controlled(is_extension_controlled); 1730 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", 1731 disabled, extension_controlled); 1732 1733#endif // !defined(OS_CHROMEOS) 1734} 1735 1736} // namespace options 1737