Re-factored printing defines and build configs.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / browser_options_handler.cc
blob78264eccb43ffb7c3d64fb31575af0517a8e2e1c
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/shell.h"
104 #include "chrome/browser/browser_process_platform_part.h"
105 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
106 #include "chrome/browser/chromeos/chromeos_utils.h"
107 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
108 #include "chrome/browser/chromeos/profiles/profile_helper.h"
109 #include "chrome/browser/chromeos/reset/metrics.h"
110 #include "chrome/browser/chromeos/settings/cros_settings.h"
111 #include "chrome/browser/chromeos/system/timezone_util.h"
112 #include "chrome/browser/policy/profile_policy_connector.h"
113 #include "chrome/browser/policy/profile_policy_connector_factory.h"
114 #include "chrome/browser/ui/browser_window.h"
115 #include "chromeos/dbus/dbus_thread_manager.h"
116 #include "chromeos/dbus/power_manager_client.h"
117 #include "components/policy/core/common/policy_map.h"
118 #include "components/policy/core/common/policy_namespace.h"
119 #include "components/policy/core/common/policy_service.h"
120 #include "components/user_manager/user.h"
121 #include "components/user_manager/user_manager.h"
122 #include "policy/policy_constants.h"
123 #include "ui/chromeos/accessibility_types.h"
124 #include "ui/gfx/image/image_skia.h"
125 #endif // defined(OS_CHROMEOS)
127 #if defined(OS_CHROMEOS) && !defined(USE_ATHENA)
128 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
129 #endif
131 #if defined(OS_WIN)
132 #include "chrome/browser/extensions/settings_api_helpers.h"
133 #include "chrome/installer/util/auto_launch_util.h"
134 #include "content/public/browser/browser_url_handler.h"
135 #endif // defined(OS_WIN)
137 #if defined(ENABLE_SERVICE_DISCOVERY)
138 #include "chrome/browser/local_discovery/privet_notifications.h"
139 #endif
141 using base::UserMetricsAction;
142 using content::BrowserContext;
143 using content::BrowserThread;
144 using content::DownloadManager;
145 using content::OpenURLParams;
146 using content::Referrer;
147 using extensions::Extension;
148 using extensions::ExtensionRegistry;
150 namespace {
152 #if defined(OS_WIN)
153 void AppendExtensionData(const std::string& key,
154 const Extension* extension,
155 base::DictionaryValue* dict) {
156 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue);
157 details->SetString("id", extension ? extension->id() : std::string());
158 details->SetString("name", extension ? extension->name() : std::string());
159 dict->Set(key, details.release());
161 #endif // defined(OS_WIN)
163 } // namespace
165 namespace options {
167 BrowserOptionsHandler::BrowserOptionsHandler()
168 : page_initialized_(false),
169 template_url_service_(NULL),
170 cloud_print_mdns_ui_enabled_(false),
171 signin_observer_(this),
172 weak_ptr_factory_(this) {
173 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
175 #if defined(ENABLE_SERVICE_DISCOVERY)
176 cloud_print_mdns_ui_enabled_ = true;
177 #endif // defined(ENABLE_SERVICE_DISCOVERY)
180 BrowserOptionsHandler::~BrowserOptionsHandler() {
181 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
182 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
183 if (sync_service)
184 sync_service->RemoveObserver(this);
186 if (default_browser_worker_.get())
187 default_browser_worker_->ObserverDestroyed();
188 if (template_url_service_)
189 template_url_service_->RemoveObserver(this);
190 // There may be pending file dialogs, we need to tell them that we've gone
191 // away so they don't try and call back to us.
192 if (select_folder_dialog_.get())
193 select_folder_dialog_->ListenerDestroyed();
196 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
197 DCHECK(values);
199 #if defined(OS_CHROMEOS)
200 const int device_type_resource_id = chromeos::GetChromeDeviceTypeResourceId();
201 #else
202 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices.
203 const int device_type_resource_id = IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE;
204 #endif // defined(OS_CHROMEOS)
206 static OptionsStringResource resources[] = {
207 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT },
208 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY },
209 { "advancedSectionTitleCertificates",
210 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES },
211 { "advancedSectionTitleContent",
212 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT },
213 { "advancedSectionTitleLanguages",
214 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES },
215 { "advancedSectionTitleNetwork",
216 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK },
217 { "advancedSectionTitlePrivacy",
218 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY },
219 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE },
220 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN },
221 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY },
222 { "autoOpenFileTypesResetToDefault",
223 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT },
224 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE },
225 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON },
226 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL },
227 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
228 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
229 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
230 #if defined(OS_CHROMEOS)
231 { "disableGData", IDS_OPTIONS_DISABLE_GDATA },
232 #endif
233 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES },
234 #if defined(OS_CHROMEOS)
235 { "displayOptions",
236 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL },
237 #endif
238 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK },
239 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT },
240 { "doNotTrackConfirmEnable",
241 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE },
242 { "doNotTrackConfirmDisable",
243 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE },
244 { "downloadLocationAskForSaveLocation",
245 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION },
246 { "downloadLocationBrowseTitle",
247 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE },
248 { "downloadLocationChangeButton",
249 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON },
250 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME },
251 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING },
252 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART },
253 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION,
254 device_type_resource_id },
255 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE },
256 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON },
257 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO,
258 device_type_resource_id },
259 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED },
260 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE },
261 { "fontSettingsCustomizeFontsButton",
262 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON },
263 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM },
264 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE },
265 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
266 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
267 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE },
268 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
269 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS },
270 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP },
271 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
272 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
273 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
274 { "hotwordAudioHistoryEnable", IDS_HOTWORD_AUDIO_HISTORY_PREF_CHKBOX },
275 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX },
276 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE },
277 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE },
278 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION },
279 { "hotwordNoDSPDesc", IDS_HOTWORD_SEARCH_NO_DSP_DESCRIPTION },
280 { "hotwordAlwaysOnDesc", IDS_HOTWORD_SEARCH_ALWAYS_ON_DESCRIPTION },
281 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE },
282 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON },
283 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE },
284 { "languageAndSpellCheckSettingsButton",
285 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS },
286 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF },
287 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK },
288 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES },
289 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK },
290 { "networkPredictionEnabledDescription",
291 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
292 { "passwordsAndAutofillGroupName",
293 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME },
294 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
295 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
296 { "privacyContentSettingsButton",
297 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON },
298 { "profileAddPersonEnable", IDS_PROFILE_ADD_PERSON_ENABLE },
299 { "profileBrowserGuestEnable", IDS_PROFILE_BROWSER_GUEST_ENABLE },
300 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL },
301 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL },
302 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL },
303 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT },
304 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL },
305 { "profilesSupervisedDashboardTip",
306 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP },
307 #if defined(ENABLE_SETTINGS_APP)
308 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL },
309 #endif
310 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
311 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
312 IDS_PRODUCT_NAME },
313 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
314 { "resetProfileSettingsDescription",
315 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
316 { "resetProfileSettingsSectionTitle",
317 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
318 { "safeBrowsingEnableProtection",
319 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
320 { "safeBrowsingEnableExtendedReporting",
321 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING },
322 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
323 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
324 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME },
325 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME },
326 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
327 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME },
328 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME },
329 { "settingsTitle", IDS_SETTINGS_TITLE },
330 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS },
331 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT },
332 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE },
333 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE },
334 { "spellingPref", IDS_OPTIONS_SPELLING_PREF },
335 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION },
336 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES },
337 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB },
338 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
339 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF },
340 { "supervisedUserLabel", IDS_PROFILES_LIST_SUPERVISED_USER_LABEL },
341 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS },
342 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL },
343 { "themesGallery", IDS_THEMES_GALLERY_BUTTON },
344 { "themesGalleryURL", IDS_THEMES_GALLERY_URL },
345 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF },
346 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
347 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
348 { "translateEnableTranslate",
349 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE },
350 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
351 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS },
352 { "themesNativeButton", IDS_THEMES_GTK_BUTTON },
353 { "themesSetClassic", IDS_THEMES_SET_CLASSIC },
354 #else
355 { "themes", IDS_THEMES_GROUP_NAME },
356 #endif
357 { "themesReset", IDS_THEMES_RESET_BUTTON },
358 { "accessibilityTitle",
359 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY },
360 { "accessibilityFeaturesLink",
361 IDS_OPTIONS_ACCESSIBILITY_FEATURES_LINK },
362 #if defined(OS_CHROMEOS)
363 { "accessibilityExplanation",
364 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION },
365 { "accessibilitySettings",
366 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS },
367 { "accessibilityHighContrast",
368 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION },
369 { "accessibilityScreenMagnifier",
370 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION },
371 { "accessibilityTapDragging",
372 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION },
373 { "accessibilityScreenMagnifierOff",
374 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF },
375 { "accessibilityScreenMagnifierFull",
376 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL },
377 { "accessibilityScreenMagnifierPartial",
378 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL },
379 { "accessibilityLargeCursor",
380 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION },
381 { "accessibilityStickyKeys",
382 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION },
383 { "accessibilitySpokenFeedback",
384 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION },
385 { "accessibilityVirtualKeyboard",
386 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION },
387 { "accessibilityAlwaysShowMenu",
388 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU },
389 { "accessibilityAutoclick",
390 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION },
391 { "accessibilityAutoclickDropdown",
392 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION },
393 { "autoclickDelayExtremelyShort",
394 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT },
395 { "autoclickDelayVeryShort",
396 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT },
397 { "autoclickDelayShort",
398 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT },
399 { "autoclickDelayLong",
400 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG },
401 { "autoclickDelayVeryLong",
402 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG },
403 { "consumerManagementDescription",
404 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION },
405 { "consumerManagementEnrollButton",
406 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON },
407 { "consumerManagementEnrollingButton",
408 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLLING_BUTTON },
409 { "consumerManagementUnenrollButton",
410 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON },
411 { "consumerManagementUnenrollingButton",
412 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLLING_BUTTON },
413 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE },
414 { "enableContentProtectionAttestation",
415 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION },
416 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING },
417 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET },
418 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON },
419 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON },
420 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING },
421 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL },
422 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE },
423 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION },
424 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME },
425 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION },
426 { "powerSettingsButton",
427 IDS_OPTIONS_DEVICE_GROUP_POWER_SETTINGS_BUTTON },
428 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION },
429 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION },
430 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION },
431 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX },
432 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE },
433 { "keyboardSettingsButtonTitle",
434 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE },
435 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE },
436 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES },
437 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME },
438 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL },
439 { "syncOverview", IDS_SYNC_OVERVIEW },
440 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
441 { "thirdPartyImeConfirmEnable", IDS_OK },
442 { "thirdPartyImeConfirmDisable", IDS_CANCEL },
443 { "thirdPartyImeConfirmMessage",
444 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE },
445 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION },
446 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION },
447 { "batteryButton", IDS_OPTIONS_SETTINGS_BATTERY_DESCRIPTION},
448 { "storageButton", IDS_OPTIONS_SETTINGS_STORAGE_DESCRIPTION},
449 #else
450 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON },
451 #endif
452 #if defined(OS_CHROMEOS) && defined(USE_ASH)
453 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON },
454 #endif
455 { "advancedSectionTitleSystem",
456 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM },
457 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
458 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE },
459 #endif
460 #if !defined(OS_CHROMEOS)
461 { "gpuModeCheckbox",
462 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE },
463 { "gpuModeResetRestart",
464 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART },
465 // Strings with product-name substitutions.
466 { "syncOverview", IDS_SYNC_OVERVIEW, IDS_PRODUCT_NAME },
467 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
468 #endif
469 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL,
470 IDS_SHORT_PRODUCT_NAME },
471 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
472 IDS_PRODUCT_NAME },
473 { "defaultBrowserUnknown", IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
474 IDS_PRODUCT_NAME },
475 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT },
476 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT },
477 #if defined(OS_CHROMEOS)
478 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION,
479 IDS_SHORT_PRODUCT_NAME },
480 #endif
481 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
482 IDS_SHORT_PRODUCT_NAME },
483 #if defined(ENABLE_SERVICE_DISCOVERY)
484 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON },
485 { "cloudPrintEnableNotificationsLabel",
486 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL },
487 #endif
490 #if defined(ENABLE_SETTINGS_APP)
491 static OptionsStringResource app_resources[] = {
492 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW },
493 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL,
494 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
495 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
496 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
497 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
498 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
499 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
500 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
502 base::DictionaryValue* app_values = NULL;
503 CHECK(values->GetDictionary(kSettingsAppKey, &app_values));
504 RegisterStrings(app_values, app_resources, arraysize(app_resources));
505 #endif
507 RegisterStrings(values, resources, arraysize(resources));
508 RegisterTitle(values, "doNotTrackConfirmOverlay",
509 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE);
510 RegisterTitle(values, "spellingConfirmOverlay",
511 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE);
512 #if defined(ENABLE_PRINT_PREVIEW)
513 RegisterCloudPrintValues(values);
514 #endif
516 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL);
517 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
518 values->SetString(
519 "defaultSearchGroupLabel",
520 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
521 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL);
522 RegisterTitle(values, "hotwordConfirmOverlay",
523 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE);
525 #if defined(OS_CHROMEOS)
526 Profile* profile = Profile::FromWebUI(web_ui());
527 std::string username = profile->GetProfileName();
528 if (username.empty()) {
529 user_manager::User* user =
530 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
531 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
532 username = user->email();
534 if (!username.empty())
535 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
537 values->SetString("username", username);
538 #endif
540 // Pass along sync status early so it will be available during page init.
541 values->Set("syncData", GetSyncStateDictionary().release());
543 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
544 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
546 #if !defined(OS_CHROMEOS)
547 values->SetBoolean("metricsReportingEnabledAtStart",
548 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
549 #endif
551 #if defined(OS_CHROMEOS)
552 // TODO(pastarmovj): replace this with a call to the CrosSettings list
553 // handling functionality to come.
554 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
556 values->SetString("accessibilityLearnMoreURL",
557 chrome::kChromeAccessibilityHelpURL);
559 std::string settings_url = std::string("chrome-extension://") +
560 extension_misc::kChromeVoxExtensionId +
561 chrome::kChromeAccessibilitySettingsURL;
563 values->SetString("accessibilitySettingsURL",
564 settings_url);
566 values->SetString("contentProtectionAttestationLearnMoreURL",
567 chrome::kAttestationForContentProtectionLearnMoreURL);
569 // Creates magnifierList.
570 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue);
572 scoped_ptr<base::ListValue> option_full(new base::ListValue);
573 option_full->AppendInteger(ui::MAGNIFIER_FULL);
574 option_full->AppendString(l10n_util::GetStringUTF16(
575 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL));
576 magnifier_list->Append(option_full.release());
578 scoped_ptr<base::ListValue> option_partial(new base::ListValue);
579 option_partial->AppendInteger(ui::MAGNIFIER_PARTIAL);
580 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16(
581 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL)));
582 magnifier_list->Append(option_partial.release());
584 values->Set("magnifierList", magnifier_list.release());
585 #endif
587 #if defined(OS_MACOSX)
588 values->SetString("macPasswordsWarning",
589 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
590 values->SetBoolean("multiple_profiles",
591 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
592 #endif
594 if (ShouldShowMultiProfilesUserList())
595 values->Set("profilesInfo", GetProfilesInfoList().release());
597 values->SetBoolean("profileIsGuest",
598 Profile::FromWebUI(web_ui())->IsOffTheRecord());
600 values->SetBoolean("profileIsSupervised",
601 Profile::FromWebUI(web_ui())->IsSupervised());
603 #if !defined(OS_CHROMEOS)
604 values->SetBoolean(
605 "gpuEnabledAtStart",
606 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
607 #endif
609 #if defined(ENABLE_SERVICE_DISCOVERY)
610 values->SetBoolean("cloudPrintHideNotificationsCheckbox",
611 !local_discovery::PrivetNotificationService::IsEnabled());
612 #endif
614 values->SetBoolean("cloudPrintShowMDnsOptions",
615 cloud_print_mdns_ui_enabled_);
617 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
619 values->SetString("languagesLearnMoreURL",
620 chrome::kLanguageSettingsLearnMoreUrl);
622 values->SetBoolean(
623 "easyUnlockAllowed",
624 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
625 values->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl);
627 #if defined(OS_CHROMEOS)
628 values->SetBoolean(
629 "consumerManagementEnabled",
630 CommandLine::ForCurrentProcess()->HasSwitch(
631 chromeos::switches::kEnableConsumerManagement));
633 RegisterTitle(values, "thirdPartyImeConfirmOverlay",
634 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE);
635 #endif
637 values->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
639 values->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
641 values->SetBoolean("websiteSettingsManagerEnabled",
642 CommandLine::ForCurrentProcess()->HasSwitch(
643 switches::kEnableWebsiteSettingsManager));
645 values->SetBoolean("usingNewProfilesUI", switches::IsNewAvatarMenu());
648 #if defined(ENABLE_PRINT_PREVIEW)
649 void BrowserOptionsHandler::RegisterCloudPrintValues(
650 base::DictionaryValue* values) {
651 values->SetString("cloudPrintOptionLabel",
652 l10n_util::GetStringFUTF16(
653 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL,
654 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
656 #endif // defined(ENABLE_PRINT_PREVIEW)
658 void BrowserOptionsHandler::RegisterMessages() {
659 web_ui()->RegisterMessageCallback(
660 "becomeDefaultBrowser",
661 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
662 base::Unretained(this)));
663 web_ui()->RegisterMessageCallback(
664 "setDefaultSearchEngine",
665 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
666 base::Unretained(this)));
667 web_ui()->RegisterMessageCallback(
668 "deleteProfile",
669 base::Bind(&BrowserOptionsHandler::DeleteProfile,
670 base::Unretained(this)));
671 web_ui()->RegisterMessageCallback(
672 "themesReset",
673 base::Bind(&BrowserOptionsHandler::ThemesReset,
674 base::Unretained(this)));
675 web_ui()->RegisterMessageCallback(
676 "requestProfilesInfo",
677 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo,
678 base::Unretained(this)));
679 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
680 web_ui()->RegisterMessageCallback(
681 "themesSetNative",
682 base::Bind(&BrowserOptionsHandler::ThemesSetNative,
683 base::Unretained(this)));
684 #endif
685 web_ui()->RegisterMessageCallback(
686 "selectDownloadLocation",
687 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation,
688 base::Unretained(this)));
689 web_ui()->RegisterMessageCallback(
690 "autoOpenFileTypesAction",
691 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton,
692 base::Unretained(this)));
693 web_ui()->RegisterMessageCallback(
694 "defaultFontSizeAction",
695 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize,
696 base::Unretained(this)));
697 web_ui()->RegisterMessageCallback(
698 "defaultZoomFactorAction",
699 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor,
700 base::Unretained(this)));
701 #if defined(OS_WIN) || defined(OS_MACOSX)
702 web_ui()->RegisterMessageCallback(
703 "showManageSSLCertificates",
704 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates,
705 base::Unretained(this)));
706 #endif
707 #if defined(OS_CHROMEOS)
708 web_ui()->RegisterMessageCallback(
709 "openWallpaperManager",
710 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager,
711 base::Unretained(this)));
712 web_ui()->RegisterMessageCallback(
713 "virtualKeyboardChange",
714 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback,
715 base::Unretained(this)));
716 web_ui()->RegisterMessageCallback(
717 "onPowerwashDialogShow",
718 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow,
719 base::Unretained(this)));
720 web_ui()->RegisterMessageCallback(
721 "performFactoryResetRestart",
722 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart,
723 base::Unretained(this)));
724 #else
725 web_ui()->RegisterMessageCallback(
726 "restartBrowser",
727 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser,
728 base::Unretained(this)));
729 web_ui()->RegisterMessageCallback(
730 "showNetworkProxySettings",
731 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings,
732 base::Unretained(this)));
733 #endif // defined(OS_CHROMEOS)
735 #if defined(ENABLE_SERVICE_DISCOVERY)
736 if (cloud_print_mdns_ui_enabled_) {
737 web_ui()->RegisterMessageCallback(
738 "showCloudPrintDevicesPage",
739 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage,
740 base::Unretained(this)));
742 #endif
743 web_ui()->RegisterMessageCallback(
744 "requestHotwordAvailable",
745 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable,
746 base::Unretained(this)));
748 web_ui()->RegisterMessageCallback(
749 "launchHotwordAudioVerificationApp",
750 base::Bind(
751 &BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp,
752 base::Unretained(this)));
754 web_ui()->RegisterMessageCallback(
755 "launchEasyUnlockSetup",
756 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
757 base::Unretained(this)));
758 #if defined(OS_WIN)
759 web_ui()->RegisterMessageCallback(
760 "refreshExtensionControlIndicators",
761 base::Bind(
762 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
763 base::Unretained(this)));
764 #endif // defined(OS_WIN)
765 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
766 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
767 base::Unretained(this)));
770 void BrowserOptionsHandler::Uninitialize() {
771 registrar_.RemoveAll();
772 #if defined(OS_WIN)
773 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
774 #endif
775 #if defined(OS_CHROMEOS)
776 policy::ConsumerManagementService* consumer_management =
777 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
778 GetConsumerManagementService();
779 if (consumer_management)
780 consumer_management->RemoveObserver(this);
781 #endif
784 void BrowserOptionsHandler::OnStateChanged() {
785 UpdateSyncState();
788 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string& account_id,
789 const std::string& username,
790 const std::string& password) {
791 OnStateChanged();
794 void BrowserOptionsHandler::GoogleSignedOut(const std::string& account_id,
795 const std::string& username) {
796 OnStateChanged();
799 void BrowserOptionsHandler::PageLoadStarted() {
800 page_initialized_ = false;
803 void BrowserOptionsHandler::InitializeHandler() {
804 Profile* profile = Profile::FromWebUI(web_ui());
805 PrefService* prefs = profile->GetPrefs();
806 chrome::ChromeZoomLevelPrefs* zoom_level_prefs = profile->GetZoomLevelPrefs();
807 // Only regular profiles are able to edit default zoom level, or delete per-
808 // host zoom levels, via the settings menu. We only require a zoom_level_prefs
809 // if the profile is able to change these preference types.
810 DCHECK(zoom_level_prefs ||
811 profile->GetProfileType() != Profile::REGULAR_PROFILE);
812 if (zoom_level_prefs) {
813 default_zoom_level_subscription_ =
814 zoom_level_prefs->RegisterDefaultZoomLevelCallback(
815 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector,
816 base::Unretained(this)));
819 ProfileSyncService* sync_service(
820 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile));
821 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
822 // destruction is automatic.
823 if (sync_service)
824 sync_service->AddObserver(this);
826 SigninManagerBase* signin_manager(
827 SigninManagerFactory::GetInstance()->GetForProfile(profile));
828 if (signin_manager)
829 signin_observer_.Add(signin_manager);
831 // Create our favicon data source.
832 content::URLDataSource::Add(
833 profile, new FaviconSource(profile, FaviconSource::FAVICON));
835 default_browser_policy_.Init(
836 prefs::kDefaultBrowserSettingEnabled,
837 g_browser_process->local_state(),
838 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState,
839 base::Unretained(this)));
841 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
842 content::NotificationService::AllSources());
843 #if defined(OS_CHROMEOS)
844 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
845 content::NotificationService::AllSources());
846 #endif
847 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
848 content::Source<ThemeService>(
849 ThemeServiceFactory::GetForProfile(profile)));
850 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
851 content::Source<Profile>(profile));
852 AddTemplateUrlServiceObserver();
854 #if defined(OS_WIN)
855 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
857 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
858 if (!command_line.HasSwitch(switches::kUserDataDir)) {
859 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
860 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
861 weak_ptr_factory_.GetWeakPtr(),
862 profile->GetPath()));
864 #endif
866 // No preferences below this point may be modified by guest profiles.
867 if (Profile::FromWebUI(web_ui())->IsGuestSession())
868 return;
870 auto_open_files_.Init(
871 prefs::kDownloadExtensionsToOpen, prefs,
872 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes,
873 base::Unretained(this)));
874 profile_pref_registrar_.Init(prefs);
875 profile_pref_registrar_.Add(
876 prefs::kNetworkPredictionOptions,
877 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl,
878 base::Unretained(this)));
879 profile_pref_registrar_.Add(
880 prefs::kWebKitDefaultFontSize,
881 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
882 base::Unretained(this)));
883 profile_pref_registrar_.Add(
884 prefs::kWebKitDefaultFixedFontSize,
885 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
886 base::Unretained(this)));
887 profile_pref_registrar_.Add(
888 prefs::kSupervisedUsers,
889 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers,
890 base::Unretained(this)));
891 profile_pref_registrar_.Add(
892 prefs::kSigninAllowed,
893 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange,
894 base::Unretained(this)));
895 profile_pref_registrar_.Add(
896 prefs::kEasyUnlockPairing,
897 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock,
898 base::Unretained(this)));
900 #if defined(OS_WIN)
901 profile_pref_registrar_.Add(
902 prefs::kURLsToRestoreOnStartup,
903 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
904 base::Unretained(this)));
905 profile_pref_registrar_.Add(
906 prefs::kHomePage,
907 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
908 base::Unretained(this)));
909 #endif // defined(OS_WIN)
911 #if defined(OS_CHROMEOS)
912 if (!policy_registrar_) {
913 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
914 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
915 policy_service(),
916 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
917 policy_registrar_->Observe(
918 policy::key::kUserAvatarImage,
919 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged,
920 base::Unretained(this)));
921 policy_registrar_->Observe(
922 policy::key::kWallpaperImage,
923 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged,
924 base::Unretained(this)));
926 #else // !defined(OS_CHROMEOS)
927 profile_pref_registrar_.Add(
928 prefs::kProxy,
929 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection,
930 base::Unretained(this)));
931 #endif // !defined(OS_CHROMEOS)
934 void BrowserOptionsHandler::InitializePage() {
935 page_initialized_ = true;
937 OnTemplateURLServiceChanged();
939 ObserveThemeChanged();
940 OnStateChanged();
941 UpdateDefaultBrowserState();
943 SetupMetricsReportingSettingVisibility();
944 SetupMetricsReportingCheckbox();
945 SetupNetworkPredictionControl();
946 SetupFontSizeSelector();
947 SetupPageZoomSelector();
948 SetupAutoOpenFileTypes();
949 SetupProxySettingsSection();
950 SetupManageCertificatesSection();
951 SetupManagingSupervisedUsers();
952 SetupEasyUnlock();
953 SetupExtensionControlledIndicators();
955 #if defined(OS_CHROMEOS)
956 SetupAccessibilityFeatures();
957 policy::BrowserPolicyConnectorChromeOS* connector =
958 g_browser_process->platform_part()->browser_policy_connector_chromeos();
959 if (!connector->IsEnterpriseManaged() &&
960 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
961 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
962 web_ui()->CallJavascriptFunction(
963 "BrowserOptions.enableFactoryResetSection");
966 Profile* profile = Profile::FromWebUI(web_ui());
967 OnAccountPictureManagedChanged(
968 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
969 policy_service()->GetPolicies(
970 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
971 std::string()))
972 .Get(policy::key::kUserAvatarImage));
974 #if !defined(USE_ATHENA)
975 OnWallpaperManagedChanged(
976 chromeos::WallpaperManager::Get()->IsPolicyControlled(
977 user_manager::UserManager::Get()->GetActiveUser()->email()));
978 #endif
980 policy::ConsumerManagementService* consumer_management =
981 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
982 GetConsumerManagementService();
983 if (consumer_management) {
984 OnConsumerManagementStatusChanged();
985 consumer_management->AddObserver(this);
987 #endif
990 // static
991 void BrowserOptionsHandler::CheckAutoLaunch(
992 base::WeakPtr<BrowserOptionsHandler> weak_this,
993 const base::FilePath& profile_path) {
994 #if defined(OS_WIN)
995 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
997 // Auto-launch is not supported for secondary profiles yet.
998 if (profile_path.BaseName().value() !=
999 base::ASCIIToUTF16(chrome::kInitialProfile)) {
1000 return;
1003 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
1004 // deleted.
1005 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1006 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
1007 weak_this,
1008 auto_launch_trial::IsInAutoLaunchGroup(),
1009 auto_launch_util::AutoStartRequested(
1010 profile_path.BaseName().value(),
1011 true, // Window requested.
1012 base::FilePath())));
1013 #endif
1016 void BrowserOptionsHandler::CheckAutoLaunchCallback(
1017 bool is_in_auto_launch_group,
1018 bool will_launch_at_login) {
1019 #if defined(OS_WIN)
1020 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1022 if (is_in_auto_launch_group) {
1023 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
1024 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
1025 base::Unretained(this)));
1027 base::FundamentalValue enabled(will_launch_at_login);
1028 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1029 enabled);
1031 #endif
1034 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1035 #if defined(OS_CHROMEOS)
1036 // We're always the default browser on ChromeOS.
1037 return false;
1038 #else
1039 Profile* profile = Profile::FromWebUI(web_ui());
1040 return !profile->IsGuestSession();
1041 #endif
1044 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1045 #if defined(OS_CHROMEOS)
1046 // On Chrome OS we use different UI for multi-profiles.
1047 return false;
1048 #else
1049 Profile* profile = Profile::FromWebUI(web_ui());
1050 if (profile->IsGuestSession())
1051 return false;
1052 return profiles::IsMultipleProfilesEnabled();
1053 #endif
1056 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1057 #if defined(OS_CHROMEOS)
1058 // ChromeOS handles guest-mode restrictions in a different manner.
1059 return true;
1060 #else
1061 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1062 #endif
1065 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1066 default_browser_worker_->StartCheckIsDefault();
1069 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue* args) {
1070 // If the default browser setting is managed then we should not be able to
1071 // call this function.
1072 if (default_browser_policy_.IsManaged())
1073 return;
1075 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1076 default_browser_worker_->StartSetAsDefault();
1077 // Callback takes care of updating UI.
1079 // If the user attempted to make Chrome the default browser, then he/she
1080 // arguably wants to be notified when that changes.
1081 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1082 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
1085 int BrowserOptionsHandler::StatusStringIdForState(
1086 ShellIntegration::DefaultWebClientState state) {
1087 if (state == ShellIntegration::IS_DEFAULT)
1088 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1089 if (state == ShellIntegration::NOT_DEFAULT)
1090 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1091 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1094 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1095 ShellIntegration::DefaultWebClientUIState state) {
1096 int status_string_id;
1098 if (state == ShellIntegration::STATE_IS_DEFAULT) {
1099 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1100 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
1101 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1102 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
1103 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_SXS;
1104 } else {
1105 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1107 } else if (state == ShellIntegration::STATE_UNKNOWN) {
1108 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1109 } else {
1110 return; // Still processing.
1113 SetDefaultBrowserUIString(status_string_id);
1116 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1117 return true; // This is UI so we can allow it.
1120 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
1121 base::StringValue status_string(
1122 l10n_util::GetStringFUTF16(status_string_id,
1123 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1125 base::FundamentalValue is_default(
1126 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT);
1128 base::FundamentalValue can_be_default(
1129 !default_browser_policy_.IsManaged() &&
1130 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
1131 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
1133 web_ui()->CallJavascriptFunction(
1134 "BrowserOptions.updateDefaultBrowserState",
1135 status_string, is_default, can_be_default);
1138 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1139 if (!template_url_service_ || !template_url_service_->loaded())
1140 return;
1142 const TemplateURL* default_url =
1143 template_url_service_->GetDefaultSearchProvider();
1145 int default_index = -1;
1146 base::ListValue search_engines;
1147 TemplateURLService::TemplateURLVector model_urls(
1148 template_url_service_->GetTemplateURLs());
1149 for (size_t i = 0; i < model_urls.size(); ++i) {
1150 if (!model_urls[i]->ShowInDefaultList(
1151 template_url_service_->search_terms_data()))
1152 continue;
1154 base::DictionaryValue* entry = new base::DictionaryValue();
1155 entry->SetString("name", model_urls[i]->short_name());
1156 entry->SetInteger("index", i);
1157 search_engines.Append(entry);
1158 if (model_urls[i] == default_url)
1159 default_index = i;
1162 web_ui()->CallJavascriptFunction(
1163 "BrowserOptions.updateSearchEngines",
1164 search_engines,
1165 base::FundamentalValue(default_index),
1166 base::FundamentalValue(
1167 template_url_service_->is_default_search_managed() ||
1168 template_url_service_->IsExtensionControlledDefaultSearch()));
1170 SetupExtensionControlledIndicators();
1173 void BrowserOptionsHandler::SetDefaultSearchEngine(
1174 const base::ListValue* args) {
1175 int selected_index = -1;
1176 if (!ExtractIntegerValue(args, &selected_index)) {
1177 NOTREACHED();
1178 return;
1181 TemplateURLService::TemplateURLVector model_urls(
1182 template_url_service_->GetTemplateURLs());
1183 if (selected_index >= 0 &&
1184 selected_index < static_cast<int>(model_urls.size()))
1185 template_url_service_->SetUserSelectedDefaultSearchProvider(
1186 model_urls[selected_index]);
1188 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1191 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1192 template_url_service_ =
1193 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1194 if (template_url_service_) {
1195 template_url_service_->Load();
1196 template_url_service_->AddObserver(this);
1200 void BrowserOptionsHandler::OnExtensionLoaded(
1201 content::BrowserContext* browser_context,
1202 const Extension* extension) {
1203 SetupExtensionControlledIndicators();
1206 void BrowserOptionsHandler::OnExtensionUnloaded(
1207 content::BrowserContext* browser_context,
1208 const Extension* extension,
1209 extensions::UnloadedExtensionInfo::Reason reason) {
1210 SetupExtensionControlledIndicators();
1213 void BrowserOptionsHandler::Observe(
1214 int type,
1215 const content::NotificationSource& source,
1216 const content::NotificationDetails& details) {
1217 // Notifications are used to update the UI dynamically when settings change in
1218 // the background. If the UI is currently being loaded, no dynamic updates are
1219 // possible (as the DOM and JS are not fully loaded) or necessary (as
1220 // InitializePage() will update the UI at the end of the load).
1221 if (!page_initialized_)
1222 return;
1224 switch (type) {
1225 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
1226 ObserveThemeChanged();
1227 break;
1228 #if defined(OS_CHROMEOS)
1229 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
1230 UpdateAccountPicture();
1231 break;
1232 #endif
1233 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
1234 SendProfilesInfo();
1235 break;
1236 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
1237 // Update our sync/signin status display.
1238 OnStateChanged();
1239 break;
1240 default:
1241 NOTREACHED();
1245 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) {
1246 #if defined(OS_WIN)
1247 if (!auto_launch_trial::IsInAutoLaunchGroup())
1248 return;
1250 bool enable;
1251 CHECK_EQ(args->GetSize(), 1U);
1252 CHECK(args->GetBoolean(0, &enable));
1254 Profile* profile = Profile::FromWebUI(web_ui());
1255 content::BrowserThread::PostTask(
1256 content::BrowserThread::FILE, FROM_HERE,
1257 enable ?
1258 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin,
1259 profile->GetPath().BaseName().value(), base::FilePath()) :
1260 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin,
1261 profile->GetPath().BaseName().value()));
1262 #endif // OS_WIN
1265 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() {
1266 ProfileInfoCache& cache =
1267 g_browser_process->profile_manager()->GetProfileInfoCache();
1268 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue);
1269 base::FilePath current_profile_path =
1270 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1272 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
1273 base::DictionaryValue* profile_value = new base::DictionaryValue();
1274 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
1275 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
1276 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1277 profile_value->SetBoolean("isCurrentProfile",
1278 profile_path == current_profile_path);
1279 profile_value->SetBoolean("isSupervised",
1280 cache.ProfileIsSupervisedAtIndex(i));
1282 bool is_gaia_picture =
1283 cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
1284 cache.GetGAIAPictureOfProfileAtIndex(i);
1285 if (is_gaia_picture) {
1286 gfx::Image icon = profiles::GetAvatarIconForWebUI(
1287 cache.GetAvatarIconOfProfileAtIndex(i), true);
1288 profile_value->SetString("iconURL",
1289 webui::GetBitmapDataUrl(icon.AsBitmap()));
1290 } else {
1291 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
1292 profile_value->SetString("iconURL",
1293 profiles::GetDefaultAvatarIconUrl(icon_index));
1296 profile_info_list->Append(profile_value);
1299 return profile_info_list.Pass();
1302 void BrowserOptionsHandler::SendProfilesInfo() {
1303 if (!ShouldShowMultiProfilesUserList())
1304 return;
1305 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1306 *GetProfilesInfoList());
1309 void BrowserOptionsHandler::DeleteProfile(const base::ListValue* args) {
1310 DCHECK(args);
1311 const base::Value* file_path_value;
1312 if (!args->Get(0, &file_path_value))
1313 return;
1315 base::FilePath file_path;
1316 if (!base::GetValueAsFilePath(*file_path_value, &file_path))
1317 return;
1318 helper::DeleteProfileAtPath(file_path, web_ui());
1321 void BrowserOptionsHandler::ObserveThemeChanged() {
1322 Profile* profile = Profile::FromWebUI(web_ui());
1323 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
1324 bool is_system_theme = false;
1326 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1327 bool profile_is_supervised = profile->IsSupervised();
1328 is_system_theme = theme_service->UsingSystemTheme();
1329 base::FundamentalValue native_theme_enabled(!is_system_theme &&
1330 !profile_is_supervised);
1331 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1332 native_theme_enabled);
1333 #endif
1335 bool is_classic_theme = !is_system_theme &&
1336 theme_service->UsingDefaultTheme();
1337 base::FundamentalValue enabled(!is_classic_theme);
1338 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1339 enabled);
1342 void BrowserOptionsHandler::ThemesReset(const base::ListValue* args) {
1343 Profile* profile = Profile::FromWebUI(web_ui());
1344 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1345 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
1348 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1349 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue* args) {
1350 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1351 Profile* profile = Profile::FromWebUI(web_ui());
1352 ThemeServiceFactory::GetForProfile(profile)->UseSystemTheme();
1354 #endif
1356 #if defined(OS_CHROMEOS)
1357 void BrowserOptionsHandler::UpdateAccountPicture() {
1358 std::string email =
1359 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1360 if (!email.empty()) {
1361 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1362 base::StringValue email_value(email);
1363 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1364 email_value);
1368 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed) {
1369 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1370 base::FundamentalValue(managed));
1373 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed) {
1374 #if defined(USE_ATHENA)
1375 // In Athena, we don't allow customizing wallpaper right now.
1376 // TODO(mukai|bshe): remove this. http://crbug.com/408734
1377 managed = true;
1378 #endif
1379 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1380 base::FundamentalValue(managed));
1382 #endif
1384 scoped_ptr<base::DictionaryValue>
1385 BrowserOptionsHandler::GetSyncStateDictionary() {
1386 // The items which are to be written into |sync_status| are also described in
1387 // chrome/browser/resources/options/browser_options.js in @typedef
1388 // for SyncStatus. Please update it whenever you add or remove any keys here.
1389 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
1390 Profile* profile = Profile::FromWebUI(web_ui());
1391 if (profile->IsGuestSession()) {
1392 // Cannot display signin status when running in guest mode on chromeos
1393 // because there is no SigninManager.
1394 sync_status->SetBoolean("signinAllowed", false);
1395 return sync_status.Pass();
1398 sync_status->SetBoolean("supervisedUser", profile->IsSupervised());
1400 bool signout_prohibited = false;
1401 #if !defined(OS_CHROMEOS)
1402 // Signout is not allowed if the user has policy (crbug.com/172204).
1403 signout_prohibited =
1404 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited();
1405 #endif
1407 ProfileSyncService* service =
1408 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
1409 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1410 DCHECK(signin);
1411 sync_status->SetBoolean("signoutAllowed", !signout_prohibited);
1412 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed());
1413 sync_status->SetBoolean("syncSystemEnabled", (service != NULL));
1414 sync_status->SetBoolean("setupCompleted",
1415 service && service->HasSyncSetupCompleted());
1416 sync_status->SetBoolean("setupInProgress",
1417 service && !service->IsManaged() && service->FirstSetupInProgress());
1419 base::string16 status_label;
1420 base::string16 link_label;
1421 bool status_has_error = sync_ui_util::GetStatusLabels(
1422 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
1423 sync_ui_util::SYNC_ERROR;
1424 sync_status->SetString("statusText", status_label);
1425 sync_status->SetString("actionLinkText", link_label);
1426 sync_status->SetBoolean("hasError", status_has_error);
1428 sync_status->SetBoolean("managed", service && service->IsManaged());
1429 sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
1430 sync_status->SetBoolean("hasUnrecoverableError",
1431 service && service->HasUnrecoverableError());
1433 return sync_status.Pass();
1436 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1437 const base::ListValue* args) {
1438 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1439 select_folder_dialog_ = ui::SelectFileDialog::Create(
1440 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1441 ui::SelectFileDialog::FileTypeInfo info;
1442 info.support_drive = true;
1443 select_folder_dialog_->SelectFile(
1444 ui::SelectFileDialog::SELECT_FOLDER,
1445 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE),
1446 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory),
1447 &info,
1449 base::FilePath::StringType(),
1450 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1451 NULL);
1454 void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index,
1455 void* params) {
1456 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1457 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1458 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path);
1459 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
1462 #if defined(OS_CHROMEOS)
1463 void BrowserOptionsHandler::TouchpadExists(bool exists) {
1464 base::FundamentalValue val(exists);
1465 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val);
1468 void BrowserOptionsHandler::MouseExists(bool exists) {
1469 base::FundamentalValue val(exists);
1470 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val);
1473 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1474 const base::Value* previous_policy,
1475 const base::Value* current_policy) {
1476 const bool had_policy = previous_policy;
1477 const bool has_policy = current_policy;
1478 if (had_policy != has_policy)
1479 OnAccountPictureManagedChanged(has_policy);
1482 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1483 const base::Value* previous_policy,
1484 const base::Value* current_policy) {
1485 const bool had_policy = previous_policy;
1486 const bool has_policy = current_policy;
1487 if (had_policy != has_policy)
1488 OnWallpaperManagedChanged(has_policy);
1491 void BrowserOptionsHandler::OnPowerwashDialogShow(
1492 const base::ListValue* args) {
1493 UMA_HISTOGRAM_ENUMERATION(
1494 "Reset.ChromeOS.PowerwashDialogShown",
1495 chromeos::reset::DIALOG_FROM_OPTIONS,
1496 chromeos::reset::DIALOG_VIEW_TYPE_SIZE);
1499 void BrowserOptionsHandler::OnConsumerManagementStatusChanged() {
1500 const std::string& status = g_browser_process->platform_part()->
1501 browser_policy_connector_chromeos()->GetConsumerManagementService()->
1502 GetStatusString();
1503 web_ui()->CallJavascriptFunction(
1504 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status));
1507 #endif // defined(OS_CHROMEOS)
1509 void BrowserOptionsHandler::UpdateSyncState() {
1510 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1511 *GetSyncStateDictionary());
1514 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1515 UpdateSyncState();
1518 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1519 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1520 DownloadManager* manager = BrowserContext::GetDownloadManager(
1521 web_ui()->GetWebContents()->GetBrowserContext());
1522 if (manager)
1523 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
1526 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue* args) {
1527 int font_size;
1528 if (ExtractIntegerValue(args, &font_size)) {
1529 if (font_size > 0) {
1530 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1531 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size);
1532 SetupFontSizeSelector();
1537 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1538 const base::ListValue* args) {
1539 double zoom_factor;
1540 if (ExtractDoubleValue(args, &zoom_factor)) {
1541 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
1542 content::ZoomFactorToZoomLevel(zoom_factor));
1546 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
1547 #if defined(OS_WIN) && defined(USE_ASH)
1548 // If hardware acceleration is disabled then we need to force restart
1549 // browser in desktop mode.
1550 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1551 // Currently there are issues with determining correct browser mode
1552 // at startup.
1553 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1554 PrefService* pref_service = g_browser_process->local_state();
1555 if (!pref_service->GetBoolean(prefs::kHardwareAccelerationModeEnabled)) {
1556 chrome::AttemptRestartToDesktopMode();
1557 return;
1560 #endif
1562 #if defined(OS_WIN)
1563 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1564 // environment variable is defined. So we undefine this environment variable
1565 // before restarting, as the restarted processes will inherit their
1566 // environment variables from ours, thus suppressing crash uploads.
1567 PrefService* pref_service = g_browser_process->local_state();
1568 if (!pref_service->GetBoolean(prefs::kMetricsReportingEnabled)) {
1569 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
1570 if (exe_module) {
1571 typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
1572 ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
1573 GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
1574 if (clear)
1575 clear();
1578 #endif
1580 chrome::AttemptRestart();
1583 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1584 const base::ListValue* args) {
1585 SendProfilesInfo();
1588 #if !defined(OS_CHROMEOS)
1589 void BrowserOptionsHandler::ShowNetworkProxySettings(
1590 const base::ListValue* args) {
1591 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1592 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1593 web_ui()->GetWebContents());
1595 #endif
1597 #if defined(OS_WIN) || defined(OS_MACOSX)
1598 void BrowserOptionsHandler::ShowManageSSLCertificates(
1599 const base::ListValue* args) {
1600 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1601 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1602 web_ui()->GetWebContents());
1604 #endif
1606 #if defined(ENABLE_SERVICE_DISCOVERY)
1608 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1609 const base::ListValue* args) {
1610 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1611 // Navigate in current tab to devices page.
1612 OpenURLParams params(
1613 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1614 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false);
1615 web_ui()->GetWebContents()->OpenURL(params);
1618 #endif
1620 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1621 const base::ListValue* args) {
1622 Profile* profile = Profile::FromWebUI(web_ui());
1623 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1624 if (group != "" && group != "Disabled" &&
1625 HotwordServiceFactory::IsHotwordAllowed(profile)) {
1626 // Update the current error value.
1627 HotwordServiceFactory::IsServiceAvailable(profile);
1628 int error = HotwordServiceFactory::GetCurrentError(profile);
1630 std::string function_name;
1631 if (CommandLine::ForCurrentProcess()->HasSwitch(
1632 switches::kEnableExperimentalHotwording)) {
1633 if (HotwordServiceFactory::IsHotwordHardwareAvailable()) {
1634 function_name = "BrowserOptions.showHotwordAlwaysOnSection";
1635 } else {
1636 function_name = "BrowserOptions.showHotwordNoDspSection";
1638 } else {
1639 function_name = "BrowserOptions.showHotwordSection";
1642 if (!error) {
1643 web_ui()->CallJavascriptFunction(function_name);
1644 } else {
1645 base::string16 hotword_help_url =
1646 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1647 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1648 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1649 error_message = base::StringValue(
1650 l10n_util::GetStringFUTF16(error, hotword_help_url));
1652 web_ui()->CallJavascriptFunction(function_name, error_message);
1657 void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
1658 const base::ListValue* args) {
1659 Profile* profile = Profile::FromWebUI(web_ui());
1661 bool retrain = false;
1662 bool success = args->GetBoolean(0, &retrain);
1663 DCHECK(success);
1664 HotwordService::LaunchMode launch_mode =
1665 HotwordService::HOTWORD_AND_AUDIO_HISTORY;
1667 if (retrain) {
1668 DCHECK(profile->GetPrefs()->GetBoolean(
1669 prefs::kHotwordAlwaysOnSearchEnabled));
1670 DCHECK(profile->GetPrefs()->GetBoolean(
1671 prefs::kHotwordAudioLoggingEnabled));
1673 launch_mode = HotwordService::RETRAIN;
1674 } else if (profile->GetPrefs()->GetBoolean(
1675 prefs::kHotwordAudioLoggingEnabled)) {
1676 DCHECK(!profile->GetPrefs()->GetBoolean(
1677 prefs::kHotwordAlwaysOnSearchEnabled));
1679 // TODO(kcarattini): Make sure the Chrome Audio Logging pref is synced
1680 // to the account-level Audio History setting from footprints.
1681 launch_mode = HotwordService::HOTWORD_ONLY;
1682 } else {
1683 DCHECK(!profile->GetPrefs()->GetBoolean(
1684 prefs::kHotwordAlwaysOnSearchEnabled));
1687 HotwordService* hotword_service =
1688 HotwordServiceFactory::GetForProfile(profile);
1689 if (!hotword_service)
1690 return;
1692 hotword_service->LaunchHotwordAudioVerificationApp(launch_mode);
1695 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1696 const base::ListValue* args) {
1697 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1700 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1701 const base::ListValue* args) {
1702 SetupExtensionControlledIndicators();
1705 #if defined(OS_CHROMEOS)
1706 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1707 const base::ListValue* args) {
1708 #if !defined(USE_ATHENA)
1709 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1710 #else
1711 NOTIMPLEMENTED();
1712 #endif
1715 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1716 const base::ListValue* args) {
1717 bool enabled = false;
1718 args->GetBoolean(0, &enabled);
1720 chromeos::accessibility::EnableVirtualKeyboard(enabled);
1723 void BrowserOptionsHandler::PerformFactoryResetRestart(
1724 const base::ListValue* args) {
1725 policy::BrowserPolicyConnectorChromeOS* connector =
1726 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1727 if (connector->IsEnterpriseManaged())
1728 return;
1730 PrefService* prefs = g_browser_process->local_state();
1731 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
1732 prefs->CommitPendingWrite();
1734 // Perform sign out. Current chrome process will then terminate, new one will
1735 // be launched (as if it was a restart).
1736 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1739 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1740 PrefService* pref_service = g_browser_process->local_state();
1741 base::FundamentalValue virtual_keyboard_enabled(
1742 pref_service->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled));
1743 web_ui()->CallJavascriptFunction(
1744 "BrowserOptions.setVirtualKeyboardCheckboxState",
1745 virtual_keyboard_enabled);
1747 #endif
1749 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1750 #if defined(GOOGLE_CHROME_BUILD)
1751 // Don't show the reporting setting if we are in the guest mode.
1752 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1753 base::FundamentalValue visible(false);
1754 web_ui()->CallJavascriptFunction(
1755 "BrowserOptions.setMetricsReportingSettingVisibility", visible);
1757 #endif
1760 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1761 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1763 base::DictionaryValue dict;
1764 dict.SetInteger("value",
1765 pref_service->GetInteger(prefs::kNetworkPredictionOptions));
1766 dict.SetBoolean("disabled",
1767 !pref_service->IsUserModifiablePreference(
1768 prefs::kNetworkPredictionOptions));
1770 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1771 dict);
1774 void BrowserOptionsHandler::SetupFontSizeSelector() {
1775 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1776 const PrefService::Preference* default_font_size =
1777 pref_service->FindPreference(prefs::kWebKitDefaultFontSize);
1778 const PrefService::Preference* default_fixed_font_size =
1779 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize);
1781 base::DictionaryValue dict;
1782 dict.SetInteger("value",
1783 pref_service->GetInteger(prefs::kWebKitDefaultFontSize));
1785 // The font size control displays the value of the default font size, but
1786 // setting it alters both the default font size and the default fixed font
1787 // size. So it must be disabled when either of those prefs is not user
1788 // modifiable.
1789 dict.SetBoolean("disabled",
1790 !default_font_size->IsUserModifiable() ||
1791 !default_fixed_font_size->IsUserModifiable());
1793 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1794 // adapted to consider two prefs. It may be better to refactor
1795 // CreateValueForPref so it can be called from here.
1796 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) {
1797 dict.SetString("controlledBy", "policy");
1798 } else if (default_font_size->IsExtensionControlled() ||
1799 default_fixed_font_size->IsExtensionControlled()) {
1800 dict.SetString("controlledBy", "extension");
1803 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict);
1806 void BrowserOptionsHandler::SetupPageZoomSelector() {
1807 double default_zoom_level =
1808 content::HostZoomMap::GetDefaultForBrowserContext(
1809 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel();
1810 double default_zoom_factor =
1811 content::ZoomLevelToZoomFactor(default_zoom_level);
1813 // Generate a vector of zoom factors from an array of known presets along with
1814 // the default factor added if necessary.
1815 std::vector<double> zoom_factors =
1816 chrome_page_zoom::PresetZoomFactors(default_zoom_factor);
1818 // Iterate through the zoom factors and and build the contents of the
1819 // selector that will be sent to the javascript handler.
1820 // Each item in the list has the following parameters:
1821 // 1. Title (string).
1822 // 2. Value (double).
1823 // 3. Is selected? (bool).
1824 base::ListValue zoom_factors_value;
1825 for (std::vector<double>::const_iterator i = zoom_factors.begin();
1826 i != zoom_factors.end(); ++i) {
1827 base::ListValue* option = new base::ListValue();
1828 double factor = *i;
1829 int percent = static_cast<int>(factor * 100 + 0.5);
1830 option->Append(new base::StringValue(
1831 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
1832 option->Append(new base::FundamentalValue(factor));
1833 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
1834 option->Append(new base::FundamentalValue(selected));
1835 zoom_factors_value.Append(option);
1838 web_ui()->CallJavascriptFunction(
1839 "BrowserOptions.setupPageZoomSelector", zoom_factors_value);
1842 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
1843 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
1844 // We show the button if the user has any auto-open file types registered.
1845 DownloadManager* manager = BrowserContext::GetDownloadManager(
1846 web_ui()->GetWebContents()->GetBrowserContext());
1847 bool display = manager &&
1848 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
1849 base::FundamentalValue value(display);
1850 web_ui()->CallJavascriptFunction(
1851 "BrowserOptions.setAutoOpenFileTypesDisplayed", value);
1854 void BrowserOptionsHandler::SetupProxySettingsSection() {
1855 #if !defined(OS_CHROMEOS)
1856 // Disable the button if proxy settings are managed by a sysadmin, overridden
1857 // by an extension, or the browser is running in Windows Ash (on Windows the
1858 // proxy settings dialog will open on the Windows desktop and be invisible
1859 // to a user in Ash).
1860 bool is_win_ash = false;
1861 #if defined(OS_WIN)
1862 chrome::HostDesktopType desktop_type = helper::GetDesktopType(web_ui());
1863 is_win_ash = (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH);
1864 #endif
1865 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1866 const PrefService::Preference* proxy_config =
1867 pref_service->FindPreference(prefs::kProxy);
1868 bool is_extension_controlled = (proxy_config &&
1869 proxy_config->IsExtensionControlled());
1871 base::FundamentalValue disabled(is_win_ash || (proxy_config &&
1872 !proxy_config->IsUserModifiable()));
1873 base::FundamentalValue extension_controlled(is_extension_controlled);
1874 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
1875 disabled, extension_controlled);
1877 #if defined(OS_WIN)
1878 SetupExtensionControlledIndicators();
1879 #endif // defined(OS_WIN)
1881 #endif // !defined(OS_CHROMEOS)
1884 void BrowserOptionsHandler::SetupManageCertificatesSection() {
1885 #if defined(OS_WIN)
1886 // Disable the button if the settings page is displayed in Windows Ash,
1887 // otherwise the proxy settings dialog will open on the Windows desktop and
1888 // be invisible to a user in Ash.
1889 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH) {
1890 base::FundamentalValue enabled(false);
1891 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
1892 enabled);
1894 #endif // defined(OS_WIN)
1897 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
1898 bool has_users = !Profile::FromWebUI(web_ui())->
1899 GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
1900 base::FundamentalValue has_users_value(has_users);
1901 web_ui()->CallJavascriptFunction(
1902 "BrowserOptions.updateManagesSupervisedUsers",
1903 has_users_value);
1906 void BrowserOptionsHandler::SetupEasyUnlock() {
1907 // TODO(xiyuan): Update when pairing data is really availble.
1908 const base::ListValue* devices =
1909 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->GetRemoteDevices();
1910 bool has_pairing = devices && !devices->empty();
1911 base::FundamentalValue has_pairing_value(has_pairing);
1912 web_ui()->CallJavascriptFunction(
1913 "BrowserOptions.updateEasyUnlock",
1914 has_pairing_value);
1917 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
1918 #if defined(OS_WIN)
1919 base::DictionaryValue extension_controlled;
1921 // Check if an extension is overriding the Search Engine.
1922 const extensions::Extension* extension =
1923 extensions::GetExtensionOverridingSearchEngine(
1924 Profile::FromWebUI(web_ui()));
1925 AppendExtensionData("searchEngine", extension, &extension_controlled);
1927 // Check if an extension is overriding the Home page.
1928 extension = extensions::GetExtensionOverridingHomepage(
1929 Profile::FromWebUI(web_ui()));
1930 AppendExtensionData("homePage", extension, &extension_controlled);
1932 // Check if an extension is overriding the Startup pages.
1933 extension = extensions::GetExtensionOverridingStartupPages(
1934 Profile::FromWebUI(web_ui()));
1935 AppendExtensionData("startUpPage", extension, &extension_controlled);
1937 // Check if an extension is overriding the NTP page.
1938 GURL ntp_url(chrome::kChromeUINewTabURL);
1939 bool ignored_param;
1940 extension = NULL;
1941 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
1942 &ntp_url,
1943 web_ui()->GetWebContents()->GetBrowserContext(),
1944 &ignored_param);
1945 if (ntp_url.SchemeIs("chrome-extension")) {
1946 using extensions::ExtensionRegistry;
1947 ExtensionRegistry* registry = ExtensionRegistry::Get(
1948 Profile::FromWebUI(web_ui()));
1949 extension = registry->GetExtensionById(ntp_url.host(),
1950 ExtensionRegistry::ENABLED);
1952 AppendExtensionData("newTabPage", extension, &extension_controlled);
1954 // Check if an extension is overwriting the proxy setting.
1955 extension = extensions::GetExtensionOverridingProxy(
1956 Profile::FromWebUI(web_ui()));
1957 AppendExtensionData("proxy", extension, &extension_controlled);
1959 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
1960 extension_controlled);
1961 #endif // defined(OS_WIN)
1964 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
1965 // This function does not work for ChromeOS and non-official builds.
1966 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
1967 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
1968 bool disabled = !IsMetricsReportingUserChangable();
1970 SetMetricsReportingCheckbox(checked, disabled);
1971 #endif
1974 void BrowserOptionsHandler::HandleMetricsReportingChange(
1975 const base::ListValue* args) {
1976 bool enable;
1977 if (!args->GetBoolean(0, &enable))
1978 return;
1980 InitiateMetricsReportingChange(
1981 enable,
1982 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback,
1983 base::Unretained(this)));
1986 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
1987 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
1990 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
1991 bool disabled) {
1992 web_ui()->CallJavascriptFunction(
1993 "BrowserOptions.setMetricsReportingCheckboxState",
1994 base::FundamentalValue(checked),
1995 base::FundamentalValue(disabled));
1998 } // namespace options