Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / browser_options_handler.cc
blobb8cf8c189fb42dcd109f0ea946ab1fb7d71f5698
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 "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
13 #include "base/environment.h"
14 #include "base/memory/singleton.h"
15 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram.h"
17 #include "base/path_service.h"
18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/value_conversions.h"
24 #include "base/values.h"
25 #include "chrome/browser/auto_launch_trial.h"
26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/chrome_page_zoom.h"
29 #include "chrome/browser/custom_home_pages_table_model.h"
30 #include "chrome/browser/download/download_prefs.h"
31 #include "chrome/browser/gpu/gpu_mode_manager.h"
32 #include "chrome/browser/lifetime/application_lifetime.h"
33 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
34 #include "chrome/browser/metrics/metrics_reporting_state.h"
35 #include "chrome/browser/net/prediction_options.h"
36 #include "chrome/browser/prefs/session_startup_pref.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
38 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
41 #include "chrome/browser/profiles/profile_info_cache.h"
42 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/profiles/profile_metrics.h"
44 #include "chrome/browser/profiles/profile_shortcut_manager.h"
45 #include "chrome/browser/profiles/profile_window.h"
46 #include "chrome/browser/profiles/profiles_state.h"
47 #include "chrome/browser/search/hotword_service.h"
48 #include "chrome/browser/search/hotword_service_factory.h"
49 #include "chrome/browser/search/search.h"
50 #include "chrome/browser/search_engines/template_url_service_factory.h"
51 #include "chrome/browser/signin/easy_unlock_service.h"
52 #include "chrome/browser/signin/signin_manager_factory.h"
53 #include "chrome/browser/sync/profile_sync_service.h"
54 #include "chrome/browser/sync/profile_sync_service_factory.h"
55 #include "chrome/browser/sync/sync_ui_util.h"
56 #include "chrome/browser/themes/theme_service.h"
57 #include "chrome/browser/themes/theme_service_factory.h"
58 #include "chrome/browser/ui/browser_finder.h"
59 #include "chrome/browser/ui/chrome_select_file_policy.h"
60 #include "chrome/browser/ui/host_desktop.h"
61 #include "chrome/browser/ui/webui/favicon_source.h"
62 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
63 #include "chrome/common/chrome_constants.h"
64 #include "chrome/common/chrome_paths.h"
65 #include "chrome/common/chrome_switches.h"
66 #include "chrome/common/extensions/extension_constants.h"
67 #include "chrome/common/pref_names.h"
68 #include "chrome/common/url_constants.h"
69 #include "chrome/grit/chromium_strings.h"
70 #include "chrome/grit/generated_resources.h"
71 #include "chrome/grit/locale_settings.h"
72 #include "chromeos/chromeos_switches.h"
73 #include "components/search_engines/template_url.h"
74 #include "components/search_engines/template_url_service.h"
75 #include "components/signin/core/browser/signin_manager.h"
76 #include "components/signin/core/common/profile_management_switches.h"
77 #include "components/user_manager/user_type.h"
78 #include "content/public/browser/browser_thread.h"
79 #include "content/public/browser/download_manager.h"
80 #include "content/public/browser/navigation_controller.h"
81 #include "content/public/browser/notification_details.h"
82 #include "content/public/browser/notification_service.h"
83 #include "content/public/browser/notification_source.h"
84 #include "content/public/browser/notification_types.h"
85 #include "content/public/browser/url_data_source.h"
86 #include "content/public/browser/user_metrics.h"
87 #include "content/public/browser/web_contents.h"
88 #include "content/public/common/page_zoom.h"
89 #include "extensions/browser/extension_registry.h"
90 #include "google_apis/gaia/gaia_auth_util.h"
91 #include "google_apis/gaia/google_service_auth_error.h"
92 #include "third_party/skia/include/core/SkBitmap.h"
93 #include "ui/base/l10n/l10n_util.h"
94 #include "ui/base/webui/web_ui_util.h"
96 #if !defined(OS_CHROMEOS)
97 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
98 #endif
100 #if defined(OS_CHROMEOS)
101 #include "ash/ash_switches.h"
102 #include "ash/desktop_background/user_wallpaper_delegate.h"
103 #include "ash/magnifier/magnifier_constants.h"
104 #include "ash/shell.h"
105 #include "chrome/browser/browser_process_platform_part.h"
106 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
107 #include "chrome/browser/chromeos/chromeos_utils.h"
108 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
109 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
110 #include "chrome/browser/chromeos/profiles/profile_helper.h"
111 #include "chrome/browser/chromeos/reset/metrics.h"
112 #include "chrome/browser/chromeos/settings/cros_settings.h"
113 #include "chrome/browser/chromeos/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 "components/user_manager/user.h"
123 #include "components/user_manager/user_manager.h"
124 #include "policy/policy_constants.h"
125 #include "ui/gfx/image/image_skia.h"
126 #endif // defined(OS_CHROMEOS)
128 #if defined(OS_WIN)
129 #include "chrome/browser/extensions/settings_api_helpers.h"
130 #include "chrome/installer/util/auto_launch_util.h"
131 #include "content/public/browser/browser_url_handler.h"
132 #endif // defined(OS_WIN)
134 #if defined(ENABLE_SERVICE_DISCOVERY)
135 #include "chrome/browser/local_discovery/privet_notifications.h"
136 #endif
138 using base::UserMetricsAction;
139 using content::BrowserContext;
140 using content::BrowserThread;
141 using content::DownloadManager;
142 using content::OpenURLParams;
143 using content::Referrer;
144 using extensions::Extension;
145 using extensions::ExtensionRegistry;
147 namespace {
149 #if defined(OS_WIN)
150 void AppendExtensionData(const std::string& key,
151 const Extension* extension,
152 base::DictionaryValue* dict) {
153 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue);
154 details->SetString("id", extension ? extension->id() : std::string());
155 details->SetString("name", extension ? extension->name() : std::string());
156 dict->Set(key, details.release());
158 #endif // defined(OS_WIN)
160 } // namespace
162 namespace options {
164 BrowserOptionsHandler::BrowserOptionsHandler()
165 : page_initialized_(false),
166 template_url_service_(NULL),
167 cloud_print_mdns_ui_enabled_(false),
168 signin_observer_(this),
169 weak_ptr_factory_(this) {
170 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
172 #if defined(ENABLE_SERVICE_DISCOVERY)
173 cloud_print_mdns_ui_enabled_ = true;
174 #endif // defined(ENABLE_SERVICE_DISCOVERY)
177 BrowserOptionsHandler::~BrowserOptionsHandler() {
178 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
179 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
180 if (sync_service)
181 sync_service->RemoveObserver(this);
183 if (default_browser_worker_.get())
184 default_browser_worker_->ObserverDestroyed();
185 if (template_url_service_)
186 template_url_service_->RemoveObserver(this);
187 // There may be pending file dialogs, we need to tell them that we've gone
188 // away so they don't try and call back to us.
189 if (select_folder_dialog_.get())
190 select_folder_dialog_->ListenerDestroyed();
193 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
194 DCHECK(values);
196 #if defined(OS_CHROMEOS)
197 const int device_type_resource_id = chromeos::GetChromeDeviceTypeResourceId();
198 #else
199 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices.
200 const int device_type_resource_id = IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE;
201 #endif // defined(OS_CHROMEOS)
203 static OptionsStringResource resources[] = {
204 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT },
205 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY },
206 { "advancedSectionTitleCertificates",
207 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES },
208 { "advancedSectionTitleContent",
209 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT },
210 { "advancedSectionTitleLanguages",
211 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES },
212 { "advancedSectionTitleNetwork",
213 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK },
214 { "advancedSectionTitlePrivacy",
215 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY },
216 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE },
217 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN },
218 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY },
219 { "autoOpenFileTypesResetToDefault",
220 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT },
221 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE },
222 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON },
223 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL },
224 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
225 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
226 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
227 #if defined(OS_CHROMEOS)
228 { "disableGData", IDS_OPTIONS_DISABLE_GDATA },
229 #endif
230 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES },
231 #if defined(OS_CHROMEOS)
232 { "displayOptions",
233 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL },
234 #endif
235 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK },
236 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT },
237 { "doNotTrackConfirmEnable",
238 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE },
239 { "doNotTrackConfirmDisable",
240 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE },
241 { "downloadLocationAskForSaveLocation",
242 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION },
243 { "downloadLocationBrowseTitle",
244 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE },
245 { "downloadLocationChangeButton",
246 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON },
247 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME },
248 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING },
249 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART },
250 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION,
251 device_type_resource_id },
252 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE },
253 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON },
254 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO,
255 device_type_resource_id },
256 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED },
257 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE },
258 { "fontSettingsCustomizeFontsButton",
259 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON },
260 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM },
261 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE },
262 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
263 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
264 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE },
265 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
266 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS },
267 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP },
268 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
269 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
270 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
271 { "hotwordAlwaysOnSearchEnable", IDS_HOTWORD_ALWAYS_ON_SEARCH_PREF_CHKBOX },
272 { "hotwordAudioHistoryEnable", IDS_HOTWORD_AUDIO_HISTORY_PREF_CHKBOX },
273 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX },
274 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE },
275 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE },
276 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION },
277 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE },
278 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON },
279 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE },
280 { "languageAndSpellCheckSettingsButton",
281 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS },
282 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF },
283 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK },
284 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES },
285 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK },
286 { "networkPredictionEnabledDescription",
287 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
288 { "passwordsAndAutofillGroupName",
289 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME },
290 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
291 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
292 { "privacyContentSettingsButton",
293 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON },
294 { "profileAddPersonEnable", IDS_PROFILE_ADD_PERSON_ENABLE },
295 { "profileBrowserGuestEnable", IDS_PROFILE_BROWSER_GUEST_ENABLE },
296 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL },
297 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL },
298 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL },
299 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT },
300 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL },
301 { "profilesSupervisedDashboardTip",
302 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP },
303 #if defined(ENABLE_SETTINGS_APP)
304 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL },
305 #endif
306 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
307 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
308 IDS_PRODUCT_NAME },
309 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
310 { "resetProfileSettingsDescription",
311 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
312 { "resetProfileSettingsSectionTitle",
313 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
314 { "safeBrowsingEnableProtection",
315 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
316 { "safeBrowsingEnableExtendedReporting",
317 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING },
318 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
319 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
320 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME },
321 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME },
322 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
323 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME },
324 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME },
325 { "sectionTitleVoice", IDS_OPTIONS_VOICE_GROUP_NAME },
326 { "settingsTitle", IDS_SETTINGS_TITLE },
327 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS },
328 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT },
329 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE },
330 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE },
331 { "spellingPref", IDS_OPTIONS_SPELLING_PREF },
332 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION },
333 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES },
334 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB },
335 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
336 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF },
337 { "supervisedUserLabel", IDS_PROFILES_LIST_SUPERVISED_USER_LABEL },
338 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS },
339 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL },
340 { "themesGallery", IDS_THEMES_GALLERY_BUTTON },
341 { "themesGalleryURL", IDS_THEMES_GALLERY_URL },
342 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF },
343 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
344 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
345 { "translateEnableTranslate",
346 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE },
347 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
348 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS },
349 { "themesNativeButton", IDS_THEMES_GTK_BUTTON },
350 { "themesSetClassic", IDS_THEMES_SET_CLASSIC },
351 #else
352 { "themes", IDS_THEMES_GROUP_NAME },
353 #endif
354 { "themesReset", IDS_THEMES_RESET_BUTTON },
355 { "accessibilityTitle",
356 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY },
357 { "accessibilityFeaturesLink",
358 IDS_OPTIONS_ACCESSIBILITY_FEATURES_LINK },
359 #if defined(OS_CHROMEOS)
360 { "accessibilityExplanation",
361 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION },
362 { "accessibilitySettings",
363 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS },
364 { "accessibilityHighContrast",
365 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION },
366 { "accessibilityScreenMagnifier",
367 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION },
368 { "accessibilityTapDragging",
369 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION },
370 { "accessibilityScreenMagnifierOff",
371 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF },
372 { "accessibilityScreenMagnifierFull",
373 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL },
374 { "accessibilityScreenMagnifierPartial",
375 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL },
376 { "accessibilityLargeCursor",
377 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION },
378 { "accessibilityStickyKeys",
379 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION },
380 { "accessibilitySpokenFeedback",
381 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION },
382 { "accessibilityVirtualKeyboard",
383 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION },
384 { "accessibilityAlwaysShowMenu",
385 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU },
386 { "accessibilityAutoclick",
387 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION },
388 { "accessibilityAutoclickDropdown",
389 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION },
390 { "autoclickDelayExtremelyShort",
391 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT },
392 { "autoclickDelayVeryShort",
393 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT },
394 { "autoclickDelayShort",
395 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT },
396 { "autoclickDelayLong",
397 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG },
398 { "autoclickDelayVeryLong",
399 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG },
400 { "consumerManagementDescription",
401 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION },
402 { "consumerManagementEnrollButton",
403 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON },
404 { "consumerManagementEnrollingButton",
405 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLLING_BUTTON },
406 { "consumerManagementUnenrollButton",
407 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON },
408 { "consumerManagementUnenrollingButton",
409 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLLING_BUTTON },
410 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE },
411 { "enableContentProtectionAttestation",
412 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION },
413 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING },
414 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET },
415 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON },
416 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON },
417 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING },
418 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL },
419 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE },
420 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION },
421 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME },
422 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION },
423 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION },
424 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION },
425 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION },
426 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX },
427 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE },
428 { "keyboardSettingsButtonTitle",
429 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE },
430 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE },
431 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES },
432 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME },
433 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL },
434 { "syncOverview", IDS_SYNC_OVERVIEW },
435 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
436 { "thirdPartyImeConfirmEnable", IDS_OK },
437 { "thirdPartyImeConfirmDisable", IDS_CANCEL },
438 { "thirdPartyImeConfirmMessage",
439 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE },
440 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION },
441 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION },
442 { "batteryButton", IDS_OPTIONS_SETTINGS_BATTERY_DESCRIPTION},
443 { "storageButton", IDS_OPTIONS_SETTINGS_STORAGE_DESCRIPTION},
444 #else
445 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON },
446 #endif
447 #if defined(OS_CHROMEOS) && defined(USE_ASH)
448 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON },
449 #endif
450 { "advancedSectionTitleSystem",
451 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM },
452 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
453 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE },
454 #endif
455 #if !defined(OS_CHROMEOS)
456 { "gpuModeCheckbox",
457 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE },
458 { "gpuModeResetRestart",
459 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART },
460 // Strings with product-name substitutions.
461 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME },
462 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
463 #endif
464 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL,
465 IDS_SHORT_PRODUCT_NAME },
466 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
467 IDS_PRODUCT_NAME },
468 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
469 IDS_PRODUCT_NAME },
470 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT },
471 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT },
472 #if defined(OS_CHROMEOS)
473 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION,
474 IDS_SHORT_PRODUCT_NAME },
475 #endif
476 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
477 IDS_SHORT_PRODUCT_NAME },
478 #if defined(ENABLE_SERVICE_DISCOVERY)
479 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON },
480 { "cloudPrintEnableNotificationsLabel",
481 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL },
482 #endif
485 #if defined(ENABLE_SETTINGS_APP)
486 static OptionsStringResource app_resources[] = {
487 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW },
488 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL,
489 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
490 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
491 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
492 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
493 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
494 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
495 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
497 base::DictionaryValue* app_values = NULL;
498 CHECK(values->GetDictionary(kSettingsAppKey, &app_values));
499 RegisterStrings(app_values, app_resources, arraysize(app_resources));
500 #endif
502 RegisterStrings(values, resources, arraysize(resources));
503 RegisterTitle(values, "doNotTrackConfirmOverlay",
504 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE);
505 RegisterTitle(values, "spellingConfirmOverlay",
506 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE);
507 #if defined(ENABLE_FULL_PRINTING)
508 RegisterCloudPrintValues(values);
509 #endif
511 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL);
512 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
513 values->SetString(
514 "defaultSearchGroupLabel",
515 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
516 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL);
517 RegisterTitle(values, "hotwordConfirmOverlay",
518 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE);
520 #if defined(OS_CHROMEOS)
521 Profile* profile = Profile::FromWebUI(web_ui());
522 std::string username = profile->GetProfileName();
523 if (username.empty()) {
524 user_manager::User* user =
525 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
526 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
527 username = user->email();
529 if (!username.empty())
530 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
532 values->SetString("username", username);
533 #endif
535 // Pass along sync status early so it will be available during page init.
536 values->Set("syncData", GetSyncStateDictionary().release());
538 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
539 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
541 #if !defined(OS_CHROMEOS)
542 values->SetBoolean("metricsReportingEnabledAtStart",
543 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
544 #endif
546 #if defined(OS_CHROMEOS)
547 // TODO(pastarmovj): replace this with a call to the CrosSettings list
548 // handling functionality to come.
549 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
551 values->SetString("accessibilityLearnMoreURL",
552 chrome::kChromeAccessibilityHelpURL);
554 std::string settings_url = std::string("chrome-extension://") +
555 extension_misc::kChromeVoxExtensionId +
556 chrome::kChromeAccessibilitySettingsURL;
558 values->SetString("accessibilitySettingsURL",
559 settings_url);
561 values->SetString("contentProtectionAttestationLearnMoreURL",
562 chrome::kAttestationForContentProtectionLearnMoreURL);
564 // Creates magnifierList.
565 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue);
567 scoped_ptr<base::ListValue> option_full(new base::ListValue);
568 option_full->AppendInteger(ash::MAGNIFIER_FULL);
569 option_full->AppendString(l10n_util::GetStringUTF16(
570 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL));
571 magnifier_list->Append(option_full.release());
573 scoped_ptr<base::ListValue> option_partial(new base::ListValue);
574 option_partial->AppendInteger(ash::MAGNIFIER_PARTIAL);
575 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16(
576 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL)));
577 magnifier_list->Append(option_partial.release());
579 values->Set("magnifierList", magnifier_list.release());
580 #endif
582 #if defined(OS_MACOSX)
583 values->SetString("macPasswordsWarning",
584 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
585 values->SetBoolean("multiple_profiles",
586 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
587 #endif
589 if (ShouldShowMultiProfilesUserList())
590 values->Set("profilesInfo", GetProfilesInfoList().release());
592 values->SetBoolean("profileIsGuest",
593 Profile::FromWebUI(web_ui())->IsOffTheRecord());
595 values->SetBoolean("profileIsSupervised",
596 Profile::FromWebUI(web_ui())->IsSupervised());
598 #if !defined(OS_CHROMEOS)
599 values->SetBoolean(
600 "gpuEnabledAtStart",
601 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
602 #endif
604 #if defined(ENABLE_SERVICE_DISCOVERY)
605 values->SetBoolean("cloudPrintHideNotificationsCheckbox",
606 !local_discovery::PrivetNotificationService::IsEnabled());
607 #endif
609 values->SetBoolean("cloudPrintShowMDnsOptions",
610 cloud_print_mdns_ui_enabled_);
612 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
614 values->SetString("languagesLearnMoreURL",
615 chrome::kLanguageSettingsLearnMoreUrl);
617 values->SetBoolean(
618 "easyUnlockAllowed",
619 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
620 values->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl);
622 #if defined(OS_CHROMEOS)
623 values->SetBoolean(
624 "consumerManagementEnabled",
625 CommandLine::ForCurrentProcess()->HasSwitch(
626 chromeos::switches::kEnableConsumerManagement));
628 RegisterTitle(values, "thirdPartyImeConfirmOverlay",
629 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE);
630 #endif
632 values->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
634 values->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
636 values->SetBoolean("websiteSettingsManagerEnabled",
637 CommandLine::ForCurrentProcess()->HasSwitch(
638 switches::kEnableWebsiteSettingsManager));
640 values->SetBoolean("usingNewProfilesUI", switches::IsNewAvatarMenu());
643 #if defined(ENABLE_FULL_PRINTING)
644 void BrowserOptionsHandler::RegisterCloudPrintValues(
645 base::DictionaryValue* values) {
646 values->SetString("cloudPrintOptionLabel",
647 l10n_util::GetStringFUTF16(
648 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL,
649 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
651 #endif // defined(ENABLE_FULL_PRINTING)
653 void BrowserOptionsHandler::RegisterMessages() {
654 web_ui()->RegisterMessageCallback(
655 "becomeDefaultBrowser",
656 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
657 base::Unretained(this)));
658 web_ui()->RegisterMessageCallback(
659 "setDefaultSearchEngine",
660 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
661 base::Unretained(this)));
662 web_ui()->RegisterMessageCallback(
663 "deleteProfile",
664 base::Bind(&BrowserOptionsHandler::DeleteProfile,
665 base::Unretained(this)));
666 web_ui()->RegisterMessageCallback(
667 "themesReset",
668 base::Bind(&BrowserOptionsHandler::ThemesReset,
669 base::Unretained(this)));
670 web_ui()->RegisterMessageCallback(
671 "requestProfilesInfo",
672 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo,
673 base::Unretained(this)));
674 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
675 web_ui()->RegisterMessageCallback(
676 "themesSetNative",
677 base::Bind(&BrowserOptionsHandler::ThemesSetNative,
678 base::Unretained(this)));
679 #endif
680 web_ui()->RegisterMessageCallback(
681 "selectDownloadLocation",
682 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation,
683 base::Unretained(this)));
684 web_ui()->RegisterMessageCallback(
685 "autoOpenFileTypesAction",
686 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton,
687 base::Unretained(this)));
688 web_ui()->RegisterMessageCallback(
689 "defaultFontSizeAction",
690 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize,
691 base::Unretained(this)));
692 web_ui()->RegisterMessageCallback(
693 "defaultZoomFactorAction",
694 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor,
695 base::Unretained(this)));
696 #if defined(OS_WIN) || defined(OS_MACOSX)
697 web_ui()->RegisterMessageCallback(
698 "showManageSSLCertificates",
699 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates,
700 base::Unretained(this)));
701 #endif
702 #if defined(OS_CHROMEOS)
703 web_ui()->RegisterMessageCallback(
704 "openWallpaperManager",
705 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager,
706 base::Unretained(this)));
707 web_ui()->RegisterMessageCallback(
708 "virtualKeyboardChange",
709 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback,
710 base::Unretained(this)));
711 web_ui()->RegisterMessageCallback(
712 "onPowerwashDialogShow",
713 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow,
714 base::Unretained(this)));
715 web_ui()->RegisterMessageCallback(
716 "performFactoryResetRestart",
717 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart,
718 base::Unretained(this)));
719 #else
720 web_ui()->RegisterMessageCallback(
721 "restartBrowser",
722 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser,
723 base::Unretained(this)));
724 web_ui()->RegisterMessageCallback(
725 "showNetworkProxySettings",
726 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings,
727 base::Unretained(this)));
728 #endif // defined(OS_CHROMEOS)
730 #if defined(ENABLE_SERVICE_DISCOVERY)
731 if (cloud_print_mdns_ui_enabled_) {
732 web_ui()->RegisterMessageCallback(
733 "showCloudPrintDevicesPage",
734 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage,
735 base::Unretained(this)));
737 #endif
738 web_ui()->RegisterMessageCallback(
739 "requestHotwordAvailable",
740 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable,
741 base::Unretained(this)));
743 web_ui()->RegisterMessageCallback(
744 "launchHotwordAudioVerificationApp",
745 base::Bind(
746 &BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp,
747 base::Unretained(this)));
749 web_ui()->RegisterMessageCallback(
750 "launchEasyUnlockSetup",
751 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
752 base::Unretained(this)));
753 #if defined(OS_WIN)
754 web_ui()->RegisterMessageCallback(
755 "refreshExtensionControlIndicators",
756 base::Bind(
757 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
758 base::Unretained(this)));
759 #endif // defined(OS_WIN)
760 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
761 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
762 base::Unretained(this)));
765 void BrowserOptionsHandler::Uninitialize() {
766 registrar_.RemoveAll();
767 #if defined(OS_WIN)
768 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
769 #endif
770 #if defined(OS_CHROMEOS)
771 policy::ConsumerManagementService* consumer_management =
772 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
773 GetConsumerManagementService();
774 if (consumer_management)
775 consumer_management->RemoveObserver(this);
776 #endif
779 void BrowserOptionsHandler::OnStateChanged() {
780 UpdateSyncState();
783 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string& account_id,
784 const std::string& username,
785 const std::string& password) {
786 OnStateChanged();
789 void BrowserOptionsHandler::GoogleSignedOut(const std::string& account_id,
790 const std::string& username) {
791 OnStateChanged();
794 void BrowserOptionsHandler::PageLoadStarted() {
795 page_initialized_ = false;
798 void BrowserOptionsHandler::InitializeHandler() {
799 Profile* profile = Profile::FromWebUI(web_ui());
800 PrefService* prefs = profile->GetPrefs();
801 chrome::ChromeZoomLevelPrefs* zoom_level_prefs = profile->GetZoomLevelPrefs();
802 // Only regular profiles are able to edit default zoom level, or delete per-
803 // host zoom levels, via the settings menu. We only require a zoom_level_prefs
804 // if the profile is able to change these preference types.
805 DCHECK(zoom_level_prefs ||
806 profile->GetProfileType() != Profile::REGULAR_PROFILE);
807 if (zoom_level_prefs) {
808 default_zoom_level_subscription_ =
809 zoom_level_prefs->RegisterDefaultZoomLevelCallback(
810 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector,
811 base::Unretained(this)));
814 ProfileSyncService* sync_service(
815 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile));
816 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
817 // destruction is automatic.
818 if (sync_service)
819 sync_service->AddObserver(this);
821 SigninManagerBase* signin_manager(
822 SigninManagerFactory::GetInstance()->GetForProfile(profile));
823 if (signin_manager)
824 signin_observer_.Add(signin_manager);
826 // Create our favicon data source.
827 content::URLDataSource::Add(
828 profile, new FaviconSource(profile, FaviconSource::FAVICON));
830 default_browser_policy_.Init(
831 prefs::kDefaultBrowserSettingEnabled,
832 g_browser_process->local_state(),
833 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState,
834 base::Unretained(this)));
836 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
837 content::NotificationService::AllSources());
838 #if defined(OS_CHROMEOS)
839 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
840 content::NotificationService::AllSources());
841 #endif
842 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
843 content::Source<ThemeService>(
844 ThemeServiceFactory::GetForProfile(profile)));
845 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
846 content::Source<Profile>(profile));
847 AddTemplateUrlServiceObserver();
849 #if defined(OS_WIN)
850 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
852 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
853 if (!command_line.HasSwitch(switches::kUserDataDir)) {
854 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
855 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
856 weak_ptr_factory_.GetWeakPtr(),
857 profile->GetPath()));
859 #endif
861 // No preferences below this point may be modified by guest profiles.
862 if (Profile::FromWebUI(web_ui())->IsGuestSession())
863 return;
865 auto_open_files_.Init(
866 prefs::kDownloadExtensionsToOpen, prefs,
867 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes,
868 base::Unretained(this)));
869 profile_pref_registrar_.Init(prefs);
870 profile_pref_registrar_.Add(
871 prefs::kNetworkPredictionOptions,
872 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl,
873 base::Unretained(this)));
874 profile_pref_registrar_.Add(
875 prefs::kWebKitDefaultFontSize,
876 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
877 base::Unretained(this)));
878 profile_pref_registrar_.Add(
879 prefs::kWebKitDefaultFixedFontSize,
880 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
881 base::Unretained(this)));
882 profile_pref_registrar_.Add(
883 prefs::kSupervisedUsers,
884 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers,
885 base::Unretained(this)));
886 profile_pref_registrar_.Add(
887 prefs::kSigninAllowed,
888 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange,
889 base::Unretained(this)));
890 profile_pref_registrar_.Add(
891 prefs::kEasyUnlockPairing,
892 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock,
893 base::Unretained(this)));
895 #if defined(OS_WIN)
896 profile_pref_registrar_.Add(
897 prefs::kURLsToRestoreOnStartup,
898 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
899 base::Unretained(this)));
900 profile_pref_registrar_.Add(
901 prefs::kHomePage,
902 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
903 base::Unretained(this)));
904 #endif // defined(OS_WIN)
906 #if defined(OS_CHROMEOS)
907 if (!policy_registrar_) {
908 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
909 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
910 policy_service(),
911 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
912 policy_registrar_->Observe(
913 policy::key::kUserAvatarImage,
914 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged,
915 base::Unretained(this)));
916 policy_registrar_->Observe(
917 policy::key::kWallpaperImage,
918 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged,
919 base::Unretained(this)));
921 #else // !defined(OS_CHROMEOS)
922 profile_pref_registrar_.Add(
923 prefs::kProxy,
924 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection,
925 base::Unretained(this)));
926 #endif // !defined(OS_CHROMEOS)
929 void BrowserOptionsHandler::InitializePage() {
930 page_initialized_ = true;
932 OnTemplateURLServiceChanged();
934 ObserveThemeChanged();
935 OnStateChanged();
936 UpdateDefaultBrowserState();
938 SetupMetricsReportingSettingVisibility();
939 SetupMetricsReportingCheckbox();
940 SetupNetworkPredictionControl();
941 SetupFontSizeSelector();
942 SetupPageZoomSelector();
943 SetupAutoOpenFileTypes();
944 SetupProxySettingsSection();
945 SetupManageCertificatesSection();
946 SetupManagingSupervisedUsers();
947 SetupEasyUnlock();
948 SetupExtensionControlledIndicators();
950 #if defined(OS_CHROMEOS)
951 SetupAccessibilityFeatures();
952 policy::BrowserPolicyConnectorChromeOS* connector =
953 g_browser_process->platform_part()->browser_policy_connector_chromeos();
954 if (!connector->IsEnterpriseManaged() &&
955 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
956 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
957 web_ui()->CallJavascriptFunction(
958 "BrowserOptions.enableFactoryResetSection");
961 Profile* profile = Profile::FromWebUI(web_ui());
962 OnAccountPictureManagedChanged(
963 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
964 policy_service()->GetPolicies(
965 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
966 std::string()))
967 .Get(policy::key::kUserAvatarImage));
969 OnWallpaperManagedChanged(
970 chromeos::WallpaperManager::Get()->IsPolicyControlled(
971 user_manager::UserManager::Get()->GetActiveUser()->email()));
973 policy::ConsumerManagementService* consumer_management =
974 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
975 GetConsumerManagementService();
976 if (consumer_management) {
977 OnConsumerManagementStatusChanged();
978 consumer_management->AddObserver(this);
980 #endif
983 // static
984 void BrowserOptionsHandler::CheckAutoLaunch(
985 base::WeakPtr<BrowserOptionsHandler> weak_this,
986 const base::FilePath& profile_path) {
987 #if defined(OS_WIN)
988 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
990 // Auto-launch is not supported for secondary profiles yet.
991 if (profile_path.BaseName().value() !=
992 base::ASCIIToUTF16(chrome::kInitialProfile)) {
993 return;
996 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
997 // deleted.
998 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
999 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
1000 weak_this,
1001 auto_launch_trial::IsInAutoLaunchGroup(),
1002 auto_launch_util::AutoStartRequested(
1003 profile_path.BaseName().value(),
1004 true, // Window requested.
1005 base::FilePath())));
1006 #endif
1009 void BrowserOptionsHandler::CheckAutoLaunchCallback(
1010 bool is_in_auto_launch_group,
1011 bool will_launch_at_login) {
1012 #if defined(OS_WIN)
1013 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1015 if (is_in_auto_launch_group) {
1016 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
1017 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
1018 base::Unretained(this)));
1020 base::FundamentalValue enabled(will_launch_at_login);
1021 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1022 enabled);
1024 #endif
1027 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1028 #if defined(OS_CHROMEOS)
1029 // We're always the default browser on ChromeOS.
1030 return false;
1031 #else
1032 Profile* profile = Profile::FromWebUI(web_ui());
1033 return !profile->IsGuestSession();
1034 #endif
1037 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1038 #if defined(OS_CHROMEOS)
1039 // On Chrome OS we use different UI for multi-profiles.
1040 return false;
1041 #else
1042 if (helper::GetDesktopType(web_ui()) != chrome::HOST_DESKTOP_TYPE_NATIVE)
1043 return false;
1044 Profile* profile = Profile::FromWebUI(web_ui());
1045 if (profile->IsGuestSession())
1046 return false;
1047 return profiles::IsMultipleProfilesEnabled();
1048 #endif
1051 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1052 #if defined(OS_CHROMEOS)
1053 // ChromeOS handles guest-mode restrictions in a different manner.
1054 return true;
1055 #else
1056 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1057 #endif
1060 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1061 default_browser_worker_->StartCheckIsDefault();
1064 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue* args) {
1065 // If the default browser setting is managed then we should not be able to
1066 // call this function.
1067 if (default_browser_policy_.IsManaged())
1068 return;
1070 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1071 default_browser_worker_->StartSetAsDefault();
1072 // Callback takes care of updating UI.
1074 // If the user attempted to make Chrome the default browser, then he/she
1075 // arguably wants to be notified when that changes.
1076 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1077 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
1080 int BrowserOptionsHandler::StatusStringIdForState(
1081 ShellIntegration::DefaultWebClientState state) {
1082 if (state == ShellIntegration::IS_DEFAULT)
1083 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1084 if (state == ShellIntegration::NOT_DEFAULT)
1085 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1086 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1089 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1090 ShellIntegration::DefaultWebClientUIState state) {
1091 int status_string_id;
1093 if (state == ShellIntegration::STATE_IS_DEFAULT) {
1094 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1095 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
1096 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1097 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
1098 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_SXS;
1099 } else {
1100 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1102 } else if (state == ShellIntegration::STATE_UNKNOWN) {
1103 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1104 } else {
1105 return; // Still processing.
1108 SetDefaultBrowserUIString(status_string_id);
1111 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1112 return true; // This is UI so we can allow it.
1115 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
1116 base::StringValue status_string(
1117 l10n_util::GetStringFUTF16(status_string_id,
1118 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1120 base::FundamentalValue is_default(
1121 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT);
1123 base::FundamentalValue can_be_default(
1124 !default_browser_policy_.IsManaged() &&
1125 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
1126 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
1128 web_ui()->CallJavascriptFunction(
1129 "BrowserOptions.updateDefaultBrowserState",
1130 status_string, is_default, can_be_default);
1133 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1134 if (!template_url_service_ || !template_url_service_->loaded())
1135 return;
1137 const TemplateURL* default_url =
1138 template_url_service_->GetDefaultSearchProvider();
1140 int default_index = -1;
1141 base::ListValue search_engines;
1142 TemplateURLService::TemplateURLVector model_urls(
1143 template_url_service_->GetTemplateURLs());
1144 for (size_t i = 0; i < model_urls.size(); ++i) {
1145 if (!model_urls[i]->ShowInDefaultList(
1146 template_url_service_->search_terms_data()))
1147 continue;
1149 base::DictionaryValue* entry = new base::DictionaryValue();
1150 entry->SetString("name", model_urls[i]->short_name());
1151 entry->SetInteger("index", i);
1152 search_engines.Append(entry);
1153 if (model_urls[i] == default_url)
1154 default_index = i;
1157 web_ui()->CallJavascriptFunction(
1158 "BrowserOptions.updateSearchEngines",
1159 search_engines,
1160 base::FundamentalValue(default_index),
1161 base::FundamentalValue(
1162 template_url_service_->is_default_search_managed() ||
1163 template_url_service_->IsExtensionControlledDefaultSearch()));
1165 SetupExtensionControlledIndicators();
1168 void BrowserOptionsHandler::SetDefaultSearchEngine(
1169 const base::ListValue* args) {
1170 int selected_index = -1;
1171 if (!ExtractIntegerValue(args, &selected_index)) {
1172 NOTREACHED();
1173 return;
1176 TemplateURLService::TemplateURLVector model_urls(
1177 template_url_service_->GetTemplateURLs());
1178 if (selected_index >= 0 &&
1179 selected_index < static_cast<int>(model_urls.size()))
1180 template_url_service_->SetUserSelectedDefaultSearchProvider(
1181 model_urls[selected_index]);
1183 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1186 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1187 template_url_service_ =
1188 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1189 if (template_url_service_) {
1190 template_url_service_->Load();
1191 template_url_service_->AddObserver(this);
1195 void BrowserOptionsHandler::OnExtensionLoaded(
1196 content::BrowserContext* browser_context,
1197 const Extension* extension) {
1198 SetupExtensionControlledIndicators();
1201 void BrowserOptionsHandler::OnExtensionUnloaded(
1202 content::BrowserContext* browser_context,
1203 const Extension* extension,
1204 extensions::UnloadedExtensionInfo::Reason reason) {
1205 SetupExtensionControlledIndicators();
1208 void BrowserOptionsHandler::Observe(
1209 int type,
1210 const content::NotificationSource& source,
1211 const content::NotificationDetails& details) {
1212 // Notifications are used to update the UI dynamically when settings change in
1213 // the background. If the UI is currently being loaded, no dynamic updates are
1214 // possible (as the DOM and JS are not fully loaded) or necessary (as
1215 // InitializePage() will update the UI at the end of the load).
1216 if (!page_initialized_)
1217 return;
1219 switch (type) {
1220 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
1221 ObserveThemeChanged();
1222 break;
1223 #if defined(OS_CHROMEOS)
1224 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
1225 UpdateAccountPicture();
1226 break;
1227 #endif
1228 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
1229 SendProfilesInfo();
1230 break;
1231 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
1232 // Update our sync/signin status display.
1233 OnStateChanged();
1234 break;
1235 default:
1236 NOTREACHED();
1240 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) {
1241 #if defined(OS_WIN)
1242 if (!auto_launch_trial::IsInAutoLaunchGroup())
1243 return;
1245 bool enable;
1246 CHECK_EQ(args->GetSize(), 1U);
1247 CHECK(args->GetBoolean(0, &enable));
1249 Profile* profile = Profile::FromWebUI(web_ui());
1250 content::BrowserThread::PostTask(
1251 content::BrowserThread::FILE, FROM_HERE,
1252 enable ?
1253 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin,
1254 profile->GetPath().BaseName().value(), base::FilePath()) :
1255 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin,
1256 profile->GetPath().BaseName().value()));
1257 #endif // OS_WIN
1260 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() {
1261 ProfileInfoCache& cache =
1262 g_browser_process->profile_manager()->GetProfileInfoCache();
1263 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue);
1264 base::FilePath current_profile_path =
1265 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1267 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
1268 base::DictionaryValue* profile_value = new base::DictionaryValue();
1269 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
1270 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
1271 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1272 profile_value->SetBoolean("isCurrentProfile",
1273 profile_path == current_profile_path);
1274 profile_value->SetBoolean("isSupervised",
1275 cache.ProfileIsSupervisedAtIndex(i));
1277 bool is_gaia_picture =
1278 cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
1279 cache.GetGAIAPictureOfProfileAtIndex(i);
1280 if (is_gaia_picture) {
1281 gfx::Image icon = profiles::GetAvatarIconForWebUI(
1282 cache.GetAvatarIconOfProfileAtIndex(i), true);
1283 profile_value->SetString("iconURL",
1284 webui::GetBitmapDataUrl(icon.AsBitmap()));
1285 } else {
1286 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
1287 profile_value->SetString("iconURL",
1288 profiles::GetDefaultAvatarIconUrl(icon_index));
1291 profile_info_list->Append(profile_value);
1294 return profile_info_list.Pass();
1297 void BrowserOptionsHandler::SendProfilesInfo() {
1298 if (!ShouldShowMultiProfilesUserList())
1299 return;
1300 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1301 *GetProfilesInfoList());
1304 void BrowserOptionsHandler::DeleteProfile(const base::ListValue* args) {
1305 DCHECK(args);
1306 const base::Value* file_path_value;
1307 if (!args->Get(0, &file_path_value))
1308 return;
1310 base::FilePath file_path;
1311 if (!base::GetValueAsFilePath(*file_path_value, &file_path))
1312 return;
1313 helper::DeleteProfileAtPath(file_path, web_ui());
1316 void BrowserOptionsHandler::ObserveThemeChanged() {
1317 Profile* profile = Profile::FromWebUI(web_ui());
1318 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
1319 bool is_system_theme = false;
1321 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1322 bool profile_is_supervised = profile->IsSupervised();
1323 is_system_theme = theme_service->UsingSystemTheme();
1324 base::FundamentalValue native_theme_enabled(!is_system_theme &&
1325 !profile_is_supervised);
1326 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1327 native_theme_enabled);
1328 #endif
1330 bool is_classic_theme = !is_system_theme &&
1331 theme_service->UsingDefaultTheme();
1332 base::FundamentalValue enabled(!is_classic_theme);
1333 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1334 enabled);
1337 void BrowserOptionsHandler::ThemesReset(const base::ListValue* args) {
1338 Profile* profile = Profile::FromWebUI(web_ui());
1339 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1340 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
1343 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1344 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue* args) {
1345 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1346 Profile* profile = Profile::FromWebUI(web_ui());
1347 ThemeServiceFactory::GetForProfile(profile)->UseSystemTheme();
1349 #endif
1351 #if defined(OS_CHROMEOS)
1352 void BrowserOptionsHandler::UpdateAccountPicture() {
1353 std::string email =
1354 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1355 if (!email.empty()) {
1356 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1357 base::StringValue email_value(email);
1358 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1359 email_value);
1363 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed) {
1364 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1365 base::FundamentalValue(managed));
1368 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed) {
1369 #if defined(USE_ATHENA)
1370 // In Athena, we don't allow customizing wallpaper right now.
1371 // TODO(mukai|bshe): remove this. http://crbug.com/408734
1372 managed = true;
1373 #endif
1374 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1375 base::FundamentalValue(managed));
1377 #endif
1379 scoped_ptr<base::DictionaryValue>
1380 BrowserOptionsHandler::GetSyncStateDictionary() {
1381 // The items which are to be written into |sync_status| are also described in
1382 // chrome/browser/resources/options/browser_options.js in @typedef
1383 // for SyncStatus. Please update it whenever you add or remove any keys here.
1384 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
1385 Profile* profile = Profile::FromWebUI(web_ui());
1386 if (profile->IsGuestSession()) {
1387 // Cannot display signin status when running in guest mode on chromeos
1388 // because there is no SigninManager.
1389 sync_status->SetBoolean("signinAllowed", false);
1390 return sync_status.Pass();
1393 sync_status->SetBoolean("supervisedUser", profile->IsSupervised());
1395 bool signout_prohibited = false;
1396 #if !defined(OS_CHROMEOS)
1397 // Signout is not allowed if the user has policy (crbug.com/172204).
1398 signout_prohibited =
1399 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited();
1400 #endif
1402 ProfileSyncService* service =
1403 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
1404 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1405 DCHECK(signin);
1406 sync_status->SetBoolean("signoutAllowed", !signout_prohibited);
1407 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed());
1408 sync_status->SetBoolean("syncSystemEnabled", (service != NULL));
1409 sync_status->SetBoolean("setupCompleted",
1410 service && service->HasSyncSetupCompleted());
1411 sync_status->SetBoolean("setupInProgress",
1412 service && !service->IsManaged() && service->FirstSetupInProgress());
1414 base::string16 status_label;
1415 base::string16 link_label;
1416 bool status_has_error = sync_ui_util::GetStatusLabels(
1417 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
1418 sync_ui_util::SYNC_ERROR;
1419 sync_status->SetString("statusText", status_label);
1420 sync_status->SetString("actionLinkText", link_label);
1421 sync_status->SetBoolean("hasError", status_has_error);
1423 sync_status->SetBoolean("managed", service && service->IsManaged());
1424 sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
1425 sync_status->SetBoolean("hasUnrecoverableError",
1426 service && service->HasUnrecoverableError());
1428 return sync_status.Pass();
1431 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1432 const base::ListValue* args) {
1433 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1434 select_folder_dialog_ = ui::SelectFileDialog::Create(
1435 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1436 ui::SelectFileDialog::FileTypeInfo info;
1437 info.support_drive = true;
1438 select_folder_dialog_->SelectFile(
1439 ui::SelectFileDialog::SELECT_FOLDER,
1440 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE),
1441 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory),
1442 &info,
1444 base::FilePath::StringType(),
1445 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1446 NULL);
1449 void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index,
1450 void* params) {
1451 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1452 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1453 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path);
1454 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
1457 #if defined(OS_CHROMEOS)
1458 void BrowserOptionsHandler::TouchpadExists(bool exists) {
1459 base::FundamentalValue val(exists);
1460 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val);
1463 void BrowserOptionsHandler::MouseExists(bool exists) {
1464 base::FundamentalValue val(exists);
1465 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val);
1468 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1469 const base::Value* previous_policy,
1470 const base::Value* current_policy) {
1471 const bool had_policy = previous_policy;
1472 const bool has_policy = current_policy;
1473 if (had_policy != has_policy)
1474 OnAccountPictureManagedChanged(has_policy);
1477 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1478 const base::Value* previous_policy,
1479 const base::Value* current_policy) {
1480 const bool had_policy = previous_policy;
1481 const bool has_policy = current_policy;
1482 if (had_policy != has_policy)
1483 OnWallpaperManagedChanged(has_policy);
1486 void BrowserOptionsHandler::OnPowerwashDialogShow(
1487 const base::ListValue* args) {
1488 UMA_HISTOGRAM_ENUMERATION(
1489 "Reset.ChromeOS.PowerwashDialogShown",
1490 chromeos::reset::DIALOG_FROM_OPTIONS,
1491 chromeos::reset::DIALOG_VIEW_TYPE_SIZE);
1494 void BrowserOptionsHandler::OnConsumerManagementStatusChanged() {
1495 const std::string& status = g_browser_process->platform_part()->
1496 browser_policy_connector_chromeos()->GetConsumerManagementService()->
1497 GetStatusString();
1498 web_ui()->CallJavascriptFunction(
1499 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status));
1502 #endif // defined(OS_CHROMEOS)
1504 void BrowserOptionsHandler::UpdateSyncState() {
1505 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1506 *GetSyncStateDictionary());
1509 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1510 UpdateSyncState();
1513 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1514 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1515 DownloadManager* manager = BrowserContext::GetDownloadManager(
1516 web_ui()->GetWebContents()->GetBrowserContext());
1517 if (manager)
1518 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
1521 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue* args) {
1522 int font_size;
1523 if (ExtractIntegerValue(args, &font_size)) {
1524 if (font_size > 0) {
1525 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1526 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size);
1527 SetupFontSizeSelector();
1532 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1533 const base::ListValue* args) {
1534 double zoom_factor;
1535 if (ExtractDoubleValue(args, &zoom_factor)) {
1536 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
1537 content::ZoomFactorToZoomLevel(zoom_factor));
1541 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
1542 #if defined(OS_WIN) && defined(USE_ASH)
1543 // If hardware acceleration is disabled then we need to force restart
1544 // browser in desktop mode.
1545 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1546 // Currently there are issues with determining correct browser mode
1547 // at startup.
1548 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1549 PrefService* pref_service = g_browser_process->local_state();
1550 if (!pref_service->GetBoolean(prefs::kHardwareAccelerationModeEnabled)) {
1551 chrome::AttemptRestartToDesktopMode();
1552 return;
1555 #endif
1557 #if defined(OS_WIN)
1558 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1559 // environment variable is defined. So we undefine this environment variable
1560 // before restarting, as the restarted processes will inherit their
1561 // environment variables from ours, thus suppressing crash uploads.
1562 PrefService* pref_service = g_browser_process->local_state();
1563 if (!pref_service->GetBoolean(prefs::kMetricsReportingEnabled)) {
1564 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
1565 if (exe_module) {
1566 typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
1567 ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
1568 GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
1569 if (clear)
1570 clear();
1573 #endif
1575 chrome::AttemptRestart();
1578 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1579 const base::ListValue* args) {
1580 SendProfilesInfo();
1583 #if !defined(OS_CHROMEOS)
1584 void BrowserOptionsHandler::ShowNetworkProxySettings(
1585 const base::ListValue* args) {
1586 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1587 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1588 web_ui()->GetWebContents());
1590 #endif
1592 #if defined(OS_WIN) || defined(OS_MACOSX)
1593 void BrowserOptionsHandler::ShowManageSSLCertificates(
1594 const base::ListValue* args) {
1595 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1596 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1597 web_ui()->GetWebContents());
1599 #endif
1601 #if defined(ENABLE_SERVICE_DISCOVERY)
1603 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1604 const base::ListValue* args) {
1605 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1606 // Navigate in current tab to devices page.
1607 OpenURLParams params(
1608 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1609 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false);
1610 web_ui()->GetWebContents()->OpenURL(params);
1613 #endif
1615 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1616 const base::ListValue* args) {
1617 Profile* profile = Profile::FromWebUI(web_ui());
1618 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1619 base::FundamentalValue enabled(
1620 profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled));
1621 if (group != "" && group != "Disabled" &&
1622 HotwordServiceFactory::IsHotwordAllowed(profile)) {
1623 // Update the current error value.
1624 HotwordServiceFactory::IsServiceAvailable(profile);
1625 int error = HotwordServiceFactory::GetCurrentError(profile);
1626 if (!error) {
1627 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
1628 enabled);
1629 } else {
1630 base::string16 hotword_help_url =
1631 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1632 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1633 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1634 error_message = base::StringValue(
1635 l10n_util::GetStringFUTF16(error, hotword_help_url));
1637 web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
1638 enabled, error_message);
1640 if (CommandLine::ForCurrentProcess()->HasSwitch(
1641 switches::kEnableExperimentalHotwording)) {
1642 web_ui()->CallJavascriptFunction(
1643 "BrowserOptions.showHotwordAlwaysOnSection");
1648 void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
1649 const base::ListValue* args) {
1650 Profile* profile = Profile::FromWebUI(web_ui());
1652 bool retrain = false;
1653 bool success = args->GetBoolean(0, &retrain);
1654 DCHECK(success);
1655 HotwordService::LaunchMode launch_mode =
1656 HotwordService::HOTWORD_AND_AUDIO_HISTORY;
1658 if (retrain) {
1659 DCHECK(profile->GetPrefs()->GetBoolean(
1660 prefs::kHotwordAlwaysOnSearchEnabled));
1661 DCHECK(profile->GetPrefs()->GetBoolean(
1662 prefs::kHotwordAudioLoggingEnabled));
1664 launch_mode = HotwordService::SPEECH_TRAINING;
1665 } else if (profile->GetPrefs()->GetBoolean(
1666 prefs::kHotwordAudioLoggingEnabled)) {
1667 DCHECK(!profile->GetPrefs()->GetBoolean(
1668 prefs::kHotwordAlwaysOnSearchEnabled));
1670 // TODO(kcarattini): Make sure the Chrome Audio Logging pref is synced
1671 // to the account-level Audio History setting from footprints.
1672 launch_mode = HotwordService::HOTWORD_ONLY;
1673 } else {
1674 DCHECK(!profile->GetPrefs()->GetBoolean(
1675 prefs::kHotwordAlwaysOnSearchEnabled));
1678 HotwordService* hotword_service =
1679 HotwordServiceFactory::GetForProfile(profile);
1680 if (!hotword_service)
1681 return;
1683 hotword_service->LaunchHotwordAudioVerificationApp(launch_mode);
1686 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1687 const base::ListValue* args) {
1688 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1691 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1692 const base::ListValue* args) {
1693 SetupExtensionControlledIndicators();
1696 #if defined(OS_CHROMEOS)
1697 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1698 const base::ListValue* args) {
1699 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1702 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1703 const base::ListValue* args) {
1704 bool enabled = false;
1705 args->GetBoolean(0, &enabled);
1707 chromeos::accessibility::EnableVirtualKeyboard(enabled);
1710 void BrowserOptionsHandler::PerformFactoryResetRestart(
1711 const base::ListValue* args) {
1712 policy::BrowserPolicyConnectorChromeOS* connector =
1713 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1714 if (connector->IsEnterpriseManaged())
1715 return;
1717 PrefService* prefs = g_browser_process->local_state();
1718 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
1719 prefs->CommitPendingWrite();
1721 // Perform sign out. Current chrome process will then terminate, new one will
1722 // be launched (as if it was a restart).
1723 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1726 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1727 PrefService* pref_service = g_browser_process->local_state();
1728 base::FundamentalValue virtual_keyboard_enabled(
1729 pref_service->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled));
1730 web_ui()->CallJavascriptFunction(
1731 "BrowserOptions.setVirtualKeyboardCheckboxState",
1732 virtual_keyboard_enabled);
1734 #endif
1736 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1737 #if defined(GOOGLE_CHROME_BUILD)
1738 // Don't show the reporting setting if we are in the guest mode.
1739 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1740 base::FundamentalValue visible(false);
1741 web_ui()->CallJavascriptFunction(
1742 "BrowserOptions.setMetricsReportingSettingVisibility", visible);
1744 #endif
1747 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1748 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1750 base::DictionaryValue dict;
1751 dict.SetInteger("value",
1752 pref_service->GetInteger(prefs::kNetworkPredictionOptions));
1753 dict.SetBoolean("disabled",
1754 !pref_service->IsUserModifiablePreference(
1755 prefs::kNetworkPredictionOptions));
1757 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1758 dict);
1761 void BrowserOptionsHandler::SetupFontSizeSelector() {
1762 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1763 const PrefService::Preference* default_font_size =
1764 pref_service->FindPreference(prefs::kWebKitDefaultFontSize);
1765 const PrefService::Preference* default_fixed_font_size =
1766 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize);
1768 base::DictionaryValue dict;
1769 dict.SetInteger("value",
1770 pref_service->GetInteger(prefs::kWebKitDefaultFontSize));
1772 // The font size control displays the value of the default font size, but
1773 // setting it alters both the default font size and the default fixed font
1774 // size. So it must be disabled when either of those prefs is not user
1775 // modifiable.
1776 dict.SetBoolean("disabled",
1777 !default_font_size->IsUserModifiable() ||
1778 !default_fixed_font_size->IsUserModifiable());
1780 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1781 // adapted to consider two prefs. It may be better to refactor
1782 // CreateValueForPref so it can be called from here.
1783 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) {
1784 dict.SetString("controlledBy", "policy");
1785 } else if (default_font_size->IsExtensionControlled() ||
1786 default_fixed_font_size->IsExtensionControlled()) {
1787 dict.SetString("controlledBy", "extension");
1790 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict);
1793 void BrowserOptionsHandler::SetupPageZoomSelector() {
1794 double default_zoom_level =
1795 content::HostZoomMap::GetDefaultForBrowserContext(
1796 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel();
1797 double default_zoom_factor =
1798 content::ZoomLevelToZoomFactor(default_zoom_level);
1800 // Generate a vector of zoom factors from an array of known presets along with
1801 // the default factor added if necessary.
1802 std::vector<double> zoom_factors =
1803 chrome_page_zoom::PresetZoomFactors(default_zoom_factor);
1805 // Iterate through the zoom factors and and build the contents of the
1806 // selector that will be sent to the javascript handler.
1807 // Each item in the list has the following parameters:
1808 // 1. Title (string).
1809 // 2. Value (double).
1810 // 3. Is selected? (bool).
1811 base::ListValue zoom_factors_value;
1812 for (std::vector<double>::const_iterator i = zoom_factors.begin();
1813 i != zoom_factors.end(); ++i) {
1814 base::ListValue* option = new base::ListValue();
1815 double factor = *i;
1816 int percent = static_cast<int>(factor * 100 + 0.5);
1817 option->Append(new base::StringValue(
1818 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
1819 option->Append(new base::FundamentalValue(factor));
1820 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
1821 option->Append(new base::FundamentalValue(selected));
1822 zoom_factors_value.Append(option);
1825 web_ui()->CallJavascriptFunction(
1826 "BrowserOptions.setupPageZoomSelector", zoom_factors_value);
1829 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1830 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1831 // We show the button if the user has any auto-open file types registered.
1832 DownloadManager* manager = BrowserContext::GetDownloadManager(
1833 web_ui()->GetWebContents()->GetBrowserContext());
1834 bool display = manager &&
1835 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
1836 base::FundamentalValue value(display);
1837 web_ui()->CallJavascriptFunction(
1838 "BrowserOptions.setAutoOpenFileTypesDisplayed", value);
1841 void BrowserOptionsHandler::SetupProxySettingsSection() {
1842 #if !defined(OS_CHROMEOS)
1843 // Disable the button if proxy settings are managed by a sysadmin, overridden
1844 // by an extension, or the browser is running in Windows Ash (on Windows the
1845 // proxy settings dialog will open on the Windows desktop and be invisible
1846 // to a user in Ash).
1847 bool is_win_ash = false;
1848 #if defined(OS_WIN)
1849 chrome::HostDesktopType desktop_type = helper::GetDesktopType(web_ui());
1850 is_win_ash = (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH);
1851 #endif
1852 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1853 const PrefService::Preference* proxy_config =
1854 pref_service->FindPreference(prefs::kProxy);
1855 bool is_extension_controlled = (proxy_config &&
1856 proxy_config->IsExtensionControlled());
1858 base::FundamentalValue disabled(is_win_ash || (proxy_config &&
1859 !proxy_config->IsUserModifiable()));
1860 base::FundamentalValue extension_controlled(is_extension_controlled);
1861 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
1862 disabled, extension_controlled);
1864 #if defined(OS_WIN)
1865 SetupExtensionControlledIndicators();
1866 #endif // defined(OS_WIN)
1868 #endif // !defined(OS_CHROMEOS)
1871 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1872 #if defined(OS_WIN)
1873 // Disable the button if the settings page is displayed in Windows Ash,
1874 // otherwise the proxy settings dialog will open on the Windows desktop and
1875 // be invisible to a user in Ash.
1876 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH) {
1877 base::FundamentalValue enabled(false);
1878 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1879 enabled);
1881 #endif // defined(OS_WIN)
1884 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1885 bool has_users = !Profile::FromWebUI(web_ui())->
1886 GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
1887 base::FundamentalValue has_users_value(has_users);
1888 web_ui()->CallJavascriptFunction(
1889 "BrowserOptions.updateManagesSupervisedUsers",
1890 has_users_value);
1893 void BrowserOptionsHandler::SetupEasyUnlock() {
1894 // TODO(xiyuan): Update when pairing data is really availble.
1895 const base::ListValue* devices =
1896 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->GetRemoteDevices();
1897 bool has_pairing = devices && !devices->empty();
1898 base::FundamentalValue has_pairing_value(has_pairing);
1899 web_ui()->CallJavascriptFunction(
1900 "BrowserOptions.updateEasyUnlock",
1901 has_pairing_value);
1904 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
1905 #if defined(OS_WIN)
1906 base::DictionaryValue extension_controlled;
1908 // Check if an extension is overriding the Search Engine.
1909 const extensions::Extension* extension =
1910 extensions::GetExtensionOverridingSearchEngine(
1911 Profile::FromWebUI(web_ui()));
1912 AppendExtensionData("searchEngine", extension, &extension_controlled);
1914 // Check if an extension is overriding the Home page.
1915 extension = extensions::GetExtensionOverridingHomepage(
1916 Profile::FromWebUI(web_ui()));
1917 AppendExtensionData("homePage", extension, &extension_controlled);
1919 // Check if an extension is overriding the Startup pages.
1920 extension = extensions::GetExtensionOverridingStartupPages(
1921 Profile::FromWebUI(web_ui()));
1922 AppendExtensionData("startUpPage", extension, &extension_controlled);
1924 // Check if an extension is overriding the NTP page.
1925 GURL ntp_url(chrome::kChromeUINewTabURL);
1926 bool ignored_param;
1927 extension = NULL;
1928 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
1929 &ntp_url,
1930 web_ui()->GetWebContents()->GetBrowserContext(),
1931 &ignored_param);
1932 if (ntp_url.SchemeIs("chrome-extension")) {
1933 using extensions::ExtensionRegistry;
1934 ExtensionRegistry* registry = ExtensionRegistry::Get(
1935 Profile::FromWebUI(web_ui()));
1936 extension = registry->GetExtensionById(ntp_url.host(),
1937 ExtensionRegistry::ENABLED);
1939 AppendExtensionData("newTabPage", extension, &extension_controlled);
1941 // Check if an extension is overwriting the proxy setting.
1942 extension = extensions::GetExtensionOverridingProxy(
1943 Profile::FromWebUI(web_ui()));
1944 AppendExtensionData("proxy", extension, &extension_controlled);
1946 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1947 extension_controlled);
1948 #endif // defined(OS_WIN)
1951 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1952 // This function does not work for ChromeOS and non-official builds.
1953 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
1954 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
1955 bool disabled = !IsMetricsReportingUserChangable();
1957 SetMetricsReportingCheckbox(checked, disabled);
1958 #endif
1961 void BrowserOptionsHandler::HandleMetricsReportingChange(
1962 const base::ListValue* args) {
1963 bool enable;
1964 if (!args->GetBoolean(0, &enable))
1965 return;
1967 InitiateMetricsReportingChange(
1968 enable,
1969 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback,
1970 base::Unretained(this)));
1973 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
1974 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
1977 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
1978 bool disabled) {
1979 web_ui()->CallJavascriptFunction(
1980 "BrowserOptions.setMetricsReportingCheckboxState",
1981 base::FundamentalValue(checked),
1982 base::FundamentalValue(disabled));
1985 } // namespace options