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"
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/command_line.h"
14 #include "base/environment.h"
15 #include "base/memory/singleton.h"
16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/value_conversions.h"
24 #include "base/values.h"
25 #include "chrome/browser/auto_launch_trial.h"
26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/custom_home_pages_table_model.h"
29 #include "chrome/browser/download/download_prefs.h"
30 #include "chrome/browser/gpu/gpu_mode_manager.h"
31 #include "chrome/browser/lifetime/application_lifetime.h"
32 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
33 #include "chrome/browser/metrics/metrics_reporting_state.h"
34 #include "chrome/browser/net/prediction_options.h"
35 #include "chrome/browser/prefs/session_startup_pref.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
38 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
40 #include "chrome/browser/profiles/profile_info_cache.h"
41 #include "chrome/browser/profiles/profile_manager.h"
42 #include "chrome/browser/profiles/profile_metrics.h"
43 #include "chrome/browser/profiles/profile_shortcut_manager.h"
44 #include "chrome/browser/profiles/profile_window.h"
45 #include "chrome/browser/profiles/profiles_state.h"
46 #include "chrome/browser/search/hotword_audio_history_handler.h"
47 #include "chrome/browser/search/hotword_service.h"
48 #include "chrome/browser/search/hotword_service_factory.h"
49 #include "chrome/browser/search/search.h"
50 #include "chrome/browser/search_engines/template_url_service_factory.h"
51 #include "chrome/browser/signin/easy_unlock_service.h"
52 #include "chrome/browser/signin/signin_manager_factory.h"
53 #include "chrome/browser/sync/profile_sync_service.h"
54 #include "chrome/browser/sync/profile_sync_service_factory.h"
55 #include "chrome/browser/sync/sync_ui_util.h"
56 #include "chrome/browser/themes/theme_service.h"
57 #include "chrome/browser/themes/theme_service_factory.h"
58 #include "chrome/browser/ui/browser_finder.h"
59 #include "chrome/browser/ui/chrome_select_file_policy.h"
60 #include "chrome/browser/ui/host_desktop.h"
61 #include "chrome/browser/ui/webui/favicon_source.h"
62 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
63 #include "chrome/common/chrome_constants.h"
64 #include "chrome/common/chrome_paths.h"
65 #include "chrome/common/chrome_switches.h"
66 #include "chrome/common/extensions/extension_constants.h"
67 #include "chrome/common/pref_names.h"
68 #include "chrome/common/url_constants.h"
69 #include "chrome/grit/chromium_strings.h"
70 #include "chrome/grit/generated_resources.h"
71 #include "chrome/grit/locale_settings.h"
72 #include "components/password_manager/core/browser/password_bubble_experiment.h"
73 #include "components/policy/core/common/policy_map.h"
74 #include "components/policy/core/common/policy_namespace.h"
75 #include "components/policy/core/common/policy_service.h"
76 #include "components/proximity_auth/switches.h"
77 #include "components/proxy_config/proxy_config_pref_names.h"
78 #include "components/search_engines/template_url.h"
79 #include "components/search_engines/template_url_service.h"
80 #include "components/signin/core/browser/signin_manager.h"
81 #include "components/signin/core/common/profile_management_switches.h"
82 #include "components/ui/zoom/page_zoom.h"
83 #include "components/user_manager/user_type.h"
84 #include "content/public/browser/browser_thread.h"
85 #include "content/public/browser/download_manager.h"
86 #include "content/public/browser/navigation_controller.h"
87 #include "content/public/browser/notification_details.h"
88 #include "content/public/browser/notification_service.h"
89 #include "content/public/browser/notification_source.h"
90 #include "content/public/browser/notification_types.h"
91 #include "content/public/browser/url_data_source.h"
92 #include "content/public/browser/user_metrics.h"
93 #include "content/public/browser/web_contents.h"
94 #include "content/public/common/page_zoom.h"
95 #include "extensions/browser/extension_registry.h"
96 #include "google_apis/gaia/gaia_auth_util.h"
97 #include "google_apis/gaia/google_service_auth_error.h"
98 #include "policy/policy_constants.h"
99 #include "third_party/skia/include/core/SkBitmap.h"
100 #include "ui/base/l10n/l10n_util.h"
101 #include "ui/base/webui/web_ui_util.h"
103 #if !defined(OS_CHROMEOS)
104 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
107 #if defined(OS_CHROMEOS)
108 #include "ash/ash_switches.h"
109 #include "ash/desktop_background/user_wallpaper_delegate.h"
110 #include "ash/shell.h"
111 #include "ash/system/chromeos/devicetype_utils.h"
112 #include "chrome/browser/browser_process_platform_part.h"
113 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
114 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
115 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
116 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
117 #include "chrome/browser/chromeos/profiles/profile_helper.h"
118 #include "chrome/browser/chromeos/reset/metrics.h"
119 #include "chrome/browser/chromeos/settings/cros_settings.h"
120 #include "chrome/browser/chromeos/system/timezone_util.h"
121 #include "chrome/browser/policy/profile_policy_connector.h"
122 #include "chrome/browser/policy/profile_policy_connector_factory.h"
123 #include "chrome/browser/ui/browser_window.h"
124 #include "chromeos/chromeos_switches.h"
125 #include "chromeos/dbus/dbus_thread_manager.h"
126 #include "chromeos/dbus/power_manager_client.h"
127 #include "components/user_manager/user.h"
128 #include "components/user_manager/user_manager.h"
129 #include "ui/chromeos/accessibility_types.h"
130 #include "ui/gfx/image/image_skia.h"
131 #endif // defined(OS_CHROMEOS)
134 #include "chrome/browser/extensions/settings_api_helpers.h"
135 #include "chrome/installer/util/auto_launch_util.h"
136 #include "content/public/browser/browser_url_handler.h"
137 #endif // defined(OS_WIN)
139 #if defined(ENABLE_SERVICE_DISCOVERY)
140 #include "chrome/browser/local_discovery/privet_notifications.h"
144 #include "ash/shell.h"
147 using base::UserMetricsAction
;
148 using content::BrowserContext
;
149 using content::BrowserThread
;
150 using content::DownloadManager
;
151 using content::OpenURLParams
;
152 using content::Referrer
;
153 using extensions::Extension
;
154 using extensions::ExtensionRegistry
;
159 void AppendExtensionData(const std::string
& key
,
160 const Extension
* extension
,
161 base::DictionaryValue
* dict
) {
162 scoped_ptr
<base::DictionaryValue
> details(new base::DictionaryValue
);
163 details
->SetString("id", extension
? extension
->id() : std::string());
164 details
->SetString("name", extension
? extension
->name() : std::string());
165 dict
->Set(key
, details
.release());
167 #endif // defined(OS_WIN)
173 BrowserOptionsHandler::BrowserOptionsHandler()
174 : page_initialized_(false),
175 template_url_service_(NULL
),
176 cloud_print_mdns_ui_enabled_(false),
177 signin_observer_(this),
178 weak_ptr_factory_(this) {
179 default_browser_worker_
= new ShellIntegration::DefaultBrowserWorker(this);
181 #if defined(ENABLE_SERVICE_DISCOVERY)
182 cloud_print_mdns_ui_enabled_
= true;
183 #endif // defined(ENABLE_SERVICE_DISCOVERY)
186 BrowserOptionsHandler::~BrowserOptionsHandler() {
187 ProfileSyncService
* sync_service(ProfileSyncServiceFactory::
188 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
190 sync_service
->RemoveObserver(this);
192 if (default_browser_worker_
.get())
193 default_browser_worker_
->ObserverDestroyed();
194 if (template_url_service_
)
195 template_url_service_
->RemoveObserver(this);
196 // There may be pending file dialogs, we need to tell them that we've gone
197 // away so they don't try and call back to us.
198 if (select_folder_dialog_
.get())
199 select_folder_dialog_
->ListenerDestroyed();
201 g_browser_process
->policy_service()->RemoveObserver(
202 policy::POLICY_DOMAIN_CHROME
, this);
205 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue
* values
) {
208 #if defined(OS_CHROMEOS)
209 const int device_type_resource_id
= ash::GetChromeOSDeviceTypeResourceId();
211 const int device_type_resource_id
= IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE
;
212 #endif // defined(OS_CHROMEOS)
214 static OptionsStringResource resources
[] = {
215 // Please keep these in alphabetical order.
216 { "accessibilityFeaturesLink", IDS_OPTIONS_ACCESSIBILITY_FEATURES_LINK
},
217 { "accessibilityTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY
},
218 { "advancedSectionTitleCertificates",
219 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES
},
220 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT
},
221 { "advancedSectionTitleContent",
222 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT
},
223 { "advancedSectionTitleLanguages",
224 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES
},
225 { "advancedSectionTitleNetwork",
226 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK
},
227 { "advancedSectionTitlePrivacy",
228 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY
},
229 { "advancedSectionTitleSystem", IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM
},
230 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT
},
231 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY
},
232 { "autoOpenFileTypesResetToDefault",
233 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT
},
234 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE
},
235 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN
},
236 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON
},
237 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE
},
238 { "childLabel", IDS_PROFILES_LIST_CHILD_LABEL
},
239 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY
},
240 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL
},
241 { "defaultBrowserUnknown",
242 IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
, IDS_PRODUCT_NAME
},
243 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT
},
244 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL
},
245 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES
},
246 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL
},
247 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES
},
248 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK
},
249 { "doNotTrackConfirmDisable",
250 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE
},
251 { "doNotTrackConfirmEnable",
252 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE
},
253 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT
},
254 { "downloadLocationAskForSaveLocation",
255 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION
},
256 { "downloadLocationBrowseTitle",
257 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
},
258 { "downloadLocationChangeButton",
259 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON
},
260 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME
},
261 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION
,
262 device_type_resource_id
},
263 { "easyUnlockRequireProximityLabel",
264 IDS_OPTIONS_EASY_UNLOCK_REQUIRE_PROXIMITY_LABEL
,
265 device_type_resource_id
},
266 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE
},
267 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON
},
268 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO
,
269 device_type_resource_id
},
270 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING
},
271 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED
},
272 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE
},
273 { "fontSettingsCustomizeFontsButton",
274 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON
},
275 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM
},
276 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE
},
277 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM
},
278 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL
},
279 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE
},
280 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL
},
281 { "googleNowLauncherEnable", IDS_OPTIONS_ENABLE_GOOGLE_NOW
},
282 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS
},
283 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP
},
284 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
285 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB
},
286 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL
},
287 { "hotwordAlwaysOnAudioHistoryDescription",
288 IDS_HOTWORD_ALWAYS_ON_AUDIO_HISTORY_DESCRIPTION
},
289 { "hotwordAlwaysOnDesc", IDS_HOTWORD_SEARCH_ALWAYS_ON_DESCRIPTION
},
290 { "hotwordAudioHistoryManage", IDS_HOTWORD_AUDIO_HISTORY_MANAGE_LINK
},
291 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE
},
292 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE
},
293 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE
},
294 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION
},
295 { "hotwordNoDSPDesc", IDS_HOTWORD_SEARCH_NO_DSP_DESCRIPTION
},
296 { "hotwordRetrainLink", IDS_HOTWORD_RETRAIN_LINK
},
297 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX
},
298 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON
},
299 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE
},
300 { "languageAndSpellCheckSettingsButton",
301 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS
},
302 #if defined(OS_CHROMEOS)
303 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
304 IDS_SHORT_PRODUCT_OS_NAME
},
306 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
307 IDS_SHORT_PRODUCT_NAME
},
309 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF
},
310 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK
},
311 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES
},
312 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK
},
313 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART
},
314 { "networkPredictionEnabledDescription",
315 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
},
316 { "passwordManagerEnabled",
317 password_bubble_experiment::IsSmartLockBrandingEnabled(
318 ProfileSyncServiceFactory::GetForProfile(
319 Profile::FromWebUI(web_ui()))) ?
320 IDS_OPTIONS_PASSWORD_MANAGER_SMART_LOCK_ENABLE
:
321 IDS_OPTIONS_PASSWORD_MANAGER_ENABLE
},
322 { "passwordsAndAutofillGroupName",
323 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME
},
324 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON
},
325 { "privacyContentSettingsButton",
326 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON
},
327 { "profileAddPersonEnable", IDS_PROFILE_ADD_PERSON_ENABLE
},
328 { "profileBrowserGuestEnable", IDS_PROFILE_BROWSER_GUEST_ENABLE
},
329 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL
},
330 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL
},
331 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL
},
332 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT
},
333 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL
},
334 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
336 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL
},
337 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
339 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON
},
340 { "resetProfileSettingsDescription",
341 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION
},
342 { "resetProfileSettingsSectionTitle",
343 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE
},
344 { "safeBrowsingEnableExtendedReporting",
345 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING
},
346 { "safeBrowsingEnableProtection",
347 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION
},
348 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME
},
349 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME
},
350 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME
},
351 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME
},
352 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME
},
353 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME
},
354 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME
},
355 { "settingsTitle", IDS_SETTINGS_TITLE
},
356 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
},
357 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE
},
358 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE
},
359 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT
},
360 { "spellingPref", IDS_OPTIONS_SPELLING_PREF
},
361 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION
},
362 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES
},
363 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB
},
364 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES
},
365 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF
},
366 { "supervisedUserLabel", IDS_PROFILES_LIST_LEGACY_SUPERVISED_USER_LABEL
},
367 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS
},
368 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
369 IDS_SHORT_PRODUCT_NAME
},
370 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL
},
371 { "syncOverview", IDS_SYNC_OVERVIEW
},
372 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF
},
373 { "themesGallery", IDS_THEMES_GALLERY_BUTTON
},
374 { "themesGalleryURL", IDS_THEMES_GALLERY_URL
},
375 { "themesReset", IDS_THEMES_RESET_BUTTON
},
376 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR
},
377 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
378 { "translateEnableTranslate",
379 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE
},
380 #if defined(OS_CHROMEOS)
381 { "accessibilityAlwaysShowMenu",
382 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU
},
383 { "accessibilityAutoclick",
384 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION
},
385 { "accessibilityAutoclickDropdown",
386 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION
},
387 { "accessibilityExplanation",
388 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION
},
389 { "accessibilityHighContrast",
390 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION
},
391 { "accessibilityLargeCursor",
392 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION
},
393 { "accessibilityScreenMagnifier",
394 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION
},
395 { "accessibilityScreenMagnifierCenterFocus",
396 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_CENTER_FOCUS
},
397 { "accessibilityScreenMagnifierFull",
398 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
},
399 { "accessibilityScreenMagnifierOff",
400 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF
},
401 { "accessibilityScreenMagnifierPartial",
402 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
},
403 { "accessibilitySettings",
404 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS
},
405 { "accessibilitySpokenFeedback",
406 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION
},
407 { "accessibilityStickyKeys",
408 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION
},
409 { "accessibilityTapDragging",
410 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION
},
411 { "accessibilityVirtualKeyboard",
412 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION
},
413 { "autoclickDelayExtremelyShort",
414 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT
},
415 { "autoclickDelayLong",
416 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG
},
417 { "autoclickDelayShort",
418 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT
},
419 { "autoclickDelayVeryLong",
420 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG
},
421 { "autoclickDelayVeryShort",
422 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT
},
423 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE
},
424 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION
},
425 { "consumerManagementDescription",
426 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION
},
427 { "consumerManagementEnrollButton",
428 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON
},
429 { "consumerManagementEnrollingButton",
430 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLLING_BUTTON
},
431 { "consumerManagementUnenrollButton",
432 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON
},
433 { "consumerManagementUnenrollingButton",
434 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLLING_BUTTON
},
435 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME
},
436 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE
},
437 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION
},
438 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION
},
439 { "disableGData", IDS_OPTIONS_DISABLE_GDATA
},
440 { "displayOptions", IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL
},
441 { "enableContentProtectionAttestation",
442 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION
},
443 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX
},
444 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON
},
445 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION
,
446 IDS_SHORT_PRODUCT_NAME
},
447 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING
},
448 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL
},
449 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON
},
450 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET
},
451 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING
},
452 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE
},
453 { "keyboardSettingsButtonTitle",
454 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE
},
455 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE
},
456 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION
},
457 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES
},
458 { "powerSettingsButton",
459 IDS_OPTIONS_DEVICE_GROUP_POWER_SETTINGS_BUTTON
},
460 { "resolveTimezoneByGeoLocation",
461 IDS_OPTIONS_RESOLVE_TIMEZONE_BY_GEOLOCATION_DESCRIPTION
},
462 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME
},
463 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL
},
464 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
465 { "thirdPartyImeConfirmDisable", IDS_CANCEL
},
466 { "thirdPartyImeConfirmEnable", IDS_OK
},
467 { "thirdPartyImeConfirmMessage",
468 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE
},
469 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION
},
470 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION
},
471 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION
},
472 { "wakeOnWifiLabel", IDS_OPTIONS_SETTINGS_WAKE_ON_WIFI_DESCRIPTION
},
475 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE
},
476 { "gpuModeResetRestart",
477 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART
},
478 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
},
479 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
480 #endif // defined(OS_CHROMEOS)
482 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
483 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS
},
484 { "themesNativeButton", IDS_THEMES_GTK_BUTTON
},
485 { "themesSetClassic", IDS_THEMES_SET_CLASSIC
},
487 { "themes", IDS_THEMES_GROUP_NAME
},
488 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
490 #if defined(OS_CHROMEOS) && defined(USE_ASH)
491 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON
},
492 #endif // defined(OS_CHROMEOS) && defined(USE_ASH)
494 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
495 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE
},
496 #endif // defined(OS_MACOSX) && !defined(OS_CHROMEOS)
498 #if defined(ENABLE_SETTINGS_APP)
499 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL
},
500 #endif // defined(ENABLE_SETTINGS_APP)
502 #if defined(ENABLE_SERVICE_DISCOVERY)
503 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON
},
504 { "cloudPrintEnableNotificationsLabel",
505 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL
},
506 #endif // defined(ENABLE_SERVICE_DISCOVERY)
509 #if defined(ENABLE_SETTINGS_APP)
510 static OptionsStringResource app_resources
[] = {
511 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW
},
512 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
513 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
514 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
515 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
516 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
517 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
518 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
519 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
521 base::DictionaryValue
* app_values
= NULL
;
522 CHECK(values
->GetDictionary(kSettingsAppKey
, &app_values
));
523 RegisterStrings(app_values
, app_resources
, arraysize(app_resources
));
526 RegisterStrings(values
, resources
, arraysize(resources
));
527 RegisterTitle(values
, "doNotTrackConfirmOverlay",
528 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE
);
529 RegisterTitle(values
, "spellingConfirmOverlay",
530 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE
);
531 #if defined(ENABLE_PRINT_PREVIEW)
532 RegisterCloudPrintValues(values
);
535 values
->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL
);
536 base::string16 omnibox_url
= base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL
);
538 "defaultSearchGroupLabel",
539 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION
, omnibox_url
));
540 values
->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL
);
541 RegisterTitle(values
, "hotwordConfirmOverlay",
542 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE
);
543 values
->SetString("hotwordManageAudioHistoryURL",
544 chrome::kManageAudioHistoryURL
);
545 base::string16 supervised_user_dashboard
=
546 base::ASCIIToUTF16(chrome::kLegacySupervisedUserManagementURL
);
547 values
->SetString("profilesSupervisedDashboardTip",
548 l10n_util::GetStringFUTF16(
549 IDS_PROFILES_LEGACY_SUPERVISED_USER_DASHBOARD_TIP
,
550 supervised_user_dashboard
));
552 #if defined(OS_CHROMEOS)
553 Profile
* profile
= Profile::FromWebUI(web_ui());
554 std::string username
= profile
->GetProfileUserName();
555 if (username
.empty()) {
556 const user_manager::User
* user
=
557 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
558 if (user
&& (user
->GetType() != user_manager::USER_TYPE_GUEST
))
559 username
= user
->email();
561 if (!username
.empty())
562 username
= gaia::SanitizeEmail(gaia::CanonicalizeEmail(username
));
564 values
->SetString("username", username
);
566 // Pass along sync status early so it will be available during page init.
567 values
->Set("syncData", GetSyncStateDictionary().release());
569 values
->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL
);
571 values
->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL
);
573 #if !defined(OS_CHROMEOS)
574 values
->SetBoolean("metricsReportingEnabledAtStart",
575 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
578 #if defined(OS_CHROMEOS)
579 // TODO(pastarmovj): replace this with a call to the CrosSettings list
580 // handling functionality to come.
581 values
->Set("timezoneList", chromeos::system::GetTimezoneList().release());
583 values
->SetString("accessibilityLearnMoreURL",
584 chrome::kChromeAccessibilityHelpURL
);
586 std::string settings_url
= std::string("chrome-extension://") +
587 extension_misc::kChromeVoxExtensionId
+
588 chrome::kChromeAccessibilitySettingsURL
;
590 values
->SetString("accessibilitySettingsURL",
593 values
->SetString("contentProtectionAttestationLearnMoreURL",
594 chrome::kAttestationForContentProtectionLearnMoreURL
);
596 // Creates magnifierList.
597 scoped_ptr
<base::ListValue
> magnifier_list(new base::ListValue
);
599 scoped_ptr
<base::ListValue
> option_full(new base::ListValue
);
600 option_full
->AppendInteger(ui::MAGNIFIER_FULL
);
601 option_full
->AppendString(l10n_util::GetStringUTF16(
602 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
));
603 magnifier_list
->Append(option_full
.release());
605 scoped_ptr
<base::ListValue
> option_partial(new base::ListValue
);
606 option_partial
->AppendInteger(ui::MAGNIFIER_PARTIAL
);
607 option_partial
->Append(new base::StringValue(l10n_util::GetStringUTF16(
608 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
)));
609 magnifier_list
->Append(option_partial
.release());
611 values
->Set("magnifierList", magnifier_list
.release());
614 #if defined(OS_MACOSX)
615 values
->SetString("macPasswordsWarning",
616 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING
));
617 values
->SetBoolean("multiple_profiles",
618 g_browser_process
->profile_manager()->GetNumberOfProfiles() > 1);
621 if (ShouldShowMultiProfilesUserList())
622 values
->Set("profilesInfo", GetProfilesInfoList().release());
624 // Profile deletion is not allowed for any users using Metro mode.
625 bool allow_deletion
= true;
627 allow_deletion
= allow_deletion
&& !ash::Shell::HasInstance();
629 values
->SetBoolean("allowProfileDeletion", allow_deletion
);
631 values
->SetBoolean("profileIsGuest",
632 Profile::FromWebUI(web_ui())->IsOffTheRecord());
634 values
->SetBoolean("profileIsSupervised",
635 Profile::FromWebUI(web_ui())->IsSupervised());
637 #if !defined(OS_CHROMEOS)
640 g_browser_process
->gpu_mode_manager()->initial_gpu_mode_pref());
643 #if defined(ENABLE_SERVICE_DISCOVERY)
644 values
->SetBoolean("cloudPrintHideNotificationsCheckbox",
645 !local_discovery::PrivetNotificationService::IsEnabled());
648 values
->SetBoolean("cloudPrintShowMDnsOptions",
649 cloud_print_mdns_ui_enabled_
);
651 values
->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL
);
653 values
->SetString("languagesLearnMoreURL",
654 chrome::kLanguageSettingsLearnMoreUrl
);
658 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
659 values
->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl
);
660 values
->SetBoolean("easyUnlockProximityDetectionAllowed",
661 base::CommandLine::ForCurrentProcess()->HasSwitch(
662 proximity_auth::switches::kEnableProximityDetection
));
664 #if defined(OS_CHROMEOS)
665 values
->SetBoolean("consumerManagementEnabled",
666 base::CommandLine::ForCurrentProcess()->HasSwitch(
667 chromeos::switches::kEnableConsumerManagement
));
669 RegisterTitle(values
, "thirdPartyImeConfirmOverlay",
670 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE
);
673 values
->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
675 values
->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
677 values
->SetBoolean("usingNewProfilesUI", switches::IsNewAvatarMenu());
679 #if defined(OS_CHROMEOS)
682 chromeos::WakeOnWifiManager::Get()->WakeOnWifiSupported() &&
683 chromeos::switches::WakeOnWifiEnabled());
684 const bool have_disable_time_zone_tracking_option_switch
=
685 base::CommandLine::ForCurrentProcess()->HasSwitch(
686 chromeos::switches::kDisableTimeZoneTrackingOption
);
687 values
->SetBoolean("enableTimeZoneTrackingOption",
688 !have_disable_time_zone_tracking_option_switch
&&
689 !chromeos::system::HasSystemTimezonePolicy());
690 values
->SetBoolean("resolveTimezoneByGeolocationInitialValue",
691 Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
692 prefs::kResolveTimezoneByGeolocation
));
696 #if defined(ENABLE_PRINT_PREVIEW)
697 void BrowserOptionsHandler::RegisterCloudPrintValues(
698 base::DictionaryValue
* values
) {
699 values
->SetString("cloudPrintOptionLabel",
700 l10n_util::GetStringFUTF16(
701 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL
,
702 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
704 #endif // defined(ENABLE_PRINT_PREVIEW)
706 void BrowserOptionsHandler::RegisterMessages() {
707 web_ui()->RegisterMessageCallback(
708 "becomeDefaultBrowser",
709 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser
,
710 base::Unretained(this)));
711 web_ui()->RegisterMessageCallback(
712 "setDefaultSearchEngine",
713 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine
,
714 base::Unretained(this)));
715 web_ui()->RegisterMessageCallback(
717 base::Bind(&BrowserOptionsHandler::DeleteProfile
,
718 base::Unretained(this)));
719 web_ui()->RegisterMessageCallback(
721 base::Bind(&BrowserOptionsHandler::ThemesReset
,
722 base::Unretained(this)));
723 web_ui()->RegisterMessageCallback(
724 "requestProfilesInfo",
725 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo
,
726 base::Unretained(this)));
727 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
728 web_ui()->RegisterMessageCallback(
730 base::Bind(&BrowserOptionsHandler::ThemesSetNative
,
731 base::Unretained(this)));
733 web_ui()->RegisterMessageCallback(
734 "selectDownloadLocation",
735 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation
,
736 base::Unretained(this)));
737 web_ui()->RegisterMessageCallback(
738 "autoOpenFileTypesAction",
739 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton
,
740 base::Unretained(this)));
741 web_ui()->RegisterMessageCallback(
742 "defaultFontSizeAction",
743 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize
,
744 base::Unretained(this)));
745 web_ui()->RegisterMessageCallback(
746 "defaultZoomFactorAction",
747 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor
,
748 base::Unretained(this)));
749 #if defined(OS_WIN) || defined(OS_MACOSX)
750 web_ui()->RegisterMessageCallback(
751 "showManageSSLCertificates",
752 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates
,
753 base::Unretained(this)));
755 #if defined(OS_CHROMEOS)
756 web_ui()->RegisterMessageCallback(
757 "openWallpaperManager",
758 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager
,
759 base::Unretained(this)));
760 web_ui()->RegisterMessageCallback(
761 "virtualKeyboardChange",
762 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback
,
763 base::Unretained(this)));
764 web_ui()->RegisterMessageCallback(
765 "onPowerwashDialogShow",
766 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow
,
767 base::Unretained(this)));
768 web_ui()->RegisterMessageCallback(
769 "performFactoryResetRestart",
770 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart
,
771 base::Unretained(this)));
773 web_ui()->RegisterMessageCallback(
775 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser
,
776 base::Unretained(this)));
777 web_ui()->RegisterMessageCallback(
778 "showNetworkProxySettings",
779 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings
,
780 base::Unretained(this)));
781 #endif // defined(OS_CHROMEOS)
783 #if defined(ENABLE_SERVICE_DISCOVERY)
784 if (cloud_print_mdns_ui_enabled_
) {
785 web_ui()->RegisterMessageCallback(
786 "showCloudPrintDevicesPage",
787 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage
,
788 base::Unretained(this)));
791 web_ui()->RegisterMessageCallback(
792 "requestGoogleNowAvailable",
793 base::Bind(&BrowserOptionsHandler::HandleRequestGoogleNowAvailable
,
794 base::Unretained(this)));
796 web_ui()->RegisterMessageCallback(
797 "requestHotwordAvailable",
798 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable
,
799 base::Unretained(this)));
801 web_ui()->RegisterMessageCallback(
802 "launchHotwordAudioVerificationApp",
804 &BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp
,
805 base::Unretained(this)));
807 web_ui()->RegisterMessageCallback(
808 "launchEasyUnlockSetup",
809 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup
,
810 base::Unretained(this)));
812 web_ui()->RegisterMessageCallback(
813 "refreshExtensionControlIndicators",
815 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators
,
816 base::Unretained(this)));
817 #endif // defined(OS_WIN)
818 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
819 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange
,
820 base::Unretained(this)));
823 void BrowserOptionsHandler::Uninitialize() {
824 registrar_
.RemoveAll();
825 g_browser_process
->profile_manager()->
826 GetProfileInfoCache().RemoveObserver(this);
828 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
830 #if defined(OS_CHROMEOS)
831 policy::ConsumerManagementService
* consumer_management
=
832 g_browser_process
->platform_part()->browser_policy_connector_chromeos()->
833 GetConsumerManagementService();
834 if (consumer_management
)
835 consumer_management
->RemoveObserver(this);
839 void BrowserOptionsHandler::OnStateChanged() {
843 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string
& account_id
,
844 const std::string
& username
,
845 const std::string
& password
) {
849 void BrowserOptionsHandler::GoogleSignedOut(const std::string
& account_id
,
850 const std::string
& username
) {
854 void BrowserOptionsHandler::PageLoadStarted() {
855 page_initialized_
= false;
858 void BrowserOptionsHandler::InitializeHandler() {
859 Profile
* profile
= Profile::FromWebUI(web_ui());
860 PrefService
* prefs
= profile
->GetPrefs();
861 ChromeZoomLevelPrefs
* zoom_level_prefs
= profile
->GetZoomLevelPrefs();
862 // Only regular profiles are able to edit default zoom level, or delete per-
863 // host zoom levels, via the settings menu. We only require a zoom_level_prefs
864 // if the profile is able to change these preference types.
865 DCHECK(zoom_level_prefs
||
866 profile
->GetProfileType() != Profile::REGULAR_PROFILE
);
867 if (zoom_level_prefs
) {
868 default_zoom_level_subscription_
=
869 zoom_level_prefs
->RegisterDefaultZoomLevelCallback(
870 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector
,
871 base::Unretained(this)));
874 g_browser_process
->policy_service()->AddObserver(
875 policy::POLICY_DOMAIN_CHROME
, this);
877 g_browser_process
->profile_manager()->GetProfileInfoCache().AddObserver(this);
879 ProfileSyncService
* sync_service(
880 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
));
881 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
882 // destruction is automatic.
884 sync_service
->AddObserver(this);
886 SigninManagerBase
* signin_manager(
887 SigninManagerFactory::GetInstance()->GetForProfile(profile
));
889 signin_observer_
.Add(signin_manager
);
891 // Create our favicon data source.
892 content::URLDataSource::Add(
893 profile
, new FaviconSource(profile
, FaviconSource::FAVICON
));
895 default_browser_policy_
.Init(
896 prefs::kDefaultBrowserSettingEnabled
,
897 g_browser_process
->local_state(),
898 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState
,
899 base::Unretained(this)));
901 #if defined(OS_CHROMEOS)
902 registrar_
.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
903 content::NotificationService::AllSources());
905 registrar_
.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED
,
906 content::Source
<ThemeService
>(
907 ThemeServiceFactory::GetForProfile(profile
)));
908 registrar_
.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
,
909 content::Source
<Profile
>(profile
));
910 AddTemplateUrlServiceObserver();
913 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
915 const base::CommandLine
& command_line
=
916 *base::CommandLine::ForCurrentProcess();
917 if (!command_line
.HasSwitch(switches::kUserDataDir
)) {
918 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
919 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch
,
920 weak_ptr_factory_
.GetWeakPtr(),
921 profile
->GetPath()));
925 // No preferences below this point may be modified by guest profiles.
926 if (Profile::FromWebUI(web_ui())->IsGuestSession())
929 auto_open_files_
.Init(
930 prefs::kDownloadExtensionsToOpen
, prefs
,
931 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes
,
932 base::Unretained(this)));
933 profile_pref_registrar_
.Init(prefs
);
934 profile_pref_registrar_
.Add(
935 prefs::kNetworkPredictionOptions
,
936 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl
,
937 base::Unretained(this)));
938 profile_pref_registrar_
.Add(
939 prefs::kWebKitDefaultFontSize
,
940 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
941 base::Unretained(this)));
942 profile_pref_registrar_
.Add(
943 prefs::kWebKitDefaultFixedFontSize
,
944 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
945 base::Unretained(this)));
946 profile_pref_registrar_
.Add(
947 prefs::kSupervisedUsers
,
948 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers
,
949 base::Unretained(this)));
950 profile_pref_registrar_
.Add(
951 prefs::kSigninAllowed
,
952 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange
,
953 base::Unretained(this)));
954 profile_pref_registrar_
.Add(
955 prefs::kEasyUnlockPairing
,
956 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock
,
957 base::Unretained(this)));
960 profile_pref_registrar_
.Add(
961 prefs::kURLsToRestoreOnStartup
,
962 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
963 base::Unretained(this)));
964 profile_pref_registrar_
.Add(
966 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
967 base::Unretained(this)));
968 #endif // defined(OS_WIN)
970 #if defined(OS_CHROMEOS)
971 if (!policy_registrar_
) {
972 policy_registrar_
.reset(new policy::PolicyChangeRegistrar(
973 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile
)
975 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
, std::string())));
976 policy_registrar_
->Observe(
977 policy::key::kUserAvatarImage
,
978 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged
,
979 base::Unretained(this)));
980 policy_registrar_
->Observe(
981 policy::key::kWallpaperImage
,
982 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged
,
983 base::Unretained(this)));
985 chromeos::CrosSettings::Get()->AddSettingsObserver(
986 chromeos::kSystemTimezonePolicy
,
987 base::Bind(&BrowserOptionsHandler::OnSystemTimezonePolicyChanged
,
988 weak_ptr_factory_
.GetWeakPtr()));
989 #else // !defined(OS_CHROMEOS)
990 profile_pref_registrar_
.Add(
991 proxy_config::prefs::kProxy
,
992 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection
,
993 base::Unretained(this)));
994 #endif // !defined(OS_CHROMEOS)
997 void BrowserOptionsHandler::InitializePage() {
998 page_initialized_
= true;
1000 OnTemplateURLServiceChanged();
1002 ObserveThemeChanged();
1004 UpdateDefaultBrowserState();
1006 SetupMetricsReportingSettingVisibility();
1007 SetupMetricsReportingCheckbox();
1008 SetupNetworkPredictionControl();
1009 SetupFontSizeSelector();
1010 SetupPageZoomSelector();
1011 SetupAutoOpenFileTypes();
1012 SetupProxySettingsSection();
1013 SetupManageCertificatesSection();
1014 SetupManagingSupervisedUsers();
1016 SetupExtensionControlledIndicators();
1018 #if defined(OS_CHROMEOS)
1019 SetupAccessibilityFeatures();
1020 policy::BrowserPolicyConnectorChromeOS
* connector
=
1021 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1022 if (!connector
->IsEnterpriseManaged() &&
1023 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
1024 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
1025 web_ui()->CallJavascriptFunction(
1026 "BrowserOptions.enableFactoryResetSection");
1029 Profile
* profile
= Profile::FromWebUI(web_ui());
1030 OnAccountPictureManagedChanged(
1031 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile
)
1033 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
,
1035 .Get(policy::key::kUserAvatarImage
));
1037 OnWallpaperManagedChanged(
1038 chromeos::WallpaperManager::Get()->IsPolicyControlled(
1039 user_manager::UserManager::Get()->GetActiveUser()->email()));
1041 policy::ConsumerManagementService
* consumer_management
=
1042 g_browser_process
->platform_part()->browser_policy_connector_chromeos()->
1043 GetConsumerManagementService();
1044 if (consumer_management
) {
1045 OnConsumerManagementStatusChanged();
1046 consumer_management
->AddObserver(this);
1052 void BrowserOptionsHandler::CheckAutoLaunch(
1053 base::WeakPtr
<BrowserOptionsHandler
> weak_this
,
1054 const base::FilePath
& profile_path
) {
1056 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
1058 // Auto-launch is not supported for secondary profiles yet.
1059 if (profile_path
.BaseName().value() !=
1060 base::ASCIIToUTF16(chrome::kInitialProfile
)) {
1064 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
1066 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
1067 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback
,
1069 auto_launch_trial::IsInAutoLaunchGroup(),
1070 auto_launch_util::AutoStartRequested(
1071 profile_path
.BaseName().value(),
1072 true, // Window requested.
1073 base::FilePath())));
1077 void BrowserOptionsHandler::CheckAutoLaunchCallback(
1078 bool is_in_auto_launch_group
,
1079 bool will_launch_at_login
) {
1081 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1083 if (is_in_auto_launch_group
) {
1084 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
1085 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch
,
1086 base::Unretained(this)));
1088 base::FundamentalValue
enabled(will_launch_at_login
);
1089 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1095 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1096 #if defined(OS_CHROMEOS)
1097 // We're always the default browser on ChromeOS.
1100 Profile
* profile
= Profile::FromWebUI(web_ui());
1101 return !profile
->IsGuestSession();
1105 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1106 #if defined(OS_CHROMEOS)
1107 // On Chrome OS we use different UI for multi-profiles.
1110 Profile
* profile
= Profile::FromWebUI(web_ui());
1111 if (profile
->IsGuestSession())
1113 return profiles::IsMultipleProfilesEnabled();
1117 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1118 #if defined(OS_CHROMEOS)
1119 // ChromeOS handles guest-mode restrictions in a different manner.
1122 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1126 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1127 default_browser_worker_
->StartCheckIsDefault();
1130 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue
* args
) {
1131 // If the default browser setting is managed then we should not be able to
1132 // call this function.
1133 if (default_browser_policy_
.IsManaged())
1136 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1137 default_browser_worker_
->StartSetAsDefault();
1138 // Callback takes care of updating UI.
1140 // If the user attempted to make Chrome the default browser, notify
1141 // them when this changes.
1142 PrefService
* prefs
= Profile::FromWebUI(web_ui())->GetPrefs();
1143 prefs
->SetBoolean(prefs::kCheckDefaultBrowser
, true);
1146 int BrowserOptionsHandler::StatusStringIdForState(
1147 ShellIntegration::DefaultWebClientState state
) {
1148 if (state
== ShellIntegration::IS_DEFAULT
)
1149 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1150 if (state
== ShellIntegration::NOT_DEFAULT
)
1151 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1152 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1155 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1156 ShellIntegration::DefaultWebClientUIState state
) {
1157 int status_string_id
;
1159 if (state
== ShellIntegration::STATE_IS_DEFAULT
) {
1160 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1161 // Notify the user in the future if Chrome ceases to be the user's chosen
1163 PrefService
* prefs
= Profile::FromWebUI(web_ui())->GetPrefs();
1164 prefs
->SetBoolean(prefs::kCheckDefaultBrowser
, true);
1165 } else if (state
== ShellIntegration::STATE_NOT_DEFAULT
) {
1166 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1167 ShellIntegration::SET_DEFAULT_NOT_ALLOWED
) {
1168 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_SXS
;
1170 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1172 } else if (state
== ShellIntegration::STATE_UNKNOWN
) {
1173 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1175 return; // Still processing.
1178 SetDefaultBrowserUIString(status_string_id
);
1181 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1182 return true; // This is UI so we can allow it.
1185 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id
) {
1186 base::StringValue
status_string(
1187 l10n_util::GetStringFUTF16(status_string_id
,
1188 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)));
1190 base::FundamentalValue
is_default(
1191 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
);
1193 base::FundamentalValue
can_be_default(
1194 !default_browser_policy_
.IsManaged() &&
1195 (status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
||
1196 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
));
1198 web_ui()->CallJavascriptFunction(
1199 "BrowserOptions.updateDefaultBrowserState",
1200 status_string
, is_default
, can_be_default
);
1203 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1204 if (!template_url_service_
|| !template_url_service_
->loaded())
1207 const TemplateURL
* default_url
=
1208 template_url_service_
->GetDefaultSearchProvider();
1210 int default_index
= -1;
1211 base::ListValue search_engines
;
1212 TemplateURLService::TemplateURLVector
model_urls(
1213 template_url_service_
->GetTemplateURLs());
1214 for (size_t i
= 0; i
< model_urls
.size(); ++i
) {
1215 if (!model_urls
[i
]->ShowInDefaultList(
1216 template_url_service_
->search_terms_data()))
1219 base::DictionaryValue
* entry
= new base::DictionaryValue();
1220 entry
->SetString("name", model_urls
[i
]->short_name());
1221 entry
->SetInteger("index", i
);
1222 search_engines
.Append(entry
);
1223 if (model_urls
[i
] == default_url
)
1227 web_ui()->CallJavascriptFunction(
1228 "BrowserOptions.updateSearchEngines",
1230 base::FundamentalValue(default_index
),
1231 base::FundamentalValue(
1232 template_url_service_
->is_default_search_managed() ||
1233 template_url_service_
->IsExtensionControlledDefaultSearch()));
1235 SetupExtensionControlledIndicators();
1237 HandleRequestHotwordAvailable(nullptr);
1238 HandleRequestGoogleNowAvailable(nullptr);
1241 void BrowserOptionsHandler::SetDefaultSearchEngine(
1242 const base::ListValue
* args
) {
1243 int selected_index
= -1;
1244 if (!ExtractIntegerValue(args
, &selected_index
)) {
1249 TemplateURLService::TemplateURLVector
model_urls(
1250 template_url_service_
->GetTemplateURLs());
1251 if (selected_index
>= 0 &&
1252 selected_index
< static_cast<int>(model_urls
.size()))
1253 template_url_service_
->SetUserSelectedDefaultSearchProvider(
1254 model_urls
[selected_index
]);
1256 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1259 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1260 template_url_service_
=
1261 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1262 if (template_url_service_
) {
1263 template_url_service_
->Load();
1264 template_url_service_
->AddObserver(this);
1268 void BrowserOptionsHandler::OnExtensionLoaded(
1269 content::BrowserContext
* browser_context
,
1270 const Extension
* extension
) {
1271 SetupExtensionControlledIndicators();
1274 void BrowserOptionsHandler::OnExtensionUnloaded(
1275 content::BrowserContext
* browser_context
,
1276 const Extension
* extension
,
1277 extensions::UnloadedExtensionInfo::Reason reason
) {
1278 SetupExtensionControlledIndicators();
1281 void BrowserOptionsHandler::Observe(
1283 const content::NotificationSource
& source
,
1284 const content::NotificationDetails
& details
) {
1285 // Notifications are used to update the UI dynamically when settings change in
1286 // the background. If the UI is currently being loaded, no dynamic updates are
1287 // possible (as the DOM and JS are not fully loaded) or necessary (as
1288 // InitializePage() will update the UI at the end of the load).
1289 if (!page_initialized_
)
1293 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED
:
1294 ObserveThemeChanged();
1296 #if defined(OS_CHROMEOS)
1297 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
:
1298 UpdateAccountPicture();
1301 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
:
1302 // Update our sync/signin status display.
1310 void BrowserOptionsHandler::OnProfileAdded(const base::FilePath
& profile_path
) {
1314 void BrowserOptionsHandler::OnProfileWasRemoved(
1315 const base::FilePath
& profile_path
,
1316 const base::string16
& profile_name
) {
1320 void BrowserOptionsHandler::OnProfileNameChanged(
1321 const base::FilePath
& profile_path
,
1322 const base::string16
& old_profile_name
) {
1326 void BrowserOptionsHandler::OnProfileAvatarChanged(
1327 const base::FilePath
& profile_path
) {
1331 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue
* args
) {
1333 if (!auto_launch_trial::IsInAutoLaunchGroup())
1337 CHECK_EQ(args
->GetSize(), 1U);
1338 CHECK(args
->GetBoolean(0, &enable
));
1340 Profile
* profile
= Profile::FromWebUI(web_ui());
1341 content::BrowserThread::PostTask(
1342 content::BrowserThread::FILE, FROM_HERE
,
1344 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin
,
1345 profile
->GetPath().BaseName().value(), base::FilePath()) :
1346 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin
,
1347 profile
->GetPath().BaseName().value()));
1351 scoped_ptr
<base::ListValue
> BrowserOptionsHandler::GetProfilesInfoList() {
1352 ProfileInfoCache
& cache
=
1353 g_browser_process
->profile_manager()->GetProfileInfoCache();
1354 scoped_ptr
<base::ListValue
> profile_info_list(new base::ListValue
);
1355 base::FilePath current_profile_path
=
1356 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1358 for (size_t i
= 0, e
= cache
.GetNumberOfProfiles(); i
< e
; ++i
) {
1359 // The items in |profile_value| are also described in
1360 // chrome/browser/resources/options/browser_options.js in a @typedef for
1361 // Profile. Please update it whenever you add or remove any keys here.
1363 base::DictionaryValue
* profile_value
= new base::DictionaryValue();
1364 profile_value
->SetString("name", cache
.GetNameOfProfileAtIndex(i
));
1365 base::FilePath profile_path
= cache
.GetPathOfProfileAtIndex(i
);
1366 profile_value
->Set("filePath", base::CreateFilePathValue(profile_path
));
1367 profile_value
->SetBoolean("isCurrentProfile",
1368 profile_path
== current_profile_path
);
1369 profile_value
->SetBoolean("isSupervised",
1370 cache
.ProfileIsSupervisedAtIndex(i
));
1371 profile_value
->SetBoolean("isChild", cache
.ProfileIsChildAtIndex(i
));
1373 bool is_gaia_picture
=
1374 cache
.IsUsingGAIAPictureOfProfileAtIndex(i
) &&
1375 cache
.GetGAIAPictureOfProfileAtIndex(i
);
1376 if (is_gaia_picture
) {
1377 gfx::Image icon
= profiles::GetAvatarIconForWebUI(
1378 cache
.GetAvatarIconOfProfileAtIndex(i
), true);
1379 profile_value
->SetString("iconURL",
1380 webui::GetBitmapDataUrl(icon
.AsBitmap()));
1382 size_t icon_index
= cache
.GetAvatarIconIndexOfProfileAtIndex(i
);
1383 profile_value
->SetString("iconURL",
1384 profiles::GetDefaultAvatarIconUrl(icon_index
));
1387 profile_info_list
->Append(profile_value
);
1390 return profile_info_list
.Pass();
1393 void BrowserOptionsHandler::SendProfilesInfo() {
1394 if (!ShouldShowMultiProfilesUserList())
1396 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1397 *GetProfilesInfoList());
1400 void BrowserOptionsHandler::DeleteProfile(const base::ListValue
* args
) {
1402 const base::Value
* file_path_value
;
1403 if (!args
->Get(0, &file_path_value
)) {
1408 base::FilePath file_path
;
1409 if (!base::GetValueAsFilePath(*file_path_value
, &file_path
)) {
1414 helper::DeleteProfileAtPath(file_path
, web_ui());
1417 void BrowserOptionsHandler::ObserveThemeChanged() {
1418 Profile
* profile
= Profile::FromWebUI(web_ui());
1419 ThemeService
* theme_service
= ThemeServiceFactory::GetForProfile(profile
);
1420 bool is_system_theme
= false;
1422 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1423 bool profile_is_supervised
= profile
->IsSupervised();
1424 is_system_theme
= theme_service
->UsingSystemTheme();
1425 base::FundamentalValue
native_theme_enabled(!is_system_theme
&&
1426 !profile_is_supervised
);
1427 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1428 native_theme_enabled
);
1431 bool is_classic_theme
= !is_system_theme
&&
1432 theme_service
->UsingDefaultTheme();
1433 base::FundamentalValue
enabled(!is_classic_theme
);
1434 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1438 void BrowserOptionsHandler::ThemesReset(const base::ListValue
* args
) {
1439 Profile
* profile
= Profile::FromWebUI(web_ui());
1440 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1441 ThemeServiceFactory::GetForProfile(profile
)->UseDefaultTheme();
1444 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1445 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue
* args
) {
1446 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1447 Profile
* profile
= Profile::FromWebUI(web_ui());
1448 ThemeServiceFactory::GetForProfile(profile
)->UseSystemTheme();
1452 #if defined(OS_CHROMEOS)
1453 void BrowserOptionsHandler::UpdateAccountPicture() {
1455 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1456 if (!email
.empty()) {
1457 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1458 base::StringValue
email_value(email
);
1459 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1464 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed
) {
1465 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1466 base::FundamentalValue(managed
));
1469 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed
) {
1470 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1471 base::FundamentalValue(managed
));
1474 void BrowserOptionsHandler::OnSystemTimezonePolicyChanged() {
1475 web_ui()->CallJavascriptFunction(
1476 "BrowserOptions.setSystemTimezoneManaged",
1477 base::FundamentalValue(chromeos::system::HasSystemTimezonePolicy()));
1481 scoped_ptr
<base::DictionaryValue
>
1482 BrowserOptionsHandler::GetSyncStateDictionary() {
1483 // The items which are to be written into |sync_status| are also described in
1484 // chrome/browser/resources/options/browser_options.js in @typedef
1485 // for SyncStatus. Please update it whenever you add or remove any keys here.
1486 scoped_ptr
<base::DictionaryValue
> sync_status(new base::DictionaryValue
);
1487 Profile
* profile
= Profile::FromWebUI(web_ui());
1488 if (profile
->IsGuestSession()) {
1489 // Cannot display signin status when running in guest mode on chromeos
1490 // because there is no SigninManager.
1491 sync_status
->SetBoolean("signinAllowed", false);
1492 return sync_status
.Pass();
1495 sync_status
->SetBoolean("supervisedUser", profile
->IsSupervised());
1496 sync_status
->SetBoolean("childUser", profile
->IsChild());
1498 bool signout_prohibited
= false;
1499 #if !defined(OS_CHROMEOS)
1500 // Signout is not allowed if the user has policy (crbug.com/172204).
1501 signout_prohibited
=
1502 SigninManagerFactory::GetForProfile(profile
)->IsSignoutProhibited();
1505 ProfileSyncService
* service
=
1506 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
1507 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1509 sync_status
->SetBoolean("signoutAllowed", !signout_prohibited
);
1510 sync_status
->SetBoolean("signinAllowed", signin
->IsSigninAllowed());
1511 sync_status
->SetBoolean("syncSystemEnabled", (service
!= NULL
));
1512 sync_status
->SetBoolean("setupCompleted",
1513 service
&& service
->HasSyncSetupCompleted());
1514 sync_status
->SetBoolean("setupInProgress",
1515 service
&& !service
->IsManaged() && service
->FirstSetupInProgress());
1517 base::string16 status_label
;
1518 base::string16 link_label
;
1519 bool status_has_error
= sync_ui_util::GetStatusLabels(
1520 service
, *signin
, sync_ui_util::WITH_HTML
, &status_label
, &link_label
) ==
1521 sync_ui_util::SYNC_ERROR
;
1522 sync_status
->SetString("statusText", status_label
);
1523 sync_status
->SetString("actionLinkText", link_label
);
1524 sync_status
->SetBoolean("hasError", status_has_error
);
1526 sync_status
->SetBoolean("managed", service
&& service
->IsManaged());
1527 sync_status
->SetBoolean("signedIn", signin
->IsAuthenticated());
1528 sync_status
->SetBoolean("hasUnrecoverableError",
1529 service
&& service
->HasUnrecoverableError());
1531 return sync_status
.Pass();
1534 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1535 const base::ListValue
* args
) {
1536 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1537 select_folder_dialog_
= ui::SelectFileDialog::Create(
1538 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1539 ui::SelectFileDialog::FileTypeInfo info
;
1540 info
.support_drive
= true;
1541 select_folder_dialog_
->SelectFile(
1542 ui::SelectFileDialog::SELECT_FOLDER
,
1543 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
),
1544 pref_service
->GetFilePath(prefs::kDownloadDefaultDirectory
),
1547 base::FilePath::StringType(),
1548 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1552 void BrowserOptionsHandler::FileSelected(const base::FilePath
& path
, int index
,
1554 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1555 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1556 pref_service
->SetFilePath(prefs::kDownloadDefaultDirectory
, path
);
1557 pref_service
->SetFilePath(prefs::kSaveFileDefaultDirectory
, path
);
1560 #if defined(OS_CHROMEOS)
1561 void BrowserOptionsHandler::TouchpadExists(bool exists
) {
1562 base::FundamentalValue
val(exists
);
1563 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val
);
1566 void BrowserOptionsHandler::MouseExists(bool exists
) {
1567 base::FundamentalValue
val(exists
);
1568 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val
);
1571 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1572 const base::Value
* previous_policy
,
1573 const base::Value
* current_policy
) {
1574 const bool had_policy
= previous_policy
;
1575 const bool has_policy
= current_policy
;
1576 if (had_policy
!= has_policy
)
1577 OnAccountPictureManagedChanged(has_policy
);
1580 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1581 const base::Value
* previous_policy
,
1582 const base::Value
* current_policy
) {
1583 const bool had_policy
= previous_policy
;
1584 const bool has_policy
= current_policy
;
1585 if (had_policy
!= has_policy
)
1586 OnWallpaperManagedChanged(has_policy
);
1589 void BrowserOptionsHandler::OnPowerwashDialogShow(
1590 const base::ListValue
* args
) {
1591 UMA_HISTOGRAM_ENUMERATION(
1592 "Reset.ChromeOS.PowerwashDialogShown",
1593 chromeos::reset::DIALOG_FROM_OPTIONS
,
1594 chromeos::reset::DIALOG_VIEW_TYPE_SIZE
);
1597 void BrowserOptionsHandler::OnConsumerManagementStatusChanged() {
1598 const std::string
& status
= g_browser_process
->platform_part()->
1599 browser_policy_connector_chromeos()->GetConsumerManagementService()->
1601 web_ui()->CallJavascriptFunction(
1602 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status
));
1605 #endif // defined(OS_CHROMEOS)
1607 void BrowserOptionsHandler::UpdateSyncState() {
1608 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1609 *GetSyncStateDictionary());
1611 // A change in sign-in state also affects how hotwording and audio history are
1612 // displayed. Hide all hotwording and re-display properly.
1613 web_ui()->CallJavascriptFunction(
1614 "BrowserOptions.setAllHotwordSectionsVisible",
1615 base::FundamentalValue(false));
1616 HandleRequestHotwordAvailable(nullptr);
1619 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1623 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue
* args
) {
1624 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1625 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1626 web_ui()->GetWebContents()->GetBrowserContext());
1628 DownloadPrefs::FromDownloadManager(manager
)->ResetAutoOpen();
1631 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue
* args
) {
1633 if (ExtractIntegerValue(args
, &font_size
)) {
1634 if (font_size
> 0) {
1635 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1636 pref_service
->SetInteger(prefs::kWebKitDefaultFontSize
, font_size
);
1637 SetupFontSizeSelector();
1642 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1643 const base::ListValue
* args
) {
1645 if (ExtractDoubleValue(args
, &zoom_factor
)) {
1646 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
1647 content::ZoomFactorToZoomLevel(zoom_factor
));
1651 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue
* args
) {
1652 #if defined(OS_WIN) && defined(USE_ASH)
1653 // If hardware acceleration is disabled then we need to force restart
1654 // browser in desktop mode.
1655 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1656 // Currently there are issues with determining correct browser mode
1658 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
) {
1659 PrefService
* pref_service
= g_browser_process
->local_state();
1660 if (!pref_service
->GetBoolean(prefs::kHardwareAccelerationModeEnabled
)) {
1661 chrome::AttemptRestartToDesktopMode();
1668 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1669 // environment variable is defined. So we undefine this environment variable
1670 // before restarting, as the restarted processes will inherit their
1671 // environment variables from ours, thus suppressing crash uploads.
1672 PrefService
* pref_service
= g_browser_process
->local_state();
1673 if (!pref_service
->GetBoolean(prefs::kMetricsReportingEnabled
)) {
1674 HMODULE exe_module
= GetModuleHandle(chrome::kBrowserProcessExecutableName
);
1676 typedef void (__cdecl
*ClearBreakpadPipeEnvVar
)();
1677 ClearBreakpadPipeEnvVar clear
= reinterpret_cast<ClearBreakpadPipeEnvVar
>(
1678 GetProcAddress(exe_module
, "ClearBreakpadPipeEnvironmentVariable"));
1685 chrome::AttemptRestart();
1688 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1689 const base::ListValue
* args
) {
1693 #if !defined(OS_CHROMEOS)
1694 void BrowserOptionsHandler::ShowNetworkProxySettings(
1695 const base::ListValue
* args
) {
1696 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1697 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1698 web_ui()->GetWebContents());
1702 #if defined(OS_WIN) || defined(OS_MACOSX)
1703 void BrowserOptionsHandler::ShowManageSSLCertificates(
1704 const base::ListValue
* args
) {
1705 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1706 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1707 web_ui()->GetWebContents());
1711 #if defined(ENABLE_SERVICE_DISCOVERY)
1713 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1714 const base::ListValue
* args
) {
1715 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1716 // Navigate in current tab to devices page.
1717 OpenURLParams
params(
1718 GURL(chrome::kChromeUIDevicesURL
), Referrer(),
1719 CURRENT_TAB
, ui::PAGE_TRANSITION_LINK
, false);
1720 web_ui()->GetWebContents()->OpenURL(params
);
1725 void BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible(
1726 const base::string16
& audio_history_state
,
1727 bool success
, bool logging_enabled
) {
1728 bool visible
= logging_enabled
&& success
;
1729 web_ui()->CallJavascriptFunction(
1730 "BrowserOptions.setAudioHistorySectionVisible",
1731 base::FundamentalValue(visible
),
1732 base::StringValue(audio_history_state
));
1735 void BrowserOptionsHandler::HandleRequestGoogleNowAvailable(
1736 const base::ListValue
* args
) {
1737 bool is_search_provider_google
= false;
1738 if (template_url_service_
&& template_url_service_
->loaded()) {
1739 const TemplateURL
* default_url
=
1740 template_url_service_
->GetDefaultSearchProvider();
1741 if (default_url
&& default_url
->HasGoogleBaseURLs(
1742 template_url_service_
->search_terms_data())) {
1743 is_search_provider_google
= true;
1747 std::string group
= base::FieldTrialList::FindFullName("GoogleNowExtension");
1748 bool has_field_trial
= !group
.empty() && group
!= "Disabled";
1750 bool should_show
= is_search_provider_google
&& has_field_trial
;
1751 web_ui()->CallJavascriptFunction(
1752 "BrowserOptions.setNowSectionVisible",
1753 base::FundamentalValue(should_show
));
1756 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1757 const base::ListValue
* args
) {
1758 Profile
* profile
= Profile::FromWebUI(web_ui());
1760 bool is_search_provider_google
= false;
1761 // The check for default search provider is only valid if the
1762 // |template_url_service_| has loaded already.
1763 if (template_url_service_
&& template_url_service_
->loaded()) {
1764 const TemplateURL
* default_url
=
1765 template_url_service_
->GetDefaultSearchProvider();
1766 if (default_url
&& default_url
->HasGoogleBaseURLs(
1767 template_url_service_
->search_terms_data())) {
1768 is_search_provider_google
= true;
1770 // If the user has chosen a default search provide other than Google, turn
1771 // off hotwording since other providers don't provide that functionality.
1772 HotwordService
* hotword_service
=
1773 HotwordServiceFactory::GetForProfile(profile
);
1774 if (hotword_service
)
1775 hotword_service
->DisableHotwordPreferences();
1779 // |is_search_provider_google| may be false because |template_url_service_|
1780 // does not exist yet or because the user selected a different search
1781 // provider. In either case it does not make sense to show the hotwording
1783 if (!is_search_provider_google
) {
1784 web_ui()->CallJavascriptFunction(
1785 "BrowserOptions.setAllHotwordSectionsVisible",
1786 base::FundamentalValue(false));
1790 // Don't need to check the field trial here since |IsHotwordAllowed| also
1792 if (HotwordServiceFactory::IsHotwordAllowed(profile
)) {
1793 // Update the current error value.
1794 HotwordServiceFactory::IsServiceAvailable(profile
);
1795 int error
= HotwordServiceFactory::GetCurrentError(profile
);
1797 std::string function_name
;
1798 bool always_on
= false;
1799 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1800 bool authenticated
= signin
&& signin
->IsAuthenticated();
1801 if (HotwordServiceFactory::IsAlwaysOnAvailable() && authenticated
) {
1802 function_name
= "BrowserOptions.showHotwordAlwaysOnSection";
1804 // Show the retrain link if always-on is enabled.
1805 if (profile
->GetPrefs()->GetBoolean(
1806 prefs::kHotwordAlwaysOnSearchEnabled
)) {
1807 web_ui()->CallJavascriptFunction(
1808 "BrowserOptions.setHotwordRetrainLinkVisible",
1809 base::FundamentalValue(true));
1812 function_name
= "BrowserOptions.showHotwordNoDspSection";
1815 // Audio history should be displayed if it's enabled regardless of the
1816 // hotword error state if the user is signed in. If the user is not signed
1817 // in, audio history is meaningless. This is only displayed if always-on
1818 // hotwording is available.
1819 if (authenticated
&& always_on
) {
1820 std::string user_display_name
=
1821 signin
->GetAuthenticatedAccountInfo().email
;
1822 DCHECK(!user_display_name
.empty());
1823 base::string16 audio_history_state
=
1824 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED
,
1825 base::ASCIIToUTF16(user_display_name
));
1826 HotwordService
* hotword_service
=
1827 HotwordServiceFactory::GetForProfile(profile
);
1828 if (hotword_service
) {
1829 hotword_service
->GetAudioHistoryHandler()->GetAudioHistoryEnabled(
1831 &BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible
,
1832 weak_ptr_factory_
.GetWeakPtr(),
1833 audio_history_state
));
1838 web_ui()->CallJavascriptFunction(function_name
);
1840 base::string16 hotword_help_url
=
1841 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL
);
1842 base::StringValue
error_message(l10n_util::GetStringUTF16(error
));
1843 if (error
== IDS_HOTWORD_GENERIC_ERROR_MESSAGE
) {
1844 error_message
= base::StringValue(
1845 l10n_util::GetStringFUTF16(error
, hotword_help_url
));
1847 web_ui()->CallJavascriptFunction(function_name
, error_message
);
1852 void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
1853 const base::ListValue
* args
) {
1854 Profile
* profile
= Profile::FromWebUI(web_ui());
1856 bool retrain
= false;
1857 bool success
= args
->GetBoolean(0, &retrain
);
1859 HotwordService::LaunchMode launch_mode
=
1860 HotwordService::HOTWORD_AND_AUDIO_HISTORY
;
1863 DCHECK(profile
->GetPrefs()->GetBoolean(
1864 prefs::kHotwordAlwaysOnSearchEnabled
));
1865 DCHECK(profile
->GetPrefs()->GetBoolean(
1866 prefs::kHotwordAudioLoggingEnabled
));
1868 launch_mode
= HotwordService::RETRAIN
;
1869 } else if (profile
->GetPrefs()->GetBoolean(
1870 prefs::kHotwordAudioLoggingEnabled
)) {
1871 DCHECK(!profile
->GetPrefs()->GetBoolean(
1872 prefs::kHotwordAlwaysOnSearchEnabled
));
1873 launch_mode
= HotwordService::HOTWORD_ONLY
;
1875 DCHECK(!profile
->GetPrefs()->GetBoolean(
1876 prefs::kHotwordAlwaysOnSearchEnabled
));
1879 HotwordService
* hotword_service
=
1880 HotwordServiceFactory::GetForProfile(profile
);
1881 if (!hotword_service
)
1884 hotword_service
->OptIntoHotwording(launch_mode
);
1887 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1888 const base::ListValue
* args
) {
1889 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1892 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1893 const base::ListValue
* args
) {
1894 SetupExtensionControlledIndicators();
1897 #if defined(OS_CHROMEOS)
1898 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1899 const base::ListValue
* args
) {
1900 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1903 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1904 const base::ListValue
* args
) {
1905 bool enabled
= false;
1906 args
->GetBoolean(0, &enabled
);
1908 chromeos::accessibility::EnableVirtualKeyboard(enabled
);
1911 void BrowserOptionsHandler::PerformFactoryResetRestart(
1912 const base::ListValue
* args
) {
1913 policy::BrowserPolicyConnectorChromeOS
* connector
=
1914 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1915 if (connector
->IsEnterpriseManaged())
1918 PrefService
* prefs
= g_browser_process
->local_state();
1919 prefs
->SetBoolean(prefs::kFactoryResetRequested
, true);
1920 prefs
->CommitPendingWrite();
1922 // Perform sign out. Current chrome process will then terminate, new one will
1923 // be launched (as if it was a restart).
1924 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1927 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1928 PrefService
* pref_service
= g_browser_process
->local_state();
1929 base::FundamentalValue
virtual_keyboard_enabled(
1930 pref_service
->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled
));
1931 web_ui()->CallJavascriptFunction(
1932 "BrowserOptions.setVirtualKeyboardCheckboxState",
1933 virtual_keyboard_enabled
);
1937 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1938 #if defined(GOOGLE_CHROME_BUILD)
1939 // Don't show the reporting setting if we are in the guest mode.
1940 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1941 base::FundamentalValue
visible(false);
1942 web_ui()->CallJavascriptFunction(
1943 "BrowserOptions.setMetricsReportingSettingVisibility", visible
);
1948 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1949 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1951 base::DictionaryValue dict
;
1952 dict
.SetInteger("value",
1953 pref_service
->GetInteger(prefs::kNetworkPredictionOptions
));
1954 dict
.SetBoolean("disabled",
1955 !pref_service
->IsUserModifiablePreference(
1956 prefs::kNetworkPredictionOptions
));
1958 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1962 void BrowserOptionsHandler::SetupFontSizeSelector() {
1963 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1964 const PrefService::Preference
* default_font_size
=
1965 pref_service
->FindPreference(prefs::kWebKitDefaultFontSize
);
1966 const PrefService::Preference
* default_fixed_font_size
=
1967 pref_service
->FindPreference(prefs::kWebKitDefaultFixedFontSize
);
1969 base::DictionaryValue dict
;
1970 dict
.SetInteger("value",
1971 pref_service
->GetInteger(prefs::kWebKitDefaultFontSize
));
1973 // The font size control displays the value of the default font size, but
1974 // setting it alters both the default font size and the default fixed font
1975 // size. So it must be disabled when either of those prefs is not user
1977 dict
.SetBoolean("disabled",
1978 !default_font_size
->IsUserModifiable() ||
1979 !default_fixed_font_size
->IsUserModifiable());
1981 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1982 // adapted to consider two prefs. It may be better to refactor
1983 // CreateValueForPref so it can be called from here.
1984 if (default_font_size
->IsManaged() || default_fixed_font_size
->IsManaged()) {
1985 dict
.SetString("controlledBy", "policy");
1986 } else if (default_font_size
->IsExtensionControlled() ||
1987 default_fixed_font_size
->IsExtensionControlled()) {
1988 dict
.SetString("controlledBy", "extension");
1991 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict
);
1994 void BrowserOptionsHandler::SetupPageZoomSelector() {
1995 double default_zoom_level
=
1996 content::HostZoomMap::GetDefaultForBrowserContext(
1997 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel();
1998 double default_zoom_factor
=
1999 content::ZoomLevelToZoomFactor(default_zoom_level
);
2001 // Generate a vector of zoom factors from an array of known presets along with
2002 // the default factor added if necessary.
2003 std::vector
<double> zoom_factors
=
2004 ui_zoom::PageZoom::PresetZoomFactors(default_zoom_factor
);
2006 // Iterate through the zoom factors and and build the contents of the
2007 // selector that will be sent to the javascript handler.
2008 // Each item in the list has the following parameters:
2009 // 1. Title (string).
2010 // 2. Value (double).
2011 // 3. Is selected? (bool).
2012 base::ListValue zoom_factors_value
;
2013 for (std::vector
<double>::const_iterator i
= zoom_factors
.begin();
2014 i
!= zoom_factors
.end(); ++i
) {
2015 base::ListValue
* option
= new base::ListValue();
2017 int percent
= static_cast<int>(factor
* 100 + 0.5);
2018 option
->Append(new base::StringValue(
2019 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT
, percent
)));
2020 option
->Append(new base::FundamentalValue(factor
));
2021 bool selected
= content::ZoomValuesEqual(factor
, default_zoom_factor
);
2022 option
->Append(new base::FundamentalValue(selected
));
2023 zoom_factors_value
.Append(option
);
2026 web_ui()->CallJavascriptFunction(
2027 "BrowserOptions.setupPageZoomSelector", zoom_factors_value
);
2030 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
2031 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
2032 // We show the button if the user has any auto-open file types registered.
2033 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
2034 web_ui()->GetWebContents()->GetBrowserContext());
2035 bool display
= manager
&&
2036 DownloadPrefs::FromDownloadManager(manager
)->IsAutoOpenUsed();
2037 base::FundamentalValue
value(display
);
2038 web_ui()->CallJavascriptFunction(
2039 "BrowserOptions.setAutoOpenFileTypesDisplayed", value
);
2042 void BrowserOptionsHandler::SetupProxySettingsSection() {
2043 #if !defined(OS_CHROMEOS)
2044 // Disable the button if proxy settings are managed by a sysadmin, overridden
2045 // by an extension, or the browser is running in Windows Ash (on Windows the
2046 // proxy settings dialog will open on the Windows desktop and be invisible
2047 // to a user in Ash).
2048 bool is_win_ash
= false;
2050 chrome::HostDesktopType desktop_type
= helper::GetDesktopType(web_ui());
2051 is_win_ash
= (desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
);
2053 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
2054 const PrefService::Preference
* proxy_config
=
2055 pref_service
->FindPreference(proxy_config::prefs::kProxy
);
2056 bool is_extension_controlled
= (proxy_config
&&
2057 proxy_config
->IsExtensionControlled());
2059 base::FundamentalValue
disabled(is_win_ash
|| (proxy_config
&&
2060 !proxy_config
->IsUserModifiable()));
2061 base::FundamentalValue
extension_controlled(is_extension_controlled
);
2062 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
2063 disabled
, extension_controlled
);
2066 SetupExtensionControlledIndicators();
2067 #endif // defined(OS_WIN)
2069 #endif // !defined(OS_CHROMEOS)
2072 void BrowserOptionsHandler::SetupManageCertificatesSection() {
2074 // Disable the button if the settings page is displayed in Windows Ash,
2075 // otherwise the proxy settings dialog will open on the Windows desktop and
2076 // be invisible to a user in Ash.
2077 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH
) {
2078 base::FundamentalValue
enabled(false);
2079 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
2082 #endif // defined(OS_WIN)
2085 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
2086 bool has_users
= !Profile::FromWebUI(web_ui())->
2087 GetPrefs()->GetDictionary(prefs::kSupervisedUsers
)->empty();
2088 base::FundamentalValue
has_users_value(has_users
);
2089 web_ui()->CallJavascriptFunction(
2090 "BrowserOptions.updateManagesSupervisedUsers",
2094 void BrowserOptionsHandler::SetupEasyUnlock() {
2095 base::FundamentalValue
is_enabled(
2096 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsEnabled());
2097 web_ui()->CallJavascriptFunction(
2098 "BrowserOptions.updateEasyUnlock",
2102 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
2104 base::DictionaryValue extension_controlled
;
2106 // Check if an extension is overriding the Search Engine.
2107 const extensions::Extension
* extension
=
2108 extensions::GetExtensionOverridingSearchEngine(
2109 Profile::FromWebUI(web_ui()));
2110 AppendExtensionData("searchEngine", extension
, &extension_controlled
);
2112 // Check if an extension is overriding the Home page.
2113 extension
= extensions::GetExtensionOverridingHomepage(
2114 Profile::FromWebUI(web_ui()));
2115 AppendExtensionData("homePage", extension
, &extension_controlled
);
2117 // Check if an extension is overriding the Startup pages.
2118 extension
= extensions::GetExtensionOverridingStartupPages(
2119 Profile::FromWebUI(web_ui()));
2120 AppendExtensionData("startUpPage", extension
, &extension_controlled
);
2122 // Check if an extension is overriding the NTP page.
2123 GURL
ntp_url(chrome::kChromeUINewTabURL
);
2126 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
2128 web_ui()->GetWebContents()->GetBrowserContext(),
2130 if (ntp_url
.SchemeIs("chrome-extension")) {
2131 using extensions::ExtensionRegistry
;
2132 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
2133 Profile::FromWebUI(web_ui()));
2134 extension
= registry
->GetExtensionById(ntp_url
.host(),
2135 ExtensionRegistry::ENABLED
);
2137 AppendExtensionData("newTabPage", extension
, &extension_controlled
);
2139 // Check if an extension is overwriting the proxy setting.
2140 extension
= extensions::GetExtensionOverridingProxy(
2141 Profile::FromWebUI(web_ui()));
2142 AppendExtensionData("proxy", extension
, &extension_controlled
);
2144 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
2145 extension_controlled
);
2146 #endif // defined(OS_WIN)
2149 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
2150 // This function does not work for ChromeOS and non-official builds.
2151 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
2152 bool checked
= ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
2153 bool disabled
= !IsMetricsReportingUserChangable();
2155 SetMetricsReportingCheckbox(checked
, disabled
);
2159 void BrowserOptionsHandler::HandleMetricsReportingChange(
2160 const base::ListValue
* args
) {
2162 if (!args
->GetBoolean(0, &enable
))
2165 InitiateMetricsReportingChange(
2167 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback
,
2168 base::Unretained(this)));
2171 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled
) {
2172 SetMetricsReportingCheckbox(enabled
, !IsMetricsReportingUserChangable());
2175 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked
,
2177 web_ui()->CallJavascriptFunction(
2178 "BrowserOptions.setMetricsReportingCheckboxState",
2179 base::FundamentalValue(checked
),
2180 base::FundamentalValue(disabled
));
2183 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace
& ns
,
2184 const policy::PolicyMap
& previous
,
2185 const policy::PolicyMap
& current
) {
2186 std::set
<std::string
> different_keys
;
2187 current
.GetDifferingKeys(previous
, &different_keys
);
2188 if (ContainsKey(different_keys
, policy::key::kMetricsReportingEnabled
))
2189 SetupMetricsReportingCheckbox();
2192 } // namespace options