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/memory/singleton.h"
16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h"
18 #include "base/path_service.h"
19 #include "base/prefs/pref_service.h"
20 #include "base/prefs/scoped_user_pref_update.h"
21 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "base/value_conversions.h"
25 #include "base/values.h"
26 #include "chrome/browser/auto_launch_trial.h"
27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/chrome_page_zoom.h"
30 #include "chrome/browser/custom_home_pages_table_model.h"
31 #include "chrome/browser/download/download_prefs.h"
32 #include "chrome/browser/gpu/gpu_mode_manager.h"
33 #include "chrome/browser/lifetime/application_lifetime.h"
34 #include "chrome/browser/prefs/session_startup_pref.h"
35 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
38 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
39 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
40 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/profiles/profile_info_cache.h"
42 #include "chrome/browser/profiles/profile_info_util.h"
43 #include "chrome/browser/profiles/profile_manager.h"
44 #include "chrome/browser/profiles/profile_metrics.h"
45 #include "chrome/browser/profiles/profile_shortcut_manager.h"
46 #include "chrome/browser/profiles/profile_window.h"
47 #include "chrome/browser/profiles/profiles_state.h"
48 #include "chrome/browser/search/hotword_service.h"
49 #include "chrome/browser/search/hotword_service_factory.h"
50 #include "chrome/browser/search/search.h"
51 #include "chrome/browser/search_engines/template_url.h"
52 #include "chrome/browser/search_engines/template_url_service.h"
53 #include "chrome/browser/search_engines/template_url_service_factory.h"
54 #include "chrome/browser/signin/easy_unlock.h"
55 #include "chrome/browser/signin/signin_manager_factory.h"
56 #include "chrome/browser/sync/profile_sync_service.h"
57 #include "chrome/browser/sync/profile_sync_service_factory.h"
58 #include "chrome/browser/sync/sync_ui_util.h"
59 #include "chrome/browser/themes/theme_service.h"
60 #include "chrome/browser/themes/theme_service_factory.h"
61 #include "chrome/browser/ui/browser_finder.h"
62 #include "chrome/browser/ui/chrome_select_file_policy.h"
63 #include "chrome/browser/ui/host_desktop.h"
64 #include "chrome/browser/ui/options/options_util.h"
65 #include "chrome/browser/ui/webui/favicon_source.h"
66 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
67 #include "chrome/common/chrome_constants.h"
68 #include "chrome/common/chrome_paths.h"
69 #include "chrome/common/chrome_switches.h"
70 #include "chrome/common/net/url_fixer_upper.h"
71 #include "chrome/common/pref_names.h"
72 #include "chrome/common/url_constants.h"
73 #include "chromeos/chromeos_switches.h"
74 #include "components/signin/core/browser/signin_manager.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/browser/web_contents_view.h"
86 #include "content/public/common/page_zoom.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/magnifier/magnifier_constants.h"
104 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
105 #include "chrome/browser/chromeos/chromeos_utils.h"
106 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
107 #include "chrome/browser/chromeos/login/user.h"
108 #include "chrome/browser/chromeos/login/user_manager.h"
109 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
110 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
111 #include "chrome/browser/chromeos/reset/metrics.h"
112 #include "chrome/browser/chromeos/settings/cros_settings.h"
113 #include "chrome/browser/chromeos/system/timezone_util.h"
114 #include "chrome/browser/policy/profile_policy_connector.h"
115 #include "chrome/browser/policy/profile_policy_connector_factory.h"
116 #include "chrome/browser/ui/browser_window.h"
117 #include "chromeos/dbus/dbus_thread_manager.h"
118 #include "chromeos/dbus/power_manager_client.h"
119 #include "components/policy/core/common/policy_map.h"
120 #include "components/policy/core/common/policy_namespace.h"
121 #include "components/policy/core/common/policy_service.h"
122 #include "policy/policy_constants.h"
123 #include "ui/gfx/image/image_skia.h"
124 #endif // defined(OS_CHROMEOS)
127 #include "chrome/installer/util/auto_launch_util.h"
128 #endif // defined(OS_WIN)
130 #if defined(ENABLE_SERVICE_DISCOVERY)
131 #include "chrome/browser/local_discovery/privet_notifications.h"
134 using base::UserMetricsAction
;
135 using content::BrowserContext
;
136 using content::BrowserThread
;
137 using content::DownloadManager
;
138 using content::OpenURLParams
;
139 using content::Referrer
;
143 BrowserOptionsHandler::BrowserOptionsHandler()
144 : page_initialized_(false),
145 template_url_service_(NULL
),
146 cloud_print_mdns_ui_enabled_(false),
147 signin_observer_(this),
148 weak_ptr_factory_(this) {
149 #if !defined(OS_MACOSX)
150 default_browser_worker_
= new ShellIntegration::DefaultBrowserWorker(this);
153 #if defined(ENABLE_FULL_PRINTING)
154 #if !defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
155 // On Windows, we need the PDF plugin which is only guaranteed to exist on
156 // Google Chrome builds. Use a command-line switch for Windows non-Google
158 cloud_print_connector_ui_enabled_
=
159 CommandLine::ForCurrentProcess()->HasSwitch(
160 switches::kEnableCloudPrintProxy
);
161 #elif !defined(OS_CHROMEOS)
162 // Always enabled for Mac, Linux and Google Chrome Windows builds.
163 // Never enabled for Chrome OS, we don't even need to indicate it.
164 cloud_print_connector_ui_enabled_
= true;
166 #endif // defined(ENABLE_FULL_PRINTING)
168 #if defined(ENABLE_SERVICE_DISCOVERY)
169 cloud_print_mdns_ui_enabled_
= !CommandLine::ForCurrentProcess()->HasSwitch(
170 switches::kDisableDeviceDiscovery
);
171 #endif // defined(ENABLE_SERVICE_DISCOVERY)
174 BrowserOptionsHandler::~BrowserOptionsHandler() {
175 ProfileSyncService
* sync_service(ProfileSyncServiceFactory::
176 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
178 sync_service
->RemoveObserver(this);
180 if (default_browser_worker_
.get())
181 default_browser_worker_
->ObserverDestroyed();
182 if (template_url_service_
)
183 template_url_service_
->RemoveObserver(this);
184 // There may be pending file dialogs, we need to tell them that we've gone
185 // away so they don't try and call back to us.
186 if (select_folder_dialog_
.get())
187 select_folder_dialog_
->ListenerDestroyed();
190 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue
* values
) {
193 static OptionsStringResource resources
[] = {
194 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT
},
195 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY
},
196 { "advancedSectionTitleContent",
197 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT
},
198 { "advancedSectionTitleLanguages",
199 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES
},
200 { "advancedSectionTitleNetwork",
201 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK
},
202 { "advancedSectionTitlePrivacy",
203 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY
},
204 { "advancedSectionTitleSecurity",
205 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY
},
206 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE
},
207 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN
},
208 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY
},
209 { "autoOpenFileTypesResetToDefault",
210 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT
},
211 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE
},
212 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON
},
213 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL
},
214 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL
},
215 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES
},
216 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL
},
217 #if defined(OS_CHROMEOS)
218 { "disableGData", IDS_OPTIONS_DISABLE_GDATA
},
220 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES
},
221 #if defined(OS_CHROMEOS)
223 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL
},
225 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK
},
226 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT
},
227 { "doNotTrackConfirmEnable",
228 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE
},
229 { "doNotTrackConfirmDisable",
230 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE
},
231 { "downloadLocationAskForSaveLocation",
232 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION
},
233 { "downloadLocationBrowseTitle",
234 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
},
235 { "downloadLocationChangeButton",
236 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON
},
237 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME
},
238 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING
},
239 #if !defined(OS_CHROMEOS)
240 { "easyUnlockCheckboxLabel", IDS_OPTIONS_EASY_UNLOCK_CHECKBOX_LABEL
},
242 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE
},
243 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON
},
244 { "easyUnlockManagement", IDS_OPTIONS_EASY_UNLOCK_MANAGEMENT
},
245 { "fontSettingsCustomizeFontsButton",
246 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON
},
247 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM
},
248 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE
},
249 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM
},
250 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL
},
251 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE
},
252 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL
},
253 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS
},
254 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP
},
255 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
256 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB
},
257 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL
},
258 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX
},
259 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE
},
260 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE
},
261 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION
},
262 { "hotwordRetryDownloadButton", IDS_HOTWORD_RETRY_DOWNLOAD_BUTTON
},
263 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE
},
264 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON
},
265 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE
},
266 { "languageAndSpellCheckSettingsButton",
267 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS
},
268 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF
},
269 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK
},
270 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES
},
271 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK
},
272 { "networkPredictionEnabledDescription",
273 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION
},
274 { "passwordsAndAutofillGroupName",
275 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME
},
276 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE
},
277 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON
},
278 { "privacyContentSettingsButton",
279 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON
},
280 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL
},
281 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL
},
282 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL
},
283 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT
},
284 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL
},
285 { "profilesSupervisedDashboardTip",
286 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP
},
287 #if defined(ENABLE_SETTINGS_APP)
288 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL
},
290 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL
},
291 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
293 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON
},
294 { "resetProfileSettingsDescription",
295 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION
},
296 { "resetProfileSettingsSectionTitle",
297 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE
},
298 { "safeBrowsingEnableProtection",
299 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION
},
300 { "safeBrowsingEnableDownloadFeedback",
301 IDS_OPTIONS_SAFEBROWSING_ENABLEDOWNLOADFEEDBACK
},
302 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME
},
303 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME
},
304 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME
},
305 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME
},
306 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME
},
307 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME
},
308 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT
},
309 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE
},
310 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE
},
311 { "spellingPref", IDS_OPTIONS_SPELLING_PREF
},
312 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION
},
313 { "settingsTitle", IDS_SETTINGS_TITLE
},
314 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS
},
315 { "sslCheckRevocation", IDS_OPTIONS_SSL_CHECKREVOCATION
},
316 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES
},
317 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB
},
318 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES
},
319 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF
},
320 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS
},
321 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL
},
322 { "themesGallery", IDS_THEMES_GALLERY_BUTTON
},
323 { "themesGalleryURL", IDS_THEMES_GALLERY_URL
},
324 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF
},
325 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR
},
326 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON
},
327 { "translateEnableTranslate",
328 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE
},
329 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
330 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS
},
331 { "themesNativeButton", IDS_THEMES_GTK_BUTTON
},
332 { "themesSetClassic", IDS_THEMES_SET_CLASSIC
},
334 { "themes", IDS_THEMES_GROUP_NAME
},
336 { "themesReset", IDS_THEMES_RESET_BUTTON
},
337 #if defined(OS_CHROMEOS)
338 { "accessibilityExplanation",
339 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION
},
340 { "accessibilitySettings",
341 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS
},
342 { "accessibilityHighContrast",
343 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION
},
344 { "accessibilityScreenMagnifier",
345 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION
},
346 { "accessibilityTapDragging",
347 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION
},
348 { "accessibilityScreenMagnifierOff",
349 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF
},
350 { "accessibilityScreenMagnifierFull",
351 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
},
352 { "accessibilityScreenMagnifierPartial",
353 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
},
354 { "accessibilityLargeCursor",
355 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION
},
356 { "accessibilityStickyKeys",
357 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION
},
358 { "accessibilitySpokenFeedback",
359 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION
},
360 { "accessibilityTitle",
361 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY
},
362 { "accessibilityVirtualKeyboard",
363 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION
},
364 { "accessibilityAlwaysShowMenu",
365 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU
},
366 { "accessibilityAutoclick",
367 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION
},
368 { "accessibilityAutoclickDropdown",
369 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION
},
370 { "autoclickDelayExtremelyShort",
371 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT
},
372 { "autoclickDelayVeryShort",
373 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT
},
374 { "autoclickDelayShort",
375 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT
},
376 { "autoclickDelayLong",
377 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG
},
378 { "autoclickDelayVeryLong",
379 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG
},
380 { "enableContentProtectionAttestation",
381 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION
},
382 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING
},
383 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET
},
384 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON
},
385 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON
},
386 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING
},
387 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL
},
388 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE
},
389 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION
},
390 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME
},
391 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION
},
392 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION
},
393 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION
},
394 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION
},
395 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX
},
396 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE
},
397 { "keyboardSettingsButtonTitle",
398 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE
},
399 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE
},
400 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES
},
401 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME
},
402 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL
},
403 { "syncOverview", IDS_SYNC_OVERVIEW
},
404 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
405 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION
},
406 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION
},
408 { "cloudPrintManageButton",
409 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON
},
410 { "cloudPrintConnectorEnablingButton",
411 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON
},
412 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON
},
414 #if defined(OS_CHROMEOS) && defined(USE_ASH)
415 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON
},
417 { "advancedSectionTitleSystem",
418 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM
},
419 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
420 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE
},
422 #if !defined(OS_CHROMEOS)
424 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE
},
425 { "gpuModeResetRestart",
426 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART
},
427 // Strings with product-name substitutions.
428 { "syncOverview", IDS_SYNC_OVERVIEW
, IDS_PRODUCT_NAME
},
429 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL
},
431 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
432 IDS_SHORT_PRODUCT_NAME
},
433 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
435 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
,
437 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT
},
438 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT
},
439 #if defined(OS_CHROMEOS)
440 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION
,
441 IDS_SHORT_PRODUCT_NAME
},
443 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
444 IDS_SHORT_PRODUCT_NAME
},
445 #if defined(ENABLE_SERVICE_DISCOVERY)
446 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON
},
447 { "cloudPrintEnableNotificationsLabel",
448 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL
},
452 #if defined(ENABLE_SETTINGS_APP)
453 static OptionsStringResource app_resources
[] = {
454 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW
},
455 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL
,
456 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
457 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE
,
458 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
459 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL
,
460 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
461 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL
,
462 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME
},
464 base::DictionaryValue
* app_values
= NULL
;
465 CHECK(values
->GetDictionary(kSettingsAppKey
, &app_values
));
466 RegisterStrings(app_values
, app_resources
, arraysize(app_resources
));
469 RegisterStrings(values
, resources
, arraysize(resources
));
470 RegisterTitle(values
, "doNotTrackConfirmOverlay",
471 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE
);
472 RegisterTitle(values
, "spellingConfirmOverlay",
473 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE
);
474 #if defined(ENABLE_FULL_PRINTING)
475 RegisterCloudPrintValues(values
);
478 values
->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL
);
479 base::string16 omnibox_url
= base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL
);
481 "defaultSearchGroupLabel",
482 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION
, omnibox_url
));
483 values
->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL
);
484 RegisterTitle(values
, "hotwordConfirmOverlay",
485 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE
);
487 #if defined(OS_CHROMEOS)
488 Profile
* profile
= Profile::FromWebUI(web_ui());
489 std::string username
= profile
->GetProfileName();
490 if (username
.empty()) {
491 chromeos::User
* user
=
492 chromeos::UserManager::Get()->GetUserByProfile(profile
);
493 if (user
&& (user
->GetType() != chromeos::User::USER_TYPE_GUEST
))
494 username
= user
->email();
497 if (!username
.empty())
498 username
= gaia::SanitizeEmail(gaia::CanonicalizeEmail(username
));
500 values
->SetString("username", username
);
503 // Pass along sync status early so it will be available during page init.
504 values
->Set("syncData", GetSyncStateDictionary().release());
506 // The Reset Profile Settings feature makes no sense for an off-the-record
507 // profile (e.g. in Guest mode on Chrome OS), so hide it.
508 values
->SetBoolean("enableResetProfileSettings",
509 !Profile::FromWebUI(web_ui())->IsOffTheRecord());
511 values
->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL
);
512 values
->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL
);
514 #if defined(OS_CHROMEOS)
515 // TODO(pastarmovj): replace this with a call to the CrosSettings list
516 // handling functionality to come.
517 values
->Set("timezoneList", chromeos::system::GetTimezoneList().release());
519 values
->SetString("accessibilityLearnMoreURL",
520 chrome::kChromeAccessibilityHelpURL
);
522 std::string settings_url
= std::string("chrome-extension://") +
523 extension_misc::kChromeVoxExtensionId
+
524 chrome::kChromeAccessibilitySettingsURL
;
526 values
->SetString("accessibilitySettingsURL",
529 values
->SetString("contentProtectionAttestationLearnMoreURL",
530 chrome::kAttestationForContentProtectionLearnMoreURL
);
532 // Creates magnifierList.
533 scoped_ptr
<base::ListValue
> magnifier_list(new base::ListValue
);
535 scoped_ptr
<base::ListValue
> option_full(new base::ListValue
);
536 option_full
->AppendInteger(ash::MAGNIFIER_FULL
);
537 option_full
->AppendString(l10n_util::GetStringUTF16(
538 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL
));
539 magnifier_list
->Append(option_full
.release());
541 scoped_ptr
<base::ListValue
> option_partial(new base::ListValue
);
542 option_partial
->AppendInteger(ash::MAGNIFIER_PARTIAL
);
543 option_partial
->Append(new base::StringValue(l10n_util::GetStringUTF16(
544 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL
)));
545 magnifier_list
->Append(option_partial
.release());
547 values
->Set("magnifierList", magnifier_list
.release());
550 #if defined(OS_MACOSX)
551 values
->SetString("macPasswordsWarning",
552 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING
));
553 values
->SetBoolean("multiple_profiles",
554 g_browser_process
->profile_manager()->GetNumberOfProfiles() > 1);
557 if (ShouldShowMultiProfilesUserList())
558 values
->Set("profilesInfo", GetProfilesInfoList().release());
560 values
->SetBoolean("profileIsManaged",
561 Profile::FromWebUI(web_ui())->IsManaged());
563 #if !defined(OS_CHROMEOS)
566 g_browser_process
->gpu_mode_manager()->initial_gpu_mode_pref());
569 #if defined(ENABLE_SERVICE_DISCOVERY)
570 values
->SetBoolean("cloudPrintHideNotificationsCheckbox",
571 !local_discovery::PrivetNotificationService::IsEnabled());
574 values
->SetBoolean("cloudPrintShowMDnsOptions",
575 cloud_print_mdns_ui_enabled_
);
577 values
->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL
);
579 values
->SetString("languagesLearnMoreURL",
580 chrome::kLanguageSettingsLearnMoreUrl
);
584 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableEasyUnlock
));
585 values
->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl
);
586 values
->SetString("easyUnlockManagementURL",
587 chrome::kEasyUnlockManagementUrl
);
588 #if defined(OS_CHROMEOS)
589 values
->SetString("easyUnlockCheckboxLabel",
590 l10n_util::GetStringFUTF16(
591 IDS_OPTIONS_EASY_UNLOCK_CHECKBOX_LABEL_CHROMEOS
,
592 chromeos::GetChromeDeviceType()));
596 #if defined(ENABLE_FULL_PRINTING)
597 void BrowserOptionsHandler::RegisterCloudPrintValues(
598 base::DictionaryValue
* values
) {
599 values
->SetString("cloudPrintOptionLabel",
600 l10n_util::GetStringFUTF16(
601 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL
,
602 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
604 #if defined(OS_CHROMEOS)
605 values
->SetString("cloudPrintManageButton",
606 l10n_util::GetStringFUTF16(
607 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON
,
608 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
610 // TODO(noamsml): Remove all cloud print connector related code from the
611 // settings page as soon as the devices page is supported on all platforms.
612 values
->SetString("cloudPrintConnectorDisabledLabel",
613 l10n_util::GetStringFUTF16(
614 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL
,
615 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
)));
616 values
->SetString("cloudPrintConnectorDisabledButton",
617 l10n_util::GetStringUTF16(
618 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON
));
619 values
->SetString("cloudPrintConnectorEnabledButton",
620 l10n_util::GetStringUTF16(
621 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON
));
624 values
->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
626 #endif // defined(ENABLE_FULL_PRINTING)
628 void BrowserOptionsHandler::RegisterMessages() {
629 web_ui()->RegisterMessageCallback(
630 "becomeDefaultBrowser",
631 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser
,
632 base::Unretained(this)));
633 web_ui()->RegisterMessageCallback(
634 "setDefaultSearchEngine",
635 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine
,
636 base::Unretained(this)));
637 web_ui()->RegisterMessageCallback(
639 base::Bind(&BrowserOptionsHandler::DeleteProfile
,
640 base::Unretained(this)));
641 web_ui()->RegisterMessageCallback(
643 base::Bind(&BrowserOptionsHandler::ThemesReset
,
644 base::Unretained(this)));
645 web_ui()->RegisterMessageCallback(
646 "requestProfilesInfo",
647 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo
,
648 base::Unretained(this)));
649 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
650 web_ui()->RegisterMessageCallback(
652 base::Bind(&BrowserOptionsHandler::ThemesSetNative
,
653 base::Unretained(this)));
655 web_ui()->RegisterMessageCallback(
656 "selectDownloadLocation",
657 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation
,
658 base::Unretained(this)));
659 web_ui()->RegisterMessageCallback(
660 "autoOpenFileTypesAction",
661 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton
,
662 base::Unretained(this)));
663 web_ui()->RegisterMessageCallback(
664 "defaultFontSizeAction",
665 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize
,
666 base::Unretained(this)));
667 web_ui()->RegisterMessageCallback(
668 "defaultZoomFactorAction",
669 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor
,
670 base::Unretained(this)));
671 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
672 web_ui()->RegisterMessageCallback(
673 "showManageSSLCertificates",
674 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates
,
675 base::Unretained(this)));
677 #if defined(ENABLE_FULL_PRINTING)
678 web_ui()->RegisterMessageCallback(
679 "showCloudPrintManagePage",
680 base::Bind(&BrowserOptionsHandler::ShowCloudPrintManagePage
,
681 base::Unretained(this)));
683 #if defined(OS_CHROMEOS)
684 web_ui()->RegisterMessageCallback(
685 "openWallpaperManager",
686 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager
,
687 base::Unretained(this)));
688 web_ui()->RegisterMessageCallback(
689 "virtualKeyboardChange",
690 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback
,
691 base::Unretained(this)));
692 web_ui()->RegisterMessageCallback(
693 "onPowerwashDialogShow",
694 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow
,
695 base::Unretained(this)));
696 web_ui()->RegisterMessageCallback(
697 "performFactoryResetRestart",
698 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart
,
699 base::Unretained(this)));
701 web_ui()->RegisterMessageCallback(
703 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser
,
704 base::Unretained(this)));
705 #if defined(ENABLE_FULL_PRINTING)
706 if (cloud_print_connector_ui_enabled_
) {
707 web_ui()->RegisterMessageCallback(
708 "showCloudPrintSetupDialog",
709 base::Bind(&BrowserOptionsHandler::ShowCloudPrintSetupDialog
,
710 base::Unretained(this)));
711 web_ui()->RegisterMessageCallback(
712 "disableCloudPrintConnector",
713 base::Bind(&BrowserOptionsHandler::HandleDisableCloudPrintConnector
,
714 base::Unretained(this)));
716 #endif // defined(ENABLE_FULL_PRINTING)
717 web_ui()->RegisterMessageCallback(
718 "showNetworkProxySettings",
719 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings
,
720 base::Unretained(this)));
721 #endif // defined(OS_CHROMEOS)
723 #if defined(ENABLE_SERVICE_DISCOVERY)
724 if (cloud_print_mdns_ui_enabled_
) {
725 web_ui()->RegisterMessageCallback(
726 "showCloudPrintDevicesPage",
727 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage
,
728 base::Unretained(this)));
731 web_ui()->RegisterMessageCallback(
732 "requestHotwordAvailable",
733 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable
,
734 base::Unretained(this)));
736 web_ui()->RegisterMessageCallback(
737 "requestHotwordSetupRetry",
738 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordSetupRetry
,
739 base::Unretained(this)));
741 web_ui()->RegisterMessageCallback(
742 "launchEasyUnlockSetup",
743 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup
,
744 base::Unretained(this)));
747 void BrowserOptionsHandler::Uninitialize() {
748 registrar_
.RemoveAll();
751 void BrowserOptionsHandler::OnStateChanged() {
755 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string
& username
,
756 const std::string
& password
) {
760 void BrowserOptionsHandler::GoogleSignedOut(const std::string
& username
) {
764 void BrowserOptionsHandler::PageLoadStarted() {
765 page_initialized_
= false;
768 void BrowserOptionsHandler::InitializeHandler() {
769 Profile
* profile
= Profile::FromWebUI(web_ui());
770 PrefService
* prefs
= profile
->GetPrefs();
772 ProfileSyncService
* sync_service(
773 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
));
774 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
775 // destruction is automatic.
777 sync_service
->AddObserver(this);
779 SigninManagerBase
* signin_manager(
780 SigninManagerFactory::GetInstance()->GetForProfile(profile
));
782 signin_observer_
.Add(signin_manager
);
784 // Create our favicon data source.
785 content::URLDataSource::Add(
786 profile
, new FaviconSource(profile
, FaviconSource::FAVICON
));
788 default_browser_policy_
.Init(
789 prefs::kDefaultBrowserSettingEnabled
,
790 g_browser_process
->local_state(),
791 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState
,
792 base::Unretained(this)));
794 registrar_
.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
,
795 content::NotificationService::AllSources());
796 #if defined(OS_CHROMEOS)
797 registrar_
.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
798 content::NotificationService::AllSources());
800 registrar_
.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED
,
801 content::Source
<ThemeService
>(
802 ThemeServiceFactory::GetForProfile(profile
)));
803 registrar_
.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
,
804 content::Source
<Profile
>(profile
));
805 AddTemplateUrlServiceObserver();
808 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
809 if (!command_line
.HasSwitch(switches::kUserDataDir
)) {
810 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
811 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch
,
812 weak_ptr_factory_
.GetWeakPtr(),
813 profile
->GetPath()));
817 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
818 base::Closure cloud_print_callback
= base::Bind(
819 &BrowserOptionsHandler::OnCloudPrintPrefsChanged
, base::Unretained(this));
820 cloud_print_connector_email_
.Init(
821 prefs::kCloudPrintEmail
, prefs
, cloud_print_callback
);
822 cloud_print_connector_enabled_
.Init(
823 prefs::kCloudPrintProxyEnabled
, prefs
, cloud_print_callback
);
826 auto_open_files_
.Init(
827 prefs::kDownloadExtensionsToOpen
, prefs
,
828 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes
,
829 base::Unretained(this)));
830 default_zoom_level_
.Init(
831 prefs::kDefaultZoomLevel
, prefs
,
832 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector
,
833 base::Unretained(this)));
834 profile_pref_registrar_
.Init(prefs
);
835 profile_pref_registrar_
.Add(
836 prefs::kWebKitDefaultFontSize
,
837 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
838 base::Unretained(this)));
839 profile_pref_registrar_
.Add(
840 prefs::kWebKitDefaultFixedFontSize
,
841 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector
,
842 base::Unretained(this)));
843 profile_pref_registrar_
.Add(
844 prefs::kManagedUsers
,
845 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers
,
846 base::Unretained(this)));
847 profile_pref_registrar_
.Add(
848 prefs::kSigninAllowed
,
849 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange
,
850 base::Unretained(this)));
851 profile_pref_registrar_
.Add(
852 prefs::kEasyUnlockPairing
,
853 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock
,
854 base::Unretained(this)));
856 #if defined(OS_CHROMEOS)
857 if (!policy_registrar_
) {
858 policy_registrar_
.reset(new policy::PolicyChangeRegistrar(
859 policy::ProfilePolicyConnectorFactory::GetForProfile(profile
)->
861 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
, std::string())));
862 policy_registrar_
->Observe(
863 policy::key::kUserAvatarImage
,
864 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged
,
865 base::Unretained(this)));
866 policy_registrar_
->Observe(
867 policy::key::kWallpaperImage
,
868 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged
,
869 base::Unretained(this)));
871 #else // !defined(OS_CHROMEOS)
872 profile_pref_registrar_
.Add(
874 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection
,
875 base::Unretained(this)));
876 #endif // !defined(OS_CHROMEOS)
879 void BrowserOptionsHandler::InitializePage() {
880 page_initialized_
= true;
882 OnTemplateURLServiceChanged();
884 ObserveThemeChanged();
886 UpdateDefaultBrowserState();
888 SetupMetricsReportingSettingVisibility();
889 SetupFontSizeSelector();
890 SetupPageZoomSelector();
891 SetupAutoOpenFileTypes();
892 SetupProxySettingsSection();
893 SetupManageCertificatesSection();
894 SetupManagingSupervisedUsers();
897 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
898 if (!cloud_print_mdns_ui_enabled_
) {
899 if (cloud_print_connector_ui_enabled_
) {
900 SetupCloudPrintConnectorSection();
901 RefreshCloudPrintStatusFromService();
903 RemoveCloudPrintConnectorSection();
908 #if defined(OS_CHROMEOS)
909 SetupAccessibilityFeatures();
910 policy::BrowserPolicyConnectorChromeOS
* connector
=
911 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
912 if (!connector
->IsEnterpriseManaged() &&
913 !chromeos::UserManager::Get()->IsLoggedInAsGuest() &&
914 !chromeos::UserManager::Get()->IsLoggedInAsLocallyManagedUser()) {
915 web_ui()->CallJavascriptFunction(
916 "BrowserOptions.enableFactoryResetSection");
919 Profile
* profile
= Profile::FromWebUI(web_ui());
920 OnAccountPictureManagedChanged(
921 policy::ProfilePolicyConnectorFactory::GetForProfile(profile
)->
922 policy_service()->GetPolicies(
923 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME
,
925 .Get(policy::key::kUserAvatarImage
));
927 OnWallpaperManagedChanged(
928 chromeos::WallpaperManager::Get()->IsPolicyControlled(
929 chromeos::UserManager::Get()->GetActiveUser()->email()));
934 void BrowserOptionsHandler::CheckAutoLaunch(
935 base::WeakPtr
<BrowserOptionsHandler
> weak_this
,
936 const base::FilePath
& profile_path
) {
938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
940 // Auto-launch is not supported for secondary profiles yet.
941 if (profile_path
.BaseName().value() !=
942 base::ASCIIToUTF16(chrome::kInitialProfile
)) {
946 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
948 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
949 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback
,
951 auto_launch_trial::IsInAutoLaunchGroup(),
952 auto_launch_util::AutoStartRequested(
953 profile_path
.BaseName().value(),
954 true, // Window requested.
959 void BrowserOptionsHandler::CheckAutoLaunchCallback(
960 bool is_in_auto_launch_group
,
961 bool will_launch_at_login
) {
963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
965 if (is_in_auto_launch_group
) {
966 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
967 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch
,
968 base::Unretained(this)));
970 base::FundamentalValue
enabled(will_launch_at_login
);
971 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
977 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
978 #if defined(OS_CHROMEOS)
979 // We're always the default browser on ChromeOS.
982 Profile
* profile
= Profile::FromWebUI(web_ui());
983 return !profile
->IsGuestSession();
987 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
988 #if defined(OS_CHROMEOS)
989 // On Chrome OS we use different UI for multi-profiles.
992 if (helper::GetDesktopType(web_ui()) != chrome::HOST_DESKTOP_TYPE_NATIVE
)
994 Profile
* profile
= Profile::FromWebUI(web_ui());
995 if (profile
->IsGuestSession())
997 return profiles::IsMultipleProfilesEnabled();
1001 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1002 #if defined(OS_MACOSX)
1003 ShellIntegration::DefaultWebClientState state
=
1004 ShellIntegration::GetDefaultBrowser();
1005 int status_string_id
;
1006 if (state
== ShellIntegration::IS_DEFAULT
)
1007 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1008 else if (state
== ShellIntegration::NOT_DEFAULT
)
1009 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1011 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1013 SetDefaultBrowserUIString(status_string_id
);
1015 default_browser_worker_
->StartCheckIsDefault();
1019 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue
* args
) {
1020 // If the default browser setting is managed then we should not be able to
1021 // call this function.
1022 if (default_browser_policy_
.IsManaged())
1025 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1026 #if defined(OS_MACOSX)
1027 if (ShellIntegration::SetAsDefaultBrowser())
1028 UpdateDefaultBrowserState();
1030 default_browser_worker_
->StartSetAsDefault();
1031 // Callback takes care of updating UI.
1034 // If the user attempted to make Chrome the default browser, then he/she
1035 // arguably wants to be notified when that changes.
1036 PrefService
* prefs
= Profile::FromWebUI(web_ui())->GetPrefs();
1037 prefs
->SetBoolean(prefs::kCheckDefaultBrowser
, true);
1040 int BrowserOptionsHandler::StatusStringIdForState(
1041 ShellIntegration::DefaultWebClientState state
) {
1042 if (state
== ShellIntegration::IS_DEFAULT
)
1043 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1044 if (state
== ShellIntegration::NOT_DEFAULT
)
1045 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1046 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1049 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1050 ShellIntegration::DefaultWebClientUIState state
) {
1051 int status_string_id
;
1053 if (state
== ShellIntegration::STATE_IS_DEFAULT
) {
1054 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
;
1055 } else if (state
== ShellIntegration::STATE_NOT_DEFAULT
) {
1056 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1057 ShellIntegration::SET_DEFAULT_NOT_ALLOWED
) {
1058 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_SXS
;
1060 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
;
1062 } else if (state
== ShellIntegration::STATE_UNKNOWN
) {
1063 status_string_id
= IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN
;
1065 return; // Still processing.
1068 SetDefaultBrowserUIString(status_string_id
);
1071 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1072 return true; // This is UI so we can allow it.
1075 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id
) {
1076 base::StringValue
status_string(
1077 l10n_util::GetStringFUTF16(status_string_id
,
1078 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)));
1080 base::FundamentalValue
is_default(
1081 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
);
1083 base::FundamentalValue
can_be_default(
1084 !default_browser_policy_
.IsManaged() &&
1085 (status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_DEFAULT
||
1086 status_string_id
== IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT
));
1088 web_ui()->CallJavascriptFunction(
1089 "BrowserOptions.updateDefaultBrowserState",
1090 status_string
, is_default
, can_be_default
);
1093 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1094 if (!template_url_service_
|| !template_url_service_
->loaded())
1097 const TemplateURL
* default_url
=
1098 template_url_service_
->GetDefaultSearchProvider();
1100 int default_index
= -1;
1101 base::ListValue search_engines
;
1102 TemplateURLService::TemplateURLVector
model_urls(
1103 template_url_service_
->GetTemplateURLs());
1104 for (size_t i
= 0; i
< model_urls
.size(); ++i
) {
1105 if (!model_urls
[i
]->ShowInDefaultList())
1108 base::DictionaryValue
* entry
= new base::DictionaryValue();
1109 entry
->SetString("name", model_urls
[i
]->short_name());
1110 entry
->SetInteger("index", i
);
1111 search_engines
.Append(entry
);
1112 if (model_urls
[i
] == default_url
)
1116 web_ui()->CallJavascriptFunction(
1117 "BrowserOptions.updateSearchEngines",
1119 base::FundamentalValue(default_index
),
1120 base::FundamentalValue(
1121 template_url_service_
->is_default_search_managed() ||
1122 template_url_service_
->IsExtensionControlledDefaultSearch()));
1125 void BrowserOptionsHandler::SetDefaultSearchEngine(
1126 const base::ListValue
* args
) {
1127 int selected_index
= -1;
1128 if (!ExtractIntegerValue(args
, &selected_index
)) {
1133 TemplateURLService::TemplateURLVector
model_urls(
1134 template_url_service_
->GetTemplateURLs());
1135 if (selected_index
>= 0 &&
1136 selected_index
< static_cast<int>(model_urls
.size()))
1137 template_url_service_
->SetDefaultSearchProvider(model_urls
[selected_index
]);
1139 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1142 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1143 template_url_service_
=
1144 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1145 if (template_url_service_
) {
1146 template_url_service_
->Load();
1147 template_url_service_
->AddObserver(this);
1151 void BrowserOptionsHandler::Observe(
1153 const content::NotificationSource
& source
,
1154 const content::NotificationDetails
& details
) {
1155 // Notifications are used to update the UI dynamically when settings change in
1156 // the background. If the UI is currently being loaded, no dynamic updates are
1157 // possible (as the DOM and JS are not fully loaded) or necessary (as
1158 // InitializePage() will update the UI at the end of the load).
1159 if (!page_initialized_
)
1163 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED
:
1164 ObserveThemeChanged();
1166 #if defined(OS_CHROMEOS)
1167 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
:
1168 UpdateAccountPicture();
1171 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED
:
1174 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED
:
1175 // Update our sync/signin status display.
1183 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
1184 void BrowserOptionsHandler::OnCloudPrintPrefsChanged() {
1185 if (cloud_print_connector_ui_enabled_
)
1186 SetupCloudPrintConnectorSection();
1190 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue
* args
) {
1192 if (!auto_launch_trial::IsInAutoLaunchGroup())
1196 CHECK_EQ(args
->GetSize(), 1U);
1197 CHECK(args
->GetBoolean(0, &enable
));
1199 Profile
* profile
= Profile::FromWebUI(web_ui());
1200 content::BrowserThread::PostTask(
1201 content::BrowserThread::FILE, FROM_HERE
,
1203 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin
,
1204 profile
->GetPath().BaseName().value(), base::FilePath()) :
1205 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin
,
1206 profile
->GetPath().BaseName().value()));
1210 scoped_ptr
<base::ListValue
> BrowserOptionsHandler::GetProfilesInfoList() {
1211 ProfileInfoCache
& cache
=
1212 g_browser_process
->profile_manager()->GetProfileInfoCache();
1213 scoped_ptr
<base::ListValue
> profile_info_list(new base::ListValue
);
1214 base::FilePath current_profile_path
=
1215 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1217 for (size_t i
= 0, e
= cache
.GetNumberOfProfiles(); i
< e
; ++i
) {
1218 base::DictionaryValue
* profile_value
= new base::DictionaryValue();
1219 profile_value
->SetString("name", cache
.GetNameOfProfileAtIndex(i
));
1220 base::FilePath profile_path
= cache
.GetPathOfProfileAtIndex(i
);
1221 profile_value
->Set("filePath", base::CreateFilePathValue(profile_path
));
1222 profile_value
->SetBoolean("isCurrentProfile",
1223 profile_path
== current_profile_path
);
1224 profile_value
->SetBoolean("isManaged", cache
.ProfileIsManagedAtIndex(i
));
1226 bool is_gaia_picture
=
1227 cache
.IsUsingGAIAPictureOfProfileAtIndex(i
) &&
1228 cache
.GetGAIAPictureOfProfileAtIndex(i
);
1229 if (is_gaia_picture
) {
1230 gfx::Image icon
= profiles::GetAvatarIconForWebUI(
1231 cache
.GetAvatarIconOfProfileAtIndex(i
), true);
1232 profile_value
->SetString("iconURL",
1233 webui::GetBitmapDataUrl(icon
.AsBitmap()));
1235 size_t icon_index
= cache
.GetAvatarIconIndexOfProfileAtIndex(i
);
1236 profile_value
->SetString("iconURL",
1237 cache
.GetDefaultAvatarIconUrl(icon_index
));
1240 profile_info_list
->Append(profile_value
);
1243 return profile_info_list
.Pass();
1246 void BrowserOptionsHandler::SendProfilesInfo() {
1247 if (!ShouldShowMultiProfilesUserList())
1249 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1250 *GetProfilesInfoList());
1253 void BrowserOptionsHandler::DeleteProfile(const base::ListValue
* args
) {
1255 const base::Value
* file_path_value
;
1256 if (!args
->Get(0, &file_path_value
))
1259 base::FilePath file_path
;
1260 if (!base::GetValueAsFilePath(*file_path_value
, &file_path
))
1262 helper::DeleteProfileAtPath(file_path
, web_ui());
1265 void BrowserOptionsHandler::ObserveThemeChanged() {
1266 Profile
* profile
= Profile::FromWebUI(web_ui());
1267 ThemeService
* theme_service
= ThemeServiceFactory::GetForProfile(profile
);
1268 bool is_native_theme
= false;
1270 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1271 bool profile_is_managed
= profile
->IsManaged();
1272 is_native_theme
= theme_service
->UsingNativeTheme();
1273 base::FundamentalValue
native_theme_enabled(!is_native_theme
&&
1274 !profile_is_managed
);
1275 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1276 native_theme_enabled
);
1279 bool is_classic_theme
= !is_native_theme
&&
1280 theme_service
->UsingDefaultTheme();
1281 base::FundamentalValue
enabled(!is_classic_theme
);
1282 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1286 void BrowserOptionsHandler::ThemesReset(const base::ListValue
* args
) {
1287 Profile
* profile
= Profile::FromWebUI(web_ui());
1288 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1289 ThemeServiceFactory::GetForProfile(profile
)->UseDefaultTheme();
1292 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1293 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue
* args
) {
1294 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1295 Profile
* profile
= Profile::FromWebUI(web_ui());
1296 ThemeServiceFactory::GetForProfile(profile
)->SetNativeTheme();
1300 #if defined(OS_CHROMEOS)
1301 void BrowserOptionsHandler::UpdateAccountPicture() {
1302 std::string email
= chromeos::UserManager::Get()->GetLoggedInUser()->email();
1303 if (!email
.empty()) {
1304 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1305 base::StringValue
email_value(email
);
1306 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1311 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed
) {
1312 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1313 base::FundamentalValue(managed
));
1316 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed
) {
1317 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1318 base::FundamentalValue(managed
));
1322 scoped_ptr
<base::DictionaryValue
>
1323 BrowserOptionsHandler::GetSyncStateDictionary() {
1324 scoped_ptr
<base::DictionaryValue
> sync_status(new base::DictionaryValue
);
1325 Profile
* profile
= Profile::FromWebUI(web_ui());
1326 if (profile
->IsManaged()) {
1327 sync_status
->SetBoolean("supervisedUser", true);
1328 sync_status
->SetBoolean("signinAllowed", false);
1329 return sync_status
.Pass();
1331 if (profile
->IsGuestSession()) {
1332 // Cannot display signin status when running in guest mode on chromeos
1333 // because there is no SigninManager.
1334 sync_status
->SetBoolean("signinAllowed", false);
1335 return sync_status
.Pass();
1337 sync_status
->SetBoolean("supervisedUser", false);
1339 bool signout_prohibited
= false;
1340 #if !defined(OS_CHROMEOS)
1341 // Signout is not allowed if the user has policy (crbug.com/172204).
1342 signout_prohibited
=
1343 SigninManagerFactory::GetForProfile(profile
)->IsSignoutProhibited();
1346 ProfileSyncService
* service
=
1347 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
1348 SigninManagerBase
* signin
= SigninManagerFactory::GetForProfile(profile
);
1350 sync_status
->SetBoolean("signoutAllowed", !signout_prohibited
);
1351 sync_status
->SetBoolean("signinAllowed", signin
->IsSigninAllowed());
1352 sync_status
->SetBoolean("syncSystemEnabled", (service
!= NULL
));
1353 sync_status
->SetBoolean("setupCompleted",
1354 service
&& service
->HasSyncSetupCompleted());
1355 sync_status
->SetBoolean("setupInProgress",
1356 service
&& !service
->IsManaged() && service
->FirstSetupInProgress());
1358 base::string16 status_label
;
1359 base::string16 link_label
;
1360 bool status_has_error
= sync_ui_util::GetStatusLabels(
1361 service
, *signin
, sync_ui_util::WITH_HTML
, &status_label
, &link_label
) ==
1362 sync_ui_util::SYNC_ERROR
;
1363 sync_status
->SetString("statusText", status_label
);
1364 sync_status
->SetString("actionLinkText", link_label
);
1365 sync_status
->SetBoolean("hasError", status_has_error
);
1367 sync_status
->SetBoolean("managed", service
&& service
->IsManaged());
1368 sync_status
->SetBoolean("signedIn",
1369 !signin
->GetAuthenticatedUsername().empty());
1370 sync_status
->SetBoolean("hasUnrecoverableError",
1371 service
&& service
->HasUnrecoverableError());
1372 sync_status
->SetBoolean(
1374 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin
) &&
1375 service
&& service
->IsSyncEnabledAndLoggedIn() &&
1376 service
->IsOAuthRefreshTokenAvailable());
1378 return sync_status
.Pass();
1381 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1382 const base::ListValue
* args
) {
1383 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1384 select_folder_dialog_
= ui::SelectFileDialog::Create(
1385 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1386 ui::SelectFileDialog::FileTypeInfo info
;
1387 info
.support_drive
= true;
1388 select_folder_dialog_
->SelectFile(
1389 ui::SelectFileDialog::SELECT_FOLDER
,
1390 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE
),
1391 pref_service
->GetFilePath(prefs::kDownloadDefaultDirectory
),
1394 base::FilePath::StringType(),
1395 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(),
1399 void BrowserOptionsHandler::FileSelected(const base::FilePath
& path
, int index
,
1401 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1402 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1403 pref_service
->SetFilePath(prefs::kDownloadDefaultDirectory
, path
);
1404 pref_service
->SetFilePath(prefs::kSaveFileDefaultDirectory
, path
);
1407 #if defined(OS_CHROMEOS)
1408 void BrowserOptionsHandler::TouchpadExists(bool exists
) {
1409 base::FundamentalValue
val(exists
);
1410 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val
);
1413 void BrowserOptionsHandler::MouseExists(bool exists
) {
1414 base::FundamentalValue
val(exists
);
1415 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val
);
1418 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1419 const base::Value
* previous_policy
,
1420 const base::Value
* current_policy
) {
1421 const bool had_policy
= previous_policy
;
1422 const bool has_policy
= current_policy
;
1423 if (had_policy
!= has_policy
)
1424 OnAccountPictureManagedChanged(has_policy
);
1427 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1428 const base::Value
* previous_policy
,
1429 const base::Value
* current_policy
) {
1430 const bool had_policy
= previous_policy
;
1431 const bool has_policy
= current_policy
;
1432 if (had_policy
!= has_policy
)
1433 OnWallpaperManagedChanged(has_policy
);
1436 void BrowserOptionsHandler::OnPowerwashDialogShow(
1437 const base::ListValue
* args
) {
1438 UMA_HISTOGRAM_ENUMERATION(
1439 "Reset.ChromeOS.PowerwashDialogShown",
1440 chromeos::reset::DIALOG_FROM_OPTIONS
,
1441 chromeos::reset::DIALOG_VIEW_TYPE_SIZE
);
1444 #endif // defined(OS_CHROMEOS)
1446 void BrowserOptionsHandler::UpdateSyncState() {
1447 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1448 *GetSyncStateDictionary());
1451 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1455 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue
* args
) {
1456 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1457 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1458 web_ui()->GetWebContents()->GetBrowserContext());
1460 DownloadPrefs::FromDownloadManager(manager
)->ResetAutoOpen();
1463 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue
* args
) {
1465 if (ExtractIntegerValue(args
, &font_size
)) {
1466 if (font_size
> 0) {
1467 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1468 pref_service
->SetInteger(prefs::kWebKitDefaultFontSize
, font_size
);
1469 SetupFontSizeSelector();
1474 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1475 const base::ListValue
* args
) {
1477 if (ExtractDoubleValue(args
, &zoom_factor
)) {
1478 default_zoom_level_
.SetValue(content::ZoomFactorToZoomLevel(zoom_factor
));
1482 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue
* args
) {
1483 #if defined(OS_WIN) && defined(USE_ASH)
1484 // If hardware acceleration is disabled then we need to force restart
1485 // browser in desktop mode.
1486 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1487 // Currently there are issues with determining correct browser mode
1489 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
) {
1490 PrefService
* pref_service
= g_browser_process
->local_state();
1491 if (!pref_service
->GetBoolean(prefs::kHardwareAccelerationModeEnabled
)) {
1492 chrome::AttemptRestartToDesktopMode();
1498 chrome::AttemptRestart();
1501 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1502 const base::ListValue
* args
) {
1506 #if !defined(OS_CHROMEOS)
1507 void BrowserOptionsHandler::ShowNetworkProxySettings(
1508 const base::ListValue
* args
) {
1509 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1510 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1511 web_ui()->GetWebContents());
1515 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
1516 void BrowserOptionsHandler::ShowManageSSLCertificates(
1517 const base::ListValue
* args
) {
1518 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1519 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1520 web_ui()->GetWebContents());
1524 #if defined(ENABLE_SERVICE_DISCOVERY)
1526 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1527 const base::ListValue
* args
) {
1528 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1529 // Navigate in current tab to devices page.
1530 OpenURLParams
params(
1531 GURL(chrome::kChromeUIDevicesURL
), Referrer(),
1532 CURRENT_TAB
, content::PAGE_TRANSITION_LINK
, false);
1533 web_ui()->GetWebContents()->OpenURL(params
);
1538 #if defined(ENABLE_FULL_PRINTING)
1539 void BrowserOptionsHandler::ShowCloudPrintManagePage(
1540 const base::ListValue
* args
) {
1541 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters"));
1542 // Open a new tab in the current window for the management page.
1543 Profile
* profile
= Profile::FromWebUI(web_ui());
1544 OpenURLParams
params(
1545 CloudPrintURL(profile
).GetCloudPrintServiceManageURL(), Referrer(),
1546 NEW_FOREGROUND_TAB
, content::PAGE_TRANSITION_LINK
, false);
1547 web_ui()->GetWebContents()->OpenURL(params
);
1550 #if !defined(OS_CHROMEOS)
1551 void BrowserOptionsHandler::ShowCloudPrintSetupDialog(
1552 const base::ListValue
* args
) {
1553 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy"));
1554 // Open the connector enable page in the current tab.
1555 Profile
* profile
= Profile::FromWebUI(web_ui());
1556 OpenURLParams
params(
1557 CloudPrintURL(profile
).GetCloudPrintServiceEnableURL(
1558 CloudPrintProxyServiceFactory::GetForProfile(profile
)->proxy_id()),
1559 Referrer(), CURRENT_TAB
, content::PAGE_TRANSITION_LINK
, false);
1560 web_ui()->GetWebContents()->OpenURL(params
);
1563 void BrowserOptionsHandler::HandleDisableCloudPrintConnector(
1564 const base::ListValue
* args
) {
1565 content::RecordAction(
1566 UserMetricsAction("Options_DisableCloudPrintProxy"));
1567 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
1571 void BrowserOptionsHandler::RefreshCloudPrintStatusFromService() {
1572 if (cloud_print_connector_ui_enabled_
)
1573 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
1574 RefreshStatusFromService();
1577 void BrowserOptionsHandler::SetupCloudPrintConnectorSection() {
1578 Profile
* profile
= Profile::FromWebUI(web_ui());
1579 if (!CloudPrintProxyServiceFactory::GetForProfile(profile
)) {
1580 cloud_print_connector_ui_enabled_
= false;
1581 RemoveCloudPrintConnectorSection();
1585 bool cloud_print_connector_allowed
=
1586 !cloud_print_connector_enabled_
.IsManaged() ||
1587 cloud_print_connector_enabled_
.GetValue();
1588 base::FundamentalValue
allowed(cloud_print_connector_allowed
);
1591 if (profile
->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail
) &&
1592 cloud_print_connector_allowed
) {
1593 email
= profile
->GetPrefs()->GetString(prefs::kCloudPrintEmail
);
1595 base::FundamentalValue
disabled(email
.empty());
1597 base::string16 label_str
;
1598 if (email
.empty()) {
1599 label_str
= l10n_util::GetStringFUTF16(
1600 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL
,
1601 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
));
1603 label_str
= l10n_util::GetStringFUTF16(
1604 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL
,
1605 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT
),
1606 base::UTF8ToUTF16(email
));
1608 base::StringValue
label(label_str
);
1610 web_ui()->CallJavascriptFunction(
1611 "BrowserOptions.setupCloudPrintConnectorSection", disabled
, label
,
1615 void BrowserOptionsHandler::RemoveCloudPrintConnectorSection() {
1616 web_ui()->CallJavascriptFunction(
1617 "BrowserOptions.removeCloudPrintConnectorSection");
1619 #endif // defined(OS_CHROMEOS)
1620 #endif // defined(ENABLE_FULL_PRINTING)
1622 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1623 const base::ListValue
* args
) {
1624 Profile
* profile
= Profile::FromWebUI(web_ui());
1625 std::string group
= base::FieldTrialList::FindFullName("VoiceTrigger");
1626 if (group
!= "" && group
!= "Disabled") {
1627 if (HotwordServiceFactory::IsServiceAvailable(profile
))
1628 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection");
1632 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1633 const base::ListValue
* args
) {
1634 easy_unlock::LaunchEasyUnlockSetup(Profile::FromWebUI(web_ui()));
1637 void BrowserOptionsHandler::HandleRequestHotwordSetupRetry(
1638 const base::ListValue
* args
) {
1639 // TODO(joshtrask): invoke BrowserOptions.showHotwordSection again, passing
1640 // the new error message if any.
1641 HotwordServiceFactory::RetryHotwordExtension(Profile::FromWebUI(web_ui()));
1644 #if defined(OS_CHROMEOS)
1645 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1646 const base::ListValue
* args
) {
1647 wallpaper_manager_util::OpenWallpaperManager();
1650 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1651 const base::ListValue
* args
) {
1652 bool enabled
= false;
1653 args
->GetBoolean(0, &enabled
);
1655 chromeos::accessibility::EnableVirtualKeyboard(enabled
);
1658 void BrowserOptionsHandler::PerformFactoryResetRestart(
1659 const base::ListValue
* args
) {
1660 policy::BrowserPolicyConnectorChromeOS
* connector
=
1661 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1662 if (connector
->IsEnterpriseManaged())
1665 PrefService
* prefs
= g_browser_process
->local_state();
1666 prefs
->SetBoolean(prefs::kFactoryResetRequested
, true);
1667 prefs
->CommitPendingWrite();
1669 // Perform sign out. Current chrome process will then terminate, new one will
1670 // be launched (as if it was a restart).
1671 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1674 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1675 PrefService
* pref_service
= g_browser_process
->local_state();
1676 base::FundamentalValue
virtual_keyboard_enabled(
1677 pref_service
->GetBoolean(prefs::kVirtualKeyboardEnabled
));
1678 web_ui()->CallJavascriptFunction(
1679 "BrowserOptions.setVirtualKeyboardCheckboxState",
1680 virtual_keyboard_enabled
);
1684 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1685 #if defined(GOOGLE_CHROME_BUILD)
1686 // Don't show the reporting setting if we are in the guest mode.
1687 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1688 base::FundamentalValue
visible(false);
1689 web_ui()->CallJavascriptFunction(
1690 "BrowserOptions.setMetricsReportingSettingVisibility", visible
);
1695 void BrowserOptionsHandler::SetupFontSizeSelector() {
1696 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1697 const PrefService::Preference
* default_font_size
=
1698 pref_service
->FindPreference(prefs::kWebKitDefaultFontSize
);
1699 const PrefService::Preference
* default_fixed_font_size
=
1700 pref_service
->FindPreference(prefs::kWebKitDefaultFixedFontSize
);
1702 base::DictionaryValue dict
;
1703 dict
.SetInteger("value",
1704 pref_service
->GetInteger(prefs::kWebKitDefaultFontSize
));
1706 // The font size control displays the value of the default font size, but
1707 // setting it alters both the default font size and the default fixed font
1708 // size. So it must be disabled when either of those prefs is not user
1710 dict
.SetBoolean("disabled",
1711 !default_font_size
->IsUserModifiable() ||
1712 !default_fixed_font_size
->IsUserModifiable());
1714 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1715 // adapted to consider two prefs. It may be better to refactor
1716 // CreateValueForPref so it can be called from here.
1717 if (default_font_size
->IsManaged() || default_fixed_font_size
->IsManaged()) {
1718 dict
.SetString("controlledBy", "policy");
1719 } else if (default_font_size
->IsExtensionControlled() ||
1720 default_fixed_font_size
->IsExtensionControlled()) {
1721 dict
.SetString("controlledBy", "extension");
1724 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict
);
1727 void BrowserOptionsHandler::SetupPageZoomSelector() {
1728 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1729 double default_zoom_level
= pref_service
->GetDouble(prefs::kDefaultZoomLevel
);
1730 double default_zoom_factor
=
1731 content::ZoomLevelToZoomFactor(default_zoom_level
);
1733 // Generate a vector of zoom factors from an array of known presets along with
1734 // the default factor added if necessary.
1735 std::vector
<double> zoom_factors
=
1736 chrome_page_zoom::PresetZoomFactors(default_zoom_factor
);
1738 // Iterate through the zoom factors and and build the contents of the
1739 // selector that will be sent to the javascript handler.
1740 // Each item in the list has the following parameters:
1741 // 1. Title (string).
1742 // 2. Value (double).
1743 // 3. Is selected? (bool).
1744 base::ListValue zoom_factors_value
;
1745 for (std::vector
<double>::const_iterator i
= zoom_factors
.begin();
1746 i
!= zoom_factors
.end(); ++i
) {
1747 base::ListValue
* option
= new base::ListValue();
1749 int percent
= static_cast<int>(factor
* 100 + 0.5);
1750 option
->Append(new base::StringValue(
1751 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT
, percent
)));
1752 option
->Append(new base::FundamentalValue(factor
));
1753 bool selected
= content::ZoomValuesEqual(factor
, default_zoom_factor
);
1754 option
->Append(new base::FundamentalValue(selected
));
1755 zoom_factors_value
.Append(option
);
1758 web_ui()->CallJavascriptFunction(
1759 "BrowserOptions.setupPageZoomSelector", zoom_factors_value
);
1762 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1763 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1764 // We show the button if the user has any auto-open file types registered.
1765 DownloadManager
* manager
= BrowserContext::GetDownloadManager(
1766 web_ui()->GetWebContents()->GetBrowserContext());
1767 bool display
= manager
&&
1768 DownloadPrefs::FromDownloadManager(manager
)->IsAutoOpenUsed();
1769 base::FundamentalValue
value(display
);
1770 web_ui()->CallJavascriptFunction(
1771 "BrowserOptions.setAutoOpenFileTypesDisplayed", value
);
1774 void BrowserOptionsHandler::SetupProxySettingsSection() {
1775 #if !defined(OS_CHROMEOS)
1776 // Disable the button if proxy settings are managed by a sysadmin, overridden
1777 // by an extension, or the browser is running in Windows Ash (on Windows the
1778 // proxy settings dialog will open on the Windows desktop and be invisible
1779 // to a user in Ash).
1780 bool is_win_ash
= false;
1782 chrome::HostDesktopType desktop_type
= helper::GetDesktopType(web_ui());
1783 is_win_ash
= (desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
);
1785 PrefService
* pref_service
= Profile::FromWebUI(web_ui())->GetPrefs();
1786 const PrefService::Preference
* proxy_config
=
1787 pref_service
->FindPreference(prefs::kProxy
);
1788 bool is_extension_controlled
= (proxy_config
&&
1789 proxy_config
->IsExtensionControlled());
1791 base::FundamentalValue
disabled(is_win_ash
|| (proxy_config
&&
1792 !proxy_config
->IsUserModifiable()));
1793 base::FundamentalValue
extension_controlled(is_extension_controlled
);
1794 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection",
1795 disabled
, extension_controlled
);
1797 #endif // !defined(OS_CHROMEOS)
1800 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1802 // Disable the button if the settings page is displayed in Windows Ash,
1803 // otherwise the proxy settings dialog will open on the Windows desktop and
1804 // be invisible to a user in Ash.
1805 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH
) {
1806 base::FundamentalValue
enabled(false);
1807 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1810 #endif // defined(OS_WIN)
1813 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1814 bool has_users
= !Profile::FromWebUI(web_ui())->
1815 GetPrefs()->GetDictionary(prefs::kManagedUsers
)->empty();
1816 base::FundamentalValue
has_users_value(has_users
);
1817 web_ui()->CallJavascriptFunction(
1818 "BrowserOptions.updateManagesSupervisedUsers",
1822 void BrowserOptionsHandler::SetupEasyUnlock() {
1823 bool has_pairing
= !Profile::FromWebUI(web_ui())->GetPrefs()
1824 ->GetDictionary(prefs::kEasyUnlockPairing
)->empty();
1825 base::FundamentalValue
has_pairing_value(has_pairing
);
1826 web_ui()->CallJavascriptFunction(
1827 "BrowserOptions.updateEasyUnlock",
1831 } // namespace options