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 "chromeos/chromeos_switches.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/search_engines/template_url.h"
78 #include "components/search_engines/template_url_service.h"
79 #include "components/signin/core/browser/signin_manager.h"
80 #include "components/signin/core/common/profile_management_switches.h"
81 #include "components/ui/zoom/page_zoom.h"
82 #include "components/user_manager/user_type.h"
83 #include "content/public/browser/browser_thread.h"
84 #include "content/public/browser/download_manager.h"
85 #include "content/public/browser/navigation_controller.h"
86 #include "content/public/browser/notification_details.h"
87 #include "content/public/browser/notification_service.h"
88 #include "content/public/browser/notification_source.h"
89 #include "content/public/browser/notification_types.h"
90 #include "content/public/browser/url_data_source.h"
91 #include "content/public/browser/user_metrics.h"
92 #include "content/public/browser/web_contents.h"
93 #include "content/public/common/page_zoom.h"
94 #include "extensions/browser/extension_registry.h"
95 #include "google_apis/gaia/gaia_auth_util.h"
96 #include "google_apis/gaia/google_service_auth_error.h"
97 #include "policy/policy_constants.h"
98 #include "third_party/skia/include/core/SkBitmap.h"
99 #include "ui/base/l10n/l10n_util.h"
100 #include "ui/base/webui/web_ui_util.h"
102 #if !defined(OS_CHROMEOS)
103 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
106 #if defined(OS_CHROMEOS)
107 #include "ash/ash_switches.h"
108 #include "ash/desktop_background/user_wallpaper_delegate.h"
109 #include "ash/shell.h"
110 #include "chrome/browser/browser_process_platform_part.h"
111 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
112 #include "chrome/browser/chromeos/chromeos_utils.h"
113 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
114 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
115 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
116 #include "chrome/browser/chromeos/profiles/profile_helper.h"
117 #include "chrome/browser/chromeos/reset/metrics.h"
118 #include "chrome/browser/chromeos/settings/cros_settings.h"
119 #include "chrome/browser/chromeos/system/timezone_util.h"
120 #include "chrome/browser/policy/profile_policy_connector.h"
121 #include "chrome/browser/policy/profile_policy_connector_factory.h"
122 #include "chrome/browser/ui/browser_window.h"
123 #include "chromeos/dbus/dbus_thread_manager.h"
124 #include "chromeos/dbus/power_manager_client.h"
125 #include "components/user_manager/user.h"
126 #include "components/user_manager/user_manager.h"
127 #include "ui/chromeos/accessibility_types.h"
128 #include "ui/gfx/image/image_skia.h"
129 #endif // defined(OS_CHROMEOS)
132 #include "chrome/browser/extensions/settings_api_helpers.h"
133 #include "chrome/installer/util/auto_launch_util.h"
134 #include "content/public/browser/browser_url_handler.h"
135 #endif // defined(OS_WIN)
137 #if defined(ENABLE_SERVICE_DISCOVERY)
138 #include "chrome/browser/local_discovery/privet_notifications.h"
142 #include "ash/shell.h"
145 using base::UserMetricsAction
;
146 using content::BrowserContext
;
147 using content::BrowserThread
;
148 using content::DownloadManager
;
149 using content::OpenURLParams
;
150 using content::Referrer
;
151 using extensions::Extension
;
152 using extensions::ExtensionRegistry
;
157 void AppendExtensionData(const std::string
& key
,
158 const Extension
* extension
,
159 base::DictionaryValue
* dict
) {
160 scoped_ptr
<base::DictionaryValue
> details(new base::DictionaryValue
);
161 details
->SetString("id", extension
? extension
->id() : std::string());
162 details
->SetString("name", extension
? extension
->name() : std::string());
163 dict
->Set(key
, details
.release());
165 #endif // defined(OS_WIN)
171 BrowserOptionsHandler::BrowserOptionsHandler()
172 : page_initialized_(false),
173 template_url_service_(NULL
),
174 cloud_print_mdns_ui_enabled_(false),
175 signin_observer_(this),
176 weak_ptr_factory_(this) {
177 default_browser_worker_
= new ShellIntegration::DefaultBrowserWorker(this);
179 #if defined(ENABLE_SERVICE_DISCOVERY)
180 cloud_print_mdns_ui_enabled_
= true;
181 #endif // defined(ENABLE_SERVICE_DISCOVERY)
184 BrowserOptionsHandler::~BrowserOptionsHandler() {
185 ProfileSyncService
* sync_service(ProfileSyncServiceFactory::
186 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
188 sync_service
->RemoveObserver(this);
190 if (default_browser_worker_
.get())
191 default_browser_worker_
->ObserverDestroyed();
192 if (template_url_service_
)
193 template_url_service_
->RemoveObserver(this);
194 // There may be pending file dialogs, we need to tell them that we've gone
195 // away so they don't try and call back to us.
196 if (select_folder_dialog_
.get())
197 select_folder_dialog_
->ListenerDestroyed();
199 g_browser_process
->policy_service()->RemoveObserver(
200 policy::POLICY_DOMAIN_CHROME
, this);
203 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue
* values
) {
206 #if defined(OS_CHROMEOS)
207 const int device_type_resource_id
= chromeos::GetChromeDeviceTypeResourceId();
209 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices.
210 const int device_type_resource_id
= IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE
;
211 #endif // defined(OS_CHROMEOS)
213 static OptionsStringResource resources
[] = {
214 // Please keep these in alphabetical order.
215 { "accessibilityFeaturesLink", IDS_OPTIONS_ACCESSIBILITY_FEATURES_LINK
},
216 { "accessibilityTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY
},
217 { "advancedSectionTitleCertificates",
218 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES
},
219 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT
},
220 { "advancedSectionTitleContent",
221 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT
},
222 { "advancedSectionTitleLanguages",
223 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES
},
224 { "advancedSectionTitleNetwork",
225 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK
},
226 { "advancedSectionTitlePrivacy",
227 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY
},
228 { "advancedSectionTitleSystem", IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM
},
229 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT
},
230 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY
},
231 { "autoOpenFileTypesResetToDefault",
232 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT
},
233 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE
},
234 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN
},
235 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON
},
236 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE
},
237 { "childLabel", IDS_PROFILES_LIST_CHILD_LABEL
},
238 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY
},
239 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL
},
240 { "defaultBrowserUnknown",
241 IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
, IDS_PRODUCT_NAME
},
242 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT
},
243 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL
},
244 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES
},
245 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL
},
246 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES
},
247 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK
},
248 { "doNotTrackConfirmDisable",
249 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE
},
250 { "doNotTrackConfirmEnable",
251 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE
},
252 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT
},
253 { "downloadLocationAskForSaveLocation",
254 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION
},
255 { "downloadLocationBrowseTitle",
256 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
},
257 { "downloadLocationChangeButton",
258 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON
},
259 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME
},
260 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION
,
261 device_type_resource_id
},
262 { "easyUnlockRequireProximityLabel",
263 IDS_OPTIONS_EASY_UNLOCK_REQUIRE_PROXIMITY_LABEL
,
264 device_type_resource_id
},
265 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE
},
266 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON
},
267 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO
,
268 device_type_resource_id
},
269 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING
},
270 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED
},
271 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE
},
272 { "fontSettingsCustomizeFontsButton",
273 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON
},
274 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM
},
275 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE
},
276 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM
},
277 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL
},
278 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE
},
279 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL
},
280 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS
},
281 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP
},
282 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
283 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB
},
284 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL
},
285 { "hotwordAlwaysOnAudioHistoryDescription",
286 IDS_HOTWORD_ALWAYS_ON_AUDIO_HISTORY_DESCRIPTION
},
287 { "hotwordAlwaysOnDesc", IDS_HOTWORD_SEARCH_ALWAYS_ON_DESCRIPTION
},
288 { "hotwordAudioHistoryManage", IDS_HOTWORD_AUDIO_HISTORY_MANAGE_LINK
},
289 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE
},
290 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE
},
291 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE
},
292 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION
},
293 { "hotwordNoDSPDesc", IDS_HOTWORD_SEARCH_NO_DSP_DESCRIPTION
},
294 { "hotwordRetrainLink", IDS_HOTWORD_RETRAIN_LINK
},
295 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX
},
296 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON
},
297 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE
},
298 { "languageAndSpellCheckSettingsButton",
299 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS
},
300 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
301 IDS_SHORT_PRODUCT_NAME
},
302 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF
},
303 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK
},
304 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES
},
305 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK
},
306 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART
},
307 { "networkPredictionEnabledDescription",
308 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
},
309 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE
},
310 { "passwordsAndAutofillGroupName",
311 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME
},
312 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON
},
313 { "privacyContentSettingsButton",
314 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON
},
315 { "profileAddPersonEnable", IDS_PROFILE_ADD_PERSON_ENABLE
},
316 { "profileBrowserGuestEnable", IDS_PROFILE_BROWSER_GUEST_ENABLE
},
317 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL
},
318 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL
},
319 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL
},
320 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT
},
321 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL
},
322 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
324 { "profilesSupervisedDashboardTip",
325 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP
},
326 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL
},
327 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
329 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON
},
330 { "resetProfileSettingsDescription",
331 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION
},
332 { "resetProfileSettingsSectionTitle",
333 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE
},
334 { "safeBrowsingEnableExtendedReporting",
335 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING
},
336 { "safeBrowsingEnableProtection",
337 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION
},
338 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME
},
339 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME
},
340 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME
},
341 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME
},
342 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME
},
343 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME
},
344 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME
},
345 { "settingsTitle", IDS_SETTINGS_TITLE
},
346 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
},
347 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE
},
348 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE
},
349 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT
},
350 { "spellingPref", IDS_OPTIONS_SPELLING_PREF
},
351 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION
},
352 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES
},
353 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB
},
354 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES
},
355 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF
},
356 { "supervisedUserLabel", IDS_PROFILES_LIST_SUPERVISED_USER_LABEL
},
357 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS
},
358 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
359 IDS_SHORT_PRODUCT_NAME
},
360 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL
},
361 { "syncOverview", IDS_SYNC_OVERVIEW
},
362 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF
},
363 { "themesGallery", IDS_THEMES_GALLERY_BUTTON
},
364 { "themesGalleryURL", IDS_THEMES_GALLERY_URL
},
365 { "themesReset", IDS_THEMES_RESET_BUTTON
},
366 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR
},
367 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
368 { "translateEnableTranslate",
369 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE
},
370 #if defined(OS_CHROMEOS)
371 { "accessibilityAlwaysShowMenu",
372 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU
},
373 { "accessibilityAutoclick",
374 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION
},
375 { "accessibilityAutoclickDropdown",
376 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION
},
377 { "accessibilityExplanation",
378 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION
},
379 { "accessibilityHighContrast",
380 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION
},
381 { "accessibilityLargeCursor",
382 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION
},
383 { "accessibilityScreenMagnifier",
384 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION
},
385 { "accessibilityScreenMagnifierFull",
386 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
},
387 { "accessibilityScreenMagnifierOff",
388 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF
},
389 { "accessibilityScreenMagnifierPartial",
390 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
},
391 { "accessibilitySettings",
392 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS
},
393 { "accessibilitySpokenFeedback",
394 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION
},
395 { "accessibilityStickyKeys",
396 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION
},
397 { "accessibilityTapDragging",
398 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION
},
399 { "accessibilityVirtualKeyboard",
400 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION
},
401 { "autoclickDelayExtremelyShort",
402 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT
},
403 { "autoclickDelayLong",
404 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG
},
405 { "autoclickDelayShort",
406 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT
},
407 { "autoclickDelayVeryLong",
408 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG
},
409 { "autoclickDelayVeryShort",
410 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT
},
411 { "batteryButton", IDS_OPTIONS_SETTINGS_BATTERY_DESCRIPTION
},
412 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE
},
413 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION
},
414 { "consumerManagementDescription",
415 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION
},
416 { "consumerManagementEnrollButton",
417 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON
},
418 { "consumerManagementEnrollingButton",
419 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLLING_BUTTON
},
420 { "consumerManagementUnenrollButton",
421 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON
},
422 { "consumerManagementUnenrollingButton",
423 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLLING_BUTTON
},
424 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME
},
425 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE
},
426 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION
},
427 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION
},
428 { "disableGData", IDS_OPTIONS_DISABLE_GDATA
},
429 { "displayOptions", IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL
},
430 { "enableContentProtectionAttestation",
431 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION
},
432 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX
},
433 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON
},
434 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION
,
435 IDS_SHORT_PRODUCT_NAME
},
436 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING
},
437 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL
},
438 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON
},
439 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET
},
440 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING
},
441 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE
},
442 { "keyboardSettingsButtonTitle",
443 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE
},
444 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE
},
445 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION
},
446 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES
},
447 { "powerSettingsButton",
448 IDS_OPTIONS_DEVICE_GROUP_POWER_SETTINGS_BUTTON
},
449 { "resolveTimezoneByGeoLocation",
450 IDS_OPTIONS_RESOLVE_TIMEZONE_BY_GEOLOCATION_DESCRIPTION
},
451 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME
},
452 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL
},
453 { "storageButton", IDS_OPTIONS_SETTINGS_STORAGE_DESCRIPTION
},
454 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
455 { "thirdPartyImeConfirmDisable", IDS_CANCEL
},
456 { "thirdPartyImeConfirmEnable", IDS_OK
},
457 { "thirdPartyImeConfirmMessage",
458 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE
},
459 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION
},
460 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION
},
461 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION
},
462 { "wakeOnWifiLabel", IDS_OPTIONS_SETTINGS_WAKE_ON_WIFI_DESCRIPTION
},
465 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE
},
466 { "gpuModeResetRestart",
467 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART
},
468 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
},
469 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
470 #endif // defined(OS_CHROMEOS)
472 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
473 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS
},
474 { "themesNativeButton", IDS_THEMES_GTK_BUTTON
},
475 { "themesSetClassic", IDS_THEMES_SET_CLASSIC
},
477 { "themes", IDS_THEMES_GROUP_NAME
},
478 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
480 #if defined(OS_CHROMEOS) && defined(USE_ASH)
481 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON
},
482 #endif // defined(OS_CHROMEOS) && defined(USE_ASH)
484 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
485 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE
},
486 #endif // defined(OS_MACOSX) && !defined(OS_CHROMEOS)
488 #if defined(ENABLE_SETTINGS_APP)
489 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL
},
490 #endif // defined(ENABLE_SETTINGS_APP)
492 #if defined(ENABLE_SERVICE_DISCOVERY)
493 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON
},
494 { "cloudPrintEnableNotificationsLabel",
495 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL
},
496 #endif // defined(ENABLE_SERVICE_DISCOVERY)
499 #if defined(ENABLE_SETTINGS_APP)
500 static OptionsStringResource app_resources
[] = {
501 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW
},
502 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
503 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
504 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
505 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
506 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
507 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
508 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
509 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
511 base::DictionaryValue
* app_values
= NULL
;
512 CHECK(values
->GetDictionary(kSettingsAppKey
, &app_values
));
513 RegisterStrings(app_values
, app_resources
, arraysize(app_resources
));
516 RegisterStrings(values
, resources
, arraysize(resources
));
517 RegisterTitle(values
, "doNotTrackConfirmOverlay",
518 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE
);
519 RegisterTitle(values
, "spellingConfirmOverlay",
520 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE
);
521 #if defined(ENABLE_PRINT_PREVIEW)
522 RegisterCloudPrintValues(values
);
525 values
->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL
);
526 base::string16 omnibox_url
= base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL
);
528 "defaultSearchGroupLabel",
529 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION
, omnibox_url
));
530 values
->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL
);
531 RegisterTitle(values
, "hotwordConfirmOverlay",
532 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE
);
533 values
->SetString("hotwordManageAudioHistoryURL",
534 chrome::kManageAudioHistoryURL
);
536 #if defined(OS_CHROMEOS)
537 Profile
* profile
= Profile::FromWebUI(web_ui());
538 std::string username
= profile
->GetProfileUserName();
539 if (username
.empty()) {
540 user_manager::User
* user
=
541 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
542 if (user
&& (user
->GetType() != user_manager::USER_TYPE_GUEST
))
543 username
= user
->email();
545 if (!username
.empty())
546 username
= gaia::SanitizeEmail(gaia::CanonicalizeEmail(username
));
548 values
->SetString("username", username
);
550 // Pass along sync status early so it will be available during page init.
551 values
->Set("syncData", GetSyncStateDictionary().release());
553 values
->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL
);
555 base::string16 rappor_url
= base::ASCIIToUTF16(chrome::kRapporLearnMoreURL
);
556 values
->SetString("enableRappor",
557 l10n_util::GetStringFUTF16(IDS_OPTIONS_ENABLE_RAPPOR
, rappor_url
));
558 values
->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL
);
560 #if !defined(OS_CHROMEOS)
561 values
->SetBoolean("metricsReportingEnabledAtStart",
562 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
565 #if defined(OS_CHROMEOS)
566 // TODO(pastarmovj): replace this with a call to the CrosSettings list
567 // handling functionality to come.
568 values
->Set("timezoneList", chromeos::system::GetTimezoneList().release());
570 values
->SetString("accessibilityLearnMoreURL",
571 chrome::kChromeAccessibilityHelpURL
);
573 std::string settings_url
= std::string("chrome-extension://") +
574 extension_misc::kChromeVoxExtensionId
+
575 chrome::kChromeAccessibilitySettingsURL
;
577 values
->SetString("accessibilitySettingsURL",
580 values
->SetString("contentProtectionAttestationLearnMoreURL",
581 chrome::kAttestationForContentProtectionLearnMoreURL
);
583 // Creates magnifierList.
584 scoped_ptr
<base::ListValue
> magnifier_list(new base::ListValue
);
586 scoped_ptr
<base::ListValue
> option_full(new base::ListValue
);
587 option_full
->AppendInteger(ui::MAGNIFIER_FULL
);
588 option_full
->AppendString(l10n_util::GetStringUTF16(
589 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
));
590 magnifier_list
->Append(option_full
.release());
592 scoped_ptr
<base::ListValue
> option_partial(new base::ListValue
);
593 option_partial
->AppendInteger(ui::MAGNIFIER_PARTIAL
);
594 option_partial
->Append(new base::StringValue(l10n_util::GetStringUTF16(
595 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
)));
596 magnifier_list
->Append(option_partial
.release());
598 values
->Set("magnifierList", magnifier_list
.release());
601 #if defined(OS_MACOSX)
602 values
->SetString("macPasswordsWarning",
603 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING
));
604 values
->SetBoolean("multiple_profiles",
605 g_browser_process
->profile_manager()->GetNumberOfProfiles() > 1);
608 if (ShouldShowMultiProfilesUserList())
609 values
->Set("profilesInfo", GetProfilesInfoList().release());
611 // Profile deletion is not allowed for any users using Metro mode.
612 bool allow_deletion
= true;
614 allow_deletion
= allow_deletion
&& !ash::Shell::HasInstance();
616 values
->SetBoolean("allowProfileDeletion", allow_deletion
);
618 values
->SetBoolean("profileIsGuest",
619 Profile::FromWebUI(web_ui())->IsOffTheRecord());
621 values
->SetBoolean("profileIsSupervised",
622 Profile::FromWebUI(web_ui())->IsSupervised());
624 #if !defined(OS_CHROMEOS)
627 g_browser_process
->gpu_mode_manager()->initial_gpu_mode_pref());
630 #if defined(ENABLE_SERVICE_DISCOVERY)
631 values
->SetBoolean("cloudPrintHideNotificationsCheckbox",
632 !local_discovery::PrivetNotificationService::IsEnabled());
635 values
->SetBoolean("cloudPrintShowMDnsOptions",
636 cloud_print_mdns_ui_enabled_
);
638 values
->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL
);
640 values
->SetString("languagesLearnMoreURL",
641 chrome::kLanguageSettingsLearnMoreUrl
);
645 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
646 values
->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl
);
647 values
->SetBoolean("easyUnlockProximityDetectionAllowed",
648 base::CommandLine::ForCurrentProcess()->HasSwitch(
649 proximity_auth::switches::kEnableProximityDetection
));
651 #if defined(OS_CHROMEOS)
652 values
->SetBoolean("consumerManagementEnabled",
653 base::CommandLine::ForCurrentProcess()->HasSwitch(
654 chromeos::switches::kEnableConsumerManagement
));
656 RegisterTitle(values
, "thirdPartyImeConfirmOverlay",
657 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE
);
660 values
->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
662 values
->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
664 values
->SetBoolean("websiteSettingsManagerEnabled",
665 base::CommandLine::ForCurrentProcess()->HasSwitch(
666 switches::kEnableWebsiteSettingsManager
));
668 values
->SetBoolean("usingNewProfilesUI", switches::IsNewAvatarMenu());
670 #if defined(OS_CHROMEOS)
673 chromeos::WakeOnWifiManager::Get()->WakeOnWifiSupported() &&
674 chromeos::switches::WakeOnWifiEnabled());
675 const bool have_disable_time_zone_tracking_option_switch
=
676 base::CommandLine::ForCurrentProcess()->HasSwitch(
677 chromeos::switches::kDisableTimeZoneTrackingOption
);
678 values
->SetBoolean("enableTimeZoneTrackingOption",
679 !have_disable_time_zone_tracking_option_switch
&&
680 !chromeos::system::HasSystemTimezonePolicy());
684 #if defined(ENABLE_PRINT_PREVIEW)
685 void BrowserOptionsHandler::RegisterCloudPrintValues(
686 base::DictionaryValue
* values
) {
687 values
->SetString("cloudPrintOptionLabel",
688 l10n_util::GetStringFUTF16(
689 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL
,
690 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
692 #endif // defined(ENABLE_PRINT_PREVIEW)
694 void BrowserOptionsHandler::RegisterMessages() {
695 web_ui()->RegisterMessageCallback(
696 "becomeDefaultBrowser",
697 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser
,
698 base::Unretained(this)));
699 web_ui()->RegisterMessageCallback(
700 "setDefaultSearchEngine",
701 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine
,
702 base::Unretained(this)));
703 web_ui()->RegisterMessageCallback(
705 base::Bind(&BrowserOptionsHandler::DeleteProfile
,
706 base::Unretained(this)));
707 web_ui()->RegisterMessageCallback(
709 base::Bind(&BrowserOptionsHandler::ThemesReset
,
710 base::Unretained(this)));
711 web_ui()->RegisterMessageCallback(
712 "requestProfilesInfo",
713 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo
,
714 base::Unretained(this)));
715 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
716 web_ui()->RegisterMessageCallback(
718 base::Bind(&BrowserOptionsHandler::ThemesSetNative
,
719 base::Unretained(this)));
721 web_ui()->RegisterMessageCallback(
722 "selectDownloadLocation",
723 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation
,
724 base::Unretained(this)));
725 web_ui()->RegisterMessageCallback(
726 "autoOpenFileTypesAction",
727 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton
,
728 base::Unretained(this)));
729 web_ui()->RegisterMessageCallback(
730 "defaultFontSizeAction",
731 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize
,
732 base::Unretained(this)));
733 web_ui()->RegisterMessageCallback(
734 "defaultZoomFactorAction",
735 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor
,
736 base::Unretained(this)));
737 #if defined(OS_WIN) || defined(OS_MACOSX)
738 web_ui()->RegisterMessageCallback(
739 "showManageSSLCertificates",
740 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates
,
741 base::Unretained(this)));
743 #if defined(OS_CHROMEOS)
744 web_ui()->RegisterMessageCallback(
745 "openWallpaperManager",
746 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager
,
747 base::Unretained(this)));
748 web_ui()->RegisterMessageCallback(
749 "virtualKeyboardChange",
750 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback
,
751 base::Unretained(this)));
752 web_ui()->RegisterMessageCallback(
753 "onPowerwashDialogShow",
754 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow
,
755 base::Unretained(this)));
756 web_ui()->RegisterMessageCallback(
757 "performFactoryResetRestart",
758 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart
,
759 base::Unretained(this)));
761 web_ui()->RegisterMessageCallback(
763 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser
,
764 base::Unretained(this)));
765 web_ui()->RegisterMessageCallback(
766 "showNetworkProxySettings",
767 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings
,
768 base::Unretained(this)));
769 #endif // defined(OS_CHROMEOS)
771 #if defined(ENABLE_SERVICE_DISCOVERY)
772 if (cloud_print_mdns_ui_enabled_
) {
773 web_ui()->RegisterMessageCallback(
774 "showCloudPrintDevicesPage",
775 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage
,
776 base::Unretained(this)));
779 web_ui()->RegisterMessageCallback(
780 "requestHotwordAvailable",
781 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable
,
782 base::Unretained(this)));
784 web_ui()->RegisterMessageCallback(
785 "launchHotwordAudioVerificationApp",
787 &BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp
,
788 base::Unretained(this)));
790 web_ui()->RegisterMessageCallback(
791 "launchEasyUnlockSetup",
792 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup
,
793 base::Unretained(this)));
795 web_ui()->RegisterMessageCallback(
796 "refreshExtensionControlIndicators",
798 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators
,
799 base::Unretained(this)));
800 #endif // defined(OS_WIN)
801 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
802 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange
,
803 base::Unretained(this)));
806 void BrowserOptionsHandler::Uninitialize() {
807 registrar_
.RemoveAll();
809 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
811 #if defined(OS_CHROMEOS)
812 policy::ConsumerManagementService
* consumer_management
=
813 g_browser_process
->platform_part()->browser_policy_connector_chromeos()->
814 GetConsumerManagementService();
815 if (consumer_management
)
816 consumer_management
->RemoveObserver(this);
820 void BrowserOptionsHandler::OnStateChanged() {
824 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string
& account_id
,
825 const std::string
& username
,
826 const std::string
& password
) {
830 void BrowserOptionsHandler::GoogleSignedOut(const std::string
& account_id
,
831 const std::string
& username
) {
835 void BrowserOptionsHandler::PageLoadStarted() {
836 page_initialized_
= false;
839 void BrowserOptionsHandler::InitializeHandler() {
840 Profile
* profile
= Profile::FromWebUI(web_ui());
841 PrefService
* prefs
= profile
->GetPrefs();
842 chrome::ChromeZoomLevelPrefs
* zoom_level_prefs
= profile
->GetZoomLevelPrefs();
843 // Only regular profiles are able to edit default zoom level, or delete per-
844 // host zoom levels, via the settings menu. We only require a zoom_level_prefs
845 // if the profile is able to change these preference types.
846 DCHECK(zoom_level_prefs
||
847 profile
->GetProfileType() != Profile::REGULAR_PROFILE
);
848 if (zoom_level_prefs
) {
849 default_zoom_level_subscription_
=
850 zoom_level_prefs
->RegisterDefaultZoomLevelCallback(
851 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector
,
852 base::Unretained(this)));
855 g_browser_process
->policy_service()->AddObserver(
856 policy::POLICY_DOMAIN_CHROME
, this);
858 ProfileSyncService
* sync_service(
859 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
));
860 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
861 // destruction is automatic.
863 sync_service
->AddObserver(this);
865 SigninManagerBase
* signin_manager(
866 SigninManagerFactory::GetInstance()->GetForProfile(profile
));
868 signin_observer_
.Add(signin_manager
);
870 // Create our favicon data source.
871 content::URLDataSource::Add(
872 profile
, new FaviconSource(profile
, FaviconSource::FAVICON
));
874 default_browser_policy_
.Init(
875 prefs::kDefaultBrowserSettingEnabled
,
876 g_browser_process
->local_state(),
877 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState
,
878 base::Unretained(this)));
880 registrar_
.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
,
881 content::NotificationService::AllSources());
882 #if defined(OS_CHROMEOS)
883 registrar_
.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
884 content::NotificationService::AllSources());
886 registrar_
.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED
,
887 content::Source
<ThemeService
>(
888 ThemeServiceFactory::GetForProfile(profile
)));
889 registrar_
.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
,
890 content::Source
<Profile
>(profile
));
891 AddTemplateUrlServiceObserver();
894 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
896 const base::CommandLine
& command_line
=
897 *base::CommandLine::ForCurrentProcess();
898 if (!command_line
.HasSwitch(switches::kUserDataDir
)) {
899 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
900 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch
,
901 weak_ptr_factory_
.GetWeakPtr(),
902 profile
->GetPath()));
906 // No preferences below this point may be modified by guest profiles.
907 if (Profile::FromWebUI(web_ui())->IsGuestSession())
910 auto_open_files_
.Init(
911 prefs::kDownloadExtensionsToOpen
, prefs
,
912 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes
,
913 base::Unretained(this)));
914 profile_pref_registrar_
.Init(prefs
);
915 profile_pref_registrar_
.Add(
916 prefs::kNetworkPredictionOptions
,
917 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl
,
918 base::Unretained(this)));
919 profile_pref_registrar_
.Add(
920 prefs::kWebKitDefaultFontSize
,
921 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
922 base::Unretained(this)));
923 profile_pref_registrar_
.Add(
924 prefs::kWebKitDefaultFixedFontSize
,
925 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
926 base::Unretained(this)));
927 profile_pref_registrar_
.Add(
928 prefs::kSupervisedUsers
,
929 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers
,
930 base::Unretained(this)));
931 profile_pref_registrar_
.Add(
932 prefs::kSigninAllowed
,
933 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange
,
934 base::Unretained(this)));
935 profile_pref_registrar_
.Add(
936 prefs::kEasyUnlockPairing
,
937 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock
,
938 base::Unretained(this)));
941 profile_pref_registrar_
.Add(
942 prefs::kURLsToRestoreOnStartup
,
943 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
944 base::Unretained(this)));
945 profile_pref_registrar_
.Add(
947 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
948 base::Unretained(this)));
949 #endif // defined(OS_WIN)
951 #if defined(OS_CHROMEOS)
952 if (!policy_registrar_
) {
953 policy_registrar_
.reset(new policy::PolicyChangeRegistrar(
954 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile
)
956 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
, std::string())));
957 policy_registrar_
->Observe(
958 policy::key::kUserAvatarImage
,
959 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged
,
960 base::Unretained(this)));
961 policy_registrar_
->Observe(
962 policy::key::kWallpaperImage
,
963 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged
,
964 base::Unretained(this)));
966 chromeos::CrosSettings::Get()->AddSettingsObserver(
967 chromeos::kSystemTimezonePolicy
,
968 base::Bind(&BrowserOptionsHandler::OnSystemTimezonePolicyChanged
,
969 weak_ptr_factory_
.GetWeakPtr()));
970 #else // !defined(OS_CHROMEOS)
971 profile_pref_registrar_
.Add(
973 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection
,
974 base::Unretained(this)));
975 #endif // !defined(OS_CHROMEOS)
978 void BrowserOptionsHandler::InitializePage() {
979 page_initialized_
= true;
981 OnTemplateURLServiceChanged();
983 ObserveThemeChanged();
985 UpdateDefaultBrowserState();
987 SetupMetricsReportingSettingVisibility();
988 SetupMetricsReportingCheckbox();
989 SetupNetworkPredictionControl();
990 SetupFontSizeSelector();
991 SetupPageZoomSelector();
992 SetupAutoOpenFileTypes();
993 SetupProxySettingsSection();
994 SetupManageCertificatesSection();
995 SetupManagingSupervisedUsers();
997 SetupExtensionControlledIndicators();
999 #if defined(OS_CHROMEOS)
1000 SetupAccessibilityFeatures();
1001 policy::BrowserPolicyConnectorChromeOS
* connector
=
1002 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1003 if (!connector
->IsEnterpriseManaged() &&
1004 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
1005 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
1006 web_ui()->CallJavascriptFunction(
1007 "BrowserOptions.enableFactoryResetSection");
1010 Profile
* profile
= Profile::FromWebUI(web_ui());
1011 OnAccountPictureManagedChanged(
1012 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile
)
1014 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
,
1016 .Get(policy::key::kUserAvatarImage
));
1018 OnWallpaperManagedChanged(
1019 chromeos::WallpaperManager::Get()->IsPolicyControlled(
1020 user_manager::UserManager::Get()->GetActiveUser()->email()));
1022 policy::ConsumerManagementService
* consumer_management
=
1023 g_browser_process
->platform_part()->browser_policy_connector_chromeos()->
1024 GetConsumerManagementService();
1025 if (consumer_management
) {
1026 OnConsumerManagementStatusChanged();
1027 consumer_management
->AddObserver(this);
1033 void BrowserOptionsHandler::CheckAutoLaunch(
1034 base::WeakPtr
<BrowserOptionsHandler
> weak_this
,
1035 const base::FilePath
& profile_path
) {
1037 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
1039 // Auto-launch is not supported for secondary profiles yet.
1040 if (profile_path
.BaseName().value() !=
1041 base::ASCIIToUTF16(chrome::kInitialProfile
)) {
1045 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
1047 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
1048 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback
,
1050 auto_launch_trial::IsInAutoLaunchGroup(),
1051 auto_launch_util::AutoStartRequested(
1052 profile_path
.BaseName().value(),
1053 true, // Window requested.
1054 base::FilePath())));
1058 void BrowserOptionsHandler::CheckAutoLaunchCallback(
1059 bool is_in_auto_launch_group
,
1060 bool will_launch_at_login
) {
1062 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1064 if (is_in_auto_launch_group
) {
1065 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
1066 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch
,
1067 base::Unretained(this)));
1069 base::FundamentalValue
enabled(will_launch_at_login
);
1070 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1076 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1077 #if defined(OS_CHROMEOS)
1078 // We're always the default browser on ChromeOS.
1081 Profile
* profile
= Profile::FromWebUI(web_ui());
1082 return !profile
->IsGuestSession();
1086 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1087 #if defined(OS_CHROMEOS)
1088 // On Chrome OS we use different UI for multi-profiles.
1091 Profile
* profile
= Profile::FromWebUI(web_ui());
1092 if (profile
->IsGuestSession())
1094 return profiles::IsMultipleProfilesEnabled();
1098 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1099 #if defined(OS_CHROMEOS)
1100 // ChromeOS handles guest-mode restrictions in a different manner.
1103 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1107 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1108 default_browser_worker_
->StartCheckIsDefault();
1111 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue
* args
) {
1112 // If the default browser setting is managed then we should not be able to
1113 // call this function.
1114 if (default_browser_policy_
.IsManaged())
1117 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1118 default_browser_worker_
->StartSetAsDefault();
1119 // Callback takes care of updating UI.
1121 // If the user attempted to make Chrome the default browser, then he/she
1122 // arguably wants to be notified when that changes.
1123 PrefService
* prefs
= Profile::FromWebUI(web_ui())->GetPrefs();
1124 prefs
->SetBoolean(prefs::kCheckDefaultBrowser
, true);
1127 int BrowserOptionsHandler::StatusStringIdForState(
1128 ShellIntegration::DefaultWebClientState state
) {
1129 if (state
== ShellIntegration::IS_DEFAULT
)
1130 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1131 if (state
== ShellIntegration::NOT_DEFAULT
)
1132 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1133 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1136 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1137 ShellIntegration::DefaultWebClientUIState state
) {
1138 int status_string_id
;
1140 if (state
== ShellIntegration::STATE_IS_DEFAULT
) {
1141 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1142 } else if (state
== ShellIntegration::STATE_NOT_DEFAULT
) {
1143 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1144 ShellIntegration::SET_DEFAULT_NOT_ALLOWED
) {
1145 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_SXS
;
1147 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1149 } else if (state
== ShellIntegration::STATE_UNKNOWN
) {
1150 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1152 return; // Still processing.
1155 SetDefaultBrowserUIString(status_string_id
);
1158 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1159 return true; // This is UI so we can allow it.
1162 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id
) {
1163 base::StringValue
status_string(
1164 l10n_util::GetStringFUTF16(status_string_id
,
1165 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)));
1167 base::FundamentalValue
is_default(
1168 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
);
1170 base::FundamentalValue
can_be_default(
1171 !default_browser_policy_
.IsManaged() &&
1172 (status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
||
1173 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
));
1175 web_ui()->CallJavascriptFunction(
1176 "BrowserOptions.updateDefaultBrowserState",
1177 status_string
, is_default
, can_be_default
);
1180 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1181 if (!template_url_service_
|| !template_url_service_
->loaded())
1184 const TemplateURL
* default_url
=
1185 template_url_service_
->GetDefaultSearchProvider();
1187 int default_index
= -1;
1188 base::ListValue search_engines
;
1189 TemplateURLService::TemplateURLVector
model_urls(
1190 template_url_service_
->GetTemplateURLs());
1191 for (size_t i
= 0; i
< model_urls
.size(); ++i
) {
1192 if (!model_urls
[i
]->ShowInDefaultList(
1193 template_url_service_
->search_terms_data()))
1196 base::DictionaryValue
* entry
= new base::DictionaryValue();
1197 entry
->SetString("name", model_urls
[i
]->short_name());
1198 entry
->SetInteger("index", i
);
1199 search_engines
.Append(entry
);
1200 if (model_urls
[i
] == default_url
)
1204 web_ui()->CallJavascriptFunction(
1205 "BrowserOptions.updateSearchEngines",
1207 base::FundamentalValue(default_index
),
1208 base::FundamentalValue(
1209 template_url_service_
->is_default_search_managed() ||
1210 template_url_service_
->IsExtensionControlledDefaultSearch()));
1212 SetupExtensionControlledIndicators();
1214 HandleRequestHotwordAvailable(nullptr);
1217 void BrowserOptionsHandler::SetDefaultSearchEngine(
1218 const base::ListValue
* args
) {
1219 int selected_index
= -1;
1220 if (!ExtractIntegerValue(args
, &selected_index
)) {
1225 TemplateURLService::TemplateURLVector
model_urls(
1226 template_url_service_
->GetTemplateURLs());
1227 if (selected_index
>= 0 &&
1228 selected_index
< static_cast<int>(model_urls
.size()))
1229 template_url_service_
->SetUserSelectedDefaultSearchProvider(
1230 model_urls
[selected_index
]);
1232 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1235 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1236 template_url_service_
=
1237 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1238 if (template_url_service_
) {
1239 template_url_service_
->Load();
1240 template_url_service_
->AddObserver(this);
1244 void BrowserOptionsHandler::OnExtensionLoaded(
1245 content::BrowserContext
* browser_context
,
1246 const Extension
* extension
) {
1247 SetupExtensionControlledIndicators();
1250 void BrowserOptionsHandler::OnExtensionUnloaded(
1251 content::BrowserContext
* browser_context
,
1252 const Extension
* extension
,
1253 extensions::UnloadedExtensionInfo::Reason reason
) {
1254 SetupExtensionControlledIndicators();
1257 void BrowserOptionsHandler::Observe(
1259 const content::NotificationSource
& source
,
1260 const content::NotificationDetails
& details
) {
1261 // Notifications are used to update the UI dynamically when settings change in
1262 // the background. If the UI is currently being loaded, no dynamic updates are
1263 // possible (as the DOM and JS are not fully loaded) or necessary (as
1264 // InitializePage() will update the UI at the end of the load).
1265 if (!page_initialized_
)
1269 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED
:
1270 ObserveThemeChanged();
1272 #if defined(OS_CHROMEOS)
1273 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
:
1274 UpdateAccountPicture();
1277 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
:
1280 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
:
1281 // Update our sync/signin status display.
1289 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue
* args
) {
1291 if (!auto_launch_trial::IsInAutoLaunchGroup())
1295 CHECK_EQ(args
->GetSize(), 1U);
1296 CHECK(args
->GetBoolean(0, &enable
));
1298 Profile
* profile
= Profile::FromWebUI(web_ui());
1299 content::BrowserThread::PostTask(
1300 content::BrowserThread::FILE, FROM_HERE
,
1302 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin
,
1303 profile
->GetPath().BaseName().value(), base::FilePath()) :
1304 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin
,
1305 profile
->GetPath().BaseName().value()));
1309 scoped_ptr
<base::ListValue
> BrowserOptionsHandler::GetProfilesInfoList() {
1310 ProfileInfoCache
& cache
=
1311 g_browser_process
->profile_manager()->GetProfileInfoCache();
1312 scoped_ptr
<base::ListValue
> profile_info_list(new base::ListValue
);
1313 base::FilePath current_profile_path
=
1314 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1316 for (size_t i
= 0, e
= cache
.GetNumberOfProfiles(); i
< e
; ++i
) {
1317 // The items in |profile_value| are also described in
1318 // chrome/browser/resources/options/browser_options.js in a @typedef for
1319 // Profile. Please update it whenever you add or remove any keys here.
1321 base::DictionaryValue
* profile_value
= new base::DictionaryValue();
1322 profile_value
->SetString("name", cache
.GetNameOfProfileAtIndex(i
));
1323 base::FilePath profile_path
= cache
.GetPathOfProfileAtIndex(i
);
1324 profile_value
->Set("filePath", base::CreateFilePathValue(profile_path
));
1325 profile_value
->SetBoolean("isCurrentProfile",
1326 profile_path
== current_profile_path
);
1327 profile_value
->SetBoolean("isSupervised",
1328 cache
.ProfileIsSupervisedAtIndex(i
));
1329 profile_value
->SetBoolean("isChild", cache
.ProfileIsChildAtIndex(i
));
1331 bool is_gaia_picture
=
1332 cache
.IsUsingGAIAPictureOfProfileAtIndex(i
) &&
1333 cache
.GetGAIAPictureOfProfileAtIndex(i
);
1334 if (is_gaia_picture
) {
1335 gfx::Image icon
= profiles::GetAvatarIconForWebUI(
1336 cache
.GetAvatarIconOfProfileAtIndex(i
), true);
1337 profile_value
->SetString("iconURL",
1338 webui::GetBitmapDataUrl(icon
.AsBitmap()));
1340 size_t icon_index
= cache
.GetAvatarIconIndexOfProfileAtIndex(i
);
1341 profile_value
->SetString("iconURL",
1342 profiles::GetDefaultAvatarIconUrl(icon_index
));
1345 profile_info_list
->Append(profile_value
);
1348 return profile_info_list
.Pass();
1351 void BrowserOptionsHandler::SendProfilesInfo() {
1352 if (!ShouldShowMultiProfilesUserList())
1354 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1355 *GetProfilesInfoList());
1358 void BrowserOptionsHandler::DeleteProfile(const base::ListValue
* args
) {
1360 const base::Value
* file_path_value
;
1361 if (!args
->Get(0, &file_path_value
))
1364 base::FilePath file_path
;
1365 if (!base::GetValueAsFilePath(*file_path_value
, &file_path
))
1367 helper::DeleteProfileAtPath(file_path
, web_ui());
1370 void BrowserOptionsHandler::ObserveThemeChanged() {
1371 Profile
* profile
= Profile::FromWebUI(web_ui());
1372 ThemeService
* theme_service
= ThemeServiceFactory::GetForProfile(profile
);
1373 bool is_system_theme
= false;
1375 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1376 bool profile_is_supervised
= profile
->IsSupervised();
1377 is_system_theme
= theme_service
->UsingSystemTheme();
1378 base::FundamentalValue
native_theme_enabled(!is_system_theme
&&
1379 !profile_is_supervised
);
1380 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1381 native_theme_enabled
);
1384 bool is_classic_theme
= !is_system_theme
&&
1385 theme_service
->UsingDefaultTheme();
1386 base::FundamentalValue
enabled(!is_classic_theme
);
1387 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1391 void BrowserOptionsHandler::ThemesReset(const base::ListValue
* args
) {
1392 Profile
* profile
= Profile::FromWebUI(web_ui());
1393 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1394 ThemeServiceFactory::GetForProfile(profile
)->UseDefaultTheme();
1397 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1398 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue
* args
) {
1399 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1400 Profile
* profile
= Profile::FromWebUI(web_ui());
1401 ThemeServiceFactory::GetForProfile(profile
)->UseSystemTheme();
1405 #if defined(OS_CHROMEOS)
1406 void BrowserOptionsHandler::UpdateAccountPicture() {
1408 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1409 if (!email
.empty()) {
1410 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1411 base::StringValue
email_value(email
);
1412 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1417 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed
) {
1418 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1419 base::FundamentalValue(managed
));
1422 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed
) {
1423 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1424 base::FundamentalValue(managed
));
1427 void BrowserOptionsHandler::OnSystemTimezonePolicyChanged() {
1428 web_ui()->CallJavascriptFunction(
1429 "BrowserOptions.setSystemTimezoneManaged",
1430 base::FundamentalValue(chromeos::system::HasSystemTimezonePolicy()));
1434 scoped_ptr
<base::DictionaryValue
>
1435 BrowserOptionsHandler::GetSyncStateDictionary() {
1436 // The items which are to be written into |sync_status| are also described in
1437 // chrome/browser/resources/options/browser_options.js in @typedef
1438 // for SyncStatus. Please update it whenever you add or remove any keys here.
1439 scoped_ptr
<base::DictionaryValue
> sync_status(new base::DictionaryValue
);
1440 Profile
* profile
= Profile::FromWebUI(web_ui());
1441 if (profile
->IsGuestSession()) {
1442 // Cannot display signin status when running in guest mode on chromeos
1443 // because there is no SigninManager.
1444 sync_status
->SetBoolean("signinAllowed", false);
1445 return sync_status
.Pass();
1448 sync_status
->SetBoolean("supervisedUser", profile
->IsSupervised());
1449 sync_status
->SetBoolean("childUser", profile
->IsChild());
1451 bool signout_prohibited
= false;
1452 #if !defined(OS_CHROMEOS)
1453 // Signout is not allowed if the user has policy (crbug.com/172204).
1454 signout_prohibited
=
1455 SigninManagerFactory::GetForProfile(profile
)->IsSignoutProhibited();
1458 ProfileSyncService
* service
=
1459 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
1460 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1462 sync_status
->SetBoolean("signoutAllowed", !signout_prohibited
);
1463 sync_status
->SetBoolean("signinAllowed", signin
->IsSigninAllowed());
1464 sync_status
->SetBoolean("syncSystemEnabled", (service
!= NULL
));
1465 sync_status
->SetBoolean("setupCompleted",
1466 service
&& service
->HasSyncSetupCompleted());
1467 sync_status
->SetBoolean("setupInProgress",
1468 service
&& !service
->IsManaged() && service
->FirstSetupInProgress());
1470 base::string16 status_label
;
1471 base::string16 link_label
;
1472 bool status_has_error
= sync_ui_util::GetStatusLabels(
1473 service
, *signin
, sync_ui_util::WITH_HTML
, &status_label
, &link_label
) ==
1474 sync_ui_util::SYNC_ERROR
;
1475 sync_status
->SetString("statusText", status_label
);
1476 sync_status
->SetString("actionLinkText", link_label
);
1477 sync_status
->SetBoolean("hasError", status_has_error
);
1479 sync_status
->SetBoolean("managed", service
&& service
->IsManaged());
1480 sync_status
->SetBoolean("signedIn", signin
->IsAuthenticated());
1481 sync_status
->SetBoolean("hasUnrecoverableError",
1482 service
&& service
->HasUnrecoverableError());
1484 return sync_status
.Pass();
1487 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1488 const base::ListValue
* args
) {
1489 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1490 select_folder_dialog_
= ui::SelectFileDialog::Create(
1491 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1492 ui::SelectFileDialog::FileTypeInfo info
;
1493 info
.support_drive
= true;
1494 select_folder_dialog_
->SelectFile(
1495 ui::SelectFileDialog::SELECT_FOLDER
,
1496 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
),
1497 pref_service
->GetFilePath(prefs::kDownloadDefaultDirectory
),
1500 base::FilePath::StringType(),
1501 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1505 void BrowserOptionsHandler::FileSelected(const base::FilePath
& path
, int index
,
1507 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1508 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1509 pref_service
->SetFilePath(prefs::kDownloadDefaultDirectory
, path
);
1510 pref_service
->SetFilePath(prefs::kSaveFileDefaultDirectory
, path
);
1513 #if defined(OS_CHROMEOS)
1514 void BrowserOptionsHandler::TouchpadExists(bool exists
) {
1515 base::FundamentalValue
val(exists
);
1516 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val
);
1519 void BrowserOptionsHandler::MouseExists(bool exists
) {
1520 base::FundamentalValue
val(exists
);
1521 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val
);
1524 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1525 const base::Value
* previous_policy
,
1526 const base::Value
* current_policy
) {
1527 const bool had_policy
= previous_policy
;
1528 const bool has_policy
= current_policy
;
1529 if (had_policy
!= has_policy
)
1530 OnAccountPictureManagedChanged(has_policy
);
1533 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1534 const base::Value
* previous_policy
,
1535 const base::Value
* current_policy
) {
1536 const bool had_policy
= previous_policy
;
1537 const bool has_policy
= current_policy
;
1538 if (had_policy
!= has_policy
)
1539 OnWallpaperManagedChanged(has_policy
);
1542 void BrowserOptionsHandler::OnPowerwashDialogShow(
1543 const base::ListValue
* args
) {
1544 UMA_HISTOGRAM_ENUMERATION(
1545 "Reset.ChromeOS.PowerwashDialogShown",
1546 chromeos::reset::DIALOG_FROM_OPTIONS
,
1547 chromeos::reset::DIALOG_VIEW_TYPE_SIZE
);
1550 void BrowserOptionsHandler::OnConsumerManagementStatusChanged() {
1551 const std::string
& status
= g_browser_process
->platform_part()->
1552 browser_policy_connector_chromeos()->GetConsumerManagementService()->
1554 web_ui()->CallJavascriptFunction(
1555 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status
));
1558 #endif // defined(OS_CHROMEOS)
1560 void BrowserOptionsHandler::UpdateSyncState() {
1561 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1562 *GetSyncStateDictionary());
1564 // A change in sign-in state also affects how hotwording and audio history are
1565 // displayed. Hide all hotwording and re-display properly.
1566 web_ui()->CallJavascriptFunction(
1567 "BrowserOptions.setAllHotwordSectionsVisible",
1568 base::FundamentalValue(false));
1569 HandleRequestHotwordAvailable(nullptr);
1572 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1576 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue
* args
) {
1577 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1578 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1579 web_ui()->GetWebContents()->GetBrowserContext());
1581 DownloadPrefs::FromDownloadManager(manager
)->ResetAutoOpen();
1584 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue
* args
) {
1586 if (ExtractIntegerValue(args
, &font_size
)) {
1587 if (font_size
> 0) {
1588 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1589 pref_service
->SetInteger(prefs::kWebKitDefaultFontSize
, font_size
);
1590 SetupFontSizeSelector();
1595 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1596 const base::ListValue
* args
) {
1598 if (ExtractDoubleValue(args
, &zoom_factor
)) {
1599 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
1600 content::ZoomFactorToZoomLevel(zoom_factor
));
1604 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue
* args
) {
1605 #if defined(OS_WIN) && defined(USE_ASH)
1606 // If hardware acceleration is disabled then we need to force restart
1607 // browser in desktop mode.
1608 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1609 // Currently there are issues with determining correct browser mode
1611 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
) {
1612 PrefService
* pref_service
= g_browser_process
->local_state();
1613 if (!pref_service
->GetBoolean(prefs::kHardwareAccelerationModeEnabled
)) {
1614 chrome::AttemptRestartToDesktopMode();
1621 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1622 // environment variable is defined. So we undefine this environment variable
1623 // before restarting, as the restarted processes will inherit their
1624 // environment variables from ours, thus suppressing crash uploads.
1625 PrefService
* pref_service
= g_browser_process
->local_state();
1626 if (!pref_service
->GetBoolean(prefs::kMetricsReportingEnabled
)) {
1627 HMODULE exe_module
= GetModuleHandle(chrome::kBrowserProcessExecutableName
);
1629 typedef void (__cdecl
*ClearBreakpadPipeEnvVar
)();
1630 ClearBreakpadPipeEnvVar clear
= reinterpret_cast<ClearBreakpadPipeEnvVar
>(
1631 GetProcAddress(exe_module
, "ClearBreakpadPipeEnvironmentVariable"));
1638 chrome::AttemptRestart();
1641 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1642 const base::ListValue
* args
) {
1646 #if !defined(OS_CHROMEOS)
1647 void BrowserOptionsHandler::ShowNetworkProxySettings(
1648 const base::ListValue
* args
) {
1649 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1650 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1651 web_ui()->GetWebContents());
1655 #if defined(OS_WIN) || defined(OS_MACOSX)
1656 void BrowserOptionsHandler::ShowManageSSLCertificates(
1657 const base::ListValue
* args
) {
1658 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1659 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1660 web_ui()->GetWebContents());
1664 #if defined(ENABLE_SERVICE_DISCOVERY)
1666 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1667 const base::ListValue
* args
) {
1668 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1669 // Navigate in current tab to devices page.
1670 OpenURLParams
params(
1671 GURL(chrome::kChromeUIDevicesURL
), Referrer(),
1672 CURRENT_TAB
, ui::PAGE_TRANSITION_LINK
, false);
1673 web_ui()->GetWebContents()->OpenURL(params
);
1678 void BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible(
1679 const base::string16
& audio_history_state
,
1680 bool success
, bool logging_enabled
) {
1681 bool visible
= logging_enabled
&& success
;
1682 web_ui()->CallJavascriptFunction(
1683 "BrowserOptions.setAudioHistorySectionVisible",
1684 base::FundamentalValue(visible
),
1685 base::StringValue(audio_history_state
));
1688 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1689 const base::ListValue
* args
) {
1690 Profile
* profile
= Profile::FromWebUI(web_ui());
1692 bool is_search_provider_google
= false;
1693 // The check for default search provider is only valid if the
1694 // |template_url_service_| has loaded already.
1695 if (template_url_service_
&& template_url_service_
->loaded()) {
1696 const TemplateURL
* default_url
=
1697 template_url_service_
->GetDefaultSearchProvider();
1698 if (default_url
&& default_url
->HasGoogleBaseURLs(
1699 template_url_service_
->search_terms_data())) {
1700 is_search_provider_google
= true;
1702 // If the user has chosen a default search provide other than Google, turn
1703 // off hotwording since other providers don't provide that functionality.
1704 HotwordService
* hotword_service
=
1705 HotwordServiceFactory::GetForProfile(profile
);
1706 if (hotword_service
)
1707 hotword_service
->DisableHotwordPreferences();
1711 // |is_search_provider_google| may be false because |template_url_service_|
1712 // does not exist yet or because the user selected a different search
1713 // provider. In either case it does not make sense to show the hotwording
1715 if (!is_search_provider_google
) {
1716 web_ui()->CallJavascriptFunction(
1717 "BrowserOptions.setAllHotwordSectionsVisible",
1718 base::FundamentalValue(false));
1722 std::string group
= base::FieldTrialList::FindFullName("VoiceTrigger");
1723 if (!group
.empty() && group
!= "Disabled" &&
1724 HotwordServiceFactory::IsHotwordAllowed(profile
)) {
1725 // Update the current error value.
1726 HotwordServiceFactory::IsServiceAvailable(profile
);
1727 int error
= HotwordServiceFactory::GetCurrentError(profile
);
1729 std::string function_name
;
1730 bool always_on
= false;
1731 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1732 bool authenticated
= signin
&& signin
->IsAuthenticated();
1733 if (HotwordService::IsExperimentalHotwordingEnabled()) {
1734 if (HotwordServiceFactory::IsHotwordHardwareAvailable() &&
1736 function_name
= "BrowserOptions.showHotwordAlwaysOnSection";
1738 // Show the retrain link if always-on is enabled.
1739 if (profile
->GetPrefs()->GetBoolean(
1740 prefs::kHotwordAlwaysOnSearchEnabled
)) {
1741 web_ui()->CallJavascriptFunction(
1742 "BrowserOptions.setHotwordRetrainLinkVisible",
1743 base::FundamentalValue(true));
1746 function_name
= "BrowserOptions.showHotwordNoDspSection";
1749 function_name
= "BrowserOptions.showHotwordSection";
1752 // Audio history should be displayed if it's enabled regardless of the
1753 // hotword error state if the user is signed in. If the user is not signed
1754 // in, audio history is meaningless. This is only displayed if always-on
1755 // hotwording is available.
1756 if (HotwordService::IsExperimentalHotwordingEnabled() &&
1757 authenticated
&& always_on
) {
1758 std::string user_display_name
= signin
->GetAuthenticatedUsername();
1759 DCHECK(!user_display_name
.empty());
1760 base::string16 audio_history_state
=
1761 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED
,
1762 base::ASCIIToUTF16(user_display_name
));
1763 HotwordService
* hotword_service
=
1764 HotwordServiceFactory::GetForProfile(profile
);
1765 if (hotword_service
) {
1766 hotword_service
->GetAudioHistoryHandler()->GetAudioHistoryEnabled(
1768 &BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible
,
1769 weak_ptr_factory_
.GetWeakPtr(),
1770 audio_history_state
));
1775 web_ui()->CallJavascriptFunction(function_name
);
1777 base::string16 hotword_help_url
=
1778 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL
);
1779 base::StringValue
error_message(l10n_util::GetStringUTF16(error
));
1780 if (error
== IDS_HOTWORD_GENERIC_ERROR_MESSAGE
) {
1781 error_message
= base::StringValue(
1782 l10n_util::GetStringFUTF16(error
, hotword_help_url
));
1784 web_ui()->CallJavascriptFunction(function_name
, error_message
);
1789 void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
1790 const base::ListValue
* args
) {
1791 Profile
* profile
= Profile::FromWebUI(web_ui());
1793 bool retrain
= false;
1794 bool success
= args
->GetBoolean(0, &retrain
);
1796 HotwordService::LaunchMode launch_mode
=
1797 HotwordService::HOTWORD_AND_AUDIO_HISTORY
;
1800 DCHECK(profile
->GetPrefs()->GetBoolean(
1801 prefs::kHotwordAlwaysOnSearchEnabled
));
1802 DCHECK(profile
->GetPrefs()->GetBoolean(
1803 prefs::kHotwordAudioLoggingEnabled
));
1805 launch_mode
= HotwordService::RETRAIN
;
1806 } else if (profile
->GetPrefs()->GetBoolean(
1807 prefs::kHotwordAudioLoggingEnabled
)) {
1808 DCHECK(!profile
->GetPrefs()->GetBoolean(
1809 prefs::kHotwordAlwaysOnSearchEnabled
));
1810 launch_mode
= HotwordService::HOTWORD_ONLY
;
1812 DCHECK(!profile
->GetPrefs()->GetBoolean(
1813 prefs::kHotwordAlwaysOnSearchEnabled
));
1816 HotwordService
* hotword_service
=
1817 HotwordServiceFactory::GetForProfile(profile
);
1818 if (!hotword_service
)
1821 hotword_service
->LaunchHotwordAudioVerificationApp(launch_mode
);
1824 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1825 const base::ListValue
* args
) {
1826 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1829 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1830 const base::ListValue
* args
) {
1831 SetupExtensionControlledIndicators();
1834 #if defined(OS_CHROMEOS)
1835 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1836 const base::ListValue
* args
) {
1837 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1840 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1841 const base::ListValue
* args
) {
1842 bool enabled
= false;
1843 args
->GetBoolean(0, &enabled
);
1845 chromeos::accessibility::EnableVirtualKeyboard(enabled
);
1848 void BrowserOptionsHandler::PerformFactoryResetRestart(
1849 const base::ListValue
* args
) {
1850 policy::BrowserPolicyConnectorChromeOS
* connector
=
1851 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1852 if (connector
->IsEnterpriseManaged())
1855 PrefService
* prefs
= g_browser_process
->local_state();
1856 prefs
->SetBoolean(prefs::kFactoryResetRequested
, true);
1857 prefs
->CommitPendingWrite();
1859 // Perform sign out. Current chrome process will then terminate, new one will
1860 // be launched (as if it was a restart).
1861 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1864 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1865 PrefService
* pref_service
= g_browser_process
->local_state();
1866 base::FundamentalValue
virtual_keyboard_enabled(
1867 pref_service
->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled
));
1868 web_ui()->CallJavascriptFunction(
1869 "BrowserOptions.setVirtualKeyboardCheckboxState",
1870 virtual_keyboard_enabled
);
1874 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1875 #if defined(GOOGLE_CHROME_BUILD)
1876 // Don't show the reporting setting if we are in the guest mode.
1877 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1878 base::FundamentalValue
visible(false);
1879 web_ui()->CallJavascriptFunction(
1880 "BrowserOptions.setMetricsReportingSettingVisibility", visible
);
1885 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1886 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1888 base::DictionaryValue dict
;
1889 dict
.SetInteger("value",
1890 pref_service
->GetInteger(prefs::kNetworkPredictionOptions
));
1891 dict
.SetBoolean("disabled",
1892 !pref_service
->IsUserModifiablePreference(
1893 prefs::kNetworkPredictionOptions
));
1895 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1899 void BrowserOptionsHandler::SetupFontSizeSelector() {
1900 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1901 const PrefService::Preference
* default_font_size
=
1902 pref_service
->FindPreference(prefs::kWebKitDefaultFontSize
);
1903 const PrefService::Preference
* default_fixed_font_size
=
1904 pref_service
->FindPreference(prefs::kWebKitDefaultFixedFontSize
);
1906 base::DictionaryValue dict
;
1907 dict
.SetInteger("value",
1908 pref_service
->GetInteger(prefs::kWebKitDefaultFontSize
));
1910 // The font size control displays the value of the default font size, but
1911 // setting it alters both the default font size and the default fixed font
1912 // size. So it must be disabled when either of those prefs is not user
1914 dict
.SetBoolean("disabled",
1915 !default_font_size
->IsUserModifiable() ||
1916 !default_fixed_font_size
->IsUserModifiable());
1918 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1919 // adapted to consider two prefs. It may be better to refactor
1920 // CreateValueForPref so it can be called from here.
1921 if (default_font_size
->IsManaged() || default_fixed_font_size
->IsManaged()) {
1922 dict
.SetString("controlledBy", "policy");
1923 } else if (default_font_size
->IsExtensionControlled() ||
1924 default_fixed_font_size
->IsExtensionControlled()) {
1925 dict
.SetString("controlledBy", "extension");
1928 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict
);
1931 void BrowserOptionsHandler::SetupPageZoomSelector() {
1932 double default_zoom_level
=
1933 content::HostZoomMap::GetDefaultForBrowserContext(
1934 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel();
1935 double default_zoom_factor
=
1936 content::ZoomLevelToZoomFactor(default_zoom_level
);
1938 // Generate a vector of zoom factors from an array of known presets along with
1939 // the default factor added if necessary.
1940 std::vector
<double> zoom_factors
=
1941 ui_zoom::PageZoom::PresetZoomFactors(default_zoom_factor
);
1943 // Iterate through the zoom factors and and build the contents of the
1944 // selector that will be sent to the javascript handler.
1945 // Each item in the list has the following parameters:
1946 // 1. Title (string).
1947 // 2. Value (double).
1948 // 3. Is selected? (bool).
1949 base::ListValue zoom_factors_value
;
1950 for (std::vector
<double>::const_iterator i
= zoom_factors
.begin();
1951 i
!= zoom_factors
.end(); ++i
) {
1952 base::ListValue
* option
= new base::ListValue();
1954 int percent
= static_cast<int>(factor
* 100 + 0.5);
1955 option
->Append(new base::StringValue(
1956 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT
, percent
)));
1957 option
->Append(new base::FundamentalValue(factor
));
1958 bool selected
= content::ZoomValuesEqual(factor
, default_zoom_factor
);
1959 option
->Append(new base::FundamentalValue(selected
));
1960 zoom_factors_value
.Append(option
);
1963 web_ui()->CallJavascriptFunction(
1964 "BrowserOptions.setupPageZoomSelector", zoom_factors_value
);
1967 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1968 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1969 // We show the button if the user has any auto-open file types registered.
1970 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1971 web_ui()->GetWebContents()->GetBrowserContext());
1972 bool display
= manager
&&
1973 DownloadPrefs::FromDownloadManager(manager
)->IsAutoOpenUsed();
1974 base::FundamentalValue
value(display
);
1975 web_ui()->CallJavascriptFunction(
1976 "BrowserOptions.setAutoOpenFileTypesDisplayed", value
);
1979 void BrowserOptionsHandler::SetupProxySettingsSection() {
1980 #if !defined(OS_CHROMEOS)
1981 // Disable the button if proxy settings are managed by a sysadmin, overridden
1982 // by an extension, or the browser is running in Windows Ash (on Windows the
1983 // proxy settings dialog will open on the Windows desktop and be invisible
1984 // to a user in Ash).
1985 bool is_win_ash
= false;
1987 chrome::HostDesktopType desktop_type
= helper::GetDesktopType(web_ui());
1988 is_win_ash
= (desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
);
1990 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1991 const PrefService::Preference
* proxy_config
=
1992 pref_service
->FindPreference(prefs::kProxy
);
1993 bool is_extension_controlled
= (proxy_config
&&
1994 proxy_config
->IsExtensionControlled());
1996 base::FundamentalValue
disabled(is_win_ash
|| (proxy_config
&&
1997 !proxy_config
->IsUserModifiable()));
1998 base::FundamentalValue
extension_controlled(is_extension_controlled
);
1999 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
2000 disabled
, extension_controlled
);
2003 SetupExtensionControlledIndicators();
2004 #endif // defined(OS_WIN)
2006 #endif // !defined(OS_CHROMEOS)
2009 void BrowserOptionsHandler::SetupManageCertificatesSection() {
2011 // Disable the button if the settings page is displayed in Windows Ash,
2012 // otherwise the proxy settings dialog will open on the Windows desktop and
2013 // be invisible to a user in Ash.
2014 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH
) {
2015 base::FundamentalValue
enabled(false);
2016 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
2019 #endif // defined(OS_WIN)
2022 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
2023 bool has_users
= !Profile::FromWebUI(web_ui())->
2024 GetPrefs()->GetDictionary(prefs::kSupervisedUsers
)->empty();
2025 base::FundamentalValue
has_users_value(has_users
);
2026 web_ui()->CallJavascriptFunction(
2027 "BrowserOptions.updateManagesSupervisedUsers",
2031 void BrowserOptionsHandler::SetupEasyUnlock() {
2032 base::FundamentalValue
is_enabled(
2033 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsEnabled());
2034 web_ui()->CallJavascriptFunction(
2035 "BrowserOptions.updateEasyUnlock",
2039 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
2041 base::DictionaryValue extension_controlled
;
2043 // Check if an extension is overriding the Search Engine.
2044 const extensions::Extension
* extension
=
2045 extensions::GetExtensionOverridingSearchEngine(
2046 Profile::FromWebUI(web_ui()));
2047 AppendExtensionData("searchEngine", extension
, &extension_controlled
);
2049 // Check if an extension is overriding the Home page.
2050 extension
= extensions::GetExtensionOverridingHomepage(
2051 Profile::FromWebUI(web_ui()));
2052 AppendExtensionData("homePage", extension
, &extension_controlled
);
2054 // Check if an extension is overriding the Startup pages.
2055 extension
= extensions::GetExtensionOverridingStartupPages(
2056 Profile::FromWebUI(web_ui()));
2057 AppendExtensionData("startUpPage", extension
, &extension_controlled
);
2059 // Check if an extension is overriding the NTP page.
2060 GURL
ntp_url(chrome::kChromeUINewTabURL
);
2063 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
2065 web_ui()->GetWebContents()->GetBrowserContext(),
2067 if (ntp_url
.SchemeIs("chrome-extension")) {
2068 using extensions::ExtensionRegistry
;
2069 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
2070 Profile::FromWebUI(web_ui()));
2071 extension
= registry
->GetExtensionById(ntp_url
.host(),
2072 ExtensionRegistry::ENABLED
);
2074 AppendExtensionData("newTabPage", extension
, &extension_controlled
);
2076 // Check if an extension is overwriting the proxy setting.
2077 extension
= extensions::GetExtensionOverridingProxy(
2078 Profile::FromWebUI(web_ui()));
2079 AppendExtensionData("proxy", extension
, &extension_controlled
);
2081 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
2082 extension_controlled
);
2083 #endif // defined(OS_WIN)
2086 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
2087 // This function does not work for ChromeOS and non-official builds.
2088 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
2089 bool checked
= ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
2090 bool disabled
= !IsMetricsReportingUserChangable();
2092 SetMetricsReportingCheckbox(checked
, disabled
);
2096 void BrowserOptionsHandler::HandleMetricsReportingChange(
2097 const base::ListValue
* args
) {
2099 if (!args
->GetBoolean(0, &enable
))
2102 InitiateMetricsReportingChange(
2104 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback
,
2105 base::Unretained(this)));
2108 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled
) {
2109 SetMetricsReportingCheckbox(enabled
, !IsMetricsReportingUserChangable());
2112 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked
,
2114 web_ui()->CallJavascriptFunction(
2115 "BrowserOptions.setMetricsReportingCheckboxState",
2116 base::FundamentalValue(checked
),
2117 base::FundamentalValue(disabled
));
2120 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace
& ns
,
2121 const policy::PolicyMap
& previous
,
2122 const policy::PolicyMap
& current
) {
2123 std::set
<std::string
> different_keys
;
2124 current
.GetDifferingKeys(previous
, &different_keys
);
2125 if (ContainsKey(different_keys
, policy::key::kMetricsReportingEnabled
))
2126 SetupMetricsReportingCheckbox();
2129 } // namespace options