1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
10 #include "apps/shell_window.h"
11 #include "apps/shell_window_registry.h"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/memory/singleton.h"
16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h"
18 #include "base/path_service.h"
19 #include "base/prefs/pref_service.h"
20 #include "base/prefs/scoped_user_pref_update.h"
21 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/value_conversions.h"
25 #include "base/values.h"
26 #include "chrome/browser/auto_launch_trial.h"
27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/chrome_page_zoom.h"
30 #include "chrome/browser/custom_home_pages_table_model.h"
31 #include "chrome/browser/download/download_prefs.h"
32 #include "chrome/browser/gpu/gpu_mode_manager.h"
33 #include "chrome/browser/lifetime/application_lifetime.h"
34 #include "chrome/browser/prefs/session_startup_pref.h"
35 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
38 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
39 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
40 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/profiles/profile_info_cache.h"
42 #include "chrome/browser/profiles/profile_info_util.h"
43 #include "chrome/browser/profiles/profile_manager.h"
44 #include "chrome/browser/profiles/profile_metrics.h"
45 #include "chrome/browser/profiles/profile_shortcut_manager.h"
46 #include "chrome/browser/profiles/profile_window.h"
47 #include "chrome/browser/profiles/profiles_state.h"
48 #include "chrome/browser/search/search.h"
49 #include "chrome/browser/search_engines/template_url.h"
50 #include "chrome/browser/search_engines/template_url_service.h"
51 #include "chrome/browser/search_engines/template_url_service_factory.h"
52 #include "chrome/browser/signin/signin_manager.h"
53 #include "chrome/browser/signin/signin_manager_factory.h"
54 #include "chrome/browser/sync/profile_sync_service.h"
55 #include "chrome/browser/sync/profile_sync_service_factory.h"
56 #include "chrome/browser/sync/sync_ui_util.h"
57 #include "chrome/browser/themes/theme_service.h"
58 #include "chrome/browser/themes/theme_service_factory.h"
59 #include "chrome/browser/ui/browser_finder.h"
60 #include "chrome/browser/ui/chrome_select_file_policy.h"
61 #include "chrome/browser/ui/host_desktop.h"
62 #include "chrome/browser/ui/options/options_util.h"
63 #include "chrome/browser/ui/webui/favicon_source.h"
64 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
65 #include "chrome/common/chrome_constants.h"
66 #include "chrome/common/chrome_paths.h"
67 #include "chrome/common/chrome_switches.h"
68 #include "chrome/common/net/url_fixer_upper.h"
69 #include "chrome/common/pref_names.h"
70 #include "chrome/common/url_constants.h"
71 #include "chromeos/chromeos_switches.h"
72 #include "content/public/browser/browser_thread.h"
73 #include "content/public/browser/download_manager.h"
74 #include "content/public/browser/navigation_controller.h"
75 #include "content/public/browser/notification_details.h"
76 #include "content/public/browser/notification_service.h"
77 #include "content/public/browser/notification_source.h"
78 #include "content/public/browser/notification_types.h"
79 #include "content/public/browser/url_data_source.h"
80 #include "content/public/browser/user_metrics.h"
81 #include "content/public/browser/web_contents.h"
82 #include "content/public/browser/web_contents_view.h"
83 #include "content/public/common/page_zoom.h"
84 #include "google_apis/gaia/gaia_auth_util.h"
85 #include "google_apis/gaia/google_service_auth_error.h"
86 #include "grit/chromium_strings.h"
87 #include "grit/generated_resources.h"
88 #include "grit/locale_settings.h"
89 #include "grit/theme_resources.h"
90 #include "third_party/skia/include/core/SkBitmap.h"
91 #include "ui/base/l10n/l10n_util.h"
92 #include "ui/base/webui/web_ui_util.h"
94 #if !defined(OS_CHROMEOS)
95 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
98 #if defined(OS_CHROMEOS)
99 #include "ash/ash_switches.h"
100 #include "ash/magnifier/magnifier_constants.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.h"
104 #include "chrome/browser/chromeos/login/user_manager.h"
105 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
106 #include "chrome/browser/chromeos/settings/cros_settings.h"
107 #include "chrome/browser/chromeos/system/timezone_util.h"
108 #include "chrome/browser/policy/profile_policy_connector.h"
109 #include "chrome/browser/policy/profile_policy_connector_factory.h"
110 #include "chrome/browser/ui/browser_window.h"
111 #include "chromeos/dbus/dbus_thread_manager.h"
112 #include "chromeos/dbus/power_manager_client.h"
113 #include "components/policy/core/common/policy_map.h"
114 #include "components/policy/core/common/policy_namespace.h"
115 #include "components/policy/core/common/policy_service.h"
116 #include "policy/policy_constants.h"
117 #include "ui/gfx/image/image_skia.h"
118 #endif // defined(OS_CHROMEOS)
121 #include "chrome/installer/util/auto_launch_util.h"
122 #endif // defined(OS_WIN)
124 #if defined(ENABLE_MDNS)
125 #include "chrome/browser/local_discovery/privet_notifications.h"
128 using base::UserMetricsAction;
129 using content::BrowserContext;
130 using content::BrowserThread;
131 using content::DownloadManager;
132 using content::OpenURLParams;
133 using content::Referrer;
139 bool ShouldShowMultiProfilesUserList(chrome::HostDesktopType desktop_type) {
140 #if defined(OS_CHROMEOS)
141 // On Chrome OS we use different UI for multi-profiles.
144 if (desktop_type != chrome::HOST_DESKTOP_TYPE_NATIVE)
146 return profiles::IsMultipleProfilesEnabled();
152 BrowserOptionsHandler::BrowserOptionsHandler()
153 : page_initialized_(false),
154 template_url_service_(NULL),
155 cloud_print_mdns_ui_enabled_(false),
156 weak_ptr_factory_(this) {
157 #if !defined(OS_MACOSX)
158 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
161 #if defined(ENABLE_FULL_PRINTING)
162 #if !defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
163 // On Windows, we need the PDF plugin which is only guaranteed to exist on
164 // Google Chrome builds. Use a command-line switch for Windows non-Google
166 cloud_print_connector_ui_enabled_ =
167 CommandLine::ForCurrentProcess()->HasSwitch(
168 switches::kEnableCloudPrintProxy);
169 #elif !defined(OS_CHROMEOS)
170 // Always enabled for Mac, Linux and Google Chrome Windows builds.
171 // Never enabled for Chrome OS, we don't even need to indicate it.
172 cloud_print_connector_ui_enabled_ = true;
174 #endif // defined(ENABLE_FULL_PRINTING)
176 #if defined(ENABLE_MDNS)
177 cloud_print_mdns_ui_enabled_ = !CommandLine::ForCurrentProcess()->HasSwitch(
178 switches::kDisableDeviceDiscovery);
179 #endif // defined(ENABLE_MDNS)
182 BrowserOptionsHandler::~BrowserOptionsHandler() {
183 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
184 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
186 sync_service->RemoveObserver(this);
188 if (default_browser_worker_.get())
189 default_browser_worker_->ObserverDestroyed();
190 if (template_url_service_)
191 template_url_service_->RemoveObserver(this);
192 // There may be pending file dialogs, we need to tell them that we've gone
193 // away so they don't try and call back to us.
194 if (select_folder_dialog_.get())
195 select_folder_dialog_->ListenerDestroyed();
198 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
201 static OptionsStringResource resources[] = {
202 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT },
203 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY },
204 { "advancedSectionTitleContent",
205 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT },
206 { "advancedSectionTitleLanguages",
207 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES },
208 { "advancedSectionTitleNetwork",
209 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK },
210 { "advancedSectionTitlePrivacy",
211 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY },
212 { "advancedSectionTitleSecurity",
213 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY },
214 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE },
215 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN },
216 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY },
217 { "autoOpenFileTypesResetToDefault",
218 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT },
219 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE },
220 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON },
221 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL },
222 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
223 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
224 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
225 #if defined(OS_CHROMEOS)
226 { "disableGData", IDS_OPTIONS_DISABLE_GDATA },
228 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES },
229 #if defined(OS_CHROMEOS)
231 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL },
233 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK },
234 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT },
235 { "doNotTrackConfirmEnable",
236 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE },
237 { "doNotTrackConfirmDisable",
238 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE },
239 { "downloadLocationAskForSaveLocation",
240 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION },
241 { "downloadLocationBrowseTitle",
242 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE },
243 { "downloadLocationChangeButton",
244 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON },
245 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME },
246 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING },
247 { "fontSettingsCustomizeFontsButton",
248 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON },
249 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM },
250 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE },
251 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
252 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
253 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE },
254 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
255 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS },
256 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP },
257 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
258 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
259 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
260 { "hotwordSearchDescription", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION },
261 { "hotwordSearchIncognito", IDS_HOTWORD_SEARCH_INCOGNITO_PREF_CHKBOX },
262 { "hotwordSearchTimeout", IDS_HOTWORD_SEARCH_TIMEOUT_PREF_CHKBOX },
263 { "hotwordSearchTimeoutDescription",
264 IDS_HOTWORD_SEARCH_TIMEOUT_PREF_DESCRIPTION },
265 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON },
266 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE },
267 { "languageAndSpellCheckSettingsButton",
268 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS },
269 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF },
270 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK },
271 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES },
272 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK },
273 { "networkPredictionEnabledDescription",
274 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
275 { "passwordsAndAutofillGroupName",
276 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME },
277 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
278 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
279 { "privacyContentSettingsButton",
280 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON },
281 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL },
282 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL },
283 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL },
284 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT },
285 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL },
286 { "profilesSupervisedDashboardTip",
287 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP },
288 #if defined(ENABLE_SETTINGS_APP)
289 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL },
291 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
292 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
294 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
295 { "resetProfileSettingsDescription",
296 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
297 { "resetProfileSettingsSectionTitle",
298 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
299 { "safeBrowsingEnableProtection",
300 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
301 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
302 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
303 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME },
304 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
305 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME },
306 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME },
307 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT },
308 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE },
309 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE },
310 { "spellingPref", IDS_OPTIONS_SPELLING_PREF },
311 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION },
312 { "settingsTitle", IDS_SETTINGS_TITLE },
313 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS },
314 { "sslCheckRevocation", IDS_OPTIONS_SSL_CHECKREVOCATION },
315 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES },
316 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB },
317 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
318 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF },
319 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS },
320 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL },
321 { "themesGallery", IDS_THEMES_GALLERY_BUTTON },
322 { "themesGalleryURL", IDS_THEMES_GALLERY_URL },
323 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF },
324 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
325 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
326 { "translateEnableTranslate",
327 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE },
328 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
329 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS },
330 { "themesNativeButton", IDS_THEMES_GTK_BUTTON },
331 { "themesSetClassic", IDS_THEMES_SET_CLASSIC },
333 { "themes", IDS_THEMES_GROUP_NAME },
335 { "themesReset", IDS_THEMES_RESET_BUTTON },
336 #if defined(OS_CHROMEOS)
337 { "accessibilityExplanation",
338 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION },
339 { "accessibilitySettings",
340 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS },
341 { "accessibilityHighContrast",
342 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION },
343 { "accessibilityScreenMagnifier",
344 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION },
345 { "accessibilityTapDragging",
346 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION },
347 { "accessibilityScreenMagnifierOff",
348 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF },
349 { "accessibilityScreenMagnifierFull",
350 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL },
351 { "accessibilityScreenMagnifierPartial",
352 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL },
353 { "accessibilityLargeCursor",
354 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION },
355 { "accessibilityStickyKeys",
356 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION },
357 { "accessibilitySpokenFeedback",
358 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION },
359 { "accessibilityTitle",
360 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY },
361 { "accessibilityVirtualKeyboard",
362 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION },
363 { "accessibilityAlwaysShowMenu",
364 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU },
365 { "accessibilityAutoclick",
366 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION },
367 { "accessibilityAutoclickDropdown",
368 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION },
369 { "autoclickDelayExtremelyShort",
370 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT },
371 { "autoclickDelayVeryShort",
372 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT },
373 { "autoclickDelayShort",
374 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT },
375 { "autoclickDelayLong",
376 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG },
377 { "autoclickDelayVeryLong",
378 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG },
379 { "enableContentProtectionAttestation",
380 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION },
381 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING },
382 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET },
383 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON },
384 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON },
385 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING },
386 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL },
387 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE },
388 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION },
389 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME },
390 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION },
391 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION },
392 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION },
393 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION },
394 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX },
395 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE },
396 { "keyboardSettingsButtonTitle",
397 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE },
398 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE },
399 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES },
400 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME },
401 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL },
402 { "syncOverview", IDS_SYNC_OVERVIEW },
403 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
404 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION },
405 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION },
407 { "cloudPrintManageButton",
408 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON},
409 { "cloudPrintConnectorEnablingButton",
410 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON },
411 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON },
413 #if defined(OS_CHROMEOS) && defined(USE_ASH)
414 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON },
416 { "advancedSectionTitleSystem",
417 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM },
418 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
419 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE },
421 #if !defined(OS_CHROMEOS)
423 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE },
424 { "gpuModeResetRestart",
425 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART },
426 // Strings with product-name substitutions.
427 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME },
428 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
430 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL,
431 IDS_SHORT_PRODUCT_NAME },
432 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
434 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
436 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT,
438 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT, IDS_PRODUCT_NAME },
439 #if defined(OS_CHROMEOS)
440 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION,
441 IDS_SHORT_PRODUCT_NAME },
443 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
444 IDS_SHORT_PRODUCT_NAME },
445 #if defined(ENABLE_MDNS)
446 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON },
447 { "cloudPrintEnableNotificationsLabel",
448 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL },
452 #if defined(ENABLE_SETTINGS_APP)
453 static OptionsStringResource app_resources[] = {
454 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW },
455 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL,
456 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
457 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
458 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
459 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
460 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
461 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
462 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
464 base::DictionaryValue* app_values = NULL;
465 CHECK(values->GetDictionary(kSettingsAppKey, &app_values));
466 RegisterStrings(app_values, app_resources, arraysize(app_resources));
469 RegisterStrings(values, resources, arraysize(resources));
470 RegisterTitle(values, "doNotTrackConfirmOverlay",
471 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE);
472 RegisterTitle(values, "spellingConfirmOverlay",
473 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE);
474 #if defined(ENABLE_FULL_PRINTING)
475 RegisterCloudPrintValues(values);
478 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL);
479 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
481 "defaultSearchGroupLabel",
482 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
483 base::string16 hotword_url = base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
485 "hotwordSearchEnable",
486 l10n_util::GetStringFUTF16(IDS_HOTWORD_SEARCH_PREF_CHKBOX, hotword_url));
488 #if defined(OS_CHROMEOS)
489 Profile* profile = Profile::FromWebUI(web_ui());
490 std::string username = profile->GetProfileName();
491 if (username.empty()) {
492 chromeos::User* user =
493 chromeos::UserManager::Get()->GetUserByProfile(profile);
494 if (user && (user->GetType() != chromeos::User::USER_TYPE_GUEST))
495 username = user->email();
497 if (!username.empty())
498 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
500 values->SetString("username", username);
503 // Pass along sync status early so it will be available during page init.
504 values->Set("syncData", GetSyncStateDictionary().release());
506 // The Reset Profile Settings feature makes no sense for an off-the-record
507 // profile (e.g. in Guest mode on Chrome OS), so hide it.
508 values->SetBoolean("enableResetProfileSettings",
509 !Profile::FromWebUI(web_ui())->IsOffTheRecord());
511 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
512 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
514 #if defined(OS_CHROMEOS)
515 // TODO(pastarmovj): replace this with a call to the CrosSettings list
516 // handling functionality to come.
517 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
519 values->SetString("accessibilityLearnMoreURL",
520 chrome::kChromeAccessibilityHelpURL);
522 std::string settings_url = std::string("chrome-extension://") +
523 extension_misc::kChromeVoxExtensionId +
524 chrome::kChromeAccessibilitySettingsURL;
526 values->SetString("accessibilitySettingsURL",
529 values->SetString("contentProtectionAttestationLearnMoreURL",
530 chrome::kAttestationForContentProtectionLearnMoreURL);
532 // Creates magnifierList.
533 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue);
535 scoped_ptr<base::ListValue> option_full(new base::ListValue);
536 option_full->AppendInteger(ash::MAGNIFIER_FULL);
537 option_full->AppendString(l10n_util::GetStringUTF16(
538 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL));
539 magnifier_list->Append(option_full.release());
541 scoped_ptr<base::ListValue> option_partial(new base::ListValue);
542 option_partial->AppendInteger(ash::MAGNIFIER_PARTIAL);
543 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16(
544 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL)));
545 magnifier_list->Append(option_partial.release());
547 values->Set("magnifierList", magnifier_list.release());
549 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
550 values->SetBoolean("enableStickyKeys",
551 command_line.HasSwitch(switches::kEnableStickyKeys));
554 #if defined(OS_MACOSX)
555 values->SetString("macPasswordsWarning",
556 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
557 values->SetBoolean("multiple_profiles",
558 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
561 if (ShouldShowMultiProfilesUserList(helper::GetDesktopType(web_ui())))
562 values->Set("profilesInfo", GetProfilesInfoList().release());
564 values->SetBoolean("profileIsManaged",
565 Profile::FromWebUI(web_ui())->IsManaged());
567 #if !defined(OS_CHROMEOS)
570 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
573 #if defined(ENABLE_MDNS)
574 values->SetBoolean("cloudPrintHideNotificationsCheckbox",
575 !local_discovery::PrivetNotificationService::IsEnabled());
578 values->SetBoolean("cloudPrintShowMDnsOptions",
579 cloud_print_mdns_ui_enabled_);
581 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
583 values->SetString("languagesLearnMoreURL",
584 chrome::kLanguageSettingsLearnMoreUrl);
587 #if defined(ENABLE_FULL_PRINTING)
588 void BrowserOptionsHandler::RegisterCloudPrintValues(
589 base::DictionaryValue* values) {
590 values->SetString("cloudPrintOptionLabel",
591 l10n_util::GetStringFUTF16(
592 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL,
593 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
595 #if defined(OS_CHROMEOS)
596 values->SetString("cloudPrintManageButton",
597 l10n_util::GetStringFUTF16(
598 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON,
599 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
601 // TODO(noamsml): Remove all cloud print connector related code from the
602 // settings page as soon as the devices page is supported on all platforms.
603 values->SetString("cloudPrintConnectorDisabledLabel",
604 l10n_util::GetStringFUTF16(
605 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL,
606 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
607 values->SetString("cloudPrintConnectorDisabledButton",
608 l10n_util::GetStringUTF16(
609 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON));
610 values->SetString("cloudPrintConnectorEnabledButton",
611 l10n_util::GetStringUTF16(
612 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON));
615 #endif // defined(ENABLE_FULL_PRINTING)
617 void BrowserOptionsHandler::RegisterMessages() {
618 web_ui()->RegisterMessageCallback(
619 "becomeDefaultBrowser",
620 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
621 base::Unretained(this)));
622 web_ui()->RegisterMessageCallback(
623 "setDefaultSearchEngine",
624 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
625 base::Unretained(this)));
626 web_ui()->RegisterMessageCallback(
628 base::Bind(&BrowserOptionsHandler::DeleteProfile,
629 base::Unretained(this)));
630 web_ui()->RegisterMessageCallback(
632 base::Bind(&BrowserOptionsHandler::ThemesReset,
633 base::Unretained(this)));
634 web_ui()->RegisterMessageCallback(
635 "requestProfilesInfo",
636 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo,
637 base::Unretained(this)));
638 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
639 web_ui()->RegisterMessageCallback(
641 base::Bind(&BrowserOptionsHandler::ThemesSetNative,
642 base::Unretained(this)));
644 web_ui()->RegisterMessageCallback(
645 "selectDownloadLocation",
646 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation,
647 base::Unretained(this)));
648 web_ui()->RegisterMessageCallback(
649 "autoOpenFileTypesAction",
650 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton,
651 base::Unretained(this)));
652 web_ui()->RegisterMessageCallback(
653 "defaultFontSizeAction",
654 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize,
655 base::Unretained(this)));
656 web_ui()->RegisterMessageCallback(
657 "defaultZoomFactorAction",
658 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor,
659 base::Unretained(this)));
660 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
661 web_ui()->RegisterMessageCallback(
662 "showManageSSLCertificates",
663 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates,
664 base::Unretained(this)));
666 #if defined(ENABLE_FULL_PRINTING)
667 web_ui()->RegisterMessageCallback(
668 "showCloudPrintManagePage",
669 base::Bind(&BrowserOptionsHandler::ShowCloudPrintManagePage,
670 base::Unretained(this)));
672 #if defined(OS_CHROMEOS)
673 web_ui()->RegisterMessageCallback(
674 "openWallpaperManager",
675 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager,
676 base::Unretained(this)));
677 web_ui()->RegisterMessageCallback(
678 "virtualKeyboardChange",
679 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback,
680 base::Unretained(this)));
681 web_ui()->RegisterMessageCallback(
682 "performFactoryResetRestart",
683 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart,
684 base::Unretained(this)));
686 web_ui()->RegisterMessageCallback(
688 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser,
689 base::Unretained(this)));
690 #if defined(ENABLE_FULL_PRINTING)
691 if (cloud_print_connector_ui_enabled_) {
692 web_ui()->RegisterMessageCallback(
693 "showCloudPrintSetupDialog",
694 base::Bind(&BrowserOptionsHandler::ShowCloudPrintSetupDialog,
695 base::Unretained(this)));
696 web_ui()->RegisterMessageCallback(
697 "disableCloudPrintConnector",
698 base::Bind(&BrowserOptionsHandler::HandleDisableCloudPrintConnector,
699 base::Unretained(this)));
701 #endif // defined(ENABLE_FULL_PRINTING)
702 web_ui()->RegisterMessageCallback(
703 "showNetworkProxySettings",
704 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings,
705 base::Unretained(this)));
706 #endif // defined(OS_CHROMEOS)
708 #if defined(ENABLE_MDNS)
709 if (cloud_print_mdns_ui_enabled_) {
710 web_ui()->RegisterMessageCallback(
711 "showCloudPrintDevicesPage",
712 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage,
713 base::Unretained(this)));
716 web_ui()->RegisterMessageCallback(
717 "requestHotwordAvailabile",
718 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable,
719 base::Unretained(this)));
722 void BrowserOptionsHandler::Uninitialize() {
723 registrar_.RemoveAll();
726 void BrowserOptionsHandler::OnStateChanged() {
730 void BrowserOptionsHandler::PageLoadStarted() {
731 page_initialized_ = false;
734 void BrowserOptionsHandler::InitializeHandler() {
735 Profile* profile = Profile::FromWebUI(web_ui());
736 PrefService* prefs = profile->GetPrefs();
738 ProfileSyncService* sync_service(
739 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile));
741 sync_service->AddObserver(this);
743 // Create our favicon data source.
744 content::URLDataSource::Add(
745 profile, new FaviconSource(profile, FaviconSource::FAVICON));
747 default_browser_policy_.Init(
748 prefs::kDefaultBrowserSettingEnabled,
749 g_browser_process->local_state(),
750 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState,
751 base::Unretained(this)));
753 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
754 content::NotificationService::AllSources());
755 #if defined(OS_CHROMEOS)
756 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
757 content::NotificationService::AllSources());
759 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
760 content::Source<ThemeService>(
761 ThemeServiceFactory::GetForProfile(profile)));
762 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
763 content::Source<Profile>(profile));
764 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
765 content::Source<Profile>(profile));
766 AddTemplateUrlServiceObserver();
769 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
770 if (!command_line.HasSwitch(switches::kUserDataDir)) {
771 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
772 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
773 weak_ptr_factory_.GetWeakPtr(),
774 profile->GetPath()));
778 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
779 base::Closure cloud_print_callback = base::Bind(
780 &BrowserOptionsHandler::OnCloudPrintPrefsChanged, base::Unretained(this));
781 cloud_print_connector_email_.Init(
782 prefs::kCloudPrintEmail, prefs, cloud_print_callback);
783 cloud_print_connector_enabled_.Init(
784 prefs::kCloudPrintProxyEnabled, prefs, cloud_print_callback);
787 auto_open_files_.Init(
788 prefs::kDownloadExtensionsToOpen, prefs,
789 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes,
790 base::Unretained(this)));
791 default_zoom_level_.Init(
792 prefs::kDefaultZoomLevel, prefs,
793 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector,
794 base::Unretained(this)));
795 profile_pref_registrar_.Init(prefs);
796 profile_pref_registrar_.Add(
797 prefs::kWebKitDefaultFontSize,
798 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
799 base::Unretained(this)));
800 profile_pref_registrar_.Add(
801 prefs::kWebKitDefaultFixedFontSize,
802 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
803 base::Unretained(this)));
804 profile_pref_registrar_.Add(
805 prefs::kManagedUsers,
806 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers,
807 base::Unretained(this)));
808 profile_pref_registrar_.Add(
809 prefs::kSigninAllowed,
810 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange,
811 base::Unretained(this)));
813 #if defined(OS_CHROMEOS)
814 if (!policy_registrar_) {
815 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
816 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
818 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
819 policy_registrar_->Observe(
820 policy::key::kUserAvatarImage,
821 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged,
822 base::Unretained(this)));
824 #else // !defined(OS_CHROMEOS)
825 profile_pref_registrar_.Add(
827 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection,
828 base::Unretained(this)));
829 #endif // !defined(OS_CHROMEOS)
832 void BrowserOptionsHandler::InitializePage() {
833 page_initialized_ = true;
835 OnTemplateURLServiceChanged();
837 ObserveThemeChanged();
839 UpdateDefaultBrowserState();
841 SetupMetricsReportingSettingVisibility();
842 SetupFontSizeSelector();
843 SetupPageZoomSelector();
844 SetupAutoOpenFileTypes();
845 SetupProxySettingsSection();
846 SetupManageCertificatesSection();
847 SetupManagingSupervisedUsers();
849 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
850 if (!cloud_print_mdns_ui_enabled_) {
851 if (cloud_print_connector_ui_enabled_) {
852 SetupCloudPrintConnectorSection();
853 RefreshCloudPrintStatusFromService();
855 RemoveCloudPrintConnectorSection();
860 #if defined(OS_CHROMEOS)
861 SetupAccessibilityFeatures();
862 policy::BrowserPolicyConnectorChromeOS* connector =
863 g_browser_process->platform_part()->browser_policy_connector_chromeos();
864 if (!connector->IsEnterpriseManaged() &&
865 !chromeos::UserManager::Get()->IsLoggedInAsGuest() &&
866 !chromeos::UserManager::Get()->IsLoggedInAsLocallyManagedUser()) {
867 web_ui()->CallJavascriptFunction(
868 "BrowserOptions.enableFactoryResetSection");
871 OnAccountPictureManagedChanged(
872 policy::ProfilePolicyConnectorFactory::GetForProfile(
873 Profile::FromWebUI(web_ui()))->
874 policy_service()->GetPolicies(
875 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
877 .Get(policy::key::kUserAvatarImage));
882 void BrowserOptionsHandler::CheckAutoLaunch(
883 base::WeakPtr<BrowserOptionsHandler> weak_this,
884 const base::FilePath& profile_path) {
886 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
888 // Auto-launch is not supported for secondary profiles yet.
889 if (profile_path.BaseName().value() !=
890 base::ASCIIToUTF16(chrome::kInitialProfile)) {
894 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
896 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
897 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
899 auto_launch_trial::IsInAutoLaunchGroup(),
900 auto_launch_util::AutoStartRequested(
901 profile_path.BaseName().value(),
902 true, // Window requested.
907 void BrowserOptionsHandler::CheckAutoLaunchCallback(
908 bool is_in_auto_launch_group,
909 bool will_launch_at_login) {
911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
913 if (is_in_auto_launch_group) {
914 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
915 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
916 base::Unretained(this)));
918 base::FundamentalValue enabled(will_launch_at_login);
919 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
925 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
926 #if defined(OS_MACOSX)
927 ShellIntegration::DefaultWebClientState state =
928 ShellIntegration::GetDefaultBrowser();
929 int status_string_id;
930 if (state == ShellIntegration::IS_DEFAULT)
931 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
932 else if (state == ShellIntegration::NOT_DEFAULT)
933 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
935 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
937 SetDefaultBrowserUIString(status_string_id);
939 default_browser_worker_->StartCheckIsDefault();
943 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue* args) {
944 // If the default browser setting is managed then we should not be able to
945 // call this function.
946 if (default_browser_policy_.IsManaged())
949 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
950 #if defined(OS_MACOSX)
951 if (ShellIntegration::SetAsDefaultBrowser())
952 UpdateDefaultBrowserState();
954 default_browser_worker_->StartSetAsDefault();
955 // Callback takes care of updating UI.
958 // If the user attempted to make Chrome the default browser, then he/she
959 // arguably wants to be notified when that changes.
960 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
961 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
964 int BrowserOptionsHandler::StatusStringIdForState(
965 ShellIntegration::DefaultWebClientState state) {
966 if (state == ShellIntegration::IS_DEFAULT)
967 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
968 if (state == ShellIntegration::NOT_DEFAULT)
969 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
970 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
973 void BrowserOptionsHandler::SetDefaultWebClientUIState(
974 ShellIntegration::DefaultWebClientUIState state) {
975 int status_string_id;
977 if (state == ShellIntegration::STATE_IS_DEFAULT) {
978 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
979 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
980 if (ShellIntegration::CanSetAsDefaultBrowser() ==
981 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
982 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_SXS;
984 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
986 } else if (state == ShellIntegration::STATE_UNKNOWN) {
987 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
989 return; // Still processing.
992 SetDefaultBrowserUIString(status_string_id);
995 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
996 return true; // This is UI so we can allow it.
999 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
1000 base::StringValue status_string(
1001 l10n_util::GetStringFUTF16(status_string_id,
1002 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1004 base::FundamentalValue is_default(
1005 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT);
1007 base::FundamentalValue can_be_default(
1008 !default_browser_policy_.IsManaged() &&
1009 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
1010 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
1012 web_ui()->CallJavascriptFunction(
1013 "BrowserOptions.updateDefaultBrowserState",
1014 status_string, is_default, can_be_default);
1017 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1018 if (!template_url_service_ || !template_url_service_->loaded())
1021 const TemplateURL* default_url =
1022 template_url_service_->GetDefaultSearchProvider();
1024 int default_index = -1;
1025 base::ListValue search_engines;
1026 TemplateURLService::TemplateURLVector model_urls(
1027 template_url_service_->GetTemplateURLs());
1028 for (size_t i = 0; i < model_urls.size(); ++i) {
1029 if (!model_urls[i]->ShowInDefaultList())
1032 base::DictionaryValue* entry = new base::DictionaryValue();
1033 entry->SetString("name", model_urls[i]->short_name());
1034 entry->SetInteger("index", i);
1035 search_engines.Append(entry);
1036 if (model_urls[i] == default_url)
1040 web_ui()->CallJavascriptFunction(
1041 "BrowserOptions.updateSearchEngines",
1043 base::FundamentalValue(default_index),
1044 base::FundamentalValue(
1045 template_url_service_->is_default_search_managed() ||
1046 template_url_service_->IsExtensionControlledDefaultSearch()));
1049 void BrowserOptionsHandler::SetDefaultSearchEngine(
1050 const base::ListValue* args) {
1051 int selected_index = -1;
1052 if (!ExtractIntegerValue(args, &selected_index)) {
1057 TemplateURLService::TemplateURLVector model_urls(
1058 template_url_service_->GetTemplateURLs());
1059 if (selected_index >= 0 &&
1060 selected_index < static_cast<int>(model_urls.size()))
1061 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]);
1063 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1066 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1067 template_url_service_ =
1068 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1069 if (template_url_service_) {
1070 template_url_service_->Load();
1071 template_url_service_->AddObserver(this);
1075 void BrowserOptionsHandler::Observe(
1077 const content::NotificationSource& source,
1078 const content::NotificationDetails& details) {
1079 // Notifications are used to update the UI dynamically when settings change in
1080 // the background. If the UI is currently being loaded, no dynamic updates are
1081 // possible (as the DOM and JS are not fully loaded) or necessary (as
1082 // InitializePage() will update the UI at the end of the load).
1083 if (!page_initialized_)
1087 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
1088 ObserveThemeChanged();
1090 #if defined(OS_CHROMEOS)
1091 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
1092 UpdateAccountPicture();
1095 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
1098 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL:
1099 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT:
1100 // Update our sync/signin status display.
1108 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
1109 void BrowserOptionsHandler::OnCloudPrintPrefsChanged() {
1110 if (cloud_print_connector_ui_enabled_)
1111 SetupCloudPrintConnectorSection();
1115 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) {
1117 if (!auto_launch_trial::IsInAutoLaunchGroup())
1121 CHECK_EQ(args->GetSize(), 1U);
1122 CHECK(args->GetBoolean(0, &enable));
1124 Profile* profile = Profile::FromWebUI(web_ui());
1125 content::BrowserThread::PostTask(
1126 content::BrowserThread::FILE, FROM_HERE,
1128 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin,
1129 profile->GetPath().BaseName().value(), base::FilePath()) :
1130 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin,
1131 profile->GetPath().BaseName().value()));
1135 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() {
1136 ProfileInfoCache& cache =
1137 g_browser_process->profile_manager()->GetProfileInfoCache();
1138 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue);
1139 base::FilePath current_profile_path =
1140 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1142 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
1143 base::DictionaryValue* profile_value = new base::DictionaryValue();
1144 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
1145 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
1146 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1147 profile_value->SetBoolean("isCurrentProfile",
1148 profile_path == current_profile_path);
1149 profile_value->SetBoolean("isManaged", cache.ProfileIsManagedAtIndex(i));
1151 bool is_gaia_picture =
1152 cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
1153 cache.GetGAIAPictureOfProfileAtIndex(i);
1154 if (is_gaia_picture) {
1155 gfx::Image icon = profiles::GetAvatarIconForWebUI(
1156 cache.GetAvatarIconOfProfileAtIndex(i), true);
1157 profile_value->SetString("iconURL",
1158 webui::GetBitmapDataUrl(icon.AsBitmap()));
1160 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
1161 profile_value->SetString("iconURL",
1162 cache.GetDefaultAvatarIconUrl(icon_index));
1165 profile_info_list->Append(profile_value);
1168 return profile_info_list.Pass();
1171 void BrowserOptionsHandler::SendProfilesInfo() {
1172 if (!ShouldShowMultiProfilesUserList(helper::GetDesktopType(web_ui())))
1174 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1175 *GetProfilesInfoList());
1178 void BrowserOptionsHandler::DeleteProfile(const base::ListValue* args) {
1180 const base::Value* file_path_value;
1181 if (!args->Get(0, &file_path_value))
1184 base::FilePath file_path;
1185 if (!base::GetValueAsFilePath(*file_path_value, &file_path))
1187 helper::DeleteProfileAtPath(file_path, web_ui());
1190 void BrowserOptionsHandler::ObserveThemeChanged() {
1191 Profile* profile = Profile::FromWebUI(web_ui());
1192 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
1193 bool is_native_theme = false;
1195 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1196 bool profile_is_managed = profile->IsManaged();
1197 is_native_theme = theme_service->UsingNativeTheme();
1198 base::FundamentalValue native_theme_enabled(!is_native_theme &&
1199 !profile_is_managed);
1200 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1201 native_theme_enabled);
1204 bool is_classic_theme = !is_native_theme &&
1205 theme_service->UsingDefaultTheme();
1206 base::FundamentalValue enabled(!is_classic_theme);
1207 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1211 void BrowserOptionsHandler::ThemesReset(const base::ListValue* args) {
1212 Profile* profile = Profile::FromWebUI(web_ui());
1213 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1214 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
1217 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1218 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue* args) {
1219 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1220 Profile* profile = Profile::FromWebUI(web_ui());
1221 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme();
1225 #if defined(OS_CHROMEOS)
1226 void BrowserOptionsHandler::UpdateAccountPicture() {
1227 std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
1228 if (!email.empty()) {
1229 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1230 base::StringValue email_value(email);
1231 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1236 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed) {
1237 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1238 base::FundamentalValue(managed));
1242 scoped_ptr<base::DictionaryValue>
1243 BrowserOptionsHandler::GetSyncStateDictionary() {
1244 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
1245 Profile* profile = Profile::FromWebUI(web_ui());
1246 if (profile->IsManaged()) {
1247 sync_status->SetBoolean("supervisedUser", true);
1248 sync_status->SetBoolean("signinAllowed", false);
1249 return sync_status.Pass();
1251 if (profile->IsGuestSession()) {
1252 // Cannot display signin status when running in guest mode on chromeos
1253 // because there is no SigninManager.
1254 sync_status->SetBoolean("signinAllowed", false);
1255 return sync_status.Pass();
1257 sync_status->SetBoolean("supervisedUser", false);
1259 bool signout_prohibited = false;
1260 #if !defined(OS_CHROMEOS)
1261 // Signout is not allowed if the user has policy (crbug.com/172204).
1262 signout_prohibited =
1263 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited();
1266 ProfileSyncService* service =
1267 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
1268 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1270 sync_status->SetBoolean("signoutAllowed", !signout_prohibited);
1271 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed());
1272 sync_status->SetBoolean("syncSystemEnabled", !!service);
1273 sync_status->SetBoolean("setupCompleted",
1274 service && service->HasSyncSetupCompleted());
1275 sync_status->SetBoolean("setupInProgress",
1276 service && !service->IsManaged() && service->FirstSetupInProgress());
1278 base::string16 status_label;
1279 base::string16 link_label;
1280 bool status_has_error = sync_ui_util::GetStatusLabels(
1281 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
1282 sync_ui_util::SYNC_ERROR;
1283 sync_status->SetString("statusText", status_label);
1284 sync_status->SetString("actionLinkText", link_label);
1285 sync_status->SetBoolean("hasError", status_has_error);
1287 sync_status->SetBoolean("managed", service && service->IsManaged());
1288 sync_status->SetBoolean("signedIn",
1289 !signin->GetAuthenticatedUsername().empty());
1290 sync_status->SetBoolean("hasUnrecoverableError",
1291 service && service->HasUnrecoverableError());
1292 sync_status->SetBoolean(
1294 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) &&
1295 service && service->IsSyncEnabledAndLoggedIn() &&
1296 service->IsOAuthRefreshTokenAvailable());
1298 return sync_status.Pass();
1301 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1302 const base::ListValue* args) {
1303 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1304 select_folder_dialog_ = ui::SelectFileDialog::Create(
1305 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1306 ui::SelectFileDialog::FileTypeInfo info;
1307 info.support_drive = true;
1308 select_folder_dialog_->SelectFile(
1309 ui::SelectFileDialog::SELECT_FOLDER,
1310 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE),
1311 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory),
1314 base::FilePath::StringType(),
1315 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(),
1319 void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index,
1321 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1322 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1323 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path);
1324 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
1327 #if defined(OS_CHROMEOS)
1328 void BrowserOptionsHandler::TouchpadExists(bool exists) {
1329 base::FundamentalValue val(exists);
1330 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val);
1333 void BrowserOptionsHandler::MouseExists(bool exists) {
1334 base::FundamentalValue val(exists);
1335 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val);
1338 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1339 const base::Value* previous_policy,
1340 const base::Value* current_policy) {
1341 const bool had_policy = !!previous_policy;
1342 const bool has_policy = !!current_policy;
1343 if (had_policy != has_policy)
1344 OnAccountPictureManagedChanged(has_policy);
1347 #endif // defined(OS_CHROMEOS)
1349 void BrowserOptionsHandler::UpdateSyncState() {
1350 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1351 *GetSyncStateDictionary());
1354 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1358 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1359 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1360 DownloadManager* manager = BrowserContext::GetDownloadManager(
1361 web_ui()->GetWebContents()->GetBrowserContext());
1363 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
1366 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue* args) {
1368 if (ExtractIntegerValue(args, &font_size)) {
1369 if (font_size > 0) {
1370 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1371 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size);
1372 SetupFontSizeSelector();
1377 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1378 const base::ListValue* args) {
1380 if (ExtractDoubleValue(args, &zoom_factor)) {
1381 default_zoom_level_.SetValue(content::ZoomFactorToZoomLevel(zoom_factor));
1385 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
1386 #if defined(OS_WIN) && defined(USE_ASH)
1387 // If hardware acceleration is disabled then we need to force restart
1388 // browser in desktop mode.
1389 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1390 // Currently there are issues with determining correct browser mode
1392 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1393 PrefService* pref_service = g_browser_process->local_state();
1394 if (!pref_service->GetBoolean(prefs::kHardwareAccelerationModeEnabled)) {
1395 chrome::AttemptRestartToDesktopMode();
1401 chrome::AttemptRestart();
1404 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1405 const base::ListValue* args) {
1409 #if !defined(OS_CHROMEOS)
1410 void BrowserOptionsHandler::ShowNetworkProxySettings(
1411 const base::ListValue* args) {
1412 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1413 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1414 web_ui()->GetWebContents());
1418 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
1419 void BrowserOptionsHandler::ShowManageSSLCertificates(
1420 const base::ListValue* args) {
1421 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1422 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1423 web_ui()->GetWebContents());
1427 #if defined(ENABLE_MDNS)
1429 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1430 const base::ListValue* args) {
1431 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1432 // Navigate in current tab to devices page.
1433 OpenURLParams params(
1434 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1435 CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
1436 web_ui()->GetWebContents()->OpenURL(params);
1441 #if defined(ENABLE_FULL_PRINTING)
1442 void BrowserOptionsHandler::ShowCloudPrintManagePage(
1443 const base::ListValue* args) {
1444 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters"));
1445 // Open a new tab in the current window for the management page.
1446 Profile* profile = Profile::FromWebUI(web_ui());
1447 OpenURLParams params(
1448 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), Referrer(),
1449 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false);
1450 web_ui()->GetWebContents()->OpenURL(params);
1453 #if !defined(OS_CHROMEOS)
1454 void BrowserOptionsHandler::ShowCloudPrintSetupDialog(
1455 const base::ListValue* args) {
1456 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy"));
1457 // Open the connector enable page in the current tab.
1458 Profile* profile = Profile::FromWebUI(web_ui());
1459 OpenURLParams params(
1460 CloudPrintURL(profile).GetCloudPrintServiceEnableURL(
1461 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()),
1462 Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
1463 web_ui()->GetWebContents()->OpenURL(params);
1466 void BrowserOptionsHandler::HandleDisableCloudPrintConnector(
1467 const base::ListValue* args) {
1468 content::RecordAction(
1469 UserMetricsAction("Options_DisableCloudPrintProxy"));
1470 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
1474 void BrowserOptionsHandler::RefreshCloudPrintStatusFromService() {
1475 if (cloud_print_connector_ui_enabled_)
1476 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
1477 RefreshStatusFromService();
1480 void BrowserOptionsHandler::SetupCloudPrintConnectorSection() {
1481 Profile* profile = Profile::FromWebUI(web_ui());
1482 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) {
1483 cloud_print_connector_ui_enabled_ = false;
1484 RemoveCloudPrintConnectorSection();
1488 bool cloud_print_connector_allowed =
1489 !cloud_print_connector_enabled_.IsManaged() ||
1490 cloud_print_connector_enabled_.GetValue();
1491 base::FundamentalValue allowed(cloud_print_connector_allowed);
1494 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) &&
1495 cloud_print_connector_allowed) {
1496 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail);
1498 base::FundamentalValue disabled(email.empty());
1500 base::string16 label_str;
1501 if (email.empty()) {
1502 label_str = l10n_util::GetStringFUTF16(
1503 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL,
1504 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT));
1506 label_str = l10n_util::GetStringFUTF16(
1507 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL,
1508 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT),
1509 base::UTF8ToUTF16(email));
1511 base::StringValue label(label_str);
1513 web_ui()->CallJavascriptFunction(
1514 "BrowserOptions.setupCloudPrintConnectorSection", disabled, label,
1518 void BrowserOptionsHandler::RemoveCloudPrintConnectorSection() {
1519 web_ui()->CallJavascriptFunction(
1520 "BrowserOptions.removeCloudPrintConnectorSection");
1522 #endif // defined(OS_CHROMEOS)
1523 #endif // defined(ENABLE_FULL_PRINTING)
1525 void BrowserOptionsHandler::SendHotwordAvailable() {
1526 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1527 if (group != "" && group != "Disabled")
1528 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection");
1531 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1532 const base::ListValue* args) {
1533 SendHotwordAvailable();
1536 #if defined(OS_CHROMEOS)
1537 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1538 const base::ListValue* args) {
1539 wallpaper_manager_util::OpenWallpaperManager();
1542 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1543 const base::ListValue* args) {
1544 bool enabled = false;
1545 args->GetBoolean(0, &enabled);
1547 chromeos::accessibility::EnableVirtualKeyboard(enabled);
1550 void BrowserOptionsHandler::PerformFactoryResetRestart(
1551 const base::ListValue* args) {
1552 policy::BrowserPolicyConnectorChromeOS* connector =
1553 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1554 if (connector->IsEnterpriseManaged())
1557 PrefService* prefs = g_browser_process->local_state();
1558 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
1559 prefs->CommitPendingWrite();
1561 // Perform sign out. Current chrome process will then terminate, new one will
1562 // be launched (as if it was a restart).
1563 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1566 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1567 PrefService* pref_service = g_browser_process->local_state();
1568 base::FundamentalValue virtual_keyboard_enabled(
1569 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled));
1570 web_ui()->CallJavascriptFunction(
1571 "BrowserOptions.setVirtualKeyboardCheckboxState",
1572 virtual_keyboard_enabled);
1576 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1577 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS)
1578 // Don't show the reporting setting if we are in the guest mode.
1579 if (CommandLine::ForCurrentProcess()->HasSwitch(
1580 chromeos::switches::kGuestSession)) {
1581 base::FundamentalValue visible(false);
1582 web_ui()->CallJavascriptFunction(
1583 "BrowserOptions.setMetricsReportingSettingVisibility", visible);
1588 void BrowserOptionsHandler::SetupFontSizeSelector() {
1589 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1590 const PrefService::Preference* default_font_size =
1591 pref_service->FindPreference(prefs::kWebKitDefaultFontSize);
1592 const PrefService::Preference* default_fixed_font_size =
1593 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize);
1595 base::DictionaryValue dict;
1596 dict.SetInteger("value",
1597 pref_service->GetInteger(prefs::kWebKitDefaultFontSize));
1599 // The font size control displays the value of the default font size, but
1600 // setting it alters both the default font size and the default fixed font
1601 // size. So it must be disabled when either of those prefs is not user
1603 dict.SetBoolean("disabled",
1604 !default_font_size->IsUserModifiable() ||
1605 !default_fixed_font_size->IsUserModifiable());
1607 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1608 // adapted to consider two prefs. It may be better to refactor
1609 // CreateValueForPref so it can be called from here.
1610 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) {
1611 dict.SetString("controlledBy", "policy");
1612 } else if (default_font_size->IsExtensionControlled() ||
1613 default_fixed_font_size->IsExtensionControlled()) {
1614 dict.SetString("controlledBy", "extension");
1617 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict);
1620 void BrowserOptionsHandler::SetupPageZoomSelector() {
1621 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1622 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
1623 double default_zoom_factor =
1624 content::ZoomLevelToZoomFactor(default_zoom_level);
1626 // Generate a vector of zoom factors from an array of known presets along with
1627 // the default factor added if necessary.
1628 std::vector<double> zoom_factors =
1629 chrome_page_zoom::PresetZoomFactors(default_zoom_factor);
1631 // Iterate through the zoom factors and and build the contents of the
1632 // selector that will be sent to the javascript handler.
1633 // Each item in the list has the following parameters:
1634 // 1. Title (string).
1635 // 2. Value (double).
1636 // 3. Is selected? (bool).
1637 base::ListValue zoom_factors_value;
1638 for (std::vector<double>::const_iterator i = zoom_factors.begin();
1639 i != zoom_factors.end(); ++i) {
1640 base::ListValue* option = new base::ListValue();
1642 int percent = static_cast<int>(factor * 100 + 0.5);
1643 option->Append(new base::StringValue(
1644 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
1645 option->Append(new base::FundamentalValue(factor));
1646 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
1647 option->Append(new base::FundamentalValue(selected));
1648 zoom_factors_value.Append(option);
1651 web_ui()->CallJavascriptFunction(
1652 "BrowserOptions.setupPageZoomSelector", zoom_factors_value);
1655 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1656 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1657 // We show the button if the user has any auto-open file types registered.
1658 DownloadManager* manager = BrowserContext::GetDownloadManager(
1659 web_ui()->GetWebContents()->GetBrowserContext());
1660 bool display = manager &&
1661 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
1662 base::FundamentalValue value(display);
1663 web_ui()->CallJavascriptFunction(
1664 "BrowserOptions.setAutoOpenFileTypesDisplayed", value);
1667 void BrowserOptionsHandler::SetupProxySettingsSection() {
1668 #if !defined(OS_CHROMEOS)
1669 // Disable the button if proxy settings are managed by a sysadmin, overridden
1670 // by an extension, or the browser is running in Windows Ash (on Windows the
1671 // proxy settings dialog will open on the Windows desktop and be invisible
1672 // to a user in Ash).
1673 bool is_win_ash = false;
1675 chrome::HostDesktopType desktop_type = helper::GetDesktopType(web_ui());
1676 is_win_ash = (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH);
1678 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1679 const PrefService::Preference* proxy_config =
1680 pref_service->FindPreference(prefs::kProxy);
1681 bool is_extension_controlled = (proxy_config &&
1682 proxy_config->IsExtensionControlled());
1684 base::FundamentalValue disabled(is_win_ash || (proxy_config &&
1685 !proxy_config->IsUserModifiable()));
1686 base::FundamentalValue extension_controlled(is_extension_controlled);
1687 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection",
1688 disabled, extension_controlled);
1690 #endif // !defined(OS_CHROMEOS)
1693 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1695 // Disable the button if the settings page is displayed in Windows Ash,
1696 // otherwise the proxy settings dialog will open on the Windows desktop and
1697 // be invisible to a user in Ash.
1698 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH) {
1699 base::FundamentalValue enabled(false);
1700 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1703 #endif // defined(OS_WIN)
1706 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1707 bool has_users = !Profile::FromWebUI(web_ui())->
1708 GetPrefs()->GetDictionary(prefs::kManagedUsers)->empty();
1709 base::FundamentalValue has_users_value(has_users);
1710 web_ui()->CallJavascriptFunction(
1711 "BrowserOptions.updateManagesSupervisedUsers",
1715 } // namespace options