1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
10 #include "apps/app_window.h"
11 #include "apps/app_window_registry.h"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/environment.h"
16 #include "base/memory/singleton.h"
17 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram.h"
19 #include "base/path_service.h"
20 #include "base/prefs/pref_service.h"
21 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/stl_util.h"
23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/utf_string_conversions.h"
25 #include "base/value_conversions.h"
26 #include "base/values.h"
27 #include "chrome/browser/auto_launch_trial.h"
28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/chrome_page_zoom.h"
31 #include "chrome/browser/custom_home_pages_table_model.h"
32 #include "chrome/browser/download/download_prefs.h"
33 #include "chrome/browser/gpu/gpu_mode_manager.h"
34 #include "chrome/browser/lifetime/application_lifetime.h"
35 #include "chrome/browser/net/prediction_options.h"
36 #include "chrome/browser/prefs/session_startup_pref.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
38 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
41 #include "chrome/browser/profiles/profile_info_cache.h"
42 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/profiles/profile_metrics.h"
44 #include "chrome/browser/profiles/profile_shortcut_manager.h"
45 #include "chrome/browser/profiles/profile_window.h"
46 #include "chrome/browser/profiles/profiles_state.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 "chromeos/chromeos_switches.h"
70 #include "components/search_engines/template_url.h"
71 #include "components/search_engines/template_url_service.h"
72 #include "components/signin/core/browser/signin_manager.h"
73 #include "components/signin/core/common/profile_management_switches.h"
74 #include "components/user_manager/user_type.h"
75 #include "content/public/browser/browser_thread.h"
76 #include "content/public/browser/download_manager.h"
77 #include "content/public/browser/navigation_controller.h"
78 #include "content/public/browser/notification_details.h"
79 #include "content/public/browser/notification_service.h"
80 #include "content/public/browser/notification_source.h"
81 #include "content/public/browser/notification_types.h"
82 #include "content/public/browser/url_data_source.h"
83 #include "content/public/browser/user_metrics.h"
84 #include "content/public/browser/web_contents.h"
85 #include "content/public/common/page_zoom.h"
86 #include "extensions/browser/extension_registry.h"
87 #include "google_apis/gaia/gaia_auth_util.h"
88 #include "google_apis/gaia/google_service_auth_error.h"
89 #include "grit/chromium_strings.h"
90 #include "grit/generated_resources.h"
91 #include "grit/locale_settings.h"
92 #include "grit/theme_resources.h"
93 #include "third_party/skia/include/core/SkBitmap.h"
94 #include "ui/base/l10n/l10n_util.h"
95 #include "ui/base/webui/web_ui_util.h"
97 #if !defined(OS_CHROMEOS)
98 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
101 #if defined(OS_CHROMEOS)
102 #include "ash/ash_switches.h"
103 #include "ash/desktop_background/user_wallpaper_delegate.h"
104 #include "ash/magnifier/magnifier_constants.h"
105 #include "ash/shell.h"
106 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
107 #include "chrome/browser/chromeos/chromeos_utils.h"
108 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
109 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
110 #include "chrome/browser/chromeos/profiles/profile_helper.h"
111 #include "chrome/browser/chromeos/reset/metrics.h"
112 #include "chrome/browser/chromeos/settings/cros_settings.h"
113 #include "chrome/browser/chromeos/settings/device_settings_service.h"
114 #include "chrome/browser/chromeos/system/timezone_util.h"
115 #include "chrome/browser/policy/profile_policy_connector.h"
116 #include "chrome/browser/policy/profile_policy_connector_factory.h"
117 #include "chrome/browser/ui/browser_window.h"
118 #include "chromeos/dbus/dbus_thread_manager.h"
119 #include "chromeos/dbus/power_manager_client.h"
120 #include "components/policy/core/common/policy_map.h"
121 #include "components/policy/core/common/policy_namespace.h"
122 #include "components/policy/core/common/policy_service.h"
123 #include "components/user_manager/user.h"
124 #include "components/user_manager/user_manager.h"
125 #include "policy/policy_constants.h"
126 #include "policy/proto/device_management_backend.pb.h"
127 #include "ui/gfx/image/image_skia.h"
128 #endif // defined(OS_CHROMEOS)
131 #include "chrome/browser/extensions/settings_api_helpers.h"
132 #include "chrome/installer/util/auto_launch_util.h"
133 #include "content/public/browser/browser_url_handler.h"
134 #endif // defined(OS_WIN)
136 #if defined(ENABLE_SERVICE_DISCOVERY)
137 #include "chrome/browser/local_discovery/privet_notifications.h"
140 using base::UserMetricsAction
;
141 using content::BrowserContext
;
142 using content::BrowserThread
;
143 using content::DownloadManager
;
144 using content::OpenURLParams
;
145 using content::Referrer
;
146 using extensions::Extension
;
147 using extensions::ExtensionRegistry
;
152 void AppendExtensionData(const std::string
& key
,
153 const Extension
* extension
,
154 base::DictionaryValue
* dict
) {
155 scoped_ptr
<base::DictionaryValue
> details(new base::DictionaryValue
);
156 details
->SetString("id", extension
? extension
->id() : std::string());
157 details
->SetString("name", extension
? extension
->name() : std::string());
158 dict
->Set(key
, details
.release());
160 #endif // defined(OS_WIN)
166 BrowserOptionsHandler::BrowserOptionsHandler()
167 : page_initialized_(false),
168 template_url_service_(NULL
),
169 cloud_print_mdns_ui_enabled_(false),
170 signin_observer_(this),
171 weak_ptr_factory_(this) {
172 default_browser_worker_
= new ShellIntegration::DefaultBrowserWorker(this);
174 #if defined(ENABLE_SERVICE_DISCOVERY)
175 cloud_print_mdns_ui_enabled_
= true;
176 #endif // defined(ENABLE_SERVICE_DISCOVERY)
179 BrowserOptionsHandler::~BrowserOptionsHandler() {
180 ProfileSyncService
* sync_service(ProfileSyncServiceFactory::
181 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
183 sync_service
->RemoveObserver(this);
185 if (default_browser_worker_
.get())
186 default_browser_worker_
->ObserverDestroyed();
187 if (template_url_service_
)
188 template_url_service_
->RemoveObserver(this);
189 // There may be pending file dialogs, we need to tell them that we've gone
190 // away so they don't try and call back to us.
191 if (select_folder_dialog_
.get())
192 select_folder_dialog_
->ListenerDestroyed();
195 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue
* values
) {
198 const bool using_new_profiles_ui
= switches::IsNewAvatarMenu();
200 #if defined(OS_CHROMEOS)
201 const int device_type_resource_id
= chromeos::GetChromeDeviceTypeResourceId();
203 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices.
204 const int device_type_resource_id
= IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE
;
205 #endif // defined(OS_CHROMEOS)
207 static OptionsStringResource resources
[] = {
208 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT
},
209 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY
},
210 { "advancedSectionTitleCertificates",
211 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES
},
212 { "advancedSectionTitleContent",
213 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT
},
214 { "advancedSectionTitleLanguages",
215 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES
},
216 { "advancedSectionTitleNetwork",
217 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK
},
218 { "advancedSectionTitlePrivacy",
219 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY
},
220 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE
},
221 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN
},
222 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY
},
223 { "autoOpenFileTypesResetToDefault",
224 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT
},
225 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE
},
226 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON
},
227 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL
},
228 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL
},
229 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES
},
230 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL
},
231 #if defined(OS_CHROMEOS)
232 { "disableGData", IDS_OPTIONS_DISABLE_GDATA
},
234 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES
},
235 #if defined(OS_CHROMEOS)
237 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL
},
239 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK
},
240 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT
},
241 { "doNotTrackConfirmEnable",
242 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE
},
243 { "doNotTrackConfirmDisable",
244 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE
},
245 { "downloadLocationAskForSaveLocation",
246 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION
},
247 { "downloadLocationBrowseTitle",
248 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
},
249 { "downloadLocationChangeButton",
250 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON
},
251 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME
},
252 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING
},
253 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART
},
254 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION
,
255 device_type_resource_id
},
256 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE
},
257 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON
},
258 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO
,
259 device_type_resource_id
},
260 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED
},
261 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE
},
262 { "fontSettingsCustomizeFontsButton",
263 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON
},
264 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM
},
265 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE
},
266 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM
},
267 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL
},
268 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE
},
269 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL
},
270 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS
},
271 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP
},
272 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
273 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB
},
274 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL
},
275 { "hotwordAlwaysOnSearchEnable", IDS_HOTWORD_ALWAYS_ON_SEARCH_PREF_CHKBOX
},
276 { "hotwordAudioHistoryEnable", IDS_HOTWORD_AUDIO_HISTORY_PREF_CHKBOX
},
277 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX
},
278 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE
},
279 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE
},
280 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION
},
281 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE
},
282 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON
},
283 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE
},
284 { "languageAndSpellCheckSettingsButton",
285 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS
},
286 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF
},
287 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK
},
288 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES
},
289 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK
},
290 { "networkPredictionEnabledDescription",
291 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
},
292 { "passwordsAndAutofillGroupName",
293 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME
},
294 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE
},
295 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON
},
296 { "privacyContentSettingsButton",
297 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON
},
298 { "profilesCreate", using_new_profiles_ui
?
299 IDS_NEW_PROFILES_CREATE_BUTTON_LABEL
:
300 IDS_PROFILES_CREATE_BUTTON_LABEL
},
301 { "profilesDelete", using_new_profiles_ui
?
302 IDS_NEW_PROFILES_DELETE_BUTTON_LABEL
:
303 IDS_PROFILES_DELETE_BUTTON_LABEL
},
304 { "profilesDeleteSingle", using_new_profiles_ui
?
305 IDS_NEW_PROFILES_DELETE_SINGLE_BUTTON_LABEL
:
306 IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL
},
307 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT
},
308 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL
},
309 { "profilesSupervisedDashboardTip",
310 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP
},
311 #if defined(ENABLE_SETTINGS_APP)
312 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL
},
314 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL
},
315 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
317 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON
},
318 { "resetProfileSettingsDescription",
319 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION
},
320 { "resetProfileSettingsSectionTitle",
321 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE
},
322 { "safeBrowsingEnableProtection",
323 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION
},
324 { "safeBrowsingEnableExtendedReporting",
325 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING
},
326 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME
},
327 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME
},
328 { "sectionTitleUsers", using_new_profiles_ui
?
329 IDS_NEW_PROFILES_OPTIONS_GROUP_NAME
:
330 IDS_PROFILES_OPTIONS_GROUP_NAME
},
331 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME
},
332 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME
},
333 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME
},
334 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME
},
335 { "sectionTitleVoice", IDS_OPTIONS_VOICE_GROUP_NAME
},
336 { "settingsTitle", IDS_SETTINGS_TITLE
},
337 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
},
338 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT
},
339 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE
},
340 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE
},
341 { "spellingPref", IDS_OPTIONS_SPELLING_PREF
},
342 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION
},
343 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES
},
344 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB
},
345 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES
},
346 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF
},
347 { "supervisedUserLabel", IDS_PROFILES_LIST_SUPERVISED_USER_LABEL
},
348 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS
},
349 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL
},
350 { "themesGallery", IDS_THEMES_GALLERY_BUTTON
},
351 { "themesGalleryURL", IDS_THEMES_GALLERY_URL
},
352 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF
},
353 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR
},
354 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
355 { "translateEnableTranslate",
356 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE
},
357 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
358 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS
},
359 { "themesNativeButton", IDS_THEMES_GTK_BUTTON
},
360 { "themesSetClassic", IDS_THEMES_SET_CLASSIC
},
362 { "themes", IDS_THEMES_GROUP_NAME
},
364 { "themesReset", IDS_THEMES_RESET_BUTTON
},
365 #if defined(OS_CHROMEOS)
366 { "accessibilityExplanation",
367 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION
},
368 { "accessibilitySettings",
369 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS
},
370 { "accessibilityHighContrast",
371 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION
},
372 { "accessibilityScreenMagnifier",
373 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION
},
374 { "accessibilityTapDragging",
375 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION
},
376 { "accessibilityScreenMagnifierOff",
377 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF
},
378 { "accessibilityScreenMagnifierFull",
379 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
},
380 { "accessibilityScreenMagnifierPartial",
381 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
},
382 { "accessibilityLargeCursor",
383 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION
},
384 { "accessibilityStickyKeys",
385 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION
},
386 { "accessibilitySpokenFeedback",
387 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION
},
388 { "accessibilityTitle",
389 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY
},
390 { "accessibilityVirtualKeyboard",
391 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION
},
392 { "accessibilityAlwaysShowMenu",
393 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU
},
394 { "accessibilityAutoclick",
395 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION
},
396 { "accessibilityAutoclickDropdown",
397 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION
},
398 { "autoclickDelayExtremelyShort",
399 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT
},
400 { "autoclickDelayVeryShort",
401 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT
},
402 { "autoclickDelayShort",
403 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT
},
404 { "autoclickDelayLong",
405 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG
},
406 { "autoclickDelayVeryLong",
407 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG
},
408 { "consumerManagementDescription",
409 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION
},
410 { "consumerManagementEnrollButton",
411 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON
},
412 { "consumerManagementUnenrollButton",
413 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON
},
414 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE
},
415 { "enableContentProtectionAttestation",
416 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION
},
417 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING
},
418 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET
},
419 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON
},
420 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON
},
421 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING
},
422 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL
},
423 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE
},
424 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION
},
425 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME
},
426 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION
},
427 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION
},
428 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION
},
429 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION
},
430 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX
},
431 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE
},
432 { "keyboardSettingsButtonTitle",
433 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE
},
434 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE
},
435 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES
},
436 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME
},
437 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL
},
438 { "syncOverview", IDS_SYNC_OVERVIEW
},
439 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
440 { "thirdPartyImeConfirmEnable", IDS_OK
},
441 { "thirdPartyImeConfirmDisable", IDS_CANCEL
},
442 { "thirdPartyImeConfirmMessage",
443 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE
},
444 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION
},
445 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION
},
447 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
},
449 #if defined(OS_CHROMEOS) && defined(USE_ASH)
450 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON
},
452 { "advancedSectionTitleSystem",
453 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM
},
454 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
455 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE
},
457 #if !defined(OS_CHROMEOS)
459 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE
},
460 { "gpuModeResetRestart",
461 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART
},
462 // Strings with product-name substitutions.
463 { "syncOverview", IDS_SYNC_OVERVIEW
, IDS_PRODUCT_NAME
},
464 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
466 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
467 IDS_SHORT_PRODUCT_NAME
},
468 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
470 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
,
472 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT
},
473 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT
},
474 #if defined(OS_CHROMEOS)
475 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION
,
476 IDS_SHORT_PRODUCT_NAME
},
478 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
479 IDS_SHORT_PRODUCT_NAME
},
480 #if defined(ENABLE_SERVICE_DISCOVERY)
481 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON
},
482 { "cloudPrintEnableNotificationsLabel",
483 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL
},
487 #if defined(ENABLE_SETTINGS_APP)
488 static OptionsStringResource app_resources
[] = {
489 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW
},
490 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
491 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
492 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
493 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
494 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
495 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
496 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
497 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
499 base::DictionaryValue
* app_values
= NULL
;
500 CHECK(values
->GetDictionary(kSettingsAppKey
, &app_values
));
501 RegisterStrings(app_values
, app_resources
, arraysize(app_resources
));
504 RegisterStrings(values
, resources
, arraysize(resources
));
505 RegisterTitle(values
, "doNotTrackConfirmOverlay",
506 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE
);
507 RegisterTitle(values
, "spellingConfirmOverlay",
508 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE
);
509 #if defined(ENABLE_FULL_PRINTING)
510 RegisterCloudPrintValues(values
);
513 values
->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL
);
514 base::string16 omnibox_url
= base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL
);
516 "defaultSearchGroupLabel",
517 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION
, omnibox_url
));
518 values
->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL
);
519 RegisterTitle(values
, "hotwordConfirmOverlay",
520 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE
);
522 #if defined(OS_CHROMEOS)
523 Profile
* profile
= Profile::FromWebUI(web_ui());
524 std::string username
= profile
->GetProfileName();
525 if (username
.empty()) {
526 user_manager::User
* user
=
527 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
528 if (user
&& (user
->GetType() != user_manager::USER_TYPE_GUEST
))
529 username
= user
->email();
532 if (!username
.empty())
533 username
= gaia::SanitizeEmail(gaia::CanonicalizeEmail(username
));
535 values
->SetString("username", username
);
538 // Pass along sync status early so it will be available during page init.
539 values
->Set("syncData", GetSyncStateDictionary().release());
541 // The Reset Profile Settings feature makes no sense for an off-the-record
542 // profile (e.g. in Guest mode on Chrome OS), so hide it.
543 values
->SetBoolean("enableResetProfileSettings",
544 !Profile::FromWebUI(web_ui())->IsOffTheRecord());
546 values
->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL
);
547 values
->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL
);
549 #if !defined(OS_CHROMEOS)
550 PrefService
* pref_service
= g_browser_process
->local_state();
551 values
->SetBoolean("metricsReportingEnabledAtStart", pref_service
->GetBoolean(
552 prefs::kMetricsReportingEnabled
));
555 #if defined(OS_CHROMEOS)
556 // TODO(pastarmovj): replace this with a call to the CrosSettings list
557 // handling functionality to come.
558 values
->Set("timezoneList", chromeos::system::GetTimezoneList().release());
560 values
->SetString("accessibilityLearnMoreURL",
561 chrome::kChromeAccessibilityHelpURL
);
563 std::string settings_url
= std::string("chrome-extension://") +
564 extension_misc::kChromeVoxExtensionId
+
565 chrome::kChromeAccessibilitySettingsURL
;
567 values
->SetString("accessibilitySettingsURL",
570 values
->SetString("contentProtectionAttestationLearnMoreURL",
571 chrome::kAttestationForContentProtectionLearnMoreURL
);
573 // Creates magnifierList.
574 scoped_ptr
<base::ListValue
> magnifier_list(new base::ListValue
);
576 scoped_ptr
<base::ListValue
> option_full(new base::ListValue
);
577 option_full
->AppendInteger(ash::MAGNIFIER_FULL
);
578 option_full
->AppendString(l10n_util::GetStringUTF16(
579 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
));
580 magnifier_list
->Append(option_full
.release());
582 scoped_ptr
<base::ListValue
> option_partial(new base::ListValue
);
583 option_partial
->AppendInteger(ash::MAGNIFIER_PARTIAL
);
584 option_partial
->Append(new base::StringValue(l10n_util::GetStringUTF16(
585 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
)));
586 magnifier_list
->Append(option_partial
.release());
588 values
->Set("magnifierList", magnifier_list
.release());
591 #if defined(OS_MACOSX)
592 values
->SetString("macPasswordsWarning",
593 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING
));
594 values
->SetBoolean("multiple_profiles",
595 g_browser_process
->profile_manager()->GetNumberOfProfiles() > 1);
598 if (ShouldShowMultiProfilesUserList())
599 values
->Set("profilesInfo", GetProfilesInfoList().release());
601 values
->SetBoolean("profileIsSupervised",
602 Profile::FromWebUI(web_ui())->IsSupervised());
604 #if !defined(OS_CHROMEOS)
607 g_browser_process
->gpu_mode_manager()->initial_gpu_mode_pref());
610 #if defined(ENABLE_SERVICE_DISCOVERY)
611 values
->SetBoolean("cloudPrintHideNotificationsCheckbox",
612 !local_discovery::PrivetNotificationService::IsEnabled());
615 values
->SetBoolean("cloudPrintShowMDnsOptions",
616 cloud_print_mdns_ui_enabled_
);
618 values
->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL
);
620 values
->SetString("languagesLearnMoreURL",
621 chrome::kLanguageSettingsLearnMoreUrl
);
625 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
626 values
->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl
);
628 #if defined(OS_CHROMEOS)
630 "consumerManagementEnabled",
631 CommandLine::ForCurrentProcess()->HasSwitch(
632 chromeos::switches::kEnableConsumerManagement
));
634 const enterprise_management::PolicyData
* policy_data
=
635 chromeos::DeviceSettingsService::Get()->policy_data();
637 "consumerManagementEnrolled",
639 policy_data
->management_mode() ==
640 enterprise_management::PolicyData::CONSUMER_MANAGED
);
642 RegisterTitle(values
, "thirdPartyImeConfirmOverlay",
643 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE
);
646 values
->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
648 values
->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
650 values
->SetBoolean("websiteSettingsManagerEnabled",
651 CommandLine::ForCurrentProcess()->HasSwitch(
652 switches::kEnableWebsiteSettingsManager
));
654 values
->SetBoolean("usingNewProfilesUI", using_new_profiles_ui
);
657 #if defined(ENABLE_FULL_PRINTING)
658 void BrowserOptionsHandler::RegisterCloudPrintValues(
659 base::DictionaryValue
* values
) {
660 values
->SetString("cloudPrintOptionLabel",
661 l10n_util::GetStringFUTF16(
662 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL
,
663 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
665 #endif // defined(ENABLE_FULL_PRINTING)
667 void BrowserOptionsHandler::RegisterMessages() {
668 web_ui()->RegisterMessageCallback(
669 "becomeDefaultBrowser",
670 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser
,
671 base::Unretained(this)));
672 web_ui()->RegisterMessageCallback(
673 "setDefaultSearchEngine",
674 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine
,
675 base::Unretained(this)));
676 web_ui()->RegisterMessageCallback(
678 base::Bind(&BrowserOptionsHandler::DeleteProfile
,
679 base::Unretained(this)));
680 web_ui()->RegisterMessageCallback(
682 base::Bind(&BrowserOptionsHandler::ThemesReset
,
683 base::Unretained(this)));
684 web_ui()->RegisterMessageCallback(
685 "requestProfilesInfo",
686 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo
,
687 base::Unretained(this)));
688 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
689 web_ui()->RegisterMessageCallback(
691 base::Bind(&BrowserOptionsHandler::ThemesSetNative
,
692 base::Unretained(this)));
694 web_ui()->RegisterMessageCallback(
695 "selectDownloadLocation",
696 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation
,
697 base::Unretained(this)));
698 web_ui()->RegisterMessageCallback(
699 "autoOpenFileTypesAction",
700 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton
,
701 base::Unretained(this)));
702 web_ui()->RegisterMessageCallback(
703 "defaultFontSizeAction",
704 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize
,
705 base::Unretained(this)));
706 web_ui()->RegisterMessageCallback(
707 "defaultZoomFactorAction",
708 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor
,
709 base::Unretained(this)));
710 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
711 web_ui()->RegisterMessageCallback(
712 "showManageSSLCertificates",
713 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates
,
714 base::Unretained(this)));
716 #if defined(OS_CHROMEOS)
717 web_ui()->RegisterMessageCallback(
718 "openWallpaperManager",
719 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager
,
720 base::Unretained(this)));
721 web_ui()->RegisterMessageCallback(
722 "virtualKeyboardChange",
723 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback
,
724 base::Unretained(this)));
725 web_ui()->RegisterMessageCallback(
726 "onPowerwashDialogShow",
727 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow
,
728 base::Unretained(this)));
729 web_ui()->RegisterMessageCallback(
730 "performFactoryResetRestart",
731 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart
,
732 base::Unretained(this)));
734 web_ui()->RegisterMessageCallback(
736 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser
,
737 base::Unretained(this)));
738 web_ui()->RegisterMessageCallback(
739 "showNetworkProxySettings",
740 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings
,
741 base::Unretained(this)));
742 #endif // defined(OS_CHROMEOS)
744 #if defined(ENABLE_SERVICE_DISCOVERY)
745 if (cloud_print_mdns_ui_enabled_
) {
746 web_ui()->RegisterMessageCallback(
747 "showCloudPrintDevicesPage",
748 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage
,
749 base::Unretained(this)));
752 web_ui()->RegisterMessageCallback(
753 "requestHotwordAvailable",
754 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable
,
755 base::Unretained(this)));
757 web_ui()->RegisterMessageCallback(
758 "launchEasyUnlockSetup",
759 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup
,
760 base::Unretained(this)));
762 web_ui()->RegisterMessageCallback(
763 "refreshExtensionControlIndicators",
765 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators
,
766 base::Unretained(this)));
767 #endif // defined(OS_WIN)
770 void BrowserOptionsHandler::Uninitialize() {
771 registrar_
.RemoveAll();
773 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
777 void BrowserOptionsHandler::OnStateChanged() {
781 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string
& username
,
782 const std::string
& password
) {
786 void BrowserOptionsHandler::GoogleSignedOut(const std::string
& username
) {
790 void BrowserOptionsHandler::PageLoadStarted() {
791 page_initialized_
= false;
794 void BrowserOptionsHandler::InitializeHandler() {
795 Profile
* profile
= Profile::FromWebUI(web_ui());
796 PrefService
* prefs
= profile
->GetPrefs();
798 ProfileSyncService
* sync_service(
799 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
));
800 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
801 // destruction is automatic.
803 sync_service
->AddObserver(this);
805 SigninManagerBase
* signin_manager(
806 SigninManagerFactory::GetInstance()->GetForProfile(profile
));
808 signin_observer_
.Add(signin_manager
);
810 // Create our favicon data source.
811 content::URLDataSource::Add(
812 profile
, new FaviconSource(profile
, FaviconSource::FAVICON
));
814 default_browser_policy_
.Init(
815 prefs::kDefaultBrowserSettingEnabled
,
816 g_browser_process
->local_state(),
817 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState
,
818 base::Unretained(this)));
820 registrar_
.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
,
821 content::NotificationService::AllSources());
822 #if defined(OS_CHROMEOS)
823 registrar_
.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
824 content::NotificationService::AllSources());
826 registrar_
.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED
,
827 content::Source
<ThemeService
>(
828 ThemeServiceFactory::GetForProfile(profile
)));
829 registrar_
.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
,
830 content::Source
<Profile
>(profile
));
831 AddTemplateUrlServiceObserver();
834 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
836 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
837 if (!command_line
.HasSwitch(switches::kUserDataDir
)) {
838 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
839 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch
,
840 weak_ptr_factory_
.GetWeakPtr(),
841 profile
->GetPath()));
845 auto_open_files_
.Init(
846 prefs::kDownloadExtensionsToOpen
, prefs
,
847 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes
,
848 base::Unretained(this)));
849 default_zoom_level_
.Init(
850 prefs::kDefaultZoomLevel
, prefs
,
851 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector
,
852 base::Unretained(this)));
853 profile_pref_registrar_
.Init(prefs
);
854 profile_pref_registrar_
.Add(
855 prefs::kNetworkPredictionOptions
,
856 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl
,
857 base::Unretained(this)));
858 profile_pref_registrar_
.Add(
859 prefs::kWebKitDefaultFontSize
,
860 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
861 base::Unretained(this)));
862 profile_pref_registrar_
.Add(
863 prefs::kWebKitDefaultFixedFontSize
,
864 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
865 base::Unretained(this)));
866 profile_pref_registrar_
.Add(
867 prefs::kSupervisedUsers
,
868 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers
,
869 base::Unretained(this)));
870 profile_pref_registrar_
.Add(
871 prefs::kSigninAllowed
,
872 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange
,
873 base::Unretained(this)));
874 profile_pref_registrar_
.Add(
875 prefs::kEasyUnlockPairing
,
876 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock
,
877 base::Unretained(this)));
880 profile_pref_registrar_
.Add(
881 prefs::kURLsToRestoreOnStartup
,
882 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
883 base::Unretained(this)));
884 profile_pref_registrar_
.Add(
886 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators
,
887 base::Unretained(this)));
888 #endif // defined(OS_WIN)
890 #if defined(OS_CHROMEOS)
891 if (!policy_registrar_
) {
892 policy_registrar_
.reset(new policy::PolicyChangeRegistrar(
893 policy::ProfilePolicyConnectorFactory::GetForProfile(profile
)->
895 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
, std::string())));
896 policy_registrar_
->Observe(
897 policy::key::kUserAvatarImage
,
898 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged
,
899 base::Unretained(this)));
900 policy_registrar_
->Observe(
901 policy::key::kWallpaperImage
,
902 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged
,
903 base::Unretained(this)));
905 #else // !defined(OS_CHROMEOS)
906 profile_pref_registrar_
.Add(
908 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection
,
909 base::Unretained(this)));
910 #endif // !defined(OS_CHROMEOS)
913 void BrowserOptionsHandler::InitializePage() {
914 page_initialized_
= true;
916 OnTemplateURLServiceChanged();
918 ObserveThemeChanged();
920 UpdateDefaultBrowserState();
922 SetupMetricsReportingSettingVisibility();
923 SetupNetworkPredictionControl();
924 SetupFontSizeSelector();
925 SetupPageZoomSelector();
926 SetupAutoOpenFileTypes();
927 SetupProxySettingsSection();
928 SetupManageCertificatesSection();
929 SetupManagingSupervisedUsers();
931 SetupExtensionControlledIndicators();
933 #if defined(OS_CHROMEOS)
934 SetupAccessibilityFeatures();
935 policy::BrowserPolicyConnectorChromeOS
* connector
=
936 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
937 if (!connector
->IsEnterpriseManaged() &&
938 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
939 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
940 web_ui()->CallJavascriptFunction(
941 "BrowserOptions.enableFactoryResetSection");
944 Profile
* profile
= Profile::FromWebUI(web_ui());
945 OnAccountPictureManagedChanged(
946 policy::ProfilePolicyConnectorFactory::GetForProfile(profile
)->
947 policy_service()->GetPolicies(
948 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
,
950 .Get(policy::key::kUserAvatarImage
));
952 OnWallpaperManagedChanged(
953 chromeos::WallpaperManager::Get()->IsPolicyControlled(
954 user_manager::UserManager::Get()->GetActiveUser()->email()));
959 void BrowserOptionsHandler::CheckAutoLaunch(
960 base::WeakPtr
<BrowserOptionsHandler
> weak_this
,
961 const base::FilePath
& profile_path
) {
963 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
965 // Auto-launch is not supported for secondary profiles yet.
966 if (profile_path
.BaseName().value() !=
967 base::ASCIIToUTF16(chrome::kInitialProfile
)) {
971 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
973 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
974 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback
,
976 auto_launch_trial::IsInAutoLaunchGroup(),
977 auto_launch_util::AutoStartRequested(
978 profile_path
.BaseName().value(),
979 true, // Window requested.
984 void BrowserOptionsHandler::CheckAutoLaunchCallback(
985 bool is_in_auto_launch_group
,
986 bool will_launch_at_login
) {
988 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
990 if (is_in_auto_launch_group
) {
991 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
992 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch
,
993 base::Unretained(this)));
995 base::FundamentalValue
enabled(will_launch_at_login
);
996 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1002 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1003 #if defined(OS_CHROMEOS)
1004 // We're always the default browser on ChromeOS.
1007 Profile
* profile
= Profile::FromWebUI(web_ui());
1008 return !profile
->IsGuestSession();
1012 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1013 #if defined(OS_CHROMEOS)
1014 // On Chrome OS we use different UI for multi-profiles.
1017 if (helper::GetDesktopType(web_ui()) != chrome::HOST_DESKTOP_TYPE_NATIVE
)
1019 Profile
* profile
= Profile::FromWebUI(web_ui());
1020 if (profile
->IsGuestSession())
1022 return profiles::IsMultipleProfilesEnabled();
1026 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1027 #if defined(OS_CHROMEOS)
1028 // ChromeOS handles guest-mode restrictions in a different manner.
1031 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1035 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1036 default_browser_worker_
->StartCheckIsDefault();
1039 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue
* args
) {
1040 // If the default browser setting is managed then we should not be able to
1041 // call this function.
1042 if (default_browser_policy_
.IsManaged())
1045 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1046 default_browser_worker_
->StartSetAsDefault();
1047 // Callback takes care of updating UI.
1049 // If the user attempted to make Chrome the default browser, then he/she
1050 // arguably wants to be notified when that changes.
1051 PrefService
* prefs
= Profile::FromWebUI(web_ui())->GetPrefs();
1052 prefs
->SetBoolean(prefs::kCheckDefaultBrowser
, true);
1055 int BrowserOptionsHandler::StatusStringIdForState(
1056 ShellIntegration::DefaultWebClientState state
) {
1057 if (state
== ShellIntegration::IS_DEFAULT
)
1058 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1059 if (state
== ShellIntegration::NOT_DEFAULT
)
1060 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1061 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1064 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1065 ShellIntegration::DefaultWebClientUIState state
) {
1066 int status_string_id
;
1068 if (state
== ShellIntegration::STATE_IS_DEFAULT
) {
1069 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1070 } else if (state
== ShellIntegration::STATE_NOT_DEFAULT
) {
1071 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1072 ShellIntegration::SET_DEFAULT_NOT_ALLOWED
) {
1073 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_SXS
;
1075 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1077 } else if (state
== ShellIntegration::STATE_UNKNOWN
) {
1078 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1080 return; // Still processing.
1083 SetDefaultBrowserUIString(status_string_id
);
1086 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1087 return true; // This is UI so we can allow it.
1090 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id
) {
1091 base::StringValue
status_string(
1092 l10n_util::GetStringFUTF16(status_string_id
,
1093 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)));
1095 base::FundamentalValue
is_default(
1096 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
);
1098 base::FundamentalValue
can_be_default(
1099 !default_browser_policy_
.IsManaged() &&
1100 (status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
||
1101 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
));
1103 web_ui()->CallJavascriptFunction(
1104 "BrowserOptions.updateDefaultBrowserState",
1105 status_string
, is_default
, can_be_default
);
1108 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1109 if (!template_url_service_
|| !template_url_service_
->loaded())
1112 const TemplateURL
* default_url
=
1113 template_url_service_
->GetDefaultSearchProvider();
1115 int default_index
= -1;
1116 base::ListValue search_engines
;
1117 TemplateURLService::TemplateURLVector
model_urls(
1118 template_url_service_
->GetTemplateURLs());
1119 for (size_t i
= 0; i
< model_urls
.size(); ++i
) {
1120 if (!model_urls
[i
]->ShowInDefaultList(
1121 template_url_service_
->search_terms_data()))
1124 base::DictionaryValue
* entry
= new base::DictionaryValue();
1125 entry
->SetString("name", model_urls
[i
]->short_name());
1126 entry
->SetInteger("index", i
);
1127 search_engines
.Append(entry
);
1128 if (model_urls
[i
] == default_url
)
1132 web_ui()->CallJavascriptFunction(
1133 "BrowserOptions.updateSearchEngines",
1135 base::FundamentalValue(default_index
),
1136 base::FundamentalValue(
1137 template_url_service_
->is_default_search_managed() ||
1138 template_url_service_
->IsExtensionControlledDefaultSearch()));
1140 SetupExtensionControlledIndicators();
1143 void BrowserOptionsHandler::SetDefaultSearchEngine(
1144 const base::ListValue
* args
) {
1145 int selected_index
= -1;
1146 if (!ExtractIntegerValue(args
, &selected_index
)) {
1151 TemplateURLService::TemplateURLVector
model_urls(
1152 template_url_service_
->GetTemplateURLs());
1153 if (selected_index
>= 0 &&
1154 selected_index
< static_cast<int>(model_urls
.size()))
1155 template_url_service_
->SetUserSelectedDefaultSearchProvider(
1156 model_urls
[selected_index
]);
1158 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1161 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1162 template_url_service_
=
1163 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1164 if (template_url_service_
) {
1165 template_url_service_
->Load();
1166 template_url_service_
->AddObserver(this);
1170 void BrowserOptionsHandler::OnExtensionLoaded(
1171 content::BrowserContext
* browser_context
,
1172 const Extension
* extension
) {
1173 SetupExtensionControlledIndicators();
1176 void BrowserOptionsHandler::OnExtensionUnloaded(
1177 content::BrowserContext
* browser_context
,
1178 const Extension
* extension
,
1179 extensions::UnloadedExtensionInfo::Reason reason
) {
1180 SetupExtensionControlledIndicators();
1183 void BrowserOptionsHandler::Observe(
1185 const content::NotificationSource
& source
,
1186 const content::NotificationDetails
& details
) {
1187 // Notifications are used to update the UI dynamically when settings change in
1188 // the background. If the UI is currently being loaded, no dynamic updates are
1189 // possible (as the DOM and JS are not fully loaded) or necessary (as
1190 // InitializePage() will update the UI at the end of the load).
1191 if (!page_initialized_
)
1195 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED
:
1196 ObserveThemeChanged();
1198 #if defined(OS_CHROMEOS)
1199 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
:
1200 UpdateAccountPicture();
1203 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
:
1206 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
:
1207 // Update our sync/signin status display.
1215 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue
* args
) {
1217 if (!auto_launch_trial::IsInAutoLaunchGroup())
1221 CHECK_EQ(args
->GetSize(), 1U);
1222 CHECK(args
->GetBoolean(0, &enable
));
1224 Profile
* profile
= Profile::FromWebUI(web_ui());
1225 content::BrowserThread::PostTask(
1226 content::BrowserThread::FILE, FROM_HERE
,
1228 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin
,
1229 profile
->GetPath().BaseName().value(), base::FilePath()) :
1230 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin
,
1231 profile
->GetPath().BaseName().value()));
1235 scoped_ptr
<base::ListValue
> BrowserOptionsHandler::GetProfilesInfoList() {
1236 ProfileInfoCache
& cache
=
1237 g_browser_process
->profile_manager()->GetProfileInfoCache();
1238 scoped_ptr
<base::ListValue
> profile_info_list(new base::ListValue
);
1239 base::FilePath current_profile_path
=
1240 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1242 for (size_t i
= 0, e
= cache
.GetNumberOfProfiles(); i
< e
; ++i
) {
1243 base::DictionaryValue
* profile_value
= new base::DictionaryValue();
1244 profile_value
->SetString("name", cache
.GetNameOfProfileAtIndex(i
));
1245 base::FilePath profile_path
= cache
.GetPathOfProfileAtIndex(i
);
1246 profile_value
->Set("filePath", base::CreateFilePathValue(profile_path
));
1247 profile_value
->SetBoolean("isCurrentProfile",
1248 profile_path
== current_profile_path
);
1249 profile_value
->SetBoolean("isSupervised",
1250 cache
.ProfileIsSupervisedAtIndex(i
));
1252 bool is_gaia_picture
=
1253 cache
.IsUsingGAIAPictureOfProfileAtIndex(i
) &&
1254 cache
.GetGAIAPictureOfProfileAtIndex(i
);
1255 if (is_gaia_picture
) {
1256 gfx::Image icon
= profiles::GetAvatarIconForWebUI(
1257 cache
.GetAvatarIconOfProfileAtIndex(i
), true);
1258 profile_value
->SetString("iconURL",
1259 webui::GetBitmapDataUrl(icon
.AsBitmap()));
1261 size_t icon_index
= cache
.GetAvatarIconIndexOfProfileAtIndex(i
);
1262 profile_value
->SetString("iconURL",
1263 profiles::GetDefaultAvatarIconUrl(icon_index
));
1266 profile_info_list
->Append(profile_value
);
1269 return profile_info_list
.Pass();
1272 void BrowserOptionsHandler::SendProfilesInfo() {
1273 if (!ShouldShowMultiProfilesUserList())
1275 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1276 *GetProfilesInfoList());
1279 void BrowserOptionsHandler::DeleteProfile(const base::ListValue
* args
) {
1281 const base::Value
* file_path_value
;
1282 if (!args
->Get(0, &file_path_value
))
1285 base::FilePath file_path
;
1286 if (!base::GetValueAsFilePath(*file_path_value
, &file_path
))
1288 helper::DeleteProfileAtPath(file_path
, web_ui());
1291 void BrowserOptionsHandler::ObserveThemeChanged() {
1292 Profile
* profile
= Profile::FromWebUI(web_ui());
1293 ThemeService
* theme_service
= ThemeServiceFactory::GetForProfile(profile
);
1294 bool is_system_theme
= false;
1296 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1297 bool profile_is_supervised
= profile
->IsSupervised();
1298 is_system_theme
= theme_service
->UsingSystemTheme();
1299 base::FundamentalValue
native_theme_enabled(!is_system_theme
&&
1300 !profile_is_supervised
);
1301 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1302 native_theme_enabled
);
1305 bool is_classic_theme
= !is_system_theme
&&
1306 theme_service
->UsingDefaultTheme();
1307 base::FundamentalValue
enabled(!is_classic_theme
);
1308 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1312 void BrowserOptionsHandler::ThemesReset(const base::ListValue
* args
) {
1313 Profile
* profile
= Profile::FromWebUI(web_ui());
1314 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1315 ThemeServiceFactory::GetForProfile(profile
)->UseDefaultTheme();
1318 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1319 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue
* args
) {
1320 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1321 Profile
* profile
= Profile::FromWebUI(web_ui());
1322 ThemeServiceFactory::GetForProfile(profile
)->UseSystemTheme();
1326 #if defined(OS_CHROMEOS)
1327 void BrowserOptionsHandler::UpdateAccountPicture() {
1329 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1330 if (!email
.empty()) {
1331 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1332 base::StringValue
email_value(email
);
1333 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1338 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed
) {
1339 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1340 base::FundamentalValue(managed
));
1343 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed
) {
1344 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1345 base::FundamentalValue(managed
));
1349 scoped_ptr
<base::DictionaryValue
>
1350 BrowserOptionsHandler::GetSyncStateDictionary() {
1351 scoped_ptr
<base::DictionaryValue
> sync_status(new base::DictionaryValue
);
1352 Profile
* profile
= Profile::FromWebUI(web_ui());
1353 if (profile
->IsGuestSession()) {
1354 // Cannot display signin status when running in guest mode on chromeos
1355 // because there is no SigninManager.
1356 sync_status
->SetBoolean("signinAllowed", false);
1357 return sync_status
.Pass();
1360 sync_status
->SetBoolean("supervisedUser", profile
->IsSupervised());
1362 bool signout_prohibited
= false;
1363 #if !defined(OS_CHROMEOS)
1364 // Signout is not allowed if the user has policy (crbug.com/172204).
1365 signout_prohibited
=
1366 SigninManagerFactory::GetForProfile(profile
)->IsSignoutProhibited();
1369 ProfileSyncService
* service
=
1370 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
1371 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1373 sync_status
->SetBoolean("signoutAllowed", !signout_prohibited
);
1374 sync_status
->SetBoolean("signinAllowed", signin
->IsSigninAllowed());
1375 sync_status
->SetBoolean("syncSystemEnabled", (service
!= NULL
));
1376 sync_status
->SetBoolean("setupCompleted",
1377 service
&& service
->HasSyncSetupCompleted());
1378 sync_status
->SetBoolean("setupInProgress",
1379 service
&& !service
->IsManaged() && service
->FirstSetupInProgress());
1381 base::string16 status_label
;
1382 base::string16 link_label
;
1383 bool status_has_error
= sync_ui_util::GetStatusLabels(
1384 service
, *signin
, sync_ui_util::WITH_HTML
, &status_label
, &link_label
) ==
1385 sync_ui_util::SYNC_ERROR
;
1386 sync_status
->SetString("statusText", status_label
);
1387 sync_status
->SetString("actionLinkText", link_label
);
1388 sync_status
->SetBoolean("hasError", status_has_error
);
1390 sync_status
->SetBoolean("managed", service
&& service
->IsManaged());
1391 sync_status
->SetBoolean("signedIn",
1392 !signin
->GetAuthenticatedUsername().empty());
1393 sync_status
->SetBoolean("hasUnrecoverableError",
1394 service
&& service
->HasUnrecoverableError());
1396 return sync_status
.Pass();
1399 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1400 const base::ListValue
* args
) {
1401 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1402 select_folder_dialog_
= ui::SelectFileDialog::Create(
1403 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1404 ui::SelectFileDialog::FileTypeInfo info
;
1405 info
.support_drive
= true;
1406 select_folder_dialog_
->SelectFile(
1407 ui::SelectFileDialog::SELECT_FOLDER
,
1408 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
),
1409 pref_service
->GetFilePath(prefs::kDownloadDefaultDirectory
),
1412 base::FilePath::StringType(),
1413 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1417 void BrowserOptionsHandler::FileSelected(const base::FilePath
& path
, int index
,
1419 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1420 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1421 pref_service
->SetFilePath(prefs::kDownloadDefaultDirectory
, path
);
1422 pref_service
->SetFilePath(prefs::kSaveFileDefaultDirectory
, path
);
1425 #if defined(OS_CHROMEOS)
1426 void BrowserOptionsHandler::TouchpadExists(bool exists
) {
1427 base::FundamentalValue
val(exists
);
1428 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val
);
1431 void BrowserOptionsHandler::MouseExists(bool exists
) {
1432 base::FundamentalValue
val(exists
);
1433 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val
);
1436 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1437 const base::Value
* previous_policy
,
1438 const base::Value
* current_policy
) {
1439 const bool had_policy
= previous_policy
;
1440 const bool has_policy
= current_policy
;
1441 if (had_policy
!= has_policy
)
1442 OnAccountPictureManagedChanged(has_policy
);
1445 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1446 const base::Value
* previous_policy
,
1447 const base::Value
* current_policy
) {
1448 const bool had_policy
= previous_policy
;
1449 const bool has_policy
= current_policy
;
1450 if (had_policy
!= has_policy
)
1451 OnWallpaperManagedChanged(has_policy
);
1454 void BrowserOptionsHandler::OnPowerwashDialogShow(
1455 const base::ListValue
* args
) {
1456 UMA_HISTOGRAM_ENUMERATION(
1457 "Reset.ChromeOS.PowerwashDialogShown",
1458 chromeos::reset::DIALOG_FROM_OPTIONS
,
1459 chromeos::reset::DIALOG_VIEW_TYPE_SIZE
);
1462 #endif // defined(OS_CHROMEOS)
1464 void BrowserOptionsHandler::UpdateSyncState() {
1465 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1466 *GetSyncStateDictionary());
1469 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1473 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue
* args
) {
1474 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1475 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1476 web_ui()->GetWebContents()->GetBrowserContext());
1478 DownloadPrefs::FromDownloadManager(manager
)->ResetAutoOpen();
1481 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue
* args
) {
1483 if (ExtractIntegerValue(args
, &font_size
)) {
1484 if (font_size
> 0) {
1485 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1486 pref_service
->SetInteger(prefs::kWebKitDefaultFontSize
, font_size
);
1487 SetupFontSizeSelector();
1492 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1493 const base::ListValue
* args
) {
1495 if (ExtractDoubleValue(args
, &zoom_factor
)) {
1496 default_zoom_level_
.SetValue(content::ZoomFactorToZoomLevel(zoom_factor
));
1500 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue
* args
) {
1501 #if defined(OS_WIN) && defined(USE_ASH)
1502 // If hardware acceleration is disabled then we need to force restart
1503 // browser in desktop mode.
1504 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1505 // Currently there are issues with determining correct browser mode
1507 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
) {
1508 PrefService
* pref_service
= g_browser_process
->local_state();
1509 if (!pref_service
->GetBoolean(prefs::kHardwareAccelerationModeEnabled
)) {
1510 chrome::AttemptRestartToDesktopMode();
1517 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1518 // environment variable is defined. So we undefine this environment variable
1519 // before restarting, as the restarted processes will inherit their
1520 // environment variables from ours, thus suppressing crash uploads.
1521 PrefService
* pref_service
= g_browser_process
->local_state();
1522 if (!pref_service
->GetBoolean(prefs::kMetricsReportingEnabled
)) {
1523 HMODULE exe_module
= GetModuleHandle(chrome::kBrowserProcessExecutableName
);
1525 typedef void (__cdecl
*ClearBreakpadPipeEnvVar
)();
1526 ClearBreakpadPipeEnvVar clear
= reinterpret_cast<ClearBreakpadPipeEnvVar
>(
1527 GetProcAddress(exe_module
, "ClearBreakpadPipeEnvironmentVariable"));
1534 chrome::AttemptRestart();
1537 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1538 const base::ListValue
* args
) {
1542 #if !defined(OS_CHROMEOS)
1543 void BrowserOptionsHandler::ShowNetworkProxySettings(
1544 const base::ListValue
* args
) {
1545 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1546 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1547 web_ui()->GetWebContents());
1551 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
1552 void BrowserOptionsHandler::ShowManageSSLCertificates(
1553 const base::ListValue
* args
) {
1554 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1555 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1556 web_ui()->GetWebContents());
1560 #if defined(ENABLE_SERVICE_DISCOVERY)
1562 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1563 const base::ListValue
* args
) {
1564 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1565 // Navigate in current tab to devices page.
1566 OpenURLParams
params(
1567 GURL(chrome::kChromeUIDevicesURL
), Referrer(),
1568 CURRENT_TAB
, content::PAGE_TRANSITION_LINK
, false);
1569 web_ui()->GetWebContents()->OpenURL(params
);
1574 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1575 const base::ListValue
* args
) {
1576 Profile
* profile
= Profile::FromWebUI(web_ui());
1577 std::string group
= base::FieldTrialList::FindFullName("VoiceTrigger");
1578 base::FundamentalValue
enabled(
1579 profile
->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled
));
1580 if (group
!= "" && group
!= "Disabled" &&
1581 HotwordServiceFactory::IsHotwordAllowed(profile
)) {
1582 // Update the current error value.
1583 HotwordServiceFactory::IsServiceAvailable(profile
);
1584 int error
= HotwordServiceFactory::GetCurrentError(profile
);
1586 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
1589 base::string16 hotword_help_url
=
1590 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL
);
1591 base::StringValue
error_message(l10n_util::GetStringUTF16(error
));
1592 if (error
== IDS_HOTWORD_GENERIC_ERROR_MESSAGE
) {
1593 error_message
= base::StringValue(
1594 l10n_util::GetStringFUTF16(error
, hotword_help_url
));
1596 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
1597 enabled
, error_message
);
1599 if (CommandLine::ForCurrentProcess()->HasSwitch(
1600 switches::kEnableExperimentalHotwording
)) {
1601 web_ui()->CallJavascriptFunction(
1602 "BrowserOptions.showHotwordAlwaysOnSection");
1607 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1608 const base::ListValue
* args
) {
1609 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1612 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1613 const base::ListValue
* args
) {
1614 SetupExtensionControlledIndicators();
1617 #if defined(OS_CHROMEOS)
1618 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1619 const base::ListValue
* args
) {
1620 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1623 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1624 const base::ListValue
* args
) {
1625 bool enabled
= false;
1626 args
->GetBoolean(0, &enabled
);
1628 chromeos::accessibility::EnableVirtualKeyboard(enabled
);
1631 void BrowserOptionsHandler::PerformFactoryResetRestart(
1632 const base::ListValue
* args
) {
1633 policy::BrowserPolicyConnectorChromeOS
* connector
=
1634 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1635 if (connector
->IsEnterpriseManaged())
1638 PrefService
* prefs
= g_browser_process
->local_state();
1639 prefs
->SetBoolean(prefs::kFactoryResetRequested
, true);
1640 prefs
->CommitPendingWrite();
1642 // Perform sign out. Current chrome process will then terminate, new one will
1643 // be launched (as if it was a restart).
1644 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1647 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1648 PrefService
* pref_service
= g_browser_process
->local_state();
1649 base::FundamentalValue
virtual_keyboard_enabled(
1650 pref_service
->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled
));
1651 web_ui()->CallJavascriptFunction(
1652 "BrowserOptions.setVirtualKeyboardCheckboxState",
1653 virtual_keyboard_enabled
);
1657 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1658 #if defined(GOOGLE_CHROME_BUILD)
1659 // Don't show the reporting setting if we are in the guest mode.
1660 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1661 base::FundamentalValue
visible(false);
1662 web_ui()->CallJavascriptFunction(
1663 "BrowserOptions.setMetricsReportingSettingVisibility", visible
);
1668 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1669 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1671 base::DictionaryValue dict
;
1672 dict
.SetInteger("value",
1673 pref_service
->GetInteger(prefs::kNetworkPredictionOptions
));
1674 dict
.SetBoolean("disabled",
1675 !pref_service
->IsUserModifiablePreference(
1676 prefs::kNetworkPredictionOptions
));
1678 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1682 void BrowserOptionsHandler::SetupFontSizeSelector() {
1683 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1684 const PrefService::Preference
* default_font_size
=
1685 pref_service
->FindPreference(prefs::kWebKitDefaultFontSize
);
1686 const PrefService::Preference
* default_fixed_font_size
=
1687 pref_service
->FindPreference(prefs::kWebKitDefaultFixedFontSize
);
1689 base::DictionaryValue dict
;
1690 dict
.SetInteger("value",
1691 pref_service
->GetInteger(prefs::kWebKitDefaultFontSize
));
1693 // The font size control displays the value of the default font size, but
1694 // setting it alters both the default font size and the default fixed font
1695 // size. So it must be disabled when either of those prefs is not user
1697 dict
.SetBoolean("disabled",
1698 !default_font_size
->IsUserModifiable() ||
1699 !default_fixed_font_size
->IsUserModifiable());
1701 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1702 // adapted to consider two prefs. It may be better to refactor
1703 // CreateValueForPref so it can be called from here.
1704 if (default_font_size
->IsManaged() || default_fixed_font_size
->IsManaged()) {
1705 dict
.SetString("controlledBy", "policy");
1706 } else if (default_font_size
->IsExtensionControlled() ||
1707 default_fixed_font_size
->IsExtensionControlled()) {
1708 dict
.SetString("controlledBy", "extension");
1711 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict
);
1714 void BrowserOptionsHandler::SetupPageZoomSelector() {
1715 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1716 double default_zoom_level
= pref_service
->GetDouble(prefs::kDefaultZoomLevel
);
1717 double default_zoom_factor
=
1718 content::ZoomLevelToZoomFactor(default_zoom_level
);
1720 // Generate a vector of zoom factors from an array of known presets along with
1721 // the default factor added if necessary.
1722 std::vector
<double> zoom_factors
=
1723 chrome_page_zoom::PresetZoomFactors(default_zoom_factor
);
1725 // Iterate through the zoom factors and and build the contents of the
1726 // selector that will be sent to the javascript handler.
1727 // Each item in the list has the following parameters:
1728 // 1. Title (string).
1729 // 2. Value (double).
1730 // 3. Is selected? (bool).
1731 base::ListValue zoom_factors_value
;
1732 for (std::vector
<double>::const_iterator i
= zoom_factors
.begin();
1733 i
!= zoom_factors
.end(); ++i
) {
1734 base::ListValue
* option
= new base::ListValue();
1736 int percent
= static_cast<int>(factor
* 100 + 0.5);
1737 option
->Append(new base::StringValue(
1738 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT
, percent
)));
1739 option
->Append(new base::FundamentalValue(factor
));
1740 bool selected
= content::ZoomValuesEqual(factor
, default_zoom_factor
);
1741 option
->Append(new base::FundamentalValue(selected
));
1742 zoom_factors_value
.Append(option
);
1745 web_ui()->CallJavascriptFunction(
1746 "BrowserOptions.setupPageZoomSelector", zoom_factors_value
);
1749 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1750 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1751 // We show the button if the user has any auto-open file types registered.
1752 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1753 web_ui()->GetWebContents()->GetBrowserContext());
1754 bool display
= manager
&&
1755 DownloadPrefs::FromDownloadManager(manager
)->IsAutoOpenUsed();
1756 base::FundamentalValue
value(display
);
1757 web_ui()->CallJavascriptFunction(
1758 "BrowserOptions.setAutoOpenFileTypesDisplayed", value
);
1761 void BrowserOptionsHandler::SetupProxySettingsSection() {
1762 #if !defined(OS_CHROMEOS)
1763 // Disable the button if proxy settings are managed by a sysadmin, overridden
1764 // by an extension, or the browser is running in Windows Ash (on Windows the
1765 // proxy settings dialog will open on the Windows desktop and be invisible
1766 // to a user in Ash).
1767 bool is_win_ash
= false;
1769 chrome::HostDesktopType desktop_type
= helper::GetDesktopType(web_ui());
1770 is_win_ash
= (desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
);
1772 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1773 const PrefService::Preference
* proxy_config
=
1774 pref_service
->FindPreference(prefs::kProxy
);
1775 bool is_extension_controlled
= (proxy_config
&&
1776 proxy_config
->IsExtensionControlled());
1778 base::FundamentalValue
disabled(is_win_ash
|| (proxy_config
&&
1779 !proxy_config
->IsUserModifiable()));
1780 base::FundamentalValue
extension_controlled(is_extension_controlled
);
1781 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
1782 disabled
, extension_controlled
);
1785 SetupExtensionControlledIndicators();
1786 #endif // defined(OS_WIN)
1788 #endif // !defined(OS_CHROMEOS)
1791 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1793 // Disable the button if the settings page is displayed in Windows Ash,
1794 // otherwise the proxy settings dialog will open on the Windows desktop and
1795 // be invisible to a user in Ash.
1796 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH
) {
1797 base::FundamentalValue
enabled(false);
1798 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1801 #endif // defined(OS_WIN)
1804 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1805 bool has_users
= !Profile::FromWebUI(web_ui())->
1806 GetPrefs()->GetDictionary(prefs::kSupervisedUsers
)->empty();
1807 base::FundamentalValue
has_users_value(has_users
);
1808 web_ui()->CallJavascriptFunction(
1809 "BrowserOptions.updateManagesSupervisedUsers",
1813 void BrowserOptionsHandler::SetupEasyUnlock() {
1814 // TODO(xiyuan): Update when pairing data is really availble.
1815 const base::ListValue
* devices
=
1816 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->GetRemoteDevices();
1817 bool has_pairing
= devices
&& !devices
->empty();
1818 base::FundamentalValue
has_pairing_value(has_pairing
);
1819 web_ui()->CallJavascriptFunction(
1820 "BrowserOptions.updateEasyUnlock",
1824 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
1826 base::DictionaryValue extension_controlled
;
1828 // Check if an extension is overriding the Search Engine.
1829 const extensions::Extension
* extension
=
1830 extensions::GetExtensionOverridingSearchEngine(
1831 Profile::FromWebUI(web_ui()));
1832 AppendExtensionData("searchEngine", extension
, &extension_controlled
);
1834 // Check if an extension is overriding the Home page.
1835 extension
= extensions::GetExtensionOverridingHomepage(
1836 Profile::FromWebUI(web_ui()));
1837 AppendExtensionData("homePage", extension
, &extension_controlled
);
1839 // Check if an extension is overriding the Startup pages.
1840 extension
= extensions::GetExtensionOverridingStartupPages(
1841 Profile::FromWebUI(web_ui()));
1842 AppendExtensionData("startUpPage", extension
, &extension_controlled
);
1844 // Check if an extension is overriding the NTP page.
1845 GURL
ntp_url(chrome::kChromeUINewTabURL
);
1848 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
1850 web_ui()->GetWebContents()->GetBrowserContext(),
1852 if (ntp_url
.SchemeIs("chrome-extension")) {
1853 using extensions::ExtensionRegistry
;
1854 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
1855 Profile::FromWebUI(web_ui()));
1856 extension
= registry
->GetExtensionById(ntp_url
.host(),
1857 ExtensionRegistry::ENABLED
);
1859 AppendExtensionData("newTabPage", extension
, &extension_controlled
);
1861 // Check if an extension is overwriting the proxy setting.
1862 extension
= extensions::GetExtensionOverridingProxy(
1863 Profile::FromWebUI(web_ui()));
1864 AppendExtensionData("proxy", extension
, &extension_controlled
);
1866 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1867 extension_controlled
);
1868 #endif // defined(OS_WIN)
1871 } // namespace options