Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / browser_options_handler.cc
blob04464575bfb1e7a236370c0f6a087c52c0cbb376
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"
7 #include <string>
8 #include <vector>
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/profile_resetter/automatic_profile_resetter.h"
38 #include "chrome/browser/profile_resetter/automatic_profile_resetter_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.h"
51 #include "chrome/browser/search_engines/template_url_service.h"
52 #include "chrome/browser/search_engines/template_url_service_factory.h"
53 #include "chrome/browser/signin/easy_unlock.h"
54 #include "chrome/browser/signin/signin_manager_factory.h"
55 #include "chrome/browser/sync/profile_sync_service.h"
56 #include "chrome/browser/sync/profile_sync_service_factory.h"
57 #include "chrome/browser/sync/sync_ui_util.h"
58 #include "chrome/browser/themes/theme_service.h"
59 #include "chrome/browser/themes/theme_service_factory.h"
60 #include "chrome/browser/ui/browser_finder.h"
61 #include "chrome/browser/ui/chrome_select_file_policy.h"
62 #include "chrome/browser/ui/host_desktop.h"
63 #include "chrome/browser/ui/options/options_util.h"
64 #include "chrome/browser/ui/webui/favicon_source.h"
65 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
66 #include "chrome/common/chrome_constants.h"
67 #include "chrome/common/chrome_paths.h"
68 #include "chrome/common/chrome_switches.h"
69 #include "chrome/common/extensions/extension_constants.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/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"
99 #endif
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/user.h"
109 #include "chrome/browser/chromeos/login/users/user_manager.h"
110 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
111 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
112 #include "chrome/browser/chromeos/reset/metrics.h"
113 #include "chrome/browser/chromeos/settings/cros_settings.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 "policy/policy_constants.h"
124 #include "ui/gfx/image/image_skia.h"
125 #endif // defined(OS_CHROMEOS)
127 #if defined(OS_WIN)
128 #include "chrome/browser/extensions/settings_api_helpers.h"
129 #include "chrome/installer/util/auto_launch_util.h"
130 #include "content/public/browser/browser_url_handler.h"
131 #endif // defined(OS_WIN)
133 #if defined(ENABLE_SERVICE_DISCOVERY)
134 #include "chrome/browser/local_discovery/privet_notifications.h"
135 #endif
137 using base::UserMetricsAction;
138 using content::BrowserContext;
139 using content::BrowserThread;
140 using content::DownloadManager;
141 using content::OpenURLParams;
142 using content::Referrer;
143 using extensions::Extension;
144 using extensions::ExtensionRegistry;
146 namespace {
148 #if defined(OS_WIN)
149 void AppendExtensionData(const std::string& key,
150 const Extension* extension,
151 base::DictionaryValue* dict) {
152 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue);
153 details->SetString("id", extension ? extension->id() : std::string());
154 details->SetString("name", extension ? extension->name() : std::string());
155 dict->Set(key, details.release());
157 #endif // defined(OS_WIN)
159 } // namespace
161 namespace options {
163 BrowserOptionsHandler::BrowserOptionsHandler()
164 : page_initialized_(false),
165 template_url_service_(NULL),
166 cloud_print_mdns_ui_enabled_(false),
167 signin_observer_(this),
168 weak_ptr_factory_(this) {
169 #if !defined(OS_MACOSX)
170 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
171 #endif
173 #if defined(ENABLE_SERVICE_DISCOVERY)
174 cloud_print_mdns_ui_enabled_ = !CommandLine::ForCurrentProcess()->HasSwitch(
175 switches::kDisableDeviceDiscovery);
176 #endif // defined(ENABLE_SERVICE_DISCOVERY)
179 BrowserOptionsHandler::~BrowserOptionsHandler() {
180 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
181 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
182 if (sync_service)
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) {
196 DCHECK(values);
198 static OptionsStringResource resources[] = {
199 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT },
200 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY },
201 { "advancedSectionTitleCertificates",
202 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES },
203 { "advancedSectionTitleContent",
204 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT },
205 { "advancedSectionTitleLanguages",
206 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES },
207 { "advancedSectionTitleNetwork",
208 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK },
209 { "advancedSectionTitlePrivacy",
210 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY },
211 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE },
212 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN },
213 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY },
214 { "autoOpenFileTypesResetToDefault",
215 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT },
216 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE },
217 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON },
218 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL },
219 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
220 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
221 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
222 #if defined(OS_CHROMEOS)
223 { "disableGData", IDS_OPTIONS_DISABLE_GDATA },
224 #endif
225 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES },
226 #if defined(OS_CHROMEOS)
227 { "displayOptions",
228 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL },
229 #endif
230 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK },
231 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT },
232 { "doNotTrackConfirmEnable",
233 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE },
234 { "doNotTrackConfirmDisable",
235 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE },
236 { "downloadLocationAskForSaveLocation",
237 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION },
238 { "downloadLocationBrowseTitle",
239 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE },
240 { "downloadLocationChangeButton",
241 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON },
242 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME },
243 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING },
244 #if !defined(OS_CHROMEOS)
245 { "easyUnlockCheckboxLabel", IDS_OPTIONS_EASY_UNLOCK_CHECKBOX_LABEL },
246 #endif
247 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE },
248 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON },
249 { "easyUnlockManagement", IDS_OPTIONS_EASY_UNLOCK_MANAGEMENT },
250 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED },
251 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE },
252 { "fontSettingsCustomizeFontsButton",
253 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON },
254 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM },
255 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE },
256 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
257 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
258 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE },
259 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
260 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS },
261 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP },
262 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
263 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
264 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
265 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX },
266 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE },
267 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE },
268 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION },
269 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE },
270 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON },
271 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE },
272 { "languageAndSpellCheckSettingsButton",
273 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS },
274 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF },
275 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK },
276 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES },
277 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK },
278 { "managedUserLabel", IDS_MANAGED_USER_AVATAR_LABEL },
279 { "networkPredictionEnabledDescription",
280 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
281 { "passwordsAndAutofillGroupName",
282 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME },
283 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
284 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
285 { "privacyContentSettingsButton",
286 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON },
287 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL },
288 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL },
289 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL },
290 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT },
291 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL },
292 { "profilesSupervisedDashboardTip",
293 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP },
294 #if defined(ENABLE_SETTINGS_APP)
295 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL },
296 #endif
297 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
298 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
299 IDS_PRODUCT_NAME },
300 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
301 { "resetProfileSettingsDescription",
302 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
303 { "resetProfileSettingsSectionTitle",
304 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
305 { "safeBrowsingEnableProtection",
306 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
307 { "safeBrowsingEnableDownloadFeedback",
308 IDS_OPTIONS_SAFEBROWSING_ENABLEDOWNLOADFEEDBACK },
309 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
310 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
311 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME },
312 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME },
313 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
314 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME },
315 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME },
316 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT },
317 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE },
318 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE },
319 { "spellingPref", IDS_OPTIONS_SPELLING_PREF },
320 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION },
321 { "settingsTitle", IDS_SETTINGS_TITLE },
322 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS },
323 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES },
324 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB },
325 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
326 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF },
327 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS },
328 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL },
329 { "themesGallery", IDS_THEMES_GALLERY_BUTTON },
330 { "themesGalleryURL", IDS_THEMES_GALLERY_URL },
331 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF },
332 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
333 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
334 { "translateEnableTranslate",
335 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE },
336 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
337 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS },
338 { "themesNativeButton", IDS_THEMES_GTK_BUTTON },
339 { "themesSetClassic", IDS_THEMES_SET_CLASSIC },
340 #else
341 { "themes", IDS_THEMES_GROUP_NAME },
342 #endif
343 { "themesReset", IDS_THEMES_RESET_BUTTON },
344 #if defined(OS_CHROMEOS)
345 { "accessibilityExplanation",
346 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION },
347 { "accessibilitySettings",
348 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS },
349 { "accessibilityHighContrast",
350 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION },
351 { "accessibilityScreenMagnifier",
352 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION },
353 { "accessibilityTapDragging",
354 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION },
355 { "accessibilityScreenMagnifierOff",
356 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF },
357 { "accessibilityScreenMagnifierFull",
358 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL },
359 { "accessibilityScreenMagnifierPartial",
360 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL },
361 { "accessibilityLargeCursor",
362 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION },
363 { "accessibilityStickyKeys",
364 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION },
365 { "accessibilitySpokenFeedback",
366 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION },
367 { "accessibilityTitle",
368 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY },
369 { "accessibilityVirtualKeyboard",
370 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION },
371 { "accessibilityAlwaysShowMenu",
372 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU },
373 { "accessibilityAutoclick",
374 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION },
375 { "accessibilityAutoclickDropdown",
376 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION },
377 { "autoclickDelayExtremelyShort",
378 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT },
379 { "autoclickDelayVeryShort",
380 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT },
381 { "autoclickDelayShort",
382 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT },
383 { "autoclickDelayLong",
384 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG },
385 { "autoclickDelayVeryLong",
386 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG },
387 { "consumerManagementEnrollButton",
388 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON },
389 { "consumerManagementEnrollDescription",
390 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_DESCRIPTION },
391 { "enableContentProtectionAttestation",
392 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION },
393 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING },
394 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET },
395 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON },
396 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON },
397 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING },
398 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL },
399 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE },
400 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION },
401 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME },
402 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION },
403 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION },
404 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION },
405 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION },
406 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX },
407 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE },
408 { "keyboardSettingsButtonTitle",
409 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE },
410 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE },
411 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES },
412 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME },
413 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL },
414 { "securityTitle", IDS_OPTIONS_SECURITY_SECTION_TITLE },
415 { "syncOverview", IDS_SYNC_OVERVIEW },
416 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
417 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION },
418 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION },
419 #else
420 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON },
421 #endif
422 #if defined(OS_CHROMEOS) && defined(USE_ASH)
423 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON },
424 #endif
425 { "advancedSectionTitleSystem",
426 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM },
427 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
428 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE },
429 #endif
430 #if !defined(OS_CHROMEOS)
431 { "gpuModeCheckbox",
432 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE },
433 { "gpuModeResetRestart",
434 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART },
435 // Strings with product-name substitutions.
436 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME },
437 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
438 #endif
439 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL,
440 IDS_SHORT_PRODUCT_NAME },
441 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
442 IDS_PRODUCT_NAME },
443 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
444 IDS_PRODUCT_NAME },
445 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT },
446 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT },
447 #if defined(OS_CHROMEOS)
448 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION,
449 IDS_SHORT_PRODUCT_NAME },
450 #endif
451 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
452 IDS_SHORT_PRODUCT_NAME },
453 #if defined(ENABLE_SERVICE_DISCOVERY)
454 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON },
455 { "cloudPrintEnableNotificationsLabel",
456 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL },
457 #endif
460 #if defined(ENABLE_SETTINGS_APP)
461 static OptionsStringResource app_resources[] = {
462 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW },
463 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL,
464 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
465 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
466 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
467 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
468 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
469 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
470 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
472 base::DictionaryValue* app_values = NULL;
473 CHECK(values->GetDictionary(kSettingsAppKey, &app_values));
474 RegisterStrings(app_values, app_resources, arraysize(app_resources));
475 #endif
477 RegisterStrings(values, resources, arraysize(resources));
478 RegisterTitle(values, "doNotTrackConfirmOverlay",
479 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE);
480 RegisterTitle(values, "spellingConfirmOverlay",
481 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE);
482 #if defined(ENABLE_FULL_PRINTING)
483 RegisterCloudPrintValues(values);
484 #endif
486 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL);
487 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
488 values->SetString(
489 "defaultSearchGroupLabel",
490 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
491 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL);
492 RegisterTitle(values, "hotwordConfirmOverlay",
493 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE);
495 #if defined(OS_CHROMEOS)
496 Profile* profile = Profile::FromWebUI(web_ui());
497 std::string username = profile->GetProfileName();
498 if (username.empty()) {
499 chromeos::User* user =
500 chromeos::UserManager::Get()->GetUserByProfile(profile);
501 if (user && (user->GetType() != chromeos::User::USER_TYPE_GUEST))
502 username = user->email();
505 if (!username.empty())
506 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
508 values->SetString("username", username);
509 #endif
511 // Pass along sync status early so it will be available during page init.
512 values->Set("syncData", GetSyncStateDictionary().release());
514 // The Reset Profile Settings feature makes no sense for an off-the-record
515 // profile (e.g. in Guest mode on Chrome OS), so hide it.
516 values->SetBoolean("enableResetProfileSettings",
517 !Profile::FromWebUI(web_ui())->IsOffTheRecord());
519 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
520 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
522 #if defined(OS_CHROMEOS)
523 // TODO(pastarmovj): replace this with a call to the CrosSettings list
524 // handling functionality to come.
525 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
527 values->SetString("accessibilityLearnMoreURL",
528 chrome::kChromeAccessibilityHelpURL);
530 std::string settings_url = std::string("chrome-extension://") +
531 extension_misc::kChromeVoxExtensionId +
532 chrome::kChromeAccessibilitySettingsURL;
534 values->SetString("accessibilitySettingsURL",
535 settings_url);
537 values->SetString("contentProtectionAttestationLearnMoreURL",
538 chrome::kAttestationForContentProtectionLearnMoreURL);
540 // Creates magnifierList.
541 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue);
543 scoped_ptr<base::ListValue> option_full(new base::ListValue);
544 option_full->AppendInteger(ash::MAGNIFIER_FULL);
545 option_full->AppendString(l10n_util::GetStringUTF16(
546 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL));
547 magnifier_list->Append(option_full.release());
549 scoped_ptr<base::ListValue> option_partial(new base::ListValue);
550 option_partial->AppendInteger(ash::MAGNIFIER_PARTIAL);
551 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16(
552 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL)));
553 magnifier_list->Append(option_partial.release());
555 values->Set("magnifierList", magnifier_list.release());
556 #endif
558 #if defined(OS_MACOSX)
559 values->SetString("macPasswordsWarning",
560 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
561 values->SetBoolean("multiple_profiles",
562 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
563 #endif
565 if (ShouldShowMultiProfilesUserList())
566 values->Set("profilesInfo", GetProfilesInfoList().release());
568 values->SetBoolean("profileIsManaged",
569 Profile::FromWebUI(web_ui())->IsManaged());
571 #if !defined(OS_CHROMEOS)
572 values->SetBoolean(
573 "gpuEnabledAtStart",
574 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
575 #endif
577 #if defined(ENABLE_SERVICE_DISCOVERY)
578 values->SetBoolean("cloudPrintHideNotificationsCheckbox",
579 !local_discovery::PrivetNotificationService::IsEnabled());
580 #endif
582 values->SetBoolean("cloudPrintShowMDnsOptions",
583 cloud_print_mdns_ui_enabled_);
585 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
587 values->SetString("languagesLearnMoreURL",
588 chrome::kLanguageSettingsLearnMoreUrl);
590 values->SetBoolean(
591 "easyUnlockEnabled",
592 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableEasyUnlock));
593 values->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl);
594 values->SetString("easyUnlockManagementURL",
595 chrome::kEasyUnlockManagementUrl);
596 #if defined(OS_CHROMEOS)
597 values->SetString("easyUnlockCheckboxLabel",
598 l10n_util::GetStringFUTF16(
599 IDS_OPTIONS_EASY_UNLOCK_CHECKBOX_LABEL_CHROMEOS,
600 chromeos::GetChromeDeviceType()));
602 values->SetBoolean(
603 "consumerManagementEnabled",
604 CommandLine::ForCurrentProcess()->HasSwitch(
605 chromeos::switches::kEnableConsumerManagement));
606 #endif
609 #if defined(ENABLE_FULL_PRINTING)
610 void BrowserOptionsHandler::RegisterCloudPrintValues(
611 base::DictionaryValue* values) {
612 values->SetString("cloudPrintOptionLabel",
613 l10n_util::GetStringFUTF16(
614 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL,
615 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
617 values->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
618 values->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
620 #endif // defined(ENABLE_FULL_PRINTING)
622 void BrowserOptionsHandler::RegisterMessages() {
623 web_ui()->RegisterMessageCallback(
624 "becomeDefaultBrowser",
625 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
626 base::Unretained(this)));
627 web_ui()->RegisterMessageCallback(
628 "setDefaultSearchEngine",
629 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
630 base::Unretained(this)));
631 web_ui()->RegisterMessageCallback(
632 "deleteProfile",
633 base::Bind(&BrowserOptionsHandler::DeleteProfile,
634 base::Unretained(this)));
635 web_ui()->RegisterMessageCallback(
636 "themesReset",
637 base::Bind(&BrowserOptionsHandler::ThemesReset,
638 base::Unretained(this)));
639 web_ui()->RegisterMessageCallback(
640 "requestProfilesInfo",
641 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo,
642 base::Unretained(this)));
643 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
644 web_ui()->RegisterMessageCallback(
645 "themesSetNative",
646 base::Bind(&BrowserOptionsHandler::ThemesSetNative,
647 base::Unretained(this)));
648 #endif
649 web_ui()->RegisterMessageCallback(
650 "selectDownloadLocation",
651 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation,
652 base::Unretained(this)));
653 web_ui()->RegisterMessageCallback(
654 "autoOpenFileTypesAction",
655 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton,
656 base::Unretained(this)));
657 web_ui()->RegisterMessageCallback(
658 "defaultFontSizeAction",
659 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize,
660 base::Unretained(this)));
661 web_ui()->RegisterMessageCallback(
662 "defaultZoomFactorAction",
663 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor,
664 base::Unretained(this)));
665 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
666 web_ui()->RegisterMessageCallback(
667 "showManageSSLCertificates",
668 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates,
669 base::Unretained(this)));
670 #endif
671 #if defined(OS_CHROMEOS)
672 web_ui()->RegisterMessageCallback(
673 "openWallpaperManager",
674 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager,
675 base::Unretained(this)));
676 web_ui()->RegisterMessageCallback(
677 "virtualKeyboardChange",
678 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback,
679 base::Unretained(this)));
680 web_ui()->RegisterMessageCallback(
681 "onPowerwashDialogShow",
682 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow,
683 base::Unretained(this)));
684 web_ui()->RegisterMessageCallback(
685 "performFactoryResetRestart",
686 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart,
687 base::Unretained(this)));
688 web_ui()->RegisterMessageCallback(
689 "enrollConsumerManagement",
690 base::Bind(&BrowserOptionsHandler::HandleEnrollConsumerManagement,
691 base::Unretained(this)));
692 #else
693 web_ui()->RegisterMessageCallback(
694 "restartBrowser",
695 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser,
696 base::Unretained(this)));
697 web_ui()->RegisterMessageCallback(
698 "showNetworkProxySettings",
699 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings,
700 base::Unretained(this)));
701 #endif // defined(OS_CHROMEOS)
703 #if defined(ENABLE_SERVICE_DISCOVERY)
704 if (cloud_print_mdns_ui_enabled_) {
705 web_ui()->RegisterMessageCallback(
706 "showCloudPrintDevicesPage",
707 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage,
708 base::Unretained(this)));
710 #endif
711 web_ui()->RegisterMessageCallback(
712 "requestHotwordAvailable",
713 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable,
714 base::Unretained(this)));
716 web_ui()->RegisterMessageCallback(
717 "launchEasyUnlockSetup",
718 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
719 base::Unretained(this)));
720 #if defined(OS_WIN)
721 web_ui()->RegisterMessageCallback(
722 "refreshExtensionControlIndicators",
723 base::Bind(
724 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
725 base::Unretained(this)));
726 #endif // defined(OS_WIN)
729 void BrowserOptionsHandler::Uninitialize() {
730 registrar_.RemoveAll();
731 #if defined(OS_WIN)
732 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
733 #endif
736 void BrowserOptionsHandler::OnStateChanged() {
737 UpdateSyncState();
740 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string& username,
741 const std::string& password) {
742 OnStateChanged();
745 void BrowserOptionsHandler::GoogleSignedOut(const std::string& username) {
746 OnStateChanged();
749 void BrowserOptionsHandler::PageLoadStarted() {
750 page_initialized_ = false;
753 void BrowserOptionsHandler::InitializeHandler() {
754 Profile* profile = Profile::FromWebUI(web_ui());
755 PrefService* prefs = profile->GetPrefs();
757 ProfileSyncService* sync_service(
758 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile));
759 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
760 // destruction is automatic.
761 if (sync_service)
762 sync_service->AddObserver(this);
764 SigninManagerBase* signin_manager(
765 SigninManagerFactory::GetInstance()->GetForProfile(profile));
766 if (signin_manager)
767 signin_observer_.Add(signin_manager);
769 // Create our favicon data source.
770 content::URLDataSource::Add(
771 profile, new FaviconSource(profile, FaviconSource::FAVICON));
773 default_browser_policy_.Init(
774 prefs::kDefaultBrowserSettingEnabled,
775 g_browser_process->local_state(),
776 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState,
777 base::Unretained(this)));
779 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
780 content::NotificationService::AllSources());
781 #if defined(OS_CHROMEOS)
782 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
783 content::NotificationService::AllSources());
784 #endif
785 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
786 content::Source<ThemeService>(
787 ThemeServiceFactory::GetForProfile(profile)));
788 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
789 content::Source<Profile>(profile));
790 AddTemplateUrlServiceObserver();
792 #if defined(OS_WIN)
793 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
795 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
796 if (!command_line.HasSwitch(switches::kUserDataDir)) {
797 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
798 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
799 weak_ptr_factory_.GetWeakPtr(),
800 profile->GetPath()));
802 #endif
804 auto_open_files_.Init(
805 prefs::kDownloadExtensionsToOpen, prefs,
806 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes,
807 base::Unretained(this)));
808 default_zoom_level_.Init(
809 prefs::kDefaultZoomLevel, prefs,
810 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector,
811 base::Unretained(this)));
812 profile_pref_registrar_.Init(prefs);
813 profile_pref_registrar_.Add(
814 prefs::kWebKitDefaultFontSize,
815 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
816 base::Unretained(this)));
817 profile_pref_registrar_.Add(
818 prefs::kWebKitDefaultFixedFontSize,
819 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
820 base::Unretained(this)));
821 profile_pref_registrar_.Add(
822 prefs::kManagedUsers,
823 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers,
824 base::Unretained(this)));
825 profile_pref_registrar_.Add(
826 prefs::kSigninAllowed,
827 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange,
828 base::Unretained(this)));
829 profile_pref_registrar_.Add(
830 prefs::kEasyUnlockPairing,
831 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock,
832 base::Unretained(this)));
834 #if defined(OS_WIN)
835 profile_pref_registrar_.Add(
836 prefs::kURLsToRestoreOnStartup,
837 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
838 base::Unretained(this)));
839 profile_pref_registrar_.Add(
840 prefs::kHomePage,
841 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
842 base::Unretained(this)));
843 #endif // defined(OS_WIN)
845 #if defined(OS_CHROMEOS)
846 if (!policy_registrar_) {
847 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
848 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
849 policy_service(),
850 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
851 policy_registrar_->Observe(
852 policy::key::kUserAvatarImage,
853 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged,
854 base::Unretained(this)));
855 policy_registrar_->Observe(
856 policy::key::kWallpaperImage,
857 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged,
858 base::Unretained(this)));
860 #else // !defined(OS_CHROMEOS)
861 profile_pref_registrar_.Add(
862 prefs::kProxy,
863 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection,
864 base::Unretained(this)));
865 #endif // !defined(OS_CHROMEOS)
868 void BrowserOptionsHandler::InitializePage() {
869 page_initialized_ = true;
871 OnTemplateURLServiceChanged();
873 ObserveThemeChanged();
874 OnStateChanged();
875 UpdateDefaultBrowserState();
877 SetupMetricsReportingSettingVisibility();
878 SetupFontSizeSelector();
879 SetupPageZoomSelector();
880 SetupAutoOpenFileTypes();
881 SetupProxySettingsSection();
882 SetupManageCertificatesSection();
883 SetupManagingSupervisedUsers();
884 SetupEasyUnlock();
885 SetupExtensionControlledIndicators();
887 #if defined(OS_CHROMEOS)
888 SetupAccessibilityFeatures();
889 policy::BrowserPolicyConnectorChromeOS* connector =
890 g_browser_process->platform_part()->browser_policy_connector_chromeos();
891 if (!connector->IsEnterpriseManaged() &&
892 !chromeos::UserManager::Get()->IsLoggedInAsGuest() &&
893 !chromeos::UserManager::Get()->IsLoggedInAsLocallyManagedUser()) {
894 web_ui()->CallJavascriptFunction(
895 "BrowserOptions.enableFactoryResetSection");
898 Profile* profile = Profile::FromWebUI(web_ui());
899 OnAccountPictureManagedChanged(
900 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
901 policy_service()->GetPolicies(
902 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
903 std::string()))
904 .Get(policy::key::kUserAvatarImage));
906 OnWallpaperManagedChanged(
907 chromeos::WallpaperManager::Get()->IsPolicyControlled(
908 chromeos::UserManager::Get()->GetActiveUser()->email()));
909 #endif
912 // static
913 void BrowserOptionsHandler::CheckAutoLaunch(
914 base::WeakPtr<BrowserOptionsHandler> weak_this,
915 const base::FilePath& profile_path) {
916 #if defined(OS_WIN)
917 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
919 // Auto-launch is not supported for secondary profiles yet.
920 if (profile_path.BaseName().value() !=
921 base::ASCIIToUTF16(chrome::kInitialProfile)) {
922 return;
925 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
926 // deleted.
927 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
928 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
929 weak_this,
930 auto_launch_trial::IsInAutoLaunchGroup(),
931 auto_launch_util::AutoStartRequested(
932 profile_path.BaseName().value(),
933 true, // Window requested.
934 base::FilePath())));
935 #endif
938 void BrowserOptionsHandler::CheckAutoLaunchCallback(
939 bool is_in_auto_launch_group,
940 bool will_launch_at_login) {
941 #if defined(OS_WIN)
942 DCHECK_CURRENTLY_ON(BrowserThread::UI);
944 if (is_in_auto_launch_group) {
945 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
946 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
947 base::Unretained(this)));
949 base::FundamentalValue enabled(will_launch_at_login);
950 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
951 enabled);
953 #endif
956 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
957 #if defined(OS_CHROMEOS)
958 // We're always the default browser on ChromeOS.
959 return false;
960 #else
961 Profile* profile = Profile::FromWebUI(web_ui());
962 return !profile->IsGuestSession();
963 #endif
966 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
967 #if defined(OS_CHROMEOS)
968 // On Chrome OS we use different UI for multi-profiles.
969 return false;
970 #else
971 if (helper::GetDesktopType(web_ui()) != chrome::HOST_DESKTOP_TYPE_NATIVE)
972 return false;
973 Profile* profile = Profile::FromWebUI(web_ui());
974 if (profile->IsGuestSession())
975 return false;
976 return profiles::IsMultipleProfilesEnabled();
977 #endif
980 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
981 #if defined(OS_CHROMEOS)
982 // ChromeOS handles guest-mode restrictions in a different manner.
983 return true;
984 #else
985 return !Profile::FromWebUI(web_ui())->IsGuestSession();
986 #endif
989 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
990 #if defined(OS_MACOSX)
991 ShellIntegration::DefaultWebClientState state =
992 ShellIntegration::GetDefaultBrowser();
993 int status_string_id;
994 if (state == ShellIntegration::IS_DEFAULT)
995 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
996 else if (state == ShellIntegration::NOT_DEFAULT)
997 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
998 else
999 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1001 SetDefaultBrowserUIString(status_string_id);
1002 #else
1003 default_browser_worker_->StartCheckIsDefault();
1004 #endif
1007 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue* args) {
1008 // If the default browser setting is managed then we should not be able to
1009 // call this function.
1010 if (default_browser_policy_.IsManaged())
1011 return;
1013 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1014 #if defined(OS_MACOSX)
1015 if (ShellIntegration::SetAsDefaultBrowser())
1016 UpdateDefaultBrowserState();
1017 #else
1018 default_browser_worker_->StartSetAsDefault();
1019 // Callback takes care of updating UI.
1020 #endif
1022 // If the user attempted to make Chrome the default browser, then he/she
1023 // arguably wants to be notified when that changes.
1024 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1025 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
1028 int BrowserOptionsHandler::StatusStringIdForState(
1029 ShellIntegration::DefaultWebClientState state) {
1030 if (state == ShellIntegration::IS_DEFAULT)
1031 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1032 if (state == ShellIntegration::NOT_DEFAULT)
1033 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1034 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1037 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1038 ShellIntegration::DefaultWebClientUIState state) {
1039 int status_string_id;
1041 if (state == ShellIntegration::STATE_IS_DEFAULT) {
1042 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1043 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
1044 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1045 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
1046 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_SXS;
1047 } else {
1048 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1050 } else if (state == ShellIntegration::STATE_UNKNOWN) {
1051 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1052 } else {
1053 return; // Still processing.
1056 SetDefaultBrowserUIString(status_string_id);
1059 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1060 return true; // This is UI so we can allow it.
1063 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
1064 base::StringValue status_string(
1065 l10n_util::GetStringFUTF16(status_string_id,
1066 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1068 base::FundamentalValue is_default(
1069 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT);
1071 base::FundamentalValue can_be_default(
1072 !default_browser_policy_.IsManaged() &&
1073 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
1074 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
1076 web_ui()->CallJavascriptFunction(
1077 "BrowserOptions.updateDefaultBrowserState",
1078 status_string, is_default, can_be_default);
1081 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1082 if (!template_url_service_ || !template_url_service_->loaded())
1083 return;
1085 const TemplateURL* default_url =
1086 template_url_service_->GetDefaultSearchProvider();
1088 int default_index = -1;
1089 base::ListValue search_engines;
1090 TemplateURLService::TemplateURLVector model_urls(
1091 template_url_service_->GetTemplateURLs());
1092 for (size_t i = 0; i < model_urls.size(); ++i) {
1093 if (!model_urls[i]->ShowInDefaultList())
1094 continue;
1096 base::DictionaryValue* entry = new base::DictionaryValue();
1097 entry->SetString("name", model_urls[i]->short_name());
1098 entry->SetInteger("index", i);
1099 search_engines.Append(entry);
1100 if (model_urls[i] == default_url)
1101 default_index = i;
1104 web_ui()->CallJavascriptFunction(
1105 "BrowserOptions.updateSearchEngines",
1106 search_engines,
1107 base::FundamentalValue(default_index),
1108 base::FundamentalValue(
1109 template_url_service_->is_default_search_managed() ||
1110 template_url_service_->IsExtensionControlledDefaultSearch()));
1112 SetupExtensionControlledIndicators();
1115 void BrowserOptionsHandler::SetDefaultSearchEngine(
1116 const base::ListValue* args) {
1117 int selected_index = -1;
1118 if (!ExtractIntegerValue(args, &selected_index)) {
1119 NOTREACHED();
1120 return;
1123 TemplateURLService::TemplateURLVector model_urls(
1124 template_url_service_->GetTemplateURLs());
1125 if (selected_index >= 0 &&
1126 selected_index < static_cast<int>(model_urls.size()))
1127 template_url_service_->SetUserSelectedDefaultSearchProvider(
1128 model_urls[selected_index]);
1130 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1133 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1134 template_url_service_ =
1135 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1136 if (template_url_service_) {
1137 template_url_service_->Load();
1138 template_url_service_->AddObserver(this);
1142 void BrowserOptionsHandler::OnExtensionLoaded(
1143 content::BrowserContext* browser_context,
1144 const Extension* extension) {
1145 SetupExtensionControlledIndicators();
1148 void BrowserOptionsHandler::OnExtensionUnloaded(
1149 content::BrowserContext* browser_context,
1150 const Extension* extension,
1151 extensions::UnloadedExtensionInfo::Reason reason) {
1152 SetupExtensionControlledIndicators();
1155 void BrowserOptionsHandler::Observe(
1156 int type,
1157 const content::NotificationSource& source,
1158 const content::NotificationDetails& details) {
1159 // Notifications are used to update the UI dynamically when settings change in
1160 // the background. If the UI is currently being loaded, no dynamic updates are
1161 // possible (as the DOM and JS are not fully loaded) or necessary (as
1162 // InitializePage() will update the UI at the end of the load).
1163 if (!page_initialized_)
1164 return;
1166 switch (type) {
1167 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
1168 ObserveThemeChanged();
1169 break;
1170 #if defined(OS_CHROMEOS)
1171 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
1172 UpdateAccountPicture();
1173 break;
1174 #endif
1175 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
1176 SendProfilesInfo();
1177 break;
1178 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
1179 // Update our sync/signin status display.
1180 OnStateChanged();
1181 break;
1182 default:
1183 NOTREACHED();
1187 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) {
1188 #if defined(OS_WIN)
1189 if (!auto_launch_trial::IsInAutoLaunchGroup())
1190 return;
1192 bool enable;
1193 CHECK_EQ(args->GetSize(), 1U);
1194 CHECK(args->GetBoolean(0, &enable));
1196 Profile* profile = Profile::FromWebUI(web_ui());
1197 content::BrowserThread::PostTask(
1198 content::BrowserThread::FILE, FROM_HERE,
1199 enable ?
1200 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin,
1201 profile->GetPath().BaseName().value(), base::FilePath()) :
1202 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin,
1203 profile->GetPath().BaseName().value()));
1204 #endif // OS_WIN
1207 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() {
1208 ProfileInfoCache& cache =
1209 g_browser_process->profile_manager()->GetProfileInfoCache();
1210 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue);
1211 base::FilePath current_profile_path =
1212 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1214 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
1215 base::DictionaryValue* profile_value = new base::DictionaryValue();
1216 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
1217 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
1218 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1219 profile_value->SetBoolean("isCurrentProfile",
1220 profile_path == current_profile_path);
1221 profile_value->SetBoolean("isManaged", cache.ProfileIsManagedAtIndex(i));
1223 bool is_gaia_picture =
1224 cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
1225 cache.GetGAIAPictureOfProfileAtIndex(i);
1226 if (is_gaia_picture) {
1227 gfx::Image icon = profiles::GetAvatarIconForWebUI(
1228 cache.GetAvatarIconOfProfileAtIndex(i), true);
1229 profile_value->SetString("iconURL",
1230 webui::GetBitmapDataUrl(icon.AsBitmap()));
1231 } else {
1232 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
1233 profile_value->SetString("iconURL",
1234 profiles::GetDefaultAvatarIconUrl(icon_index));
1237 profile_info_list->Append(profile_value);
1240 return profile_info_list.Pass();
1243 void BrowserOptionsHandler::SendProfilesInfo() {
1244 if (!ShouldShowMultiProfilesUserList())
1245 return;
1246 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1247 *GetProfilesInfoList());
1250 void BrowserOptionsHandler::DeleteProfile(const base::ListValue* args) {
1251 DCHECK(args);
1252 const base::Value* file_path_value;
1253 if (!args->Get(0, &file_path_value))
1254 return;
1256 base::FilePath file_path;
1257 if (!base::GetValueAsFilePath(*file_path_value, &file_path))
1258 return;
1259 helper::DeleteProfileAtPath(file_path, web_ui());
1262 void BrowserOptionsHandler::ObserveThemeChanged() {
1263 Profile* profile = Profile::FromWebUI(web_ui());
1264 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
1265 bool is_system_theme = false;
1267 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1268 bool profile_is_managed = profile->IsManaged();
1269 is_system_theme = theme_service->UsingSystemTheme();
1270 base::FundamentalValue native_theme_enabled(!is_system_theme &&
1271 !profile_is_managed);
1272 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1273 native_theme_enabled);
1274 #endif
1276 bool is_classic_theme = !is_system_theme &&
1277 theme_service->UsingDefaultTheme();
1278 base::FundamentalValue enabled(!is_classic_theme);
1279 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1280 enabled);
1283 void BrowserOptionsHandler::ThemesReset(const base::ListValue* args) {
1284 Profile* profile = Profile::FromWebUI(web_ui());
1285 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1286 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
1289 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1290 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue* args) {
1291 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1292 Profile* profile = Profile::FromWebUI(web_ui());
1293 ThemeServiceFactory::GetForProfile(profile)->UseSystemTheme();
1295 #endif
1297 #if defined(OS_CHROMEOS)
1298 void BrowserOptionsHandler::UpdateAccountPicture() {
1299 std::string email = chromeos::UserManager::Get()->GetLoggedInUser()->email();
1300 if (!email.empty()) {
1301 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1302 base::StringValue email_value(email);
1303 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1304 email_value);
1308 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed) {
1309 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1310 base::FundamentalValue(managed));
1313 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed) {
1314 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1315 base::FundamentalValue(managed));
1317 #endif
1319 scoped_ptr<base::DictionaryValue>
1320 BrowserOptionsHandler::GetSyncStateDictionary() {
1321 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
1322 Profile* profile = Profile::FromWebUI(web_ui());
1323 if (profile->IsGuestSession()) {
1324 // Cannot display signin status when running in guest mode on chromeos
1325 // because there is no SigninManager.
1326 sync_status->SetBoolean("signinAllowed", false);
1327 return sync_status.Pass();
1330 sync_status->SetBoolean("supervisedUser", profile->IsManaged());
1332 bool signout_prohibited = false;
1333 #if !defined(OS_CHROMEOS)
1334 // Signout is not allowed if the user has policy (crbug.com/172204).
1335 signout_prohibited =
1336 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited();
1337 #endif
1339 ProfileSyncService* service =
1340 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
1341 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1342 DCHECK(signin);
1343 sync_status->SetBoolean("signoutAllowed", !signout_prohibited);
1344 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed());
1345 sync_status->SetBoolean("syncSystemEnabled", (service != NULL));
1346 sync_status->SetBoolean("setupCompleted",
1347 service && service->HasSyncSetupCompleted());
1348 sync_status->SetBoolean("setupInProgress",
1349 service && !service->IsManaged() && service->FirstSetupInProgress());
1351 base::string16 status_label;
1352 base::string16 link_label;
1353 bool status_has_error = sync_ui_util::GetStatusLabels(
1354 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
1355 sync_ui_util::SYNC_ERROR;
1356 sync_status->SetString("statusText", status_label);
1357 sync_status->SetString("actionLinkText", link_label);
1358 sync_status->SetBoolean("hasError", status_has_error);
1360 sync_status->SetBoolean("managed", service && service->IsManaged());
1361 sync_status->SetBoolean("signedIn",
1362 !signin->GetAuthenticatedUsername().empty());
1363 sync_status->SetBoolean("hasUnrecoverableError",
1364 service && service->HasUnrecoverableError());
1366 return sync_status.Pass();
1369 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1370 const base::ListValue* args) {
1371 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1372 select_folder_dialog_ = ui::SelectFileDialog::Create(
1373 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1374 ui::SelectFileDialog::FileTypeInfo info;
1375 info.support_drive = true;
1376 select_folder_dialog_->SelectFile(
1377 ui::SelectFileDialog::SELECT_FOLDER,
1378 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE),
1379 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory),
1380 &info,
1382 base::FilePath::StringType(),
1383 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1384 NULL);
1387 void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index,
1388 void* params) {
1389 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1390 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1391 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path);
1392 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
1395 #if defined(OS_CHROMEOS)
1396 void BrowserOptionsHandler::TouchpadExists(bool exists) {
1397 base::FundamentalValue val(exists);
1398 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val);
1401 void BrowserOptionsHandler::MouseExists(bool exists) {
1402 base::FundamentalValue val(exists);
1403 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val);
1406 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1407 const base::Value* previous_policy,
1408 const base::Value* current_policy) {
1409 const bool had_policy = previous_policy;
1410 const bool has_policy = current_policy;
1411 if (had_policy != has_policy)
1412 OnAccountPictureManagedChanged(has_policy);
1415 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1416 const base::Value* previous_policy,
1417 const base::Value* current_policy) {
1418 const bool had_policy = previous_policy;
1419 const bool has_policy = current_policy;
1420 if (had_policy != has_policy)
1421 OnWallpaperManagedChanged(has_policy);
1424 void BrowserOptionsHandler::OnPowerwashDialogShow(
1425 const base::ListValue* args) {
1426 UMA_HISTOGRAM_ENUMERATION(
1427 "Reset.ChromeOS.PowerwashDialogShown",
1428 chromeos::reset::DIALOG_FROM_OPTIONS,
1429 chromeos::reset::DIALOG_VIEW_TYPE_SIZE);
1432 #endif // defined(OS_CHROMEOS)
1434 void BrowserOptionsHandler::UpdateSyncState() {
1435 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1436 *GetSyncStateDictionary());
1439 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1440 UpdateSyncState();
1443 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1444 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1445 DownloadManager* manager = BrowserContext::GetDownloadManager(
1446 web_ui()->GetWebContents()->GetBrowserContext());
1447 if (manager)
1448 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
1451 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue* args) {
1452 int font_size;
1453 if (ExtractIntegerValue(args, &font_size)) {
1454 if (font_size > 0) {
1455 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1456 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size);
1457 SetupFontSizeSelector();
1462 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1463 const base::ListValue* args) {
1464 double zoom_factor;
1465 if (ExtractDoubleValue(args, &zoom_factor)) {
1466 default_zoom_level_.SetValue(content::ZoomFactorToZoomLevel(zoom_factor));
1470 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
1471 #if defined(OS_WIN) && defined(USE_ASH)
1472 // If hardware acceleration is disabled then we need to force restart
1473 // browser in desktop mode.
1474 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1475 // Currently there are issues with determining correct browser mode
1476 // at startup.
1477 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1478 PrefService* pref_service = g_browser_process->local_state();
1479 if (!pref_service->GetBoolean(prefs::kHardwareAccelerationModeEnabled)) {
1480 chrome::AttemptRestartToDesktopMode();
1481 return;
1484 #endif
1486 chrome::AttemptRestart();
1489 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1490 const base::ListValue* args) {
1491 SendProfilesInfo();
1494 #if !defined(OS_CHROMEOS)
1495 void BrowserOptionsHandler::ShowNetworkProxySettings(
1496 const base::ListValue* args) {
1497 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1498 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1499 web_ui()->GetWebContents());
1501 #endif
1503 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
1504 void BrowserOptionsHandler::ShowManageSSLCertificates(
1505 const base::ListValue* args) {
1506 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1507 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1508 web_ui()->GetWebContents());
1510 #endif
1512 #if defined(ENABLE_SERVICE_DISCOVERY)
1514 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1515 const base::ListValue* args) {
1516 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1517 // Navigate in current tab to devices page.
1518 OpenURLParams params(
1519 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1520 CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
1521 web_ui()->GetWebContents()->OpenURL(params);
1524 #endif
1526 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1527 const base::ListValue* args) {
1528 Profile* profile = Profile::FromWebUI(web_ui());
1529 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1530 if (group != "" && group != "Disabled") {
1531 if (HotwordServiceFactory::IsServiceAvailable(profile)) {
1532 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection");
1533 } else if (HotwordServiceFactory::IsHotwordAllowed(profile)) {
1534 base::StringValue error_message(l10n_util::GetStringUTF16(
1535 HotwordServiceFactory::GetCurrentError(profile)));
1536 base::string16 hotword_help_url =
1537 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1538 base::StringValue help_link(l10n_util::GetStringFUTF16(
1539 IDS_HOTWORD_HELP_LINK, hotword_help_url));
1540 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
1541 error_message, help_link);
1546 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1547 const base::ListValue* args) {
1548 easy_unlock::LaunchEasyUnlockSetup(Profile::FromWebUI(web_ui()));
1551 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1552 const base::ListValue* args) {
1553 SetupExtensionControlledIndicators();
1556 #if defined(OS_CHROMEOS)
1557 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1558 const base::ListValue* args) {
1559 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1562 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1563 const base::ListValue* args) {
1564 bool enabled = false;
1565 args->GetBoolean(0, &enabled);
1567 chromeos::accessibility::EnableVirtualKeyboard(enabled);
1570 void BrowserOptionsHandler::PerformFactoryResetRestart(
1571 const base::ListValue* args) {
1572 policy::BrowserPolicyConnectorChromeOS* connector =
1573 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1574 if (connector->IsEnterpriseManaged())
1575 return;
1577 PrefService* prefs = g_browser_process->local_state();
1578 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
1579 prefs->CommitPendingWrite();
1581 // Perform sign out. Current chrome process will then terminate, new one will
1582 // be launched (as if it was a restart).
1583 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1586 void BrowserOptionsHandler::HandleEnrollConsumerManagement(
1587 const base::ListValue* args) {
1588 // TODO(davidyu): Implement. http://crbug.com/353050.
1591 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1592 PrefService* pref_service = g_browser_process->local_state();
1593 base::FundamentalValue virtual_keyboard_enabled(
1594 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled));
1595 web_ui()->CallJavascriptFunction(
1596 "BrowserOptions.setVirtualKeyboardCheckboxState",
1597 virtual_keyboard_enabled);
1599 #endif
1601 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1602 #if defined(GOOGLE_CHROME_BUILD)
1603 // Don't show the reporting setting if we are in the guest mode.
1604 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1605 base::FundamentalValue visible(false);
1606 web_ui()->CallJavascriptFunction(
1607 "BrowserOptions.setMetricsReportingSettingVisibility", visible);
1609 #endif
1612 void BrowserOptionsHandler::SetupFontSizeSelector() {
1613 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1614 const PrefService::Preference* default_font_size =
1615 pref_service->FindPreference(prefs::kWebKitDefaultFontSize);
1616 const PrefService::Preference* default_fixed_font_size =
1617 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize);
1619 base::DictionaryValue dict;
1620 dict.SetInteger("value",
1621 pref_service->GetInteger(prefs::kWebKitDefaultFontSize));
1623 // The font size control displays the value of the default font size, but
1624 // setting it alters both the default font size and the default fixed font
1625 // size. So it must be disabled when either of those prefs is not user
1626 // modifiable.
1627 dict.SetBoolean("disabled",
1628 !default_font_size->IsUserModifiable() ||
1629 !default_fixed_font_size->IsUserModifiable());
1631 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1632 // adapted to consider two prefs. It may be better to refactor
1633 // CreateValueForPref so it can be called from here.
1634 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) {
1635 dict.SetString("controlledBy", "policy");
1636 } else if (default_font_size->IsExtensionControlled() ||
1637 default_fixed_font_size->IsExtensionControlled()) {
1638 dict.SetString("controlledBy", "extension");
1641 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict);
1644 void BrowserOptionsHandler::SetupPageZoomSelector() {
1645 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1646 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
1647 double default_zoom_factor =
1648 content::ZoomLevelToZoomFactor(default_zoom_level);
1650 // Generate a vector of zoom factors from an array of known presets along with
1651 // the default factor added if necessary.
1652 std::vector<double> zoom_factors =
1653 chrome_page_zoom::PresetZoomFactors(default_zoom_factor);
1655 // Iterate through the zoom factors and and build the contents of the
1656 // selector that will be sent to the javascript handler.
1657 // Each item in the list has the following parameters:
1658 // 1. Title (string).
1659 // 2. Value (double).
1660 // 3. Is selected? (bool).
1661 base::ListValue zoom_factors_value;
1662 for (std::vector<double>::const_iterator i = zoom_factors.begin();
1663 i != zoom_factors.end(); ++i) {
1664 base::ListValue* option = new base::ListValue();
1665 double factor = *i;
1666 int percent = static_cast<int>(factor * 100 + 0.5);
1667 option->Append(new base::StringValue(
1668 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
1669 option->Append(new base::FundamentalValue(factor));
1670 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
1671 option->Append(new base::FundamentalValue(selected));
1672 zoom_factors_value.Append(option);
1675 web_ui()->CallJavascriptFunction(
1676 "BrowserOptions.setupPageZoomSelector", zoom_factors_value);
1679 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1680 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1681 // We show the button if the user has any auto-open file types registered.
1682 DownloadManager* manager = BrowserContext::GetDownloadManager(
1683 web_ui()->GetWebContents()->GetBrowserContext());
1684 bool display = manager &&
1685 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
1686 base::FundamentalValue value(display);
1687 web_ui()->CallJavascriptFunction(
1688 "BrowserOptions.setAutoOpenFileTypesDisplayed", value);
1691 void BrowserOptionsHandler::SetupProxySettingsSection() {
1692 #if !defined(OS_CHROMEOS)
1693 // Disable the button if proxy settings are managed by a sysadmin, overridden
1694 // by an extension, or the browser is running in Windows Ash (on Windows the
1695 // proxy settings dialog will open on the Windows desktop and be invisible
1696 // to a user in Ash).
1697 bool is_win_ash = false;
1698 #if defined(OS_WIN)
1699 chrome::HostDesktopType desktop_type = helper::GetDesktopType(web_ui());
1700 is_win_ash = (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH);
1701 #endif
1702 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1703 const PrefService::Preference* proxy_config =
1704 pref_service->FindPreference(prefs::kProxy);
1705 bool is_extension_controlled = (proxy_config &&
1706 proxy_config->IsExtensionControlled());
1708 base::FundamentalValue disabled(is_win_ash || (proxy_config &&
1709 !proxy_config->IsUserModifiable()));
1710 base::FundamentalValue extension_controlled(is_extension_controlled);
1711 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
1712 disabled, extension_controlled);
1714 #if defined(OS_WIN)
1715 SetupExtensionControlledIndicators();
1716 #endif // defined(OS_WIN)
1718 #endif // !defined(OS_CHROMEOS)
1721 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1722 #if defined(OS_WIN)
1723 // Disable the button if the settings page is displayed in Windows Ash,
1724 // otherwise the proxy settings dialog will open on the Windows desktop and
1725 // be invisible to a user in Ash.
1726 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH) {
1727 base::FundamentalValue enabled(false);
1728 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1729 enabled);
1731 #endif // defined(OS_WIN)
1734 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1735 bool has_users = !Profile::FromWebUI(web_ui())->
1736 GetPrefs()->GetDictionary(prefs::kManagedUsers)->empty();
1737 base::FundamentalValue has_users_value(has_users);
1738 web_ui()->CallJavascriptFunction(
1739 "BrowserOptions.updateManagesSupervisedUsers",
1740 has_users_value);
1743 void BrowserOptionsHandler::SetupEasyUnlock() {
1744 bool has_pairing = !Profile::FromWebUI(web_ui())->GetPrefs()
1745 ->GetDictionary(prefs::kEasyUnlockPairing)->empty();
1746 base::FundamentalValue has_pairing_value(has_pairing);
1747 web_ui()->CallJavascriptFunction(
1748 "BrowserOptions.updateEasyUnlock",
1749 has_pairing_value);
1752 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
1753 #if defined(OS_WIN)
1754 base::DictionaryValue extension_controlled;
1756 // Check if an extension is overriding the Search Engine.
1757 const extensions::Extension* extension =
1758 extensions::GetExtensionOverridingSearchEngine(
1759 Profile::FromWebUI(web_ui()), NULL);
1760 AppendExtensionData("searchEngine", extension, &extension_controlled);
1762 // Check if an extension is overriding the Home page.
1763 extension = extensions::GetExtensionOverridingHomepage(
1764 Profile::FromWebUI(web_ui()), NULL);
1765 AppendExtensionData("homePage", extension, &extension_controlled);
1767 // Check if an extension is overriding the Startup pages.
1768 extension = extensions::GetExtensionOverridingStartupPages(
1769 Profile::FromWebUI(web_ui()), NULL);
1770 AppendExtensionData("startUpPage", extension, &extension_controlled);
1772 // Check if an extension is overriding the NTP page.
1773 GURL ntp_url(chrome::kChromeUINewTabURL);
1774 bool ignored_param;
1775 extension = NULL;
1776 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
1777 &ntp_url,
1778 web_ui()->GetWebContents()->GetBrowserContext(),
1779 &ignored_param);
1780 if (ntp_url.SchemeIs("chrome-extension")) {
1781 using extensions::ExtensionRegistry;
1782 ExtensionRegistry* registry = ExtensionRegistry::Get(
1783 Profile::FromWebUI(web_ui()));
1784 extension = registry->GetExtensionById(ntp_url.host(),
1785 ExtensionRegistry::ENABLED);
1787 AppendExtensionData("newTabPage", extension, &extension_controlled);
1789 // Check if an extension is overwriting the proxy setting.
1790 extension = extensions::GetExtensionOverridingProxy(
1791 Profile::FromWebUI(web_ui()));
1792 AppendExtensionData("proxy", extension, &extension_controlled);
1794 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1795 extension_controlled);
1796 #endif // defined(OS_WIN)
1799 } // namespace options