Prepare password_bubble_experiment and password_manager_util for componentisation
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / browser_options_handler.cc
blobe83872e1a91320f9ccb2a29c331e5832f8a3131f
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 <set>
8 #include <string>
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/command_line.h"
14 #include "base/environment.h"
15 #include "base/memory/singleton.h"
16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.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/custom_home_pages_table_model.h"
29 #include "chrome/browser/download/download_prefs.h"
30 #include "chrome/browser/gpu/gpu_mode_manager.h"
31 #include "chrome/browser/lifetime/application_lifetime.h"
32 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
33 #include "chrome/browser/metrics/metrics_reporting_state.h"
34 #include "chrome/browser/net/prediction_options.h"
35 #include "chrome/browser/prefs/session_startup_pref.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
38 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
40 #include "chrome/browser/profiles/profile_info_cache.h"
41 #include "chrome/browser/profiles/profile_manager.h"
42 #include "chrome/browser/profiles/profile_metrics.h"
43 #include "chrome/browser/profiles/profile_shortcut_manager.h"
44 #include "chrome/browser/profiles/profile_window.h"
45 #include "chrome/browser/profiles/profiles_state.h"
46 #include "chrome/browser/search/hotword_audio_history_handler.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/passwords/password_bubble_experiment.h"
62 #include "chrome/browser/ui/webui/favicon_source.h"
63 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
64 #include "chrome/common/chrome_constants.h"
65 #include "chrome/common/chrome_paths.h"
66 #include "chrome/common/chrome_switches.h"
67 #include "chrome/common/extensions/extension_constants.h"
68 #include "chrome/common/pref_names.h"
69 #include "chrome/common/url_constants.h"
70 #include "chrome/grit/chromium_strings.h"
71 #include "chrome/grit/generated_resources.h"
72 #include "chrome/grit/locale_settings.h"
73 #include "components/policy/core/common/policy_map.h"
74 #include "components/policy/core/common/policy_namespace.h"
75 #include "components/policy/core/common/policy_service.h"
76 #include "components/proximity_auth/switches.h"
77 #include "components/search_engines/template_url.h"
78 #include "components/search_engines/template_url_service.h"
79 #include "components/signin/core/browser/signin_manager.h"
80 #include "components/signin/core/common/profile_management_switches.h"
81 #include "components/ui/zoom/page_zoom.h"
82 #include "components/user_manager/user_type.h"
83 #include "content/public/browser/browser_thread.h"
84 #include "content/public/browser/download_manager.h"
85 #include "content/public/browser/navigation_controller.h"
86 #include "content/public/browser/notification_details.h"
87 #include "content/public/browser/notification_service.h"
88 #include "content/public/browser/notification_source.h"
89 #include "content/public/browser/notification_types.h"
90 #include "content/public/browser/url_data_source.h"
91 #include "content/public/browser/user_metrics.h"
92 #include "content/public/browser/web_contents.h"
93 #include "content/public/common/page_zoom.h"
94 #include "extensions/browser/extension_registry.h"
95 #include "google_apis/gaia/gaia_auth_util.h"
96 #include "google_apis/gaia/google_service_auth_error.h"
97 #include "policy/policy_constants.h"
98 #include "third_party/skia/include/core/SkBitmap.h"
99 #include "ui/base/l10n/l10n_util.h"
100 #include "ui/base/webui/web_ui_util.h"
102 #if !defined(OS_CHROMEOS)
103 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
104 #endif
106 #if defined(OS_CHROMEOS)
107 #include "ash/ash_switches.h"
108 #include "ash/desktop_background/user_wallpaper_delegate.h"
109 #include "ash/shell.h"
110 #include "chrome/browser/browser_process_platform_part.h"
111 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
112 #include "chrome/browser/chromeos/chromeos_utils.h"
113 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
114 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
115 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
116 #include "chrome/browser/chromeos/profiles/profile_helper.h"
117 #include "chrome/browser/chromeos/reset/metrics.h"
118 #include "chrome/browser/chromeos/settings/cros_settings.h"
119 #include "chrome/browser/chromeos/system/timezone_util.h"
120 #include "chrome/browser/policy/profile_policy_connector.h"
121 #include "chrome/browser/policy/profile_policy_connector_factory.h"
122 #include "chrome/browser/ui/browser_window.h"
123 #include "chromeos/chromeos_switches.h"
124 #include "chromeos/dbus/dbus_thread_manager.h"
125 #include "chromeos/dbus/power_manager_client.h"
126 #include "components/user_manager/user.h"
127 #include "components/user_manager/user_manager.h"
128 #include "ui/chromeos/accessibility_types.h"
129 #include "ui/gfx/image/image_skia.h"
130 #endif // defined(OS_CHROMEOS)
132 #if defined(OS_WIN)
133 #include "chrome/browser/extensions/settings_api_helpers.h"
134 #include "chrome/installer/util/auto_launch_util.h"
135 #include "content/public/browser/browser_url_handler.h"
136 #endif // defined(OS_WIN)
138 #if defined(ENABLE_SERVICE_DISCOVERY)
139 #include "chrome/browser/local_discovery/privet_notifications.h"
140 #endif
142 #if defined(USE_ASH)
143 #include "ash/shell.h"
144 #endif
146 using base::UserMetricsAction;
147 using content::BrowserContext;
148 using content::BrowserThread;
149 using content::DownloadManager;
150 using content::OpenURLParams;
151 using content::Referrer;
152 using extensions::Extension;
153 using extensions::ExtensionRegistry;
155 namespace {
157 #if defined(OS_WIN)
158 void AppendExtensionData(const std::string& key,
159 const Extension* extension,
160 base::DictionaryValue* dict) {
161 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue);
162 details->SetString("id", extension ? extension->id() : std::string());
163 details->SetString("name", extension ? extension->name() : std::string());
164 dict->Set(key, details.release());
166 #endif // defined(OS_WIN)
168 } // namespace
170 namespace options {
172 BrowserOptionsHandler::BrowserOptionsHandler()
173 : page_initialized_(false),
174 template_url_service_(NULL),
175 cloud_print_mdns_ui_enabled_(false),
176 signin_observer_(this),
177 weak_ptr_factory_(this) {
178 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
180 #if defined(ENABLE_SERVICE_DISCOVERY)
181 cloud_print_mdns_ui_enabled_ = true;
182 #endif // defined(ENABLE_SERVICE_DISCOVERY)
185 BrowserOptionsHandler::~BrowserOptionsHandler() {
186 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
187 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui())));
188 if (sync_service)
189 sync_service->RemoveObserver(this);
191 if (default_browser_worker_.get())
192 default_browser_worker_->ObserverDestroyed();
193 if (template_url_service_)
194 template_url_service_->RemoveObserver(this);
195 // There may be pending file dialogs, we need to tell them that we've gone
196 // away so they don't try and call back to us.
197 if (select_folder_dialog_.get())
198 select_folder_dialog_->ListenerDestroyed();
200 g_browser_process->policy_service()->RemoveObserver(
201 policy::POLICY_DOMAIN_CHROME, this);
204 void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
205 DCHECK(values);
207 #if defined(OS_CHROMEOS)
208 const int device_type_resource_id = chromeos::GetChromeDeviceTypeResourceId();
209 #else
210 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices.
211 const int device_type_resource_id = IDS_EASY_UNLOCK_GENERIC_DEVICE_TYPE;
212 #endif // defined(OS_CHROMEOS)
214 static OptionsStringResource resources[] = {
215 // Please keep these in alphabetical order.
216 { "accessibilityFeaturesLink", IDS_OPTIONS_ACCESSIBILITY_FEATURES_LINK },
217 { "accessibilityTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY },
218 { "advancedSectionTitleCertificates",
219 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CERTIFICATES },
220 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT },
221 { "advancedSectionTitleContent",
222 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT },
223 { "advancedSectionTitleLanguages",
224 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES },
225 { "advancedSectionTitleNetwork",
226 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK },
227 { "advancedSectionTitlePrivacy",
228 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY },
229 { "advancedSectionTitleSystem", IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM },
230 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT },
231 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY },
232 { "autoOpenFileTypesResetToDefault",
233 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT },
234 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE },
235 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN },
236 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON },
237 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE },
238 { "childLabel", IDS_PROFILES_LIST_CHILD_LABEL },
239 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY },
240 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL },
241 { "defaultBrowserUnknown",
242 IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, IDS_PRODUCT_NAME },
243 { "defaultBrowserUseAsDefault", IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT },
244 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
245 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
246 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
247 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES },
248 { "doNotTrack", IDS_OPTIONS_ENABLE_DO_NOT_TRACK },
249 { "doNotTrackConfirmDisable",
250 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_DISABLE },
251 { "doNotTrackConfirmEnable",
252 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_ENABLE },
253 { "doNotTrackConfirmMessage", IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TEXT },
254 { "downloadLocationAskForSaveLocation",
255 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION },
256 { "downloadLocationBrowseTitle",
257 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE },
258 { "downloadLocationChangeButton",
259 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON },
260 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME },
261 { "easyUnlockDescription", IDS_OPTIONS_EASY_UNLOCK_DESCRIPTION,
262 device_type_resource_id },
263 { "easyUnlockRequireProximityLabel",
264 IDS_OPTIONS_EASY_UNLOCK_REQUIRE_PROXIMITY_LABEL,
265 device_type_resource_id },
266 { "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE },
267 { "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON },
268 { "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO,
269 device_type_resource_id },
270 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING },
271 { "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED },
272 { "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE },
273 { "fontSettingsCustomizeFontsButton",
274 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON },
275 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM },
276 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE },
277 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
278 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
279 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE },
280 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
281 { "googleNowLauncherEnable", IDS_OPTIONS_ENABLE_GOOGLE_NOW },
282 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS },
283 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP },
284 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
285 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
286 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
287 { "hotwordAlwaysOnAudioHistoryDescription",
288 IDS_HOTWORD_ALWAYS_ON_AUDIO_HISTORY_DESCRIPTION },
289 { "hotwordAlwaysOnDesc", IDS_HOTWORD_SEARCH_ALWAYS_ON_DESCRIPTION },
290 { "hotwordAudioHistoryManage", IDS_HOTWORD_AUDIO_HISTORY_MANAGE_LINK },
291 { "hotwordAudioLoggingEnable", IDS_HOTWORD_AUDIO_LOGGING_ENABLE },
292 { "hotwordConfirmDisable", IDS_HOTWORD_CONFIRM_BUBBLE_DISABLE },
293 { "hotwordConfirmEnable", IDS_HOTWORD_CONFIRM_BUBBLE_ENABLE },
294 { "hotwordConfirmMessage", IDS_HOTWORD_SEARCH_PREF_DESCRIPTION },
295 { "hotwordNoDSPDesc", IDS_HOTWORD_SEARCH_NO_DSP_DESCRIPTION },
296 { "hotwordRetrainLink", IDS_HOTWORD_RETRAIN_LINK },
297 { "hotwordSearchEnable", IDS_HOTWORD_SEARCH_PREF_CHKBOX },
298 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON },
299 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE },
300 { "languageAndSpellCheckSettingsButton",
301 IDS_OPTIONS_SETTINGS_LANGUAGE_AND_INPUT_SETTINGS },
302 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
303 IDS_SHORT_PRODUCT_NAME },
304 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF },
305 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK },
306 { "manageLanguages", IDS_OPTIONS_TRANSLATE_MANAGE_LANGUAGES },
307 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK },
308 { "metricsReportingResetRestart", IDS_OPTIONS_ENABLE_LOGGING_RESTART },
309 { "networkPredictionEnabledDescription",
310 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION },
311 { "passwordManagerEnabled",
312 password_bubble_experiment::IsSmartLockBrandingEnabled(
313 ProfileSyncServiceFactory::GetForProfile(
314 Profile::FromWebUI(web_ui()))) ?
315 IDS_OPTIONS_PASSWORD_MANAGER_SMART_LOCK_ENABLE :
316 IDS_OPTIONS_PASSWORD_MANAGER_ENABLE },
317 { "passwordsAndAutofillGroupName",
318 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME },
319 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
320 { "privacyContentSettingsButton",
321 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON },
322 { "profileAddPersonEnable", IDS_PROFILE_ADD_PERSON_ENABLE },
323 { "profileBrowserGuestEnable", IDS_PROFILE_BROWSER_GUEST_ENABLE },
324 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL },
325 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL },
326 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL },
327 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT },
328 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL },
329 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
330 IDS_PRODUCT_NAME },
331 { "profilesSupervisedDashboardTip",
332 IDS_PROFILES_SUPERVISED_USER_DASHBOARD_TIP },
333 { "proxiesLabelExtension", IDS_OPTIONS_EXTENSION_PROXIES_LABEL },
334 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
335 IDS_PRODUCT_NAME },
336 { "resetProfileSettings", IDS_RESET_PROFILE_SETTINGS_BUTTON },
337 { "resetProfileSettingsDescription",
338 IDS_RESET_PROFILE_SETTINGS_DESCRIPTION },
339 { "resetProfileSettingsSectionTitle",
340 IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE },
341 { "safeBrowsingEnableExtendedReporting",
342 IDS_OPTIONS_SAFEBROWSING_ENABLE_EXTENDED_REPORTING },
343 { "safeBrowsingEnableProtection",
344 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION },
345 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME },
346 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
347 { "sectionTitleProxy", IDS_OPTIONS_PROXY_GROUP_NAME },
348 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
349 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME },
350 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME },
351 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME },
352 { "settingsTitle", IDS_SETTINGS_TITLE },
353 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS },
354 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE },
355 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE },
356 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT },
357 { "spellingPref", IDS_OPTIONS_SPELLING_PREF },
358 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION },
359 { "startupSetPages", IDS_OPTIONS_STARTUP_SET_PAGES },
360 { "startupShowNewTab", IDS_OPTIONS_STARTUP_SHOW_NEWTAB },
361 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
362 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF },
363 { "supervisedUserLabel", IDS_PROFILES_LIST_SUPERVISED_USER_LABEL },
364 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS },
365 { "syncButtonTextSignIn", IDS_SYNC_START_SYNC_BUTTON_LABEL,
366 IDS_SHORT_PRODUCT_NAME },
367 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL },
368 { "syncOverview", IDS_SYNC_OVERVIEW },
369 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF },
370 { "themesGallery", IDS_THEMES_GALLERY_BUTTON },
371 { "themesGalleryURL", IDS_THEMES_GALLERY_URL },
372 { "themesReset", IDS_THEMES_RESET_BUTTON },
373 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
374 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
375 { "translateEnableTranslate",
376 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE },
377 #if defined(OS_CHROMEOS)
378 { "accessibilityAlwaysShowMenu",
379 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SHOULD_ALWAYS_SHOW_MENU },
380 { "accessibilityAutoclick",
381 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DESCRIPTION },
382 { "accessibilityAutoclickDropdown",
383 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DROPDOWN_DESCRIPTION },
384 { "accessibilityExplanation",
385 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_EXPLANATION },
386 { "accessibilityHighContrast",
387 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION },
388 { "accessibilityLargeCursor",
389 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_LARGE_CURSOR_DESCRIPTION },
390 { "accessibilityScreenMagnifier",
391 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION },
392 { "accessibilityScreenMagnifierFull",
393 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL },
394 { "accessibilityScreenMagnifierOff",
395 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_OFF },
396 { "accessibilityScreenMagnifierPartial",
397 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL },
398 { "accessibilitySettings",
399 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SETTINGS },
400 { "accessibilitySpokenFeedback",
401 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SPOKEN_FEEDBACK_DESCRIPTION },
402 { "accessibilityStickyKeys",
403 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_STICKY_KEYS_DESCRIPTION },
404 { "accessibilityTapDragging",
405 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_TOUCHPAD_TAP_DRAGGING_DESCRIPTION },
406 { "accessibilityVirtualKeyboard",
407 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION },
408 { "autoclickDelayExtremelyShort",
409 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_EXTREMELY_SHORT },
410 { "autoclickDelayLong",
411 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_LONG },
412 { "autoclickDelayShort",
413 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_SHORT },
414 { "autoclickDelayVeryLong",
415 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_LONG },
416 { "autoclickDelayVeryShort",
417 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_AUTOCLICK_DELAY_VERY_SHORT },
418 { "batteryButton", IDS_OPTIONS_SETTINGS_BATTERY_DESCRIPTION},
419 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE },
420 { "changePictureCaption", IDS_OPTIONS_CHANGE_PICTURE_CAPTION },
421 { "consumerManagementDescription",
422 IDS_OPTIONS_CONSUMER_MANAGEMENT_DESCRIPTION },
423 { "consumerManagementEnrollButton",
424 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLL_BUTTON },
425 { "consumerManagementEnrollingButton",
426 IDS_OPTIONS_CONSUMER_MANAGEMENT_ENROLLING_BUTTON },
427 { "consumerManagementUnenrollButton",
428 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLL_BUTTON },
429 { "consumerManagementUnenrollingButton",
430 IDS_OPTIONS_CONSUMER_MANAGEMENT_UNENROLLING_BUTTON },
431 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME },
432 { "deviceControlTitle", IDS_OPTIONS_DEVICE_CONTROL_SECTION_TITLE },
433 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION },
434 { "deviceGroupPointer", IDS_OPTIONS_DEVICE_GROUP_POINTER_SECTION },
435 { "disableGData", IDS_OPTIONS_DISABLE_GDATA },
436 { "displayOptions", IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_BUTTON_LABEL },
437 { "enableContentProtectionAttestation",
438 IDS_OPTIONS_ENABLE_CONTENT_PROTECTION_ATTESTATION },
439 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX },
440 { "factoryResetDataRestart", IDS_RELAUNCH_BUTTON },
441 { "factoryResetDescription", IDS_OPTIONS_FACTORY_RESET_DESCRIPTION,
442 IDS_SHORT_PRODUCT_NAME },
443 { "factoryResetHeading", IDS_OPTIONS_FACTORY_RESET_HEADING },
444 { "factoryResetHelpUrl", IDS_FACTORY_RESET_HELP_URL },
445 { "factoryResetRestart", IDS_OPTIONS_FACTORY_RESET_BUTTON },
446 { "factoryResetTitle", IDS_OPTIONS_FACTORY_RESET },
447 { "factoryResetWarning", IDS_OPTIONS_FACTORY_RESET_WARNING },
448 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE },
449 { "keyboardSettingsButtonTitle",
450 IDS_OPTIONS_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE },
451 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE },
452 { "mouseSpeed", IDS_OPTIONS_SETTINGS_MOUSE_SPEED_DESCRIPTION },
453 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES },
454 { "powerSettingsButton",
455 IDS_OPTIONS_DEVICE_GROUP_POWER_SETTINGS_BUTTON },
456 { "resolveTimezoneByGeoLocation",
457 IDS_OPTIONS_RESOLVE_TIMEZONE_BY_GEOLOCATION_DESCRIPTION },
458 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME },
459 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL },
460 { "storageButton", IDS_OPTIONS_SETTINGS_STORAGE_DESCRIPTION},
461 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
462 { "thirdPartyImeConfirmDisable", IDS_CANCEL },
463 { "thirdPartyImeConfirmEnable", IDS_OK },
464 { "thirdPartyImeConfirmMessage",
465 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_MESSAGE },
466 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION },
467 { "touchpadSpeed", IDS_OPTIONS_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION },
468 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION },
469 { "wakeOnWifiLabel", IDS_OPTIONS_SETTINGS_WAKE_ON_WIFI_DESCRIPTION },
470 #else
471 { "gpuModeCheckbox",
472 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE },
473 { "gpuModeResetRestart",
474 IDS_OPTIONS_SYSTEM_ENABLE_HARDWARE_ACCELERATION_MODE_RESTART },
475 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON },
476 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL },
477 #endif // defined(OS_CHROMEOS)
479 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
480 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS },
481 { "themesNativeButton", IDS_THEMES_GTK_BUTTON },
482 { "themesSetClassic", IDS_THEMES_SET_CLASSIC },
483 #else
484 { "themes", IDS_THEMES_GROUP_NAME },
485 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
487 #if defined(OS_CHROMEOS) && defined(USE_ASH)
488 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON },
489 #endif // defined(OS_CHROMEOS) && defined(USE_ASH)
491 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
492 { "backgroundModeCheckbox", IDS_OPTIONS_SYSTEM_ENABLE_BACKGROUND_MODE },
493 #endif // defined(OS_MACOSX) && !defined(OS_CHROMEOS)
495 #if defined(ENABLE_SETTINGS_APP)
496 { "profilesAppListSwitch", IDS_SETTINGS_APP_PROFILES_SWITCH_BUTTON_LABEL },
497 #endif // defined(ENABLE_SETTINGS_APP)
499 #if defined(ENABLE_SERVICE_DISCOVERY)
500 { "cloudPrintDevicesPageButton", IDS_LOCAL_DISCOVERY_DEVICES_PAGE_BUTTON },
501 { "cloudPrintEnableNotificationsLabel",
502 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_ENABLE_CHECKBOX_LABEL },
503 #endif // defined(ENABLE_SERVICE_DISCOVERY)
506 #if defined(ENABLE_SETTINGS_APP)
507 static OptionsStringResource app_resources[] = {
508 { "syncOverview", IDS_SETTINGS_APP_SYNC_OVERVIEW },
509 { "syncButtonTextStart", IDS_SYNC_START_SYNC_BUTTON_LABEL,
510 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
511 { "profilesSingleUser", IDS_PROFILES_SINGLE_USER_MESSAGE,
512 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
513 { "languageSectionLabel", IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
514 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
515 { "proxiesLabelSystem", IDS_OPTIONS_SYSTEM_PROXIES_LABEL,
516 IDS_SETTINGS_APP_LAUNCHER_PRODUCT_NAME },
518 base::DictionaryValue* app_values = NULL;
519 CHECK(values->GetDictionary(kSettingsAppKey, &app_values));
520 RegisterStrings(app_values, app_resources, arraysize(app_resources));
521 #endif
523 RegisterStrings(values, resources, arraysize(resources));
524 RegisterTitle(values, "doNotTrackConfirmOverlay",
525 IDS_OPTIONS_ENABLE_DO_NOT_TRACK_BUBBLE_TITLE);
526 RegisterTitle(values, "spellingConfirmOverlay",
527 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE);
528 #if defined(ENABLE_PRINT_PREVIEW)
529 RegisterCloudPrintValues(values);
530 #endif
532 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL);
533 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
534 values->SetString(
535 "defaultSearchGroupLabel",
536 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
537 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL);
538 RegisterTitle(values, "hotwordConfirmOverlay",
539 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE);
540 values->SetString("hotwordManageAudioHistoryURL",
541 chrome::kManageAudioHistoryURL);
543 #if defined(OS_CHROMEOS)
544 Profile* profile = Profile::FromWebUI(web_ui());
545 std::string username = profile->GetProfileUserName();
546 if (username.empty()) {
547 const user_manager::User* user =
548 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
549 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
550 username = user->email();
552 if (!username.empty())
553 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
555 values->SetString("username", username);
556 #endif
557 // Pass along sync status early so it will be available during page init.
558 values->Set("syncData", GetSyncStateDictionary().release());
560 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
562 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
564 #if !defined(OS_CHROMEOS)
565 values->SetBoolean("metricsReportingEnabledAtStart",
566 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
567 #endif
569 #if defined(OS_CHROMEOS)
570 // TODO(pastarmovj): replace this with a call to the CrosSettings list
571 // handling functionality to come.
572 values->Set("timezoneList", chromeos::system::GetTimezoneList().release());
574 values->SetString("accessibilityLearnMoreURL",
575 chrome::kChromeAccessibilityHelpURL);
577 std::string settings_url = std::string("chrome-extension://") +
578 extension_misc::kChromeVoxExtensionId +
579 chrome::kChromeAccessibilitySettingsURL;
581 values->SetString("accessibilitySettingsURL",
582 settings_url);
584 values->SetString("contentProtectionAttestationLearnMoreURL",
585 chrome::kAttestationForContentProtectionLearnMoreURL);
587 // Creates magnifierList.
588 scoped_ptr<base::ListValue> magnifier_list(new base::ListValue);
590 scoped_ptr<base::ListValue> option_full(new base::ListValue);
591 option_full->AppendInteger(ui::MAGNIFIER_FULL);
592 option_full->AppendString(l10n_util::GetStringUTF16(
593 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_FULL));
594 magnifier_list->Append(option_full.release());
596 scoped_ptr<base::ListValue> option_partial(new base::ListValue);
597 option_partial->AppendInteger(ui::MAGNIFIER_PARTIAL);
598 option_partial->Append(new base::StringValue(l10n_util::GetStringUTF16(
599 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_PARTIAL)));
600 magnifier_list->Append(option_partial.release());
602 values->Set("magnifierList", magnifier_list.release());
603 #endif
605 #if defined(OS_MACOSX)
606 values->SetString("macPasswordsWarning",
607 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
608 values->SetBoolean("multiple_profiles",
609 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
610 #endif
612 if (ShouldShowMultiProfilesUserList())
613 values->Set("profilesInfo", GetProfilesInfoList().release());
615 // Profile deletion is not allowed for any users using Metro mode.
616 bool allow_deletion = true;
617 #if defined(USE_ASH)
618 allow_deletion = allow_deletion && !ash::Shell::HasInstance();
619 #endif
620 values->SetBoolean("allowProfileDeletion", allow_deletion);
622 values->SetBoolean("profileIsGuest",
623 Profile::FromWebUI(web_ui())->IsOffTheRecord());
625 values->SetBoolean("profileIsSupervised",
626 Profile::FromWebUI(web_ui())->IsSupervised());
628 #if !defined(OS_CHROMEOS)
629 values->SetBoolean(
630 "gpuEnabledAtStart",
631 g_browser_process->gpu_mode_manager()->initial_gpu_mode_pref());
632 #endif
634 #if defined(ENABLE_SERVICE_DISCOVERY)
635 values->SetBoolean("cloudPrintHideNotificationsCheckbox",
636 !local_discovery::PrivetNotificationService::IsEnabled());
637 #endif
639 values->SetBoolean("cloudPrintShowMDnsOptions",
640 cloud_print_mdns_ui_enabled_);
642 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
644 values->SetString("languagesLearnMoreURL",
645 chrome::kLanguageSettingsLearnMoreUrl);
647 values->SetBoolean(
648 "easyUnlockAllowed",
649 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsAllowed());
650 values->SetString("easyUnlockLearnMoreURL", chrome::kEasyUnlockLearnMoreUrl);
651 values->SetBoolean("easyUnlockProximityDetectionAllowed",
652 base::CommandLine::ForCurrentProcess()->HasSwitch(
653 proximity_auth::switches::kEnableProximityDetection));
655 #if defined(OS_CHROMEOS)
656 values->SetBoolean("consumerManagementEnabled",
657 base::CommandLine::ForCurrentProcess()->HasSwitch(
658 chromeos::switches::kEnableConsumerManagement));
660 RegisterTitle(values, "thirdPartyImeConfirmOverlay",
661 IDS_OPTIONS_SETTINGS_LANGUAGES_THIRD_PARTY_WARNING_TITLE);
662 #endif
664 values->SetBoolean("showSetDefault", ShouldShowSetDefaultBrowser());
666 values->SetBoolean("allowAdvancedSettings", ShouldAllowAdvancedSettings());
668 values->SetBoolean("websiteSettingsManagerEnabled",
669 base::CommandLine::ForCurrentProcess()->HasSwitch(
670 switches::kEnableWebsiteSettingsManager));
672 values->SetBoolean("usingNewProfilesUI", switches::IsNewAvatarMenu());
674 #if defined(OS_CHROMEOS)
675 values->SetBoolean(
676 "showWakeOnWifi",
677 chromeos::WakeOnWifiManager::Get()->WakeOnWifiSupported() &&
678 chromeos::switches::WakeOnWifiEnabled());
679 const bool have_disable_time_zone_tracking_option_switch =
680 base::CommandLine::ForCurrentProcess()->HasSwitch(
681 chromeos::switches::kDisableTimeZoneTrackingOption);
682 values->SetBoolean("enableTimeZoneTrackingOption",
683 !have_disable_time_zone_tracking_option_switch &&
684 !chromeos::system::HasSystemTimezonePolicy());
685 values->SetBoolean("resolveTimezoneByGeolocationInitialValue",
686 Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
687 prefs::kResolveTimezoneByGeolocation));
688 #endif
691 #if defined(ENABLE_PRINT_PREVIEW)
692 void BrowserOptionsHandler::RegisterCloudPrintValues(
693 base::DictionaryValue* values) {
694 values->SetString("cloudPrintOptionLabel",
695 l10n_util::GetStringFUTF16(
696 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL,
697 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)));
699 #endif // defined(ENABLE_PRINT_PREVIEW)
701 void BrowserOptionsHandler::RegisterMessages() {
702 web_ui()->RegisterMessageCallback(
703 "becomeDefaultBrowser",
704 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
705 base::Unretained(this)));
706 web_ui()->RegisterMessageCallback(
707 "setDefaultSearchEngine",
708 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
709 base::Unretained(this)));
710 web_ui()->RegisterMessageCallback(
711 "deleteProfile",
712 base::Bind(&BrowserOptionsHandler::DeleteProfile,
713 base::Unretained(this)));
714 web_ui()->RegisterMessageCallback(
715 "themesReset",
716 base::Bind(&BrowserOptionsHandler::ThemesReset,
717 base::Unretained(this)));
718 web_ui()->RegisterMessageCallback(
719 "requestProfilesInfo",
720 base::Bind(&BrowserOptionsHandler::HandleRequestProfilesInfo,
721 base::Unretained(this)));
722 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
723 web_ui()->RegisterMessageCallback(
724 "themesSetNative",
725 base::Bind(&BrowserOptionsHandler::ThemesSetNative,
726 base::Unretained(this)));
727 #endif
728 web_ui()->RegisterMessageCallback(
729 "selectDownloadLocation",
730 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation,
731 base::Unretained(this)));
732 web_ui()->RegisterMessageCallback(
733 "autoOpenFileTypesAction",
734 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton,
735 base::Unretained(this)));
736 web_ui()->RegisterMessageCallback(
737 "defaultFontSizeAction",
738 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize,
739 base::Unretained(this)));
740 web_ui()->RegisterMessageCallback(
741 "defaultZoomFactorAction",
742 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor,
743 base::Unretained(this)));
744 #if defined(OS_WIN) || defined(OS_MACOSX)
745 web_ui()->RegisterMessageCallback(
746 "showManageSSLCertificates",
747 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates,
748 base::Unretained(this)));
749 #endif
750 #if defined(OS_CHROMEOS)
751 web_ui()->RegisterMessageCallback(
752 "openWallpaperManager",
753 base::Bind(&BrowserOptionsHandler::HandleOpenWallpaperManager,
754 base::Unretained(this)));
755 web_ui()->RegisterMessageCallback(
756 "virtualKeyboardChange",
757 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback,
758 base::Unretained(this)));
759 web_ui()->RegisterMessageCallback(
760 "onPowerwashDialogShow",
761 base::Bind(&BrowserOptionsHandler::OnPowerwashDialogShow,
762 base::Unretained(this)));
763 web_ui()->RegisterMessageCallback(
764 "performFactoryResetRestart",
765 base::Bind(&BrowserOptionsHandler::PerformFactoryResetRestart,
766 base::Unretained(this)));
767 #else
768 web_ui()->RegisterMessageCallback(
769 "restartBrowser",
770 base::Bind(&BrowserOptionsHandler::HandleRestartBrowser,
771 base::Unretained(this)));
772 web_ui()->RegisterMessageCallback(
773 "showNetworkProxySettings",
774 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings,
775 base::Unretained(this)));
776 #endif // defined(OS_CHROMEOS)
778 #if defined(ENABLE_SERVICE_DISCOVERY)
779 if (cloud_print_mdns_ui_enabled_) {
780 web_ui()->RegisterMessageCallback(
781 "showCloudPrintDevicesPage",
782 base::Bind(&BrowserOptionsHandler::ShowCloudPrintDevicesPage,
783 base::Unretained(this)));
785 #endif
786 web_ui()->RegisterMessageCallback(
787 "requestGoogleNowAvailable",
788 base::Bind(&BrowserOptionsHandler::HandleRequestGoogleNowAvailable,
789 base::Unretained(this)));
791 web_ui()->RegisterMessageCallback(
792 "requestHotwordAvailable",
793 base::Bind(&BrowserOptionsHandler::HandleRequestHotwordAvailable,
794 base::Unretained(this)));
796 web_ui()->RegisterMessageCallback(
797 "launchHotwordAudioVerificationApp",
798 base::Bind(
799 &BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp,
800 base::Unretained(this)));
802 web_ui()->RegisterMessageCallback(
803 "launchEasyUnlockSetup",
804 base::Bind(&BrowserOptionsHandler::HandleLaunchEasyUnlockSetup,
805 base::Unretained(this)));
806 #if defined(OS_WIN)
807 web_ui()->RegisterMessageCallback(
808 "refreshExtensionControlIndicators",
809 base::Bind(
810 &BrowserOptionsHandler::HandleRefreshExtensionControlIndicators,
811 base::Unretained(this)));
812 #endif // defined(OS_WIN)
813 web_ui()->RegisterMessageCallback("metricsReportingCheckboxChanged",
814 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingChange,
815 base::Unretained(this)));
818 void BrowserOptionsHandler::Uninitialize() {
819 registrar_.RemoveAll();
820 g_browser_process->profile_manager()->
821 GetProfileInfoCache().RemoveObserver(this);
822 #if defined(OS_WIN)
823 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
824 #endif
825 #if defined(OS_CHROMEOS)
826 policy::ConsumerManagementService* consumer_management =
827 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
828 GetConsumerManagementService();
829 if (consumer_management)
830 consumer_management->RemoveObserver(this);
831 #endif
834 void BrowserOptionsHandler::OnStateChanged() {
835 UpdateSyncState();
838 void BrowserOptionsHandler::GoogleSigninSucceeded(const std::string& account_id,
839 const std::string& username,
840 const std::string& password) {
841 OnStateChanged();
844 void BrowserOptionsHandler::GoogleSignedOut(const std::string& account_id,
845 const std::string& username) {
846 OnStateChanged();
849 void BrowserOptionsHandler::PageLoadStarted() {
850 page_initialized_ = false;
853 void BrowserOptionsHandler::InitializeHandler() {
854 Profile* profile = Profile::FromWebUI(web_ui());
855 PrefService* prefs = profile->GetPrefs();
856 chrome::ChromeZoomLevelPrefs* zoom_level_prefs = profile->GetZoomLevelPrefs();
857 // Only regular profiles are able to edit default zoom level, or delete per-
858 // host zoom levels, via the settings menu. We only require a zoom_level_prefs
859 // if the profile is able to change these preference types.
860 DCHECK(zoom_level_prefs ||
861 profile->GetProfileType() != Profile::REGULAR_PROFILE);
862 if (zoom_level_prefs) {
863 default_zoom_level_subscription_ =
864 zoom_level_prefs->RegisterDefaultZoomLevelCallback(
865 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector,
866 base::Unretained(this)));
869 g_browser_process->policy_service()->AddObserver(
870 policy::POLICY_DOMAIN_CHROME, this);
872 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
874 ProfileSyncService* sync_service(
875 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile));
876 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on
877 // destruction is automatic.
878 if (sync_service)
879 sync_service->AddObserver(this);
881 SigninManagerBase* signin_manager(
882 SigninManagerFactory::GetInstance()->GetForProfile(profile));
883 if (signin_manager)
884 signin_observer_.Add(signin_manager);
886 // Create our favicon data source.
887 content::URLDataSource::Add(
888 profile, new FaviconSource(profile, FaviconSource::FAVICON));
890 default_browser_policy_.Init(
891 prefs::kDefaultBrowserSettingEnabled,
892 g_browser_process->local_state(),
893 base::Bind(&BrowserOptionsHandler::UpdateDefaultBrowserState,
894 base::Unretained(this)));
896 #if defined(OS_CHROMEOS)
897 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
898 content::NotificationService::AllSources());
899 #endif
900 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
901 content::Source<ThemeService>(
902 ThemeServiceFactory::GetForProfile(profile)));
903 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
904 content::Source<Profile>(profile));
905 AddTemplateUrlServiceObserver();
907 #if defined(OS_WIN)
908 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
910 const base::CommandLine& command_line =
911 *base::CommandLine::ForCurrentProcess();
912 if (!command_line.HasSwitch(switches::kUserDataDir)) {
913 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
914 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
915 weak_ptr_factory_.GetWeakPtr(),
916 profile->GetPath()));
918 #endif
920 // No preferences below this point may be modified by guest profiles.
921 if (Profile::FromWebUI(web_ui())->IsGuestSession())
922 return;
924 auto_open_files_.Init(
925 prefs::kDownloadExtensionsToOpen, prefs,
926 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes,
927 base::Unretained(this)));
928 profile_pref_registrar_.Init(prefs);
929 profile_pref_registrar_.Add(
930 prefs::kNetworkPredictionOptions,
931 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl,
932 base::Unretained(this)));
933 profile_pref_registrar_.Add(
934 prefs::kWebKitDefaultFontSize,
935 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
936 base::Unretained(this)));
937 profile_pref_registrar_.Add(
938 prefs::kWebKitDefaultFixedFontSize,
939 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector,
940 base::Unretained(this)));
941 profile_pref_registrar_.Add(
942 prefs::kSupervisedUsers,
943 base::Bind(&BrowserOptionsHandler::SetupManagingSupervisedUsers,
944 base::Unretained(this)));
945 profile_pref_registrar_.Add(
946 prefs::kSigninAllowed,
947 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange,
948 base::Unretained(this)));
949 profile_pref_registrar_.Add(
950 prefs::kEasyUnlockPairing,
951 base::Bind(&BrowserOptionsHandler::SetupEasyUnlock,
952 base::Unretained(this)));
954 #if defined(OS_WIN)
955 profile_pref_registrar_.Add(
956 prefs::kURLsToRestoreOnStartup,
957 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
958 base::Unretained(this)));
959 profile_pref_registrar_.Add(
960 prefs::kHomePage,
961 base::Bind(&BrowserOptionsHandler::SetupExtensionControlledIndicators,
962 base::Unretained(this)));
963 #endif // defined(OS_WIN)
965 #if defined(OS_CHROMEOS)
966 if (!policy_registrar_) {
967 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
968 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile)
969 ->policy_service(),
970 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
971 policy_registrar_->Observe(
972 policy::key::kUserAvatarImage,
973 base::Bind(&BrowserOptionsHandler::OnUserImagePolicyChanged,
974 base::Unretained(this)));
975 policy_registrar_->Observe(
976 policy::key::kWallpaperImage,
977 base::Bind(&BrowserOptionsHandler::OnWallpaperPolicyChanged,
978 base::Unretained(this)));
980 chromeos::CrosSettings::Get()->AddSettingsObserver(
981 chromeos::kSystemTimezonePolicy,
982 base::Bind(&BrowserOptionsHandler::OnSystemTimezonePolicyChanged,
983 weak_ptr_factory_.GetWeakPtr()));
984 #else // !defined(OS_CHROMEOS)
985 profile_pref_registrar_.Add(
986 prefs::kProxy,
987 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection,
988 base::Unretained(this)));
989 #endif // !defined(OS_CHROMEOS)
992 void BrowserOptionsHandler::InitializePage() {
993 page_initialized_ = true;
995 OnTemplateURLServiceChanged();
997 ObserveThemeChanged();
998 OnStateChanged();
999 UpdateDefaultBrowserState();
1001 SetupMetricsReportingSettingVisibility();
1002 SetupMetricsReportingCheckbox();
1003 SetupNetworkPredictionControl();
1004 SetupFontSizeSelector();
1005 SetupPageZoomSelector();
1006 SetupAutoOpenFileTypes();
1007 SetupProxySettingsSection();
1008 SetupManageCertificatesSection();
1009 SetupManagingSupervisedUsers();
1010 SetupEasyUnlock();
1011 SetupExtensionControlledIndicators();
1013 #if defined(OS_CHROMEOS)
1014 SetupAccessibilityFeatures();
1015 policy::BrowserPolicyConnectorChromeOS* connector =
1016 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1017 if (!connector->IsEnterpriseManaged() &&
1018 !user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
1019 !user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
1020 web_ui()->CallJavascriptFunction(
1021 "BrowserOptions.enableFactoryResetSection");
1024 Profile* profile = Profile::FromWebUI(web_ui());
1025 OnAccountPictureManagedChanged(
1026 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile)
1027 ->policy_service()
1028 ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
1029 std::string()))
1030 .Get(policy::key::kUserAvatarImage));
1032 OnWallpaperManagedChanged(
1033 chromeos::WallpaperManager::Get()->IsPolicyControlled(
1034 user_manager::UserManager::Get()->GetActiveUser()->email()));
1036 policy::ConsumerManagementService* consumer_management =
1037 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
1038 GetConsumerManagementService();
1039 if (consumer_management) {
1040 OnConsumerManagementStatusChanged();
1041 consumer_management->AddObserver(this);
1043 #endif
1046 // static
1047 void BrowserOptionsHandler::CheckAutoLaunch(
1048 base::WeakPtr<BrowserOptionsHandler> weak_this,
1049 const base::FilePath& profile_path) {
1050 #if defined(OS_WIN)
1051 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
1053 // Auto-launch is not supported for secondary profiles yet.
1054 if (profile_path.BaseName().value() !=
1055 base::ASCIIToUTF16(chrome::kInitialProfile)) {
1056 return;
1059 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
1060 // deleted.
1061 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1062 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
1063 weak_this,
1064 auto_launch_trial::IsInAutoLaunchGroup(),
1065 auto_launch_util::AutoStartRequested(
1066 profile_path.BaseName().value(),
1067 true, // Window requested.
1068 base::FilePath())));
1069 #endif
1072 void BrowserOptionsHandler::CheckAutoLaunchCallback(
1073 bool is_in_auto_launch_group,
1074 bool will_launch_at_login) {
1075 #if defined(OS_WIN)
1076 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1078 if (is_in_auto_launch_group) {
1079 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
1080 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
1081 base::Unretained(this)));
1083 base::FundamentalValue enabled(will_launch_at_login);
1084 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
1085 enabled);
1087 #endif
1090 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() {
1091 #if defined(OS_CHROMEOS)
1092 // We're always the default browser on ChromeOS.
1093 return false;
1094 #else
1095 Profile* profile = Profile::FromWebUI(web_ui());
1096 return !profile->IsGuestSession();
1097 #endif
1100 bool BrowserOptionsHandler::ShouldShowMultiProfilesUserList() {
1101 #if defined(OS_CHROMEOS)
1102 // On Chrome OS we use different UI for multi-profiles.
1103 return false;
1104 #else
1105 Profile* profile = Profile::FromWebUI(web_ui());
1106 if (profile->IsGuestSession())
1107 return false;
1108 return profiles::IsMultipleProfilesEnabled();
1109 #endif
1112 bool BrowserOptionsHandler::ShouldAllowAdvancedSettings() {
1113 #if defined(OS_CHROMEOS)
1114 // ChromeOS handles guest-mode restrictions in a different manner.
1115 return true;
1116 #else
1117 return !Profile::FromWebUI(web_ui())->IsGuestSession();
1118 #endif
1121 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
1122 default_browser_worker_->StartCheckIsDefault();
1125 void BrowserOptionsHandler::BecomeDefaultBrowser(const base::ListValue* args) {
1126 // If the default browser setting is managed then we should not be able to
1127 // call this function.
1128 if (default_browser_policy_.IsManaged())
1129 return;
1131 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
1132 default_browser_worker_->StartSetAsDefault();
1133 // Callback takes care of updating UI.
1135 // If the user attempted to make Chrome the default browser, then he/she
1136 // arguably wants to be notified when that changes.
1137 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1138 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
1141 int BrowserOptionsHandler::StatusStringIdForState(
1142 ShellIntegration::DefaultWebClientState state) {
1143 if (state == ShellIntegration::IS_DEFAULT)
1144 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1145 if (state == ShellIntegration::NOT_DEFAULT)
1146 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1147 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1150 void BrowserOptionsHandler::SetDefaultWebClientUIState(
1151 ShellIntegration::DefaultWebClientUIState state) {
1152 int status_string_id;
1154 if (state == ShellIntegration::STATE_IS_DEFAULT) {
1155 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
1156 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) {
1157 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1158 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
1159 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_SXS;
1160 } else {
1161 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
1163 } else if (state == ShellIntegration::STATE_UNKNOWN) {
1164 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
1165 } else {
1166 return; // Still processing.
1169 SetDefaultBrowserUIString(status_string_id);
1172 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() {
1173 return true; // This is UI so we can allow it.
1176 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
1177 base::StringValue status_string(
1178 l10n_util::GetStringFUTF16(status_string_id,
1179 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1181 base::FundamentalValue is_default(
1182 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT);
1184 base::FundamentalValue can_be_default(
1185 !default_browser_policy_.IsManaged() &&
1186 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
1187 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
1189 web_ui()->CallJavascriptFunction(
1190 "BrowserOptions.updateDefaultBrowserState",
1191 status_string, is_default, can_be_default);
1194 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
1195 if (!template_url_service_ || !template_url_service_->loaded())
1196 return;
1198 const TemplateURL* default_url =
1199 template_url_service_->GetDefaultSearchProvider();
1201 int default_index = -1;
1202 base::ListValue search_engines;
1203 TemplateURLService::TemplateURLVector model_urls(
1204 template_url_service_->GetTemplateURLs());
1205 for (size_t i = 0; i < model_urls.size(); ++i) {
1206 if (!model_urls[i]->ShowInDefaultList(
1207 template_url_service_->search_terms_data()))
1208 continue;
1210 base::DictionaryValue* entry = new base::DictionaryValue();
1211 entry->SetString("name", model_urls[i]->short_name());
1212 entry->SetInteger("index", i);
1213 search_engines.Append(entry);
1214 if (model_urls[i] == default_url)
1215 default_index = i;
1218 web_ui()->CallJavascriptFunction(
1219 "BrowserOptions.updateSearchEngines",
1220 search_engines,
1221 base::FundamentalValue(default_index),
1222 base::FundamentalValue(
1223 template_url_service_->is_default_search_managed() ||
1224 template_url_service_->IsExtensionControlledDefaultSearch()));
1226 SetupExtensionControlledIndicators();
1228 HandleRequestHotwordAvailable(nullptr);
1229 HandleRequestGoogleNowAvailable(nullptr);
1232 void BrowserOptionsHandler::SetDefaultSearchEngine(
1233 const base::ListValue* args) {
1234 int selected_index = -1;
1235 if (!ExtractIntegerValue(args, &selected_index)) {
1236 NOTREACHED();
1237 return;
1240 TemplateURLService::TemplateURLVector model_urls(
1241 template_url_service_->GetTemplateURLs());
1242 if (selected_index >= 0 &&
1243 selected_index < static_cast<int>(model_urls.size()))
1244 template_url_service_->SetUserSelectedDefaultSearchProvider(
1245 model_urls[selected_index]);
1247 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
1250 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() {
1251 template_url_service_ =
1252 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1253 if (template_url_service_) {
1254 template_url_service_->Load();
1255 template_url_service_->AddObserver(this);
1259 void BrowserOptionsHandler::OnExtensionLoaded(
1260 content::BrowserContext* browser_context,
1261 const Extension* extension) {
1262 SetupExtensionControlledIndicators();
1265 void BrowserOptionsHandler::OnExtensionUnloaded(
1266 content::BrowserContext* browser_context,
1267 const Extension* extension,
1268 extensions::UnloadedExtensionInfo::Reason reason) {
1269 SetupExtensionControlledIndicators();
1272 void BrowserOptionsHandler::Observe(
1273 int type,
1274 const content::NotificationSource& source,
1275 const content::NotificationDetails& details) {
1276 // Notifications are used to update the UI dynamically when settings change in
1277 // the background. If the UI is currently being loaded, no dynamic updates are
1278 // possible (as the DOM and JS are not fully loaded) or necessary (as
1279 // InitializePage() will update the UI at the end of the load).
1280 if (!page_initialized_)
1281 return;
1283 switch (type) {
1284 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
1285 ObserveThemeChanged();
1286 break;
1287 #if defined(OS_CHROMEOS)
1288 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
1289 UpdateAccountPicture();
1290 break;
1291 #endif
1292 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
1293 // Update our sync/signin status display.
1294 OnStateChanged();
1295 break;
1296 default:
1297 NOTREACHED();
1301 void BrowserOptionsHandler::OnProfileAdded(const base::FilePath& profile_path) {
1302 SendProfilesInfo();
1305 void BrowserOptionsHandler::OnProfileWasRemoved(
1306 const base::FilePath& profile_path,
1307 const base::string16& profile_name) {
1308 SendProfilesInfo();
1311 void BrowserOptionsHandler::OnProfileNameChanged(
1312 const base::FilePath& profile_path,
1313 const base::string16& old_profile_name) {
1314 SendProfilesInfo();
1317 void BrowserOptionsHandler::OnProfileAvatarChanged(
1318 const base::FilePath& profile_path) {
1319 SendProfilesInfo();
1322 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) {
1323 #if defined(OS_WIN)
1324 if (!auto_launch_trial::IsInAutoLaunchGroup())
1325 return;
1327 bool enable;
1328 CHECK_EQ(args->GetSize(), 1U);
1329 CHECK(args->GetBoolean(0, &enable));
1331 Profile* profile = Profile::FromWebUI(web_ui());
1332 content::BrowserThread::PostTask(
1333 content::BrowserThread::FILE, FROM_HERE,
1334 enable ?
1335 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin,
1336 profile->GetPath().BaseName().value(), base::FilePath()) :
1337 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin,
1338 profile->GetPath().BaseName().value()));
1339 #endif // OS_WIN
1342 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() {
1343 ProfileInfoCache& cache =
1344 g_browser_process->profile_manager()->GetProfileInfoCache();
1345 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue);
1346 base::FilePath current_profile_path =
1347 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
1349 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
1350 // The items in |profile_value| are also described in
1351 // chrome/browser/resources/options/browser_options.js in a @typedef for
1352 // Profile. Please update it whenever you add or remove any keys here.
1354 base::DictionaryValue* profile_value = new base::DictionaryValue();
1355 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
1356 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
1357 profile_value->Set("filePath", base::CreateFilePathValue(profile_path));
1358 profile_value->SetBoolean("isCurrentProfile",
1359 profile_path == current_profile_path);
1360 profile_value->SetBoolean("isSupervised",
1361 cache.ProfileIsSupervisedAtIndex(i));
1362 profile_value->SetBoolean("isChild", cache.ProfileIsChildAtIndex(i));
1364 bool is_gaia_picture =
1365 cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
1366 cache.GetGAIAPictureOfProfileAtIndex(i);
1367 if (is_gaia_picture) {
1368 gfx::Image icon = profiles::GetAvatarIconForWebUI(
1369 cache.GetAvatarIconOfProfileAtIndex(i), true);
1370 profile_value->SetString("iconURL",
1371 webui::GetBitmapDataUrl(icon.AsBitmap()));
1372 } else {
1373 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
1374 profile_value->SetString("iconURL",
1375 profiles::GetDefaultAvatarIconUrl(icon_index));
1378 profile_info_list->Append(profile_value);
1381 return profile_info_list.Pass();
1384 void BrowserOptionsHandler::SendProfilesInfo() {
1385 if (!ShouldShowMultiProfilesUserList())
1386 return;
1387 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo",
1388 *GetProfilesInfoList());
1391 void BrowserOptionsHandler::DeleteProfile(const base::ListValue* args) {
1392 DCHECK(args);
1393 const base::Value* file_path_value;
1394 if (!args->Get(0, &file_path_value)) {
1395 NOTREACHED();
1396 return;
1399 base::FilePath file_path;
1400 if (!base::GetValueAsFilePath(*file_path_value, &file_path)) {
1401 NOTREACHED();
1402 return;
1405 helper::DeleteProfileAtPath(file_path, web_ui());
1408 void BrowserOptionsHandler::ObserveThemeChanged() {
1409 Profile* profile = Profile::FromWebUI(web_ui());
1410 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
1411 bool is_system_theme = false;
1413 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1414 bool profile_is_supervised = profile->IsSupervised();
1415 is_system_theme = theme_service->UsingSystemTheme();
1416 base::FundamentalValue native_theme_enabled(!is_system_theme &&
1417 !profile_is_supervised);
1418 web_ui()->CallJavascriptFunction("BrowserOptions.setNativeThemeButtonEnabled",
1419 native_theme_enabled);
1420 #endif
1422 bool is_classic_theme = !is_system_theme &&
1423 theme_service->UsingDefaultTheme();
1424 base::FundamentalValue enabled(!is_classic_theme);
1425 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled",
1426 enabled);
1429 void BrowserOptionsHandler::ThemesReset(const base::ListValue* args) {
1430 Profile* profile = Profile::FromWebUI(web_ui());
1431 content::RecordAction(UserMetricsAction("Options_ThemesReset"));
1432 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
1435 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1436 void BrowserOptionsHandler::ThemesSetNative(const base::ListValue* args) {
1437 content::RecordAction(UserMetricsAction("Options_GtkThemeSet"));
1438 Profile* profile = Profile::FromWebUI(web_ui());
1439 ThemeServiceFactory::GetForProfile(profile)->UseSystemTheme();
1441 #endif
1443 #if defined(OS_CHROMEOS)
1444 void BrowserOptionsHandler::UpdateAccountPicture() {
1445 std::string email =
1446 user_manager::UserManager::Get()->GetLoggedInUser()->email();
1447 if (!email.empty()) {
1448 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture");
1449 base::StringValue email_value(email);
1450 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture",
1451 email_value);
1455 void BrowserOptionsHandler::OnAccountPictureManagedChanged(bool managed) {
1456 web_ui()->CallJavascriptFunction("BrowserOptions.setAccountPictureManaged",
1457 base::FundamentalValue(managed));
1460 void BrowserOptionsHandler::OnWallpaperManagedChanged(bool managed) {
1461 web_ui()->CallJavascriptFunction("BrowserOptions.setWallpaperManaged",
1462 base::FundamentalValue(managed));
1465 void BrowserOptionsHandler::OnSystemTimezonePolicyChanged() {
1466 web_ui()->CallJavascriptFunction(
1467 "BrowserOptions.setSystemTimezoneManaged",
1468 base::FundamentalValue(chromeos::system::HasSystemTimezonePolicy()));
1470 #endif
1472 scoped_ptr<base::DictionaryValue>
1473 BrowserOptionsHandler::GetSyncStateDictionary() {
1474 // The items which are to be written into |sync_status| are also described in
1475 // chrome/browser/resources/options/browser_options.js in @typedef
1476 // for SyncStatus. Please update it whenever you add or remove any keys here.
1477 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
1478 Profile* profile = Profile::FromWebUI(web_ui());
1479 if (profile->IsGuestSession()) {
1480 // Cannot display signin status when running in guest mode on chromeos
1481 // because there is no SigninManager.
1482 sync_status->SetBoolean("signinAllowed", false);
1483 return sync_status.Pass();
1486 sync_status->SetBoolean("supervisedUser", profile->IsSupervised());
1487 sync_status->SetBoolean("childUser", profile->IsChild());
1489 bool signout_prohibited = false;
1490 #if !defined(OS_CHROMEOS)
1491 // Signout is not allowed if the user has policy (crbug.com/172204).
1492 signout_prohibited =
1493 SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited();
1494 #endif
1496 ProfileSyncService* service =
1497 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
1498 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1499 DCHECK(signin);
1500 sync_status->SetBoolean("signoutAllowed", !signout_prohibited);
1501 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed());
1502 sync_status->SetBoolean("syncSystemEnabled", (service != NULL));
1503 sync_status->SetBoolean("setupCompleted",
1504 service && service->HasSyncSetupCompleted());
1505 sync_status->SetBoolean("setupInProgress",
1506 service && !service->IsManaged() && service->FirstSetupInProgress());
1508 base::string16 status_label;
1509 base::string16 link_label;
1510 bool status_has_error = sync_ui_util::GetStatusLabels(
1511 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
1512 sync_ui_util::SYNC_ERROR;
1513 sync_status->SetString("statusText", status_label);
1514 sync_status->SetString("actionLinkText", link_label);
1515 sync_status->SetBoolean("hasError", status_has_error);
1517 sync_status->SetBoolean("managed", service && service->IsManaged());
1518 sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
1519 sync_status->SetBoolean("hasUnrecoverableError",
1520 service && service->HasUnrecoverableError());
1522 return sync_status.Pass();
1525 void BrowserOptionsHandler::HandleSelectDownloadLocation(
1526 const base::ListValue* args) {
1527 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1528 select_folder_dialog_ = ui::SelectFileDialog::Create(
1529 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
1530 ui::SelectFileDialog::FileTypeInfo info;
1531 info.support_drive = true;
1532 select_folder_dialog_->SelectFile(
1533 ui::SelectFileDialog::SELECT_FOLDER,
1534 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE),
1535 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory),
1536 &info,
1538 base::FilePath::StringType(),
1539 web_ui()->GetWebContents()->GetTopLevelNativeWindow(),
1540 NULL);
1543 void BrowserOptionsHandler::FileSelected(const base::FilePath& path, int index,
1544 void* params) {
1545 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory"));
1546 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1547 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path);
1548 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, path);
1551 #if defined(OS_CHROMEOS)
1552 void BrowserOptionsHandler::TouchpadExists(bool exists) {
1553 base::FundamentalValue val(exists);
1554 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val);
1557 void BrowserOptionsHandler::MouseExists(bool exists) {
1558 base::FundamentalValue val(exists);
1559 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val);
1562 void BrowserOptionsHandler::OnUserImagePolicyChanged(
1563 const base::Value* previous_policy,
1564 const base::Value* current_policy) {
1565 const bool had_policy = previous_policy;
1566 const bool has_policy = current_policy;
1567 if (had_policy != has_policy)
1568 OnAccountPictureManagedChanged(has_policy);
1571 void BrowserOptionsHandler::OnWallpaperPolicyChanged(
1572 const base::Value* previous_policy,
1573 const base::Value* current_policy) {
1574 const bool had_policy = previous_policy;
1575 const bool has_policy = current_policy;
1576 if (had_policy != has_policy)
1577 OnWallpaperManagedChanged(has_policy);
1580 void BrowserOptionsHandler::OnPowerwashDialogShow(
1581 const base::ListValue* args) {
1582 UMA_HISTOGRAM_ENUMERATION(
1583 "Reset.ChromeOS.PowerwashDialogShown",
1584 chromeos::reset::DIALOG_FROM_OPTIONS,
1585 chromeos::reset::DIALOG_VIEW_TYPE_SIZE);
1588 void BrowserOptionsHandler::OnConsumerManagementStatusChanged() {
1589 const std::string& status = g_browser_process->platform_part()->
1590 browser_policy_connector_chromeos()->GetConsumerManagementService()->
1591 GetStatusString();
1592 web_ui()->CallJavascriptFunction(
1593 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status));
1596 #endif // defined(OS_CHROMEOS)
1598 void BrowserOptionsHandler::UpdateSyncState() {
1599 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1600 *GetSyncStateDictionary());
1602 // A change in sign-in state also affects how hotwording and audio history are
1603 // displayed. Hide all hotwording and re-display properly.
1604 web_ui()->CallJavascriptFunction(
1605 "BrowserOptions.setAllHotwordSectionsVisible",
1606 base::FundamentalValue(false));
1607 HandleRequestHotwordAvailable(nullptr);
1610 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1611 UpdateSyncState();
1614 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1615 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1616 DownloadManager* manager = BrowserContext::GetDownloadManager(
1617 web_ui()->GetWebContents()->GetBrowserContext());
1618 if (manager)
1619 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
1622 void BrowserOptionsHandler::HandleDefaultFontSize(const base::ListValue* args) {
1623 int font_size;
1624 if (ExtractIntegerValue(args, &font_size)) {
1625 if (font_size > 0) {
1626 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1627 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size);
1628 SetupFontSizeSelector();
1633 void BrowserOptionsHandler::HandleDefaultZoomFactor(
1634 const base::ListValue* args) {
1635 double zoom_factor;
1636 if (ExtractDoubleValue(args, &zoom_factor)) {
1637 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
1638 content::ZoomFactorToZoomLevel(zoom_factor));
1642 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
1643 #if defined(OS_WIN) && defined(USE_ASH)
1644 // If hardware acceleration is disabled then we need to force restart
1645 // browser in desktop mode.
1646 // TODO(shrikant): Remove this once we fix start mode logic for browser.
1647 // Currently there are issues with determining correct browser mode
1648 // at startup.
1649 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1650 PrefService* pref_service = g_browser_process->local_state();
1651 if (!pref_service->GetBoolean(prefs::kHardwareAccelerationModeEnabled)) {
1652 chrome::AttemptRestartToDesktopMode();
1653 return;
1656 #endif
1658 #if defined(OS_WIN)
1659 // On Windows Breakpad will upload crash reports if the breakpad pipe name
1660 // environment variable is defined. So we undefine this environment variable
1661 // before restarting, as the restarted processes will inherit their
1662 // environment variables from ours, thus suppressing crash uploads.
1663 PrefService* pref_service = g_browser_process->local_state();
1664 if (!pref_service->GetBoolean(prefs::kMetricsReportingEnabled)) {
1665 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
1666 if (exe_module) {
1667 typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
1668 ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
1669 GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
1670 if (clear)
1671 clear();
1674 #endif
1676 chrome::AttemptRestart();
1679 void BrowserOptionsHandler::HandleRequestProfilesInfo(
1680 const base::ListValue* args) {
1681 SendProfilesInfo();
1684 #if !defined(OS_CHROMEOS)
1685 void BrowserOptionsHandler::ShowNetworkProxySettings(
1686 const base::ListValue* args) {
1687 content::RecordAction(UserMetricsAction("Options_ShowProxySettings"));
1688 AdvancedOptionsUtilities::ShowNetworkProxySettings(
1689 web_ui()->GetWebContents());
1691 #endif
1693 #if defined(OS_WIN) || defined(OS_MACOSX)
1694 void BrowserOptionsHandler::ShowManageSSLCertificates(
1695 const base::ListValue* args) {
1696 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates"));
1697 AdvancedOptionsUtilities::ShowManageSSLCertificates(
1698 web_ui()->GetWebContents());
1700 #endif
1702 #if defined(ENABLE_SERVICE_DISCOVERY)
1704 void BrowserOptionsHandler::ShowCloudPrintDevicesPage(
1705 const base::ListValue* args) {
1706 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1707 // Navigate in current tab to devices page.
1708 OpenURLParams params(
1709 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1710 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false);
1711 web_ui()->GetWebContents()->OpenURL(params);
1714 #endif
1716 void BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible(
1717 const base::string16& audio_history_state,
1718 bool success, bool logging_enabled) {
1719 bool visible = logging_enabled && success;
1720 web_ui()->CallJavascriptFunction(
1721 "BrowserOptions.setAudioHistorySectionVisible",
1722 base::FundamentalValue(visible),
1723 base::StringValue(audio_history_state));
1726 void BrowserOptionsHandler::HandleRequestGoogleNowAvailable(
1727 const base::ListValue* args) {
1728 bool is_search_provider_google = false;
1729 if (template_url_service_ && template_url_service_->loaded()) {
1730 const TemplateURL* default_url =
1731 template_url_service_->GetDefaultSearchProvider();
1732 if (default_url && default_url->HasGoogleBaseURLs(
1733 template_url_service_->search_terms_data())) {
1734 is_search_provider_google = true;
1738 std::string group = base::FieldTrialList::FindFullName("GoogleNowExtension");
1739 bool has_field_trial = !group.empty() && group != "Disabled";
1741 bool should_show = is_search_provider_google && has_field_trial;
1742 web_ui()->CallJavascriptFunction(
1743 "BrowserOptions.setNowSectionVisible",
1744 base::FundamentalValue(should_show));
1747 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1748 const base::ListValue* args) {
1749 Profile* profile = Profile::FromWebUI(web_ui());
1751 bool is_search_provider_google = false;
1752 // The check for default search provider is only valid if the
1753 // |template_url_service_| has loaded already.
1754 if (template_url_service_ && template_url_service_->loaded()) {
1755 const TemplateURL* default_url =
1756 template_url_service_->GetDefaultSearchProvider();
1757 if (default_url && default_url->HasGoogleBaseURLs(
1758 template_url_service_->search_terms_data())) {
1759 is_search_provider_google = true;
1760 } else {
1761 // If the user has chosen a default search provide other than Google, turn
1762 // off hotwording since other providers don't provide that functionality.
1763 HotwordService* hotword_service =
1764 HotwordServiceFactory::GetForProfile(profile);
1765 if (hotword_service)
1766 hotword_service->DisableHotwordPreferences();
1770 // |is_search_provider_google| may be false because |template_url_service_|
1771 // does not exist yet or because the user selected a different search
1772 // provider. In either case it does not make sense to show the hotwording
1773 // options.
1774 if (!is_search_provider_google) {
1775 web_ui()->CallJavascriptFunction(
1776 "BrowserOptions.setAllHotwordSectionsVisible",
1777 base::FundamentalValue(false));
1778 return;
1781 // Don't need to check the field trial here since |IsHotwordAllowed| also
1782 // checks it.
1783 if (HotwordServiceFactory::IsHotwordAllowed(profile)) {
1784 // Update the current error value.
1785 HotwordServiceFactory::IsServiceAvailable(profile);
1786 int error = HotwordServiceFactory::GetCurrentError(profile);
1788 std::string function_name;
1789 bool always_on = false;
1790 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1791 bool authenticated = signin && signin->IsAuthenticated();
1792 if (HotwordServiceFactory::IsAlwaysOnAvailable() && authenticated) {
1793 function_name = "BrowserOptions.showHotwordAlwaysOnSection";
1794 always_on = true;
1795 // Show the retrain link if always-on is enabled.
1796 if (profile->GetPrefs()->GetBoolean(
1797 prefs::kHotwordAlwaysOnSearchEnabled)) {
1798 web_ui()->CallJavascriptFunction(
1799 "BrowserOptions.setHotwordRetrainLinkVisible",
1800 base::FundamentalValue(true));
1802 } else {
1803 function_name = "BrowserOptions.showHotwordNoDspSection";
1806 // Audio history should be displayed if it's enabled regardless of the
1807 // hotword error state if the user is signed in. If the user is not signed
1808 // in, audio history is meaningless. This is only displayed if always-on
1809 // hotwording is available.
1810 if (authenticated && always_on) {
1811 std::string user_display_name = signin->GetAuthenticatedUsername();
1812 DCHECK(!user_display_name.empty());
1813 base::string16 audio_history_state =
1814 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED,
1815 base::ASCIIToUTF16(user_display_name));
1816 HotwordService* hotword_service =
1817 HotwordServiceFactory::GetForProfile(profile);
1818 if (hotword_service) {
1819 hotword_service->GetAudioHistoryHandler()->GetAudioHistoryEnabled(
1820 base::Bind(
1821 &BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible,
1822 weak_ptr_factory_.GetWeakPtr(),
1823 audio_history_state));
1827 if (!error) {
1828 web_ui()->CallJavascriptFunction(function_name);
1829 } else {
1830 base::string16 hotword_help_url =
1831 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1832 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1833 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1834 error_message = base::StringValue(
1835 l10n_util::GetStringFUTF16(error, hotword_help_url));
1837 web_ui()->CallJavascriptFunction(function_name, error_message);
1842 void BrowserOptionsHandler::HandleLaunchHotwordAudioVerificationApp(
1843 const base::ListValue* args) {
1844 Profile* profile = Profile::FromWebUI(web_ui());
1846 bool retrain = false;
1847 bool success = args->GetBoolean(0, &retrain);
1848 DCHECK(success);
1849 HotwordService::LaunchMode launch_mode =
1850 HotwordService::HOTWORD_AND_AUDIO_HISTORY;
1852 if (retrain) {
1853 DCHECK(profile->GetPrefs()->GetBoolean(
1854 prefs::kHotwordAlwaysOnSearchEnabled));
1855 DCHECK(profile->GetPrefs()->GetBoolean(
1856 prefs::kHotwordAudioLoggingEnabled));
1858 launch_mode = HotwordService::RETRAIN;
1859 } else if (profile->GetPrefs()->GetBoolean(
1860 prefs::kHotwordAudioLoggingEnabled)) {
1861 DCHECK(!profile->GetPrefs()->GetBoolean(
1862 prefs::kHotwordAlwaysOnSearchEnabled));
1863 launch_mode = HotwordService::HOTWORD_ONLY;
1864 } else {
1865 DCHECK(!profile->GetPrefs()->GetBoolean(
1866 prefs::kHotwordAlwaysOnSearchEnabled));
1869 HotwordService* hotword_service =
1870 HotwordServiceFactory::GetForProfile(profile);
1871 if (!hotword_service)
1872 return;
1874 hotword_service->OptIntoHotwording(launch_mode);
1877 void BrowserOptionsHandler::HandleLaunchEasyUnlockSetup(
1878 const base::ListValue* args) {
1879 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->LaunchSetup();
1882 void BrowserOptionsHandler::HandleRefreshExtensionControlIndicators(
1883 const base::ListValue* args) {
1884 SetupExtensionControlledIndicators();
1887 #if defined(OS_CHROMEOS)
1888 void BrowserOptionsHandler::HandleOpenWallpaperManager(
1889 const base::ListValue* args) {
1890 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
1893 void BrowserOptionsHandler::VirtualKeyboardChangeCallback(
1894 const base::ListValue* args) {
1895 bool enabled = false;
1896 args->GetBoolean(0, &enabled);
1898 chromeos::accessibility::EnableVirtualKeyboard(enabled);
1901 void BrowserOptionsHandler::PerformFactoryResetRestart(
1902 const base::ListValue* args) {
1903 policy::BrowserPolicyConnectorChromeOS* connector =
1904 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1905 if (connector->IsEnterpriseManaged())
1906 return;
1908 PrefService* prefs = g_browser_process->local_state();
1909 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
1910 prefs->CommitPendingWrite();
1912 // Perform sign out. Current chrome process will then terminate, new one will
1913 // be launched (as if it was a restart).
1914 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
1917 void BrowserOptionsHandler::SetupAccessibilityFeatures() {
1918 PrefService* pref_service = g_browser_process->local_state();
1919 base::FundamentalValue virtual_keyboard_enabled(
1920 pref_service->GetBoolean(prefs::kAccessibilityVirtualKeyboardEnabled));
1921 web_ui()->CallJavascriptFunction(
1922 "BrowserOptions.setVirtualKeyboardCheckboxState",
1923 virtual_keyboard_enabled);
1925 #endif
1927 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() {
1928 #if defined(GOOGLE_CHROME_BUILD)
1929 // Don't show the reporting setting if we are in the guest mode.
1930 if (Profile::FromWebUI(web_ui())->IsGuestSession()) {
1931 base::FundamentalValue visible(false);
1932 web_ui()->CallJavascriptFunction(
1933 "BrowserOptions.setMetricsReportingSettingVisibility", visible);
1935 #endif
1938 void BrowserOptionsHandler::SetupNetworkPredictionControl() {
1939 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1941 base::DictionaryValue dict;
1942 dict.SetInteger("value",
1943 pref_service->GetInteger(prefs::kNetworkPredictionOptions));
1944 dict.SetBoolean("disabled",
1945 !pref_service->IsUserModifiablePreference(
1946 prefs::kNetworkPredictionOptions));
1948 web_ui()->CallJavascriptFunction("BrowserOptions.setNetworkPredictionValue",
1949 dict);
1952 void BrowserOptionsHandler::SetupFontSizeSelector() {
1953 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
1954 const PrefService::Preference* default_font_size =
1955 pref_service->FindPreference(prefs::kWebKitDefaultFontSize);
1956 const PrefService::Preference* default_fixed_font_size =
1957 pref_service->FindPreference(prefs::kWebKitDefaultFixedFontSize);
1959 base::DictionaryValue dict;
1960 dict.SetInteger("value",
1961 pref_service->GetInteger(prefs::kWebKitDefaultFontSize));
1963 // The font size control displays the value of the default font size, but
1964 // setting it alters both the default font size and the default fixed font
1965 // size. So it must be disabled when either of those prefs is not user
1966 // modifiable.
1967 dict.SetBoolean("disabled",
1968 !default_font_size->IsUserModifiable() ||
1969 !default_fixed_font_size->IsUserModifiable());
1971 // This is a poor man's version of CoreOptionsHandler::CreateValueForPref,
1972 // adapted to consider two prefs. It may be better to refactor
1973 // CreateValueForPref so it can be called from here.
1974 if (default_font_size->IsManaged() || default_fixed_font_size->IsManaged()) {
1975 dict.SetString("controlledBy", "policy");
1976 } else if (default_font_size->IsExtensionControlled() ||
1977 default_fixed_font_size->IsExtensionControlled()) {
1978 dict.SetString("controlledBy", "extension");
1981 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict);
1984 void BrowserOptionsHandler::SetupPageZoomSelector() {
1985 double default_zoom_level =
1986 content::HostZoomMap::GetDefaultForBrowserContext(
1987 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel();
1988 double default_zoom_factor =
1989 content::ZoomLevelToZoomFactor(default_zoom_level);
1991 // Generate a vector of zoom factors from an array of known presets along with
1992 // the default factor added if necessary.
1993 std::vector<double> zoom_factors =
1994 ui_zoom::PageZoom::PresetZoomFactors(default_zoom_factor);
1996 // Iterate through the zoom factors and and build the contents of the
1997 // selector that will be sent to the javascript handler.
1998 // Each item in the list has the following parameters:
1999 // 1. Title (string).
2000 // 2. Value (double).
2001 // 3. Is selected? (bool).
2002 base::ListValue zoom_factors_value;
2003 for (std::vector<double>::const_iterator i = zoom_factors.begin();
2004 i != zoom_factors.end(); ++i) {
2005 base::ListValue* option = new base::ListValue();
2006 double factor = *i;
2007 int percent = static_cast<int>(factor * 100 + 0.5);
2008 option->Append(new base::StringValue(
2009 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
2010 option->Append(new base::FundamentalValue(factor));
2011 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor);
2012 option->Append(new base::FundamentalValue(selected));
2013 zoom_factors_value.Append(option);
2016 web_ui()->CallJavascriptFunction(
2017 "BrowserOptions.setupPageZoomSelector", zoom_factors_value);
2020 void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
2021 // Set the hidden state for the AutoOpenFileTypesResetToDefault button.
2022 // We show the button if the user has any auto-open file types registered.
2023 DownloadManager* manager = BrowserContext::GetDownloadManager(
2024 web_ui()->GetWebContents()->GetBrowserContext());
2025 bool display = manager &&
2026 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
2027 base::FundamentalValue value(display);
2028 web_ui()->CallJavascriptFunction(
2029 "BrowserOptions.setAutoOpenFileTypesDisplayed", value);
2032 void BrowserOptionsHandler::SetupProxySettingsSection() {
2033 #if !defined(OS_CHROMEOS)
2034 // Disable the button if proxy settings are managed by a sysadmin, overridden
2035 // by an extension, or the browser is running in Windows Ash (on Windows the
2036 // proxy settings dialog will open on the Windows desktop and be invisible
2037 // to a user in Ash).
2038 bool is_win_ash = false;
2039 #if defined(OS_WIN)
2040 chrome::HostDesktopType desktop_type = helper::GetDesktopType(web_ui());
2041 is_win_ash = (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH);
2042 #endif
2043 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
2044 const PrefService::Preference* proxy_config =
2045 pref_service->FindPreference(prefs::kProxy);
2046 bool is_extension_controlled = (proxy_config &&
2047 proxy_config->IsExtensionControlled());
2049 base::FundamentalValue disabled(is_win_ash || (proxy_config &&
2050 !proxy_config->IsUserModifiable()));
2051 base::FundamentalValue extension_controlled(is_extension_controlled);
2052 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsButton",
2053 disabled, extension_controlled);
2055 #if defined(OS_WIN)
2056 SetupExtensionControlledIndicators();
2057 #endif // defined(OS_WIN)
2059 #endif // !defined(OS_CHROMEOS)
2062 void BrowserOptionsHandler::SetupManageCertificatesSection() {
2063 #if defined(OS_WIN)
2064 // Disable the button if the settings page is displayed in Windows Ash,
2065 // otherwise the proxy settings dialog will open on the Windows desktop and
2066 // be invisible to a user in Ash.
2067 if (helper::GetDesktopType(web_ui()) == chrome::HOST_DESKTOP_TYPE_ASH) {
2068 base::FundamentalValue enabled(false);
2069 web_ui()->CallJavascriptFunction("BrowserOptions.enableCertificateButton",
2070 enabled);
2072 #endif // defined(OS_WIN)
2075 void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
2076 bool has_users = !Profile::FromWebUI(web_ui())->
2077 GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
2078 base::FundamentalValue has_users_value(has_users);
2079 web_ui()->CallJavascriptFunction(
2080 "BrowserOptions.updateManagesSupervisedUsers",
2081 has_users_value);
2084 void BrowserOptionsHandler::SetupEasyUnlock() {
2085 base::FundamentalValue is_enabled(
2086 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->IsEnabled());
2087 web_ui()->CallJavascriptFunction(
2088 "BrowserOptions.updateEasyUnlock",
2089 is_enabled);
2092 void BrowserOptionsHandler::SetupExtensionControlledIndicators() {
2093 #if defined(OS_WIN)
2094 base::DictionaryValue extension_controlled;
2096 // Check if an extension is overriding the Search Engine.
2097 const extensions::Extension* extension =
2098 extensions::GetExtensionOverridingSearchEngine(
2099 Profile::FromWebUI(web_ui()));
2100 AppendExtensionData("searchEngine", extension, &extension_controlled);
2102 // Check if an extension is overriding the Home page.
2103 extension = extensions::GetExtensionOverridingHomepage(
2104 Profile::FromWebUI(web_ui()));
2105 AppendExtensionData("homePage", extension, &extension_controlled);
2107 // Check if an extension is overriding the Startup pages.
2108 extension = extensions::GetExtensionOverridingStartupPages(
2109 Profile::FromWebUI(web_ui()));
2110 AppendExtensionData("startUpPage", extension, &extension_controlled);
2112 // Check if an extension is overriding the NTP page.
2113 GURL ntp_url(chrome::kChromeUINewTabURL);
2114 bool ignored_param;
2115 extension = NULL;
2116 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
2117 &ntp_url,
2118 web_ui()->GetWebContents()->GetBrowserContext(),
2119 &ignored_param);
2120 if (ntp_url.SchemeIs("chrome-extension")) {
2121 using extensions::ExtensionRegistry;
2122 ExtensionRegistry* registry = ExtensionRegistry::Get(
2123 Profile::FromWebUI(web_ui()));
2124 extension = registry->GetExtensionById(ntp_url.host(),
2125 ExtensionRegistry::ENABLED);
2127 AppendExtensionData("newTabPage", extension, &extension_controlled);
2129 // Check if an extension is overwriting the proxy setting.
2130 extension = extensions::GetExtensionOverridingProxy(
2131 Profile::FromWebUI(web_ui()));
2132 AppendExtensionData("proxy", extension, &extension_controlled);
2134 web_ui()->CallJavascriptFunction("BrowserOptions.toggleExtensionIndicators",
2135 extension_controlled);
2136 #endif // defined(OS_WIN)
2139 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() {
2140 // This function does not work for ChromeOS and non-official builds.
2141 #if !defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
2142 bool checked = ChromeMetricsServiceAccessor::IsMetricsReportingEnabled();
2143 bool disabled = !IsMetricsReportingUserChangable();
2145 SetMetricsReportingCheckbox(checked, disabled);
2146 #endif
2149 void BrowserOptionsHandler::HandleMetricsReportingChange(
2150 const base::ListValue* args) {
2151 bool enable;
2152 if (!args->GetBoolean(0, &enable))
2153 return;
2155 InitiateMetricsReportingChange(
2156 enable,
2157 base::Bind(&BrowserOptionsHandler::MetricsReportingChangeCallback,
2158 base::Unretained(this)));
2161 void BrowserOptionsHandler::MetricsReportingChangeCallback(bool enabled) {
2162 SetMetricsReportingCheckbox(enabled, !IsMetricsReportingUserChangable());
2165 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked,
2166 bool disabled) {
2167 web_ui()->CallJavascriptFunction(
2168 "BrowserOptions.setMetricsReportingCheckboxState",
2169 base::FundamentalValue(checked),
2170 base::FundamentalValue(disabled));
2173 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2174 const policy::PolicyMap& previous,
2175 const policy::PolicyMap& current) {
2176 std::set<std::string> different_keys;
2177 current.GetDifferingKeys(previous, &different_keys);
2178 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2179 SetupMetricsReportingCheckbox();
2182 } // namespace options