browser_options_handler.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/path_service.h" 16#include "base/prefs/pref_service.h" 17#include "base/stl_util.h" 18#include "base/strings/string_number_conversions.h" 19#include "base/utf_string_conversions.h" 20#include "base/value_conversions.h" 21#include "base/values.h" 22#include "chrome/browser/auto_launch_trial.h" 23#include "chrome/browser/browser_process.h" 24#include "chrome/browser/chrome_page_zoom.h" 25#include "chrome/browser/custom_home_pages_table_model.h" 26#include "chrome/browser/download/download_prefs.h" 27#include "chrome/browser/gpu/gpu_mode_manager.h" 28#include "chrome/browser/lifetime/application_lifetime.h" 29#include "chrome/browser/net/url_fixer_upper.h" 30#include "chrome/browser/prefs/session_startup_pref.h" 31#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 32#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" 33#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" 34#include "chrome/browser/printing/cloud_print/cloud_print_url.h" 35#include "chrome/browser/profiles/profile_info_cache.h" 36#include "chrome/browser/profiles/profile_info_util.h" 37#include "chrome/browser/profiles/profile_manager.h" 38#include "chrome/browser/profiles/profile_shortcut_manager.h" 39#include "chrome/browser/search/search.h" 40#include "chrome/browser/search_engines/template_url.h" 41#include "chrome/browser/search_engines/template_url_service.h" 42#include "chrome/browser/search_engines/template_url_service_factory.h" 43#include "chrome/browser/service/service_process_control.h" 44#include "chrome/browser/signin/signin_manager.h" 45#include "chrome/browser/signin/signin_manager_factory.h" 46#include "chrome/browser/sync/profile_sync_service.h" 47#include "chrome/browser/sync/profile_sync_service_factory.h" 48#include "chrome/browser/sync/sync_ui_util.h" 49#include "chrome/browser/themes/theme_service.h" 50#include "chrome/browser/themes/theme_service_factory.h" 51#include "chrome/browser/ui/browser_finder.h" 52#include "chrome/browser/ui/chrome_select_file_policy.h" 53#include "chrome/browser/ui/host_desktop.h" 54#include "chrome/browser/ui/options/options_util.h" 55#include "chrome/browser/ui/webui/favicon_source.h" 56#include "chrome/common/chrome_constants.h" 57#include "chrome/common/chrome_notification_types.h" 58#include "chrome/common/chrome_paths.h" 59#include "chrome/common/chrome_switches.h" 60#include "chrome/common/pref_names.h" 61#include "chrome/common/url_constants.h" 62#include "content/public/browser/browser_thread.h" 63#include "content/public/browser/download_manager.h" 64#include "content/public/browser/navigation_controller.h" 65#include "content/public/browser/notification_details.h" 66#include "content/public/browser/notification_service.h" 67#include "content/public/browser/notification_source.h" 68#include "content/public/browser/notification_types.h" 69#include "content/public/browser/url_data_source.h" 70#include "content/public/browser/user_metrics.h" 71#include "content/public/browser/web_contents.h" 72#include "content/public/browser/web_contents_view.h" 73#include "content/public/common/page_zoom.h" 74#include "google_apis/gaia/google_service_auth_error.h" 75#include "grit/chromium_strings.h" 76#include "grit/generated_resources.h" 77#include "grit/locale_settings.h" 78#include "grit/theme_resources.h" 79#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 80#include "third_party/skia/include/core/SkBitmap.h" 81#include "ui/base/l10n/l10n_util.h" 82#include "ui/webui/web_ui_util.h" 83 84#if defined(ENABLE_MANAGED_USERS) 85#include "chrome/browser/managed_mode/managed_mode.h" 86#include "chrome/browser/managed_mode/managed_user_registration_service.h" 87#include "chrome/browser/managed_mode/managed_user_registration_service_factory.h" 88#include "chrome/browser/managed_mode/managed_user_service.h" 89#include "chrome/browser/managed_mode/managed_user_service_factory.h" 90#endif 91 92#if !defined(OS_CHROMEOS) 93#include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" 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 "base/chromeos/chromeos_version.h" 101#include "chrome/browser/chromeos/accessibility/accessibility_util.h" 102#include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" 103#include "chrome/browser/chromeos/login/user_manager.h" 104#include "chrome/browser/chromeos/settings/cros_settings.h" 105#include "chrome/browser/policy/browser_policy_connector.h" 106#include "chrome/browser/ui/browser_window.h" 107#include "chrome/browser/ui/webui/options/chromeos/timezone_options_util.h" 108#include "chromeos/chromeos_switches.h" 109#include "chromeos/dbus/dbus_thread_manager.h" 110#include "chromeos/dbus/power_manager_client.h" 111#include "ui/gfx/image/image_skia.h" 112#endif // defined(OS_CHROMEOS) 113 114#if defined(OS_WIN) 115#include "chrome/installer/util/auto_launch_util.h" 116#endif // defined(OS_WIN) 117 118#if defined(TOOLKIT_GTK) 119#include "chrome/browser/ui/gtk/gtk_theme_service.h" 120#endif // defined(TOOLKIT_GTK) 121 122using content::BrowserContext; 123using content::BrowserThread; 124using content::DownloadManager; 125using content::OpenURLParams; 126using content::Referrer; 127using content::UserMetricsAction; 128 129namespace options { 130 131namespace { 132 133bool ShouldShowMultiProfilesUserList() { 134#if defined(OS_CHROMEOS) 135 // On Chrome OS we use different UI for multi-profiles. 136 return false; 137#else 138 return ProfileManager::IsMultipleProfilesEnabled(); 139#endif 140} 141 142void CreateDesktopShortcutForProfile(Profile* profile, 143 Profile::CreateStatus status) { 144 ProfileShortcutManager* shortcut_manager = 145 g_browser_process->profile_manager()->profile_shortcut_manager(); 146 if (shortcut_manager) 147 shortcut_manager->CreateProfileShortcut(profile->GetPath()); 148} 149 150void OnProfileCreated( 151 const std::vector<ProfileManager::CreateCallback>& callbacks, 152 Profile* profile, 153 Profile::CreateStatus status) { 154 std::vector<ProfileManager::CreateCallback>::const_iterator it; 155 for (it = callbacks.begin(); it != callbacks.end(); ++it) { 156 it->Run(profile, status); 157 } 158} 159 160} // namespace 161 162BrowserOptionsHandler::BrowserOptionsHandler() 163 : page_initialized_(false), 164 template_url_service_(NULL), 165 weak_ptr_factory_(this) { 166#if !defined(OS_MACOSX) 167 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); 168#endif 169#if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) 170 // On Windows, we need the PDF plugin which is only guaranteed to exist on 171 // Google Chrome builds. Use a command-line switch for Windows non-Google 172 // Chrome builds. 173 cloud_print_connector_ui_enabled_ = 174 CommandLine::ForCurrentProcess()->HasSwitch( 175 switches::kEnableCloudPrintProxy); 176#elif(!defined(OS_CHROMEOS)) 177 // Always enabled for Mac, Linux and Google Chrome Windows builds. 178 // Never enabled for Chrome OS, we don't even need to indicate it. 179 cloud_print_connector_ui_enabled_ = true; 180#endif 181} 182 183BrowserOptionsHandler::~BrowserOptionsHandler() { 184 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: 185 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); 186 if (sync_service) 187 sync_service->RemoveObserver(this); 188 189 if (default_browser_worker_.get()) 190 default_browser_worker_->ObserverDestroyed(); 191 if (template_url_service_) 192 template_url_service_->RemoveObserver(this); 193 // There may be pending file dialogs, we need to tell them that we've gone 194 // away so they don't try and call back to us. 195 if (select_folder_dialog_.get()) 196 select_folder_dialog_->ListenerDestroyed(); 197} 198 199void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) { 200 DCHECK(values); 201 202 static OptionsStringResource resources[] = { 203 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT }, 204 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY }, 205 { "advancedSectionTitleContent", 206 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, 207 { "advancedSectionTitleLanguages", 208 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES }, 209 { "advancedSectionTitleNetwork", 210 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, 211 { "advancedSectionTitlePrivacy", 212 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, 213 { "advancedSectionTitleSecurity", 214 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY }, 215 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE }, 216 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, 217 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, 218 { "autoOpenFileTypesResetToDefault", 219 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, 220 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, 221 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, 222 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL }, 223 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, 224 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, 225 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, 226#if defined(OS_CHROMEOS) 227 { "disableGData", IDS_OPTIONS_DISABLE_GDATA }, 228#endif 229 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES }, 230#if defined(OS_CHROMEOS) 231 { "displayOptions", 232 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL }, 233#endif 234 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK }, 235 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT }, 236 { "doNotTrackConfirmEnable", 237 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE }, 238 { "doNotTrackConfirmDisable", 239 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE }, 240 { "downloadLocationAskForSaveLocation", 241 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION }, 242 { "downloadLocationBrowseTitle", 243 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE }, 244 { "downloadLocationChangeButton", 245 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON }, 246 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME }, 247 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING }, 248 { "fontSettingsCustomizeFontsButton", 249 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON }, 250 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM }, 251 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE }, 252 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, 253 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, 254 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE }, 255 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, 256 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS }, 257 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP }, 258 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, 259 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, 260 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, 261 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, 262 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE }, 263 { "languageAndSpellCheckSettingsButton", 264 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS }, 265 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF }, 266 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK }, 267 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK }, 268 { "networkPredictionEnabledDescription", 269 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, 270 { "passwordsAndAutofillGroupName", 271 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME }, 272 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE }, 273 { "passwordGenerationEnabledDescription", 274 IDS_OPTIONS_PASSWORD_GENERATION_ENABLED_LABEL }, 275 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, 276 { "privacyContentSettingsButton", 277 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON }, 278 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL }, 279 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL }, 280 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL }, 281 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT }, 282 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL }, 283#if defined(ENABLE_SETTINGS_APP) 284 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL }, 285#endif 286 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL }, 287 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL, 288 IDS_PRODUCT_NAME }, 289 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON }, 290 { "resetProfileSettingsDescription", 291 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION }, 292 { "resetProfileSettingsSectionTitle", 293 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE }, 294 { "safeBrowsingEnableProtection", 295 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION }, 296 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME }, 297 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME }, 298 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME }, 299 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME }, 300 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME }, 301 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME }, 302 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT }, 303 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE }, 304 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE }, 305 { "spellingPref", IDS_OPTIONS_SPELLING_PREF }, 306 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION }, 307 { "settingsTitle", IDS_SETTINGS_TITLE }, 308 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS }, 309 { "sslCheckRevocation", IDS_OPTIONS_SSL_CHECKREVOCATION }, 310 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES }, 311 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB }, 312 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES }, 313 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF }, 314 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS }, 315 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL }, 316 { "themesGallery", IDS_THEMES_GALLERY_BUTTON }, 317 { "themesGalleryURL", IDS_THEMES_GALLERY_URL }, 318 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF }, 319 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR }, 320 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, 321 { "translateEnableTranslate", 322 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, 323#if defined(TOOLKIT_GTK) 324 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS }, 325 { "themesGTKButton", IDS_THEMES_GTK_BUTTON }, 326 { "themesSetClassic", IDS_THEMES_SET_CLASSIC }, 327#else 328 { "themes", IDS_THEMES_GROUP_NAME }, 329 { "themesReset", IDS_THEMES_RESET_BUTTON }, 330#endif 331#if defined(OS_CHROMEOS) 332 { "accessibilityExplanation", 333 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION }, 334 { "accessibilityHighContrast", 335 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION }, 336 { "accessibilityScreenMagnifier", 337 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION }, 338 { "accessibilityTapDragging", 339 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION }, 340 { "accessibilityScreenMagnifierOff", 341 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF }, 342 { "accessibilityScreenMagnifierFull", 343 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL }, 344 { "accessibilityScreenMagnifierPartial", 345 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL }, 346 { "accessibilitySpokenFeedback", 347 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION }, 348 { "accessibilityTitle", 349 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY }, 350 { "accessibilityVirtualKeyboard", 351 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION }, 352 { "accessibilityAlwaysShowMenu", 353 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU }, 354 { "advancedSectionTitleKiosk", IDS_OPTIONS_KIOSK }, 355 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING }, 356 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET }, 357 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON }, 358 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON }, 359 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING }, 360 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL }, 361 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE_CAPTION }, 362 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME }, 363 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION }, 364 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION }, 365 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION }, 366 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION }, 367 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX }, 368 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE }, 369 { "keyboardSettingsButtonTitle", 370 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE }, 371 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE }, 372 { "manageKioskAppsButton", IDS_OPTIONS_KIOSK_MANAGE_BUTTON }, 373 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES }, 374 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME }, 375 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL }, 376 { "syncOverview", IDS_SYNC_OVERVIEW }, 377 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL }, 378 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION }, 379 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION }, 380#else 381 { "cloudPrintConnectorEnabledManageButton", 382 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON}, 383 { "cloudPrintConnectorEnablingButton", 384 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON }, 385 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON }, 386#endif 387#if defined(OS_CHROMEOS) && defined(USE_ASH) 388 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON }, 389#endif 390 { "advancedSectionTitleSystem", 391 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM }, 392#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) 393 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE }, 394#endif 395#if !defined(OS_CHROMEOS) 396 { "gpuModeCheckbox", 397 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE }, 398 { "gpuModeResetRestart", 399 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART }, 400 // Strings with product-name substitutions. 401 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME }, 402 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL }, 403#endif 404 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL, 405 IDS_SHORT_PRODUCT_NAME }, 406 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE, 407 IDS_PRODUCT_NAME }, 408 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, 409 IDS_PRODUCT_NAME }, 410 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, 411 IDS_PRODUCT_NAME }, 412 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT, IDS_PRODUCT_NAME }, 413#if defined(OS_CHROMEOS) 414 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION, 415 IDS_SHORT_PRODUCT_NAME }, 416#endif 417 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, 418 IDS_SHORT_PRODUCT_NAME }, 419 }; 420 421#if defined(ENABLE_SETTINGS_APP) 422 static OptionsStringResource app_resources[] = { 423 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW }, 424 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL, 425 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 426 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE, 427 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 428 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, 429 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 430 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL, 431 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME }, 432 }; 433 DictionaryValue* app_values = NULL; 434 CHECK(values->GetDictionary(kSettingsAppKey, &app_values)); 435 RegisterStrings(app_values, app_resources, arraysize(app_resources)); 436#endif 437 438 RegisterStrings(values, resources, arraysize(resources)); 439 RegisterTitle(values, "doNotTrackConfirmOverlay", 440 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE); 441 RegisterTitle(values, "spellingConfirmOverlay", 442 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE); 443 RegisterCloudPrintValues(values); 444 445 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL); 446 string16 omnibox_url = ASCIIToUTF16(chrome::kOmniboxLearnMoreURL); 447 values->SetString( 448 "defaultSearchGroupLabel", 449 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url)); 450 451#if defined(OS_CHROMEOS) 452 const chromeos::User* user = chromeos::UserManager::Get()->GetLoggedInUser(); 453 values->SetString("username", user ? user->email() : std::string()); 454#endif 455 456 // Pass along sync status early so it will be available during page init. 457 values->Set("syncData", GetSyncStateDictionary().release()); 458 459 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 460 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 461 462#if defined(OS_CHROMEOS) 463 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); 464 465 // TODO(pastarmovj): replace this with a call to the CrosSettings list 466 // handling functionality to come. 467 values->Set("timezoneList", GetTimezoneList().release()); 468 469 values->SetString("accessibilityLearnMoreURL", 470 chrome::kChromeAccessibilityHelpURL); 471 472 // Creates magnifierList. 473 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue); 474 475 scoped_ptr<base::ListValue> option_full(new base::ListValue); 476 option_full->AppendInteger(ash::MAGNIFIER_FULL); 477 option_full->AppendString(l10n_util::GetStringUTF16( 478 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL)); 479 magnifier_list->Append(option_full.release()); 480 481 scoped_ptr<base::ListValue> option_partial(new base::ListValue); 482 option_partial->AppendInteger(ash::MAGNIFIER_PARTIAL); 483 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16( 484 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL))); 485 magnifier_list->Append(option_partial.release()); 486 487 values->Set("magnifierList", magnifier_list.release()); 488 489 // Sets flag of whether kiosk section should be enabled. 490 values->SetBoolean( 491 "enableKioskSection", 492 CommandLine::ForCurrentProcess()->HasSwitch( 493 chromeos::switches::kEnableKioskAppSettings) && 494 !CommandLine::ForCurrentProcess()->HasSwitch( 495 chromeos::switches::kDisableAppMode) && 496 (chromeos::UserManager::Get()->IsCurrentUserOwner() || 497 !base::chromeos::IsRunningOnChromeOS())); 498#endif 499 500#if defined(OS_MACOSX) 501 values->SetString("macPasswordsWarning", 502 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); 503 values->SetBoolean("multiple_profiles", 504 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); 505#endif 506 507 if (ShouldShowMultiProfilesUserList()) 508 values->Set("profilesInfo", GetProfilesInfoList().release()); 509 510#if defined(ENABLE_MANAGED_USERS) 511 ManagedUserService* service = 512 ManagedUserServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 513 values->SetBoolean("profileIsManaged", service->ProfileIsManaged()); 514#endif 515 516#if !defined(OS_CHROMEOS) 517 values->SetBoolean( 518 "gpuEnabledAtStart", 519 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref()); 520#endif 521 522 values->SetBoolean("enableResetProfileSettingsSection", 523 CommandLine::ForCurrentProcess()->HasSwitch( 524 switches::kEnableResetProfileSettings)); 525} 526 527void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) { 528#if defined(OS_CHROMEOS) 529 values->SetString("cloudPrintChromeosOptionLabel", 530 l10n_util::GetStringFUTF16( 531 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, 532 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 533 values->SetString("cloudPrintChromeosOptionButton", 534 l10n_util::GetStringFUTF16( 535 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON, 536 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 537#else 538 values->SetString("cloudPrintConnectorDisabledLabel", 539 l10n_util::GetStringFUTF16( 540 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, 541 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); 542 values->SetString("cloudPrintConnectorDisabledButton", 543 l10n_util::GetStringUTF16( 544 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON)); 545 values->SetString("cloudPrintConnectorEnabledButton", 546 l10n_util::GetStringUTF16( 547 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON)); 548#endif 549} 550 551void BrowserOptionsHandler::RegisterMessages() { 552 web_ui()->RegisterMessageCallback( 553 "becomeDefaultBrowser", 554 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, 555 base::Unretained(this))); 556 web_ui()->RegisterMessageCallback( 557 "setDefaultSearchEngine", 558 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, 559 base::Unretained(this))); 560 web_ui()->RegisterMessageCallback( 561 "createProfile", 562 base::Bind(&BrowserOptionsHandler::CreateProfile, 563 base::Unretained(this))); 564 web_ui()->RegisterMessageCallback( 565 "themesReset", 566 base::Bind(&BrowserOptionsHandler::ThemesReset, 567 base::Unretained(this))); 568#if defined(TOOLKIT_GTK) 569 web_ui()->RegisterMessageCallback( 570 "themesSetGTK", 571 base::Bind(&BrowserOptionsHandler::ThemesSetGTK, 572 base::Unretained(this))); 573#endif 574 web_ui()->RegisterMessageCallback( 575 "selectDownloadLocation", 576 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation, 577 base::Unretained(this))); 578 web_ui()->RegisterMessageCallback( 579 "autoOpenFileTypesAction", 580 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton, 581 base::Unretained(this))); 582 web_ui()->RegisterMessageCallback( 583 "defaultFontSizeAction", 584 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize, 585 base::Unretained(this))); 586 web_ui()->RegisterMessageCallback( 587 "defaultZoomFactorAction", 588 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor, 589 base::Unretained(this))); 590#if !defined(USE_NSS) && !defined(USE_OPENSSL) 591 web_ui()->RegisterMessageCallback( 592 "showManageSSLCertificates", 593 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates, 594 base::Unretained(this))); 595#endif 596 web_ui()->RegisterMessageCallback( 597 "showCloudPrintManagePage", 598 base::Bind(&BrowserOptionsHandler::ShowCloudPrintManagePage, 599 base::Unretained(this))); 600#if !defined(OS_CHROMEOS) 601 if (cloud_print_connector_ui_enabled_) { 602 web_ui()->RegisterMessageCallback( 603 "showCloudPrintSetupDialog", 604 base::Bind(&BrowserOptionsHandler::ShowCloudPrintSetupDialog, 605 base::Unretained(this))); 606 web_ui()->RegisterMessageCallback( 607 "disableCloudPrintConnector", 608 base::Bind(&BrowserOptionsHandler::HandleDisableCloudPrintConnector, 609 base::Unretained(this))); 610 } 611 web_ui()->RegisterMessageCallback( 612 "showNetworkProxySettings", 613 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings, 614 base::Unretained(this))); 615#endif 616#if defined(OS_CHROMEOS) 617 web_ui()->RegisterMessageCallback( 618 "openWallpaperManager", 619 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager, 620 base::Unretained(this))); 621 web_ui()->RegisterMessageCallback( 622 "spokenFeedbackChange", 623 base::Bind(&BrowserOptionsHandler::SpokenFeedbackChangeCallback, 624 base::Unretained(this))); 625 web_ui()->RegisterMessageCallback( 626 "highContrastChange", 627 base::Bind(&BrowserOptionsHandler::HighContrastChangeCallback, 628 base::Unretained(this))); 629 web_ui()->RegisterMessageCallback( 630 "virtualKeyboardChange", 631 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback, 632 base::Unretained(this))); 633 web_ui()->RegisterMessageCallback( 634 "performFactoryResetRestart", 635 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart, 636 base::Unretained(this))); 637#else 638 web_ui()->RegisterMessageCallback( 639 "restartBrowser", 640 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser, 641 base::Unretained(this))); 642#endif 643} 644 645void BrowserOptionsHandler::OnStateChanged() { 646 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 647 *GetSyncStateDictionary()); 648 649 SendProfilesInfo(); 650} 651 652void BrowserOptionsHandler::OnSigninAllowedPrefChange() { 653 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 654 *GetSyncStateDictionary()); 655 656 SendProfilesInfo(); 657} 658 659void BrowserOptionsHandler::UpdateInstantCheckboxState() { 660 Profile* profile = Profile::FromWebUI(web_ui()); 661 662 web_ui()->CallJavascriptFunction( 663 "BrowserOptions.updateInstantCheckboxState", 664 base::FundamentalValue(chrome::IsInstantCheckboxEnabled(profile)), 665 base::FundamentalValue(chrome::IsInstantCheckboxChecked(profile)), 666 StringValue(chrome::GetInstantCheckboxLabel(profile))); 667} 668 669void BrowserOptionsHandler::PageLoadStarted() { 670 page_initialized_ = false; 671} 672 673void BrowserOptionsHandler::InitializeHandler() { 674 Profile* profile = Profile::FromWebUI(web_ui()); 675 PrefService* prefs = profile->GetPrefs(); 676 677 ProfileSyncService* sync_service( 678 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); 679 if (sync_service) 680 sync_service->AddObserver(this); 681 682 // Create our favicon data source. 683 content::URLDataSource::Add( 684 profile, new FaviconSource(profile, FaviconSource::FAVICON)); 685 686 default_browser_policy_.Init( 687 prefs::kDefaultBrowserSettingEnabled, 688 g_browser_process->local_state(), 689 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState, 690 base::Unretained(this))); 691 692 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 693 content::NotificationService::AllSources()); 694#if defined(OS_CHROMEOS) 695 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 696 content::NotificationService::AllSources()); 697#endif 698 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 699 content::Source<ThemeService>( 700 ThemeServiceFactory::GetForProfile(profile))); 701 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 702 content::Source<Profile>(profile)); 703 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 704 content::Source<Profile>(profile)); 705 AddTemplateUrlServiceObserver(); 706 707#if defined(OS_WIN) 708 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 709 if (!command_line.HasSwitch(switches::kChromeFrame) && 710 !command_line.HasSwitch(switches::kUserDataDir)) { 711 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 712 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, 713 weak_ptr_factory_.GetWeakPtr(), 714 profile->GetPath())); 715 } 716#endif 717 718#if !defined(OS_CHROMEOS) 719 base::Closure cloud_print_callback = base::Bind( 720 &BrowserOptionsHandler::OnCloudPrintPrefsChanged, base::Unretained(this)); 721 cloud_print_connector_email_.Init( 722 prefs::kCloudPrintEmail, prefs, cloud_print_callback); 723 cloud_print_connector_enabled_.Init( 724 prefs::kCloudPrintProxyEnabled, prefs, cloud_print_callback); 725#endif 726 727 auto_open_files_.Init( 728 prefs::kDownloadExtensionsToOpen, prefs, 729 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, 730 base::Unretained(this))); 731 default_zoom_level_.Init( 732 prefs::kDefaultZoomLevel, prefs, 733 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, 734 base::Unretained(this))); 735 profile_pref_registrar_.Init(prefs); 736 profile_pref_registrar_.Add( 737 prefs::kWebKitDefaultFontSize, 738 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, 739 base::Unretained(this))); 740 profile_pref_registrar_.Add( 741 prefs::kWebKitDefaultFixedFontSize, 742 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, 743 base::Unretained(this))); 744 profile_pref_registrar_.Add( 745 prefs::kSigninAllowed, 746 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange, 747 base::Unretained(this))); 748 profile_pref_registrar_.Add( 749 prefs::kSearchSuggestEnabled, 750 base::Bind(&BrowserOptionsHandler::UpdateInstantCheckboxState, 751 base::Unretained(this))); 752 753#if !defined(OS_CHROMEOS) 754 profile_pref_registrar_.Add( 755 prefs::kProxy, 756 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection, 757 base::Unretained(this))); 758#endif // !defined(OS_CHROMEOS) 759} 760 761void BrowserOptionsHandler::InitializePage() { 762 page_initialized_ = true; 763 764 // Note that OnTemplateURLServiceChanged calls UpdateInstantCheckboxState. 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 // Update the state of the Instant checkbox as the new search engine may not 960 // support Instant. 961 UpdateInstantCheckboxState(); 962} 963 964void BrowserOptionsHandler::SetDefaultSearchEngine(const ListValue* args) { 965 int selected_index = -1; 966 if (!ExtractIntegerValue(args, &selected_index)) { 967 NOTREACHED(); 968 return; 969 } 970 971 TemplateURLService::TemplateURLVector model_urls( 972 template_url_service_->GetTemplateURLs()); 973 if (selected_index >= 0 && 974 selected_index < static_cast<int>(model_urls.size())) 975 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); 976 977 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); 978} 979 980void BrowserOptionsHandler::AddTemplateUrlServiceObserver() { 981 template_url_service_ = 982 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 983 if (template_url_service_) { 984 template_url_service_->Load(); 985 template_url_service_->AddObserver(this); 986 } 987} 988 989void BrowserOptionsHandler::Observe( 990 int type, 991 const content::NotificationSource& source, 992 const content::NotificationDetails& details) { 993 // Notifications are used to update the UI dynamically when settings change in 994 // the background. If the UI is currently being loaded, no dynamic updates are 995 // possible (as the DOM and JS are not fully loaded) or necessary (as 996 // InitializePage() will update the UI at the end of the load). 997 if (!page_initialized_) 998 return; 999 1000 switch (type) { 1001 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 1002 ObserveThemeChanged(); 1003 break; 1004#if defined(OS_CHROMEOS) 1005 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: 1006 UpdateAccountPicture(); 1007 break; 1008#endif 1009 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: 1010 SendProfilesInfo(); 1011 break; 1012 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: 1013 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: 1014 // Update our sync/signin status display. 1015 OnStateChanged(); 1016 break; 1017 default: 1018 NOTREACHED(); 1019 } 1020} 1021 1022void BrowserOptionsHandler::OnCloudPrintPrefsChanged() { 1023#if !defined(OS_CHROMEOS) 1024 if (cloud_print_connector_ui_enabled_) 1025 SetupCloudPrintConnectorSection(); 1026#endif 1027} 1028 1029void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { 1030#if defined(OS_WIN) 1031 if (!auto_launch_trial::IsInAutoLaunchGroup()) 1032 return; 1033 1034 bool enable; 1035 CHECK_EQ(args->GetSize(), 1U); 1036 CHECK(args->GetBoolean(0, &enable)); 1037 1038 Profile* profile = Profile::FromWebUI(web_ui()); 1039 content::BrowserThread::PostTask( 1040 content::BrowserThread::FILE, FROM_HERE, 1041 enable ? 1042 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin, 1043 profile->GetPath().BaseName().value(), base::FilePath()) : 1044 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin, 1045 profile->GetPath().BaseName().value())); 1046#endif // OS_WIN 1047} 1048 1049scoped_ptr<ListValue> BrowserOptionsHandler::GetProfilesInfoList() { 1050 ProfileInfoCache& cache = 1051 g_browser_process->profile_manager()->GetProfileInfoCache(); 1052 scoped_ptr<ListValue> profile_info_list(new ListValue); 1053 base::FilePath current_profile_path = 1054 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); 1055 1056 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { 1057 DictionaryValue* profile_value = new DictionaryValue(); 1058 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); 1059 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i); 1060 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); 1061 profile_value->SetBoolean("isCurrentProfile", 1062 profile_path == current_profile_path); 1063 profile_value->SetBoolean("isManaged", cache.ProfileIsManagedAtIndex(i)); 1064 1065 bool is_gaia_picture = 1066 cache.IsUsingGAIAPictureOfProfileAtIndex(i) && 1067 cache.GetGAIAPictureOfProfileAtIndex(i); 1068 if (is_gaia_picture) { 1069 gfx::Image icon = profiles::GetAvatarIconForWebUI( 1070 cache.GetAvatarIconOfProfileAtIndex(i), true); 1071 profile_value->SetString("iconURL", 1072 webui::GetBitmapDataUrl(icon.AsBitmap())); 1073 } else { 1074 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); 1075 profile_value->SetString("iconURL", 1076 cache.GetDefaultAvatarIconUrl(icon_index)); 1077 } 1078 1079 profile_info_list->Append(profile_value); 1080 } 1081 1082 return profile_info_list.Pass(); 1083} 1084 1085void BrowserOptionsHandler::SendProfilesInfo() { 1086 if (!ShouldShowMultiProfilesUserList()) 1087 return; 1088 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo", 1089 *GetProfilesInfoList()); 1090} 1091 1092void BrowserOptionsHandler::CreateProfile(const ListValue* args) { 1093#if defined(ENABLE_MANAGED_USERS) 1094 // This handler could have been called in managed mode, for example because 1095 // the user fiddled with the web inspector. Silently return in this case. 1096 Profile* profile = Profile::FromWebUI(web_ui()); 1097 ManagedUserService* service = 1098 ManagedUserServiceFactory::GetForProfile(profile); 1099 if (service->ProfileIsManaged()) 1100 return; 1101#endif 1102 1103 if (!ProfileManager::IsMultipleProfilesEnabled()) 1104 return; 1105 1106 Browser* browser = 1107 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); 1108 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; 1109 if (browser) 1110 desktop_type = browser->host_desktop_type(); 1111 1112 string16 name; 1113 string16 icon; 1114 std::vector<ProfileManager::CreateCallback> callbacks; 1115 bool create_shortcut = false; 1116 bool managed_user = false; 1117 if (args->GetString(0, &name) && args->GetString(1, &icon)) { 1118 if (args->GetBoolean(2, &create_shortcut)) { 1119 bool success = args->GetBoolean(3, &managed_user); 1120 DCHECK(success); 1121 } 1122 } 1123 1124 if (create_shortcut) 1125 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile)); 1126 1127 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) { 1128#if defined(ENABLE_MANAGED_USERS) 1129 ManagedUserRegistrationService* registration_service = 1130 ManagedUserRegistrationServiceFactory::GetForProfile(profile); 1131 callbacks.push_back(registration_service->GetRegistrationAndInitCallback()); 1132#else 1133 NOTREACHED(); 1134#endif 1135 } 1136 1137 ProfileManager::CreateMultiProfileAsync( 1138 name, icon, base::Bind(&OnProfileCreated, callbacks), 1139 desktop_type, managed_user); 1140} 1141 1142void BrowserOptionsHandler::ObserveThemeChanged() { 1143 Profile* profile = Profile::FromWebUI(web_ui()); 1144#if defined(TOOLKIT_GTK) 1145 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); 1146 bool is_gtk_theme = theme_service->UsingNativeTheme(); 1147 base::FundamentalValue gtk_enabled(!is_gtk_theme); 1148 web_ui()->CallJavascriptFunction("BrowserOptions.setGtkThemeButtonEnabled", 1149 gtk_enabled); 1150#else 1151 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); 1152 bool is_gtk_theme = false; 1153#endif 1154 1155 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); 1156 base::FundamentalValue enabled(!is_classic_theme); 1157 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled", 1158 enabled); 1159} 1160 1161void BrowserOptionsHandler::ThemesReset(const ListValue* args) { 1162 content::RecordAction(UserMetricsAction("Options_ThemesReset")); 1163 Profile* profile = Profile::FromWebUI(web_ui()); 1164 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); 1165} 1166 1167#if defined(TOOLKIT_GTK) 1168void BrowserOptionsHandler::ThemesSetGTK(const ListValue* args) { 1169 content::RecordAction(UserMetricsAction("Options_GtkThemeSet")); 1170 Profile* profile = Profile::FromWebUI(web_ui()); 1171 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); 1172} 1173#endif 1174 1175#if defined(OS_CHROMEOS) 1176void BrowserOptionsHandler::UpdateAccountPicture() { 1177 std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email(); 1178 if (!email.empty()) { 1179 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture"); 1180 base::StringValue email_value(email); 1181 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", 1182 email_value); 1183 } 1184} 1185#endif 1186 1187scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { 1188 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); 1189 Profile* profile = Profile::FromWebUI(web_ui()); 1190 if (profile->IsGuestSession()) { 1191 // Cannot display signin status when running in guest mode on chromeos 1192 // because there is no SigninManager. 1193 sync_status->SetBoolean("signinAllowed", false); 1194 return sync_status.Pass(); 1195 } 1196 1197 bool signout_prohibited = false; 1198#if !defined(OS_CHROMEOS) 1199 // Signout is not allowed if the user has policy (crbug.com/172204). 1200 signout_prohibited = 1201 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited(); 1202#endif 1203 1204 ProfileSyncService* service( 1205 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); 1206 SigninManagerBase* signin = service->signin(); 1207 sync_status->SetBoolean("signoutAllowed", !signout_prohibited); 1208 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed()); 1209 sync_status->SetBoolean("syncSystemEnabled", !!service); 1210 sync_status->SetBoolean("setupCompleted", 1211 service && service->HasSyncSetupCompleted()); 1212 sync_status->SetBoolean("setupInProgress", 1213 service && !service->IsManaged() && service->FirstSetupInProgress()); 1214 1215 string16 status_label; 1216 string16 link_label; 1217 DCHECK(signin); 1218 bool status_has_error = sync_ui_util::GetStatusLabels( 1219 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == 1220 sync_ui_util::SYNC_ERROR; 1221 sync_status->SetString("statusText", status_label); 1222 sync_status->SetString("actionLinkText", link_label); 1223 sync_status->SetBoolean("hasError", status_has_error); 1224 1225 sync_status->SetBoolean("managed", service && service->IsManaged()); 1226 sync_status->SetBoolean("signedIn", 1227 !signin->GetAuthenticatedUsername().empty()); 1228 sync_status->SetBoolean("hasUnrecoverableError", 1229 service && service->HasUnrecoverableError()); 1230 sync_status->SetBoolean( 1231 "autoLoginVisible", 1232 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) && 1233 service && service->IsSyncEnabledAndLoggedIn() && 1234 service->IsSyncTokenAvailable()); 1235 1236 return sync_status.Pass(); 1237} 1238 1239void BrowserOptionsHandler::HandleSelectDownloadLocation( 1240 const ListValue* args) { 1241 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1242 select_folder_dialog_ = ui::SelectFileDialog::Create( 1243 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); 1244 ui::SelectFileDialog::FileTypeInfo info; 1245 info.support_drive = true; 1246 select_folder_dialog_->SelectFile( 1247 ui::SelectFileDialog::SELECT_FOLDER, 1248 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), 1249 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), 1250 &info, 1251 0, 1252 base::FilePath::StringType(), 1253 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), 1254 NULL); 1255} 1256 1257void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index, 1258 void* params) { 1259 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); 1260 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1261 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); 1262} 1263 1264void BrowserOptionsHandler::OnCloudPrintSetupClosed() { 1265#if !defined(OS_CHROMEOS) 1266 if (cloud_print_connector_ui_enabled_) 1267 SetupCloudPrintConnectorSection(); 1268#endif 1269} 1270 1271#if defined(OS_CHROMEOS) 1272void BrowserOptionsHandler::TouchpadExists(bool exists) { 1273 base::FundamentalValue val(exists); 1274 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val); 1275} 1276 1277void BrowserOptionsHandler::MouseExists(bool exists) { 1278 base::FundamentalValue val(exists); 1279 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val); 1280} 1281#endif 1282 1283void BrowserOptionsHandler::HandleAutoOpenButton(const ListValue* args) { 1284 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); 1285 DownloadManager* manager = BrowserContext::GetDownloadManager( 1286 web_ui()->GetWebContents()->GetBrowserContext()); 1287 if (manager) 1288 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); 1289} 1290 1291void BrowserOptionsHandler::HandleDefaultFontSize(const ListValue* args) { 1292 int font_size; 1293 if (ExtractIntegerValue(args, &font_size)) { 1294 if (font_size > 0) { 1295 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1296 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size); 1297 SetupFontSizeSelector(); 1298 } 1299 } 1300} 1301 1302void BrowserOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { 1303 double zoom_factor; 1304 if (ExtractDoubleValue(args, &zoom_factor)) { 1305 default_zoom_level_.SetValue( 1306 WebKit::WebView::zoomFactorToZoomLevel(zoom_factor)); 1307 } 1308} 1309 1310void BrowserOptionsHandler::HandleRestartBrowser(const ListValue* args) { 1311 chrome::AttemptRestart(); 1312} 1313 1314#if !defined(OS_CHROMEOS) 1315void BrowserOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { 1316 content::RecordAction(UserMetricsAction("Options_ShowProxySettings")); 1317 AdvancedOptionsUtilities::ShowNetworkProxySettings( 1318 web_ui()->GetWebContents()); 1319} 1320#endif 1321 1322#if !defined(USE_NSS) && !defined(USE_OPENSSL) 1323void BrowserOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { 1324 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); 1325 AdvancedOptionsUtilities::ShowManageSSLCertificates( 1326 web_ui()->GetWebContents()); 1327} 1328#endif 1329 1330void BrowserOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { 1331 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); 1332 // Open a new tab in the current window for the management page. 1333 Profile* profile = Profile::FromWebUI(web_ui()); 1334 OpenURLParams params( 1335 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), Referrer(), 1336 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); 1337 web_ui()->GetWebContents()->OpenURL(params); 1338} 1339 1340#if !defined(OS_CHROMEOS) 1341void BrowserOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { 1342 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); 1343 // Open the connector enable page in the current tab. 1344 Profile* profile = Profile::FromWebUI(web_ui()); 1345 OpenURLParams params( 1346 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( 1347 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), 1348 Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 1349 web_ui()->GetWebContents()->OpenURL(params); 1350} 1351 1352void BrowserOptionsHandler::HandleDisableCloudPrintConnector( 1353 const ListValue* args) { 1354 content::RecordAction( 1355 UserMetricsAction("Options_DisableCloudPrintProxy")); 1356 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 1357 DisableForUser(); 1358} 1359 1360void BrowserOptionsHandler::RefreshCloudPrintStatusFromService() { 1361 if (cloud_print_connector_ui_enabled_) 1362 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 1363 RefreshStatusFromService(); 1364} 1365 1366void BrowserOptionsHandler::SetupCloudPrintConnectorSection() { 1367 Profile* profile = Profile::FromWebUI(web_ui()); 1368 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { 1369 cloud_print_connector_ui_enabled_ = false; 1370 RemoveCloudPrintConnectorSection(); 1371 return; 1372 } 1373 1374 bool cloud_print_connector_allowed = 1375 !cloud_print_connector_enabled_.IsManaged() || 1376 cloud_print_connector_enabled_.GetValue(); 1377 base::FundamentalValue allowed(cloud_print_connector_allowed); 1378 1379 std::string email; 1380 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && 1381 cloud_print_connector_allowed) { 1382 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); 1383 } 1384 base::FundamentalValue disabled(email.empty()); 1385 1386 string16 label_str; 1387 if (email.empty()) { 1388 label_str = l10n_util::GetStringFUTF16( 1389 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, 1390 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); 1391 } else { 1392 label_str = l10n_util::GetStringFUTF16( 1393 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, 1394 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), 1395 UTF8ToUTF16(email)); 1396 } 1397 StringValue label(label_str); 1398 1399 web_ui()->CallJavascriptFunction( 1400 "BrowserOptions.setupCloudPrintConnectorSection", disabled, label, 1401 allowed); 1402} 1403 1404void BrowserOptionsHandler::RemoveCloudPrintConnectorSection() { 1405 web_ui()->CallJavascriptFunction( 1406 "BrowserOptions.removeCloudPrintConnectorSection"); 1407} 1408#endif 1409 1410#if defined(OS_CHROMEOS) 1411void BrowserOptionsHandler::HandleOpenWallpaperManager( 1412 const ListValue* args) { 1413 wallpaper_manager_util::OpenWallpaperManager(); 1414} 1415 1416void BrowserOptionsHandler::SpokenFeedbackChangeCallback( 1417 const ListValue* args) { 1418 bool enabled = false; 1419 args->GetBoolean(0, &enabled); 1420 1421 chromeos::accessibility::EnableSpokenFeedback( 1422 enabled, NULL, ash::A11Y_NOTIFICATION_NONE); 1423} 1424 1425void BrowserOptionsHandler::HighContrastChangeCallback(const ListValue* args) { 1426 bool enabled = false; 1427 args->GetBoolean(0, &enabled); 1428 1429 chromeos::accessibility::EnableHighContrast(enabled); 1430} 1431 1432void BrowserOptionsHandler::VirtualKeyboardChangeCallback( 1433 const ListValue* args) { 1434 bool enabled = false; 1435 args->GetBoolean(0, &enabled); 1436 1437 chromeos::accessibility::EnableVirtualKeyboard(enabled); 1438} 1439 1440#if defined(OS_CHROMEOS) 1441 1442void BrowserOptionsHandler::PerformFactoryResetRestart(const ListValue* args) { 1443 if (g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) 1444 return; 1445 1446 PrefService* prefs = g_browser_process->local_state(); 1447 prefs->SetBoolean(prefs::kFactoryResetRequested, true); 1448 prefs->CommitPendingWrite(); 1449 1450 // Perform sign out. Current chrome process will then terminate, new one will 1451 // be launched (as if it was a restart). 1452 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 1453} 1454 1455#endif 1456 1457void BrowserOptionsHandler::SetupAccessibilityFeatures() { 1458 PrefService* pref_service = g_browser_process->local_state(); 1459 base::FundamentalValue spoken_feedback_enabled( 1460 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled)); 1461 web_ui()->CallJavascriptFunction( 1462 "BrowserOptions.setSpokenFeedbackCheckboxState", 1463 spoken_feedback_enabled); 1464 base::FundamentalValue high_contrast_enabled( 1465 pref_service->GetBoolean(prefs::kHighContrastEnabled)); 1466 web_ui()->CallJavascriptFunction( 1467 "BrowserOptions.setHighContrastCheckboxState", 1468 high_contrast_enabled); 1469 base::FundamentalValue virtual_keyboard_enabled( 1470 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled)); 1471 web_ui()->CallJavascriptFunction( 1472 "BrowserOptions.setVirtualKeyboardCheckboxState", 1473 virtual_keyboard_enabled); 1474} 1475#endif 1476 1477void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() { 1478#if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) 1479 // Don't show the reporting setting if we are in the guest mode. 1480 if (CommandLine::ForCurrentProcess()->HasSwitch( 1481 chromeos::switches::kGuestSession)) { 1482 base::FundamentalValue visible(false); 1483 web_ui()->CallJavascriptFunction( 1484 "BrowserOptions.setMetricsReportingSettingVisibility", visible); 1485 } 1486#endif 1487} 1488 1489void BrowserOptionsHandler::SetupPasswordGenerationSettingVisibility() { 1490 base::FundamentalValue visible( 1491 CommandLine::ForCurrentProcess()->HasSwitch( 1492 switches::kEnablePasswordGeneration)); 1493 web_ui()->CallJavascriptFunction( 1494 "BrowserOptions.setPasswordGenerationSettingVisibility", visible); 1495} 1496 1497void BrowserOptionsHandler::SetupFontSizeSelector() { 1498 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1499 const PrefService::Preference* default_font_size = 1500 pref_service->FindPreference(prefs::kWebKitDefaultFontSize); 1501 const PrefService::Preference* default_fixed_font_size = 1502 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize); 1503 1504 DictionaryValue dict; 1505 dict.SetInteger("value", 1506 pref_service->GetInteger(prefs::kWebKitDefaultFontSize)); 1507 1508 // The font size control displays the value of the default font size, but 1509 // setting it alters both the default font size and the default fixed font 1510 // size. So it must be disabled when either of those prefs is not user 1511 // modifiable. 1512 dict.SetBoolean("disabled", 1513 !default_font_size->IsUserModifiable() || 1514 !default_fixed_font_size->IsUserModifiable()); 1515 1516 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref, 1517 // adapted to consider two prefs. It may be better to refactor 1518 // CreateValueForPref so it can be called from here. 1519 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) { 1520 dict.SetString("controlledBy", "policy"); 1521 } else if (default_font_size->IsExtensionControlled() || 1522 default_fixed_font_size->IsExtensionControlled()) { 1523 dict.SetString("controlledBy", "extension"); 1524 } 1525 1526 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict); 1527} 1528 1529void BrowserOptionsHandler::SetupPageZoomSelector() { 1530 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1531 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); 1532 double default_zoom_factor = 1533 WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level); 1534 1535 // Generate a vector of zoom factors from an array of known presets along with 1536 // the default factor added if necessary. 1537 std::vector<double> zoom_factors = 1538 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); 1539 1540 // Iterate through the zoom factors and and build the contents of the 1541 // selector that will be sent to the javascript handler. 1542 // Each item in the list has the following parameters: 1543 // 1. Title (string). 1544 // 2. Value (double). 1545 // 3. Is selected? (bool). 1546 ListValue zoom_factors_value; 1547 for (std::vector<double>::const_iterator i = zoom_factors.begin(); 1548 i != zoom_factors.end(); ++i) { 1549 ListValue* option = new ListValue(); 1550 double factor = *i; 1551 int percent = static_cast<int>(factor * 100 + 0.5); 1552 option->Append(new base::StringValue( 1553 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); 1554 option->Append(new base::FundamentalValue(factor)); 1555 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); 1556 option->Append(new base::FundamentalValue(selected)); 1557 zoom_factors_value.Append(option); 1558 } 1559 1560 web_ui()->CallJavascriptFunction( 1561 "BrowserOptions.setupPageZoomSelector", zoom_factors_value); 1562} 1563 1564void BrowserOptionsHandler::SetupAutoOpenFileTypes() { 1565 // Set the hidden state for the AutoOpenFileTypesResetToDefault button. 1566 // We show the button if the user has any auto-open file types registered. 1567 DownloadManager* manager = BrowserContext::GetDownloadManager( 1568 web_ui()->GetWebContents()->GetBrowserContext()); 1569 bool display = manager && 1570 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); 1571 base::FundamentalValue value(display); 1572 web_ui()->CallJavascriptFunction( 1573 "BrowserOptions.setAutoOpenFileTypesDisplayed", value); 1574} 1575 1576void BrowserOptionsHandler::SetupProxySettingsSection() { 1577#if !defined(OS_CHROMEOS) 1578 // Disable the button if proxy settings are managed by a sysadmin or 1579 // overridden by an extension. 1580 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 1581 const PrefService::Preference* proxy_config = 1582 pref_service->FindPreference(prefs::kProxy); 1583 bool is_extension_controlled = (proxy_config && 1584 proxy_config->IsExtensionControlled()); 1585 1586 base::FundamentalValue disabled(profile_pref_registrar_.IsManaged() || 1587 is_extension_controlled); 1588 base::FundamentalValue extension_controlled(is_extension_controlled); 1589 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", 1590 disabled, extension_controlled); 1591 1592#endif // !defined(OS_CHROMEOS) 1593} 1594 1595} // namespace options 1596