OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/ui/webui/options2/browser_options_handler2.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/bind.h" | |
12 #include "base/bind_helpers.h" | |
13 #include "base/command_line.h" | |
14 #include "base/memory/singleton.h" | |
15 #include "base/path_service.h" | |
16 #include "base/stl_util.h" | |
17 #include "base/string_number_conversions.h" | |
18 #include "base/utf_string_conversions.h" | |
19 #include "base/value_conversions.h" | |
20 #include "base/values.h" | |
21 #include "chrome/browser/auto_launch_trial.h" | |
22 #include "chrome/browser/browser_process.h" | |
23 #include "chrome/browser/chrome_page_zoom.h" | |
24 #include "chrome/browser/custom_home_pages_table_model.h" | |
25 #include "chrome/browser/download/download_prefs.h" | |
26 #include "chrome/browser/instant/instant_controller.h" | |
27 #include "chrome/browser/net/url_fixer_upper.h" | |
28 #include "chrome/browser/prefs/pref_service.h" | |
29 #include "chrome/browser/prefs/session_startup_pref.h" | |
30 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | |
31 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | |
32 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | |
33 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | |
34 #include "chrome/browser/profiles/profile.h" | |
35 #include "chrome/browser/profiles/profile_info_cache.h" | |
36 #include "chrome/browser/profiles/profile_info_util.h" | |
37 #include "chrome/browser/profiles/profile_manager.h" | |
38 #include "chrome/browser/search_engines/template_url.h" | |
39 #include "chrome/browser/search_engines/template_url_service.h" | |
40 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
41 #include "chrome/browser/service/service_process_control.h" | |
42 #include "chrome/browser/signin/signin_manager.h" | |
43 #include "chrome/browser/signin/signin_manager_factory.h" | |
44 #include "chrome/browser/sync/profile_sync_service.h" | |
45 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
46 #include "chrome/browser/sync/sync_ui_util.h" | |
47 #include "chrome/browser/themes/theme_service.h" | |
48 #include "chrome/browser/themes/theme_service_factory.h" | |
49 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
50 #include "chrome/browser/ui/options/options_util.h" | |
51 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
52 #include "chrome/browser/ui/webui/favicon_source.h" | |
53 #include "chrome/browser/ui/webui/web_ui_util.h" | |
54 #include "chrome/common/chrome_constants.h" | |
55 #include "chrome/common/chrome_notification_types.h" | |
56 #include "chrome/common/chrome_paths.h" | |
57 #include "chrome/common/chrome_switches.h" | |
58 #include "chrome/common/net/gaia/google_service_auth_error.h" | |
59 #include "chrome/common/pref_names.h" | |
60 #include "chrome/common/url_constants.h" | |
61 #include "content/public/browser/browser_thread.h" | |
62 #include "content/public/browser/download_manager.h" | |
63 #include "content/public/browser/navigation_controller.h" | |
64 #include "content/public/browser/notification_details.h" | |
65 #include "content/public/browser/notification_service.h" | |
66 #include "content/public/browser/notification_source.h" | |
67 #include "content/public/browser/notification_types.h" | |
68 #include "content/public/browser/user_metrics.h" | |
69 #include "content/public/browser/web_contents.h" | |
70 #include "content/public/browser/web_contents_view.h" | |
71 #include "content/public/common/page_zoom.h" | |
72 #include "grit/chromium_strings.h" | |
73 #include "grit/generated_resources.h" | |
74 #include "grit/locale_settings.h" | |
75 #include "grit/theme_resources.h" | |
76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
77 #include "ui/base/l10n/l10n_util.h" | |
78 | |
79 #if !defined(OS_CHROMEOS) | |
80 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" | |
81 #include "chrome/browser/ui/webui/options2/advanced_options_utils2.h" | |
82 #endif | |
83 | |
84 #if defined(OS_CHROMEOS) | |
85 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | |
86 #include "chrome/browser/chromeos/cros_settings.h" | |
87 #include "chrome/browser/chromeos/login/user_manager.h" | |
88 #include "chrome/browser/chromeos/options/take_photo_dialog.h" | |
89 #include "chrome/browser/chromeos/system_settings_provider.h" | |
90 #include "chrome/browser/ui/browser_window.h" | |
91 #include "ui/gfx/image/image_skia.h" | |
92 #endif // defined(OS_CHROMEOS) | |
93 | |
94 #if defined(OS_WIN) | |
95 #include "chrome/installer/util/auto_launch_util.h" | |
96 #endif // defined(OS_WIN) | |
97 | |
98 #if defined(TOOLKIT_GTK) | |
99 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | |
100 #endif // defined(TOOLKIT_GTK) | |
101 | |
102 using content::BrowserContext; | |
103 using content::BrowserThread; | |
104 using content::DownloadManager; | |
105 using content::OpenURLParams; | |
106 using content::Referrer; | |
107 using content::UserMetricsAction; | |
108 | |
109 namespace options2 { | |
110 | |
111 BrowserOptionsHandler::BrowserOptionsHandler() | |
112 : template_url_service_(NULL), | |
113 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)), | |
114 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) { | |
115 multiprofile_ = ProfileManager::IsMultipleProfilesEnabled(); | |
116 #if !defined(OS_MACOSX) | |
117 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); | |
118 #endif | |
119 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) | |
120 // On Windows, we need the PDF plugin which is only guaranteed to exist on | |
121 // Google Chrome builds. Use a command-line switch for Windows non-Google | |
122 // Chrome builds. | |
123 cloud_print_connector_ui_enabled_ = | |
124 CommandLine::ForCurrentProcess()->HasSwitch( | |
125 switches::kEnableCloudPrintProxy); | |
126 #elif(!defined(OS_CHROMEOS)) | |
127 // Always enabled for Mac, Linux and Google Chrome Windows builds. | |
128 // Never enabled for Chrome OS, we don't even need to indicate it. | |
129 cloud_print_connector_ui_enabled_ = true; | |
130 #endif | |
131 } | |
132 | |
133 BrowserOptionsHandler::~BrowserOptionsHandler() { | |
134 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: | |
135 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); | |
136 if (sync_service) | |
137 sync_service->RemoveObserver(this); | |
138 | |
139 if (default_browser_worker_.get()) | |
140 default_browser_worker_->ObserverDestroyed(); | |
141 if (template_url_service_) | |
142 template_url_service_->RemoveObserver(this); | |
143 // There may be pending file dialogs, we need to tell them that we've gone | |
144 // away so they don't try and call back to us. | |
145 if (select_folder_dialog_.get()) | |
146 select_folder_dialog_->ListenerDestroyed(); | |
147 } | |
148 | |
149 void BrowserOptionsHandler::GetLocalizedValues(DictionaryValue* values) { | |
150 DCHECK(values); | |
151 | |
152 static OptionsStringResource resources[] = { | |
153 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT }, | |
154 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY }, | |
155 { "advancedSectionTitleContent", | |
156 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, | |
157 { "advancedSectionTitleLanguages", | |
158 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES }, | |
159 { "advancedSectionTitleNetwork", | |
160 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, | |
161 { "advancedSectionTitlePrivacy", | |
162 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, | |
163 { "advancedSectionTitleSecurity", | |
164 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY }, | |
165 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE }, | |
166 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, | |
167 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, | |
168 { "autoOpenFileTypesResetToDefault", | |
169 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, | |
170 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, | |
171 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, | |
172 { "customizeSync", IDS_OPTIONS2_CUSTOMIZE_SYNC_BUTTON_LABEL }, | |
173 { "defaultFontSizeLabel", IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, | |
174 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, | |
175 { "defaultZoomFactorLabel", IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, | |
176 #if defined(OS_CHROMEOS) | |
177 { "disableGData", IDS_OPTIONS_DISABLE_GDATA }, | |
178 #endif | |
179 { "disableWebServices", IDS_OPTIONS_DISABLE_WEB_SERVICES }, | |
180 #if defined(OS_CHROMEOS) | |
181 { "displayOptionsButton", IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE }, | |
182 { "displayOptionsTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DISPLAY }, | |
183 #endif | |
184 { "downloadLocationAskForSaveLocation", | |
185 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION }, | |
186 { "downloadLocationBrowseTitle", | |
187 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE }, | |
188 { "downloadLocationChangeButton", | |
189 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON }, | |
190 { "downloadLocationGroupName", IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME }, | |
191 { "enableLogging", IDS_OPTIONS_ENABLE_LOGGING }, | |
192 { "fontSettingsCustomizeFontsButton", | |
193 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON }, | |
194 { "fontSizeLabelCustom", IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM }, | |
195 { "fontSizeLabelLarge", IDS_OPTIONS_FONT_SIZE_LABEL_LARGE }, | |
196 { "fontSizeLabelMedium", IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, | |
197 { "fontSizeLabelSmall", IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, | |
198 { "fontSizeLabelVeryLarge", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE }, | |
199 { "fontSizeLabelVerySmall", IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, | |
200 { "hideAdvancedSettings", IDS_SETTINGS_HIDE_ADVANCED_SETTINGS }, | |
201 { "homePageNtp", IDS_OPTIONS_HOMEPAGE_NTP }, | |
202 { "homePageShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, | |
203 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, | |
204 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, | |
205 { "instantConfirmMessage", IDS_INSTANT_OPT_IN_MESSAGE }, | |
206 { "instantConfirmTitle", IDS_INSTANT_OPT_IN_TITLE }, | |
207 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, | |
208 { "improveBrowsingExperience", IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE }, | |
209 { "languageAndSpellCheckSettingsButton", | |
210 #if defined(OS_CHROMEOS) | |
211 IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE }, | |
212 #else | |
213 IDS_OPTIONS_LANGUAGE_AND_SPELLCHECK_BUTTON }, | |
214 #endif | |
215 { "linkDoctorPref", IDS_OPTIONS_LINKDOCTOR_PREF }, | |
216 { "manageAutofillSettings", IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS_LINK }, | |
217 { "managePasswords", IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK }, | |
218 { "networkPredictionEnabledDescription", | |
219 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, | |
220 { "passwordsAndAutofillGroupName", | |
221 IDS_OPTIONS_PASSWORDS_AND_FORMS_GROUP_NAME }, | |
222 { "passwordManagerEnabled", IDS_OPTIONS_PASSWORD_MANAGER_ENABLE }, | |
223 { "passwordGenerationEnabledDescription", | |
224 IDS_OPTIONS_PASSWORD_GENERATION_ENABLED_LABEL }, | |
225 { "privacyClearDataButton", IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, | |
226 { "privacyContentSettingsButton", | |
227 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON }, | |
228 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL }, | |
229 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL }, | |
230 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL }, | |
231 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT }, | |
232 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL }, | |
233 { "proxiesLabel", IDS_OPTIONS_PROXIES_LABEL }, | |
234 { "safeBrowsingEnableProtection", | |
235 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION }, | |
236 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME }, | |
237 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME }, | |
238 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME }, | |
239 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME }, | |
240 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME }, | |
241 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME }, | |
242 { "sessionRestoreOverlayMessage", IDS_SESSION_RESTORE_OVERLAY_MESSAGE }, | |
243 { "sessionRestoreOverlayTitle", IDS_SESSION_RESTORE_OVERLAY_TITLE }, | |
244 { "spellingConfirmMessage", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_TEXT }, | |
245 { "spellingConfirmTitle", IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE }, | |
246 { "spellingConfirmEnable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_ENABLE }, | |
247 { "spellingConfirmDisable", IDS_CONTENT_CONTEXT_SPELLING_BUBBLE_DISABLE }, | |
248 { "spellingPref", IDS_OPTIONS_SPELLING_PREF }, | |
249 { "startupRestoreLastSession", IDS_OPTIONS_STARTUP_RESTORE_LAST_SESSION }, | |
250 { "settingsTitle", IDS_SETTINGS_TITLE }, | |
251 { "showAdvancedSettings", IDS_SETTINGS_SHOW_ADVANCED_SETTINGS }, | |
252 { "sslCheckRevocation", IDS_OPTIONS_SSL_CHECKREVOCATION }, | |
253 { "startupSetPages", IDS_OPTIONS2_STARTUP_SET_PAGES }, | |
254 { "startupShowNewTab", IDS_OPTIONS2_STARTUP_SHOW_NEWTAB }, | |
255 { "startupShowPages", IDS_OPTIONS2_STARTUP_SHOW_PAGES }, | |
256 { "suggestPref", IDS_OPTIONS_SUGGEST_PREF }, | |
257 { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS }, | |
258 { "syncButtonTextStop", IDS_SYNC_STOP_SYNCING_BUTTON_LABEL }, | |
259 { "themesGallery", IDS_THEMES_GALLERY_BUTTON }, | |
260 { "themesGalleryURL", IDS_THEMES_GALLERY_URL }, | |
261 { "tabsToLinksPref", IDS_OPTIONS_TABS_TO_LINKS_PREF }, | |
262 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR }, | |
263 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, | |
264 { "translateEnableTranslate", | |
265 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, | |
266 #if defined(TOOLKIT_GTK) | |
267 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS }, | |
268 { "themesGTKButton", IDS_THEMES_GTK_BUTTON }, | |
269 { "themesSetClassic", IDS_THEMES_SET_CLASSIC }, | |
270 #else | |
271 { "themes", IDS_THEMES_GROUP_NAME }, | |
272 { "themesReset", IDS_THEMES_RESET_BUTTON }, | |
273 #endif | |
274 #if defined(OS_CHROMEOS) | |
275 { "accessibilityHighContrast", | |
276 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION }, | |
277 { "accessibilityScreenMagnifier", | |
278 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION }, | |
279 { "accessibilitySpokenFeedback", | |
280 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION }, | |
281 { "accessibilityTitle", | |
282 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY }, | |
283 { "accessibilityVirtualKeyboard", | |
284 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION }, | |
285 { "changePicture", IDS_OPTIONS_CHANGE_PICTURE_CAPTION }, | |
286 { "datetimeTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME }, | |
287 { "deviceGroupDescription", IDS_OPTIONS_DEVICE_GROUP_DESCRIPTION }, | |
288 { "deviceGroupPointer", IDS_OPTIONS2_DEVICE_GROUP_POINTER_SECTION }, | |
289 { "mouseSpeed", IDS_OPTIONS2_SETTINGS_MOUSE_SPEED_DESCRIPTION }, | |
290 { "touchpadSpeed", IDS_OPTIONS2_SETTINGS_TOUCHPAD_SPEED_DESCRIPTION }, | |
291 { "enableScreenlock", IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX }, | |
292 { "internetOptionsButtonTitle", IDS_OPTIONS_INTERNET_OPTIONS_BUTTON_TITLE }, | |
293 { "keyboardSettingsButtonTitle", | |
294 IDS_OPTIONS2_DEVICE_GROUP_KEYBOARD_SETTINGS_BUTTON_TITLE }, | |
295 { "manageAccountsButtonTitle", IDS_OPTIONS_ACCOUNTS_BUTTON_TITLE }, | |
296 { "noPointingDevices", IDS_OPTIONS_NO_POINTING_DEVICES }, | |
297 { "sectionTitleDevice", IDS_OPTIONS_DEVICE_GROUP_NAME }, | |
298 { "sectionTitleInternet", IDS_OPTIONS_INTERNET_OPTIONS_GROUP_LABEL }, | |
299 { "syncOverview", IDS_SYNC_OVERVIEW }, | |
300 { "syncButtonTextStart", IDS_SYNC_SETUP_BUTTON_LABEL }, | |
301 { "timezone", IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION }, | |
302 { "use24HourClock", IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION }, | |
303 #else | |
304 { "cloudPrintConnectorEnabledManageButton", | |
305 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON}, | |
306 { "cloudPrintConnectorEnablingButton", | |
307 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON }, | |
308 { "proxiesConfigureButton", IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON }, | |
309 #endif | |
310 #if defined(OS_CHROMEOS) && defined(USE_ASH) | |
311 { "setWallpaper", IDS_SET_WALLPAPER_BUTTON }, | |
312 #endif | |
313 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
314 { "advancedSectionTitleBackground", | |
315 IDS_OPTIONS_ADVANCED_SECTION_TITLE_BACKGROUND }, | |
316 { "backgroundModeCheckbox", IDS_OPTIONS_BACKGROUND_ENABLE_BACKGROUND_MODE }, | |
317 #endif | |
318 }; | |
319 | |
320 RegisterStrings(values, resources, arraysize(resources)); | |
321 RegisterCloudPrintValues(values); | |
322 | |
323 #if !defined(OS_CHROMEOS) | |
324 values->SetString( | |
325 "syncOverview", | |
326 l10n_util::GetStringFUTF16(IDS_SYNC_OVERVIEW, | |
327 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
328 values->SetString( | |
329 "syncButtonTextStart", | |
330 l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, | |
331 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | |
332 #endif | |
333 | |
334 values->SetString("syncLearnMoreURL", chrome::kSyncLearnMoreURL); | |
335 values->SetString( | |
336 "profilesSingleUser", | |
337 l10n_util::GetStringFUTF16(IDS_PROFILES_SINGLE_USER_MESSAGE, | |
338 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
339 | |
340 string16 omnibox_url = ASCIIToUTF16(chrome::kOmniboxLearnMoreURL); | |
341 values->SetString( | |
342 "defaultSearchGroupLabel", | |
343 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url)); | |
344 | |
345 string16 instant_learn_more_url = ASCIIToUTF16(chrome::kInstantLearnMoreURL); | |
346 values->SetString( | |
347 "instantPrefAndWarning", | |
348 l10n_util::GetStringFUTF16(IDS_INSTANT_PREF_WITH_WARNING, | |
349 instant_learn_more_url)); | |
350 values->SetString("instantLearnMoreLink", instant_learn_more_url); | |
351 | |
352 values->SetString( | |
353 "defaultBrowserUnknown", | |
354 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, | |
355 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
356 values->SetString( | |
357 "defaultBrowserUseAsDefault", | |
358 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, | |
359 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
360 values->SetString( | |
361 "autoLaunchText", | |
362 l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT, | |
363 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
364 | |
365 #if defined(OS_CHROMEOS) | |
366 if (chromeos::UserManager::Get()->IsUserLoggedIn()) { | |
367 values->SetString("username", | |
368 chromeos::UserManager::Get()->GetLoggedInUser().email()); | |
369 } | |
370 #endif | |
371 | |
372 // Pass along sync status early so it will be available during page init. | |
373 values->Set("syncData", GetSyncStateDictionary().release()); | |
374 | |
375 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); | |
376 values->SetString("sessionRestoreLearnMoreURL", | |
377 chrome::kSessionRestoreLearnMoreURL); | |
378 | |
379 values->SetString( | |
380 "languageSectionLabel", | |
381 l10n_util::GetStringFUTF16( | |
382 IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, | |
383 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | |
384 | |
385 #if defined(OS_CHROMEOS) | |
386 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); | |
387 | |
388 // TODO(pastarmovj): replace this with a call to the CrosSettings list | |
389 // handling functionality to come. | |
390 values->Set("timezoneList", | |
391 static_cast<chromeos::SystemSettingsProvider*>( | |
392 chromeos::CrosSettings::Get()->GetProvider( | |
393 chromeos::kSystemTimezone))->GetTimezoneList()); | |
394 #endif | |
395 #if defined(OS_MACOSX) | |
396 values->SetString("macPasswordsWarning", | |
397 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); | |
398 values->SetBoolean("multiple_profiles", | |
399 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); | |
400 #endif | |
401 | |
402 if (multiprofile_) | |
403 values->Set("profilesInfo", GetProfilesInfoList().release()); | |
404 } | |
405 | |
406 void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) { | |
407 #if defined(OS_CHROMEOS) | |
408 values->SetString("cloudPrintChromeosOptionLabel", | |
409 l10n_util::GetStringFUTF16( | |
410 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, | |
411 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
412 values->SetString("cloudPrintChromeosOptionButton", | |
413 l10n_util::GetStringFUTF16( | |
414 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON, | |
415 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
416 #else | |
417 values->SetString("cloudPrintConnectorDisabledLabel", | |
418 l10n_util::GetStringFUTF16( | |
419 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, | |
420 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
421 values->SetString("cloudPrintConnectorDisabledButton", | |
422 l10n_util::GetStringUTF16( | |
423 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON)); | |
424 values->SetString("cloudPrintConnectorEnabledButton", | |
425 l10n_util::GetStringUTF16( | |
426 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON)); | |
427 #endif | |
428 } | |
429 | |
430 void BrowserOptionsHandler::RegisterMessages() { | |
431 web_ui()->RegisterMessageCallback( | |
432 "becomeDefaultBrowser", | |
433 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, | |
434 base::Unretained(this))); | |
435 web_ui()->RegisterMessageCallback( | |
436 "setDefaultSearchEngine", | |
437 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, | |
438 base::Unretained(this))); | |
439 web_ui()->RegisterMessageCallback( | |
440 "enableInstant", | |
441 base::Bind(&BrowserOptionsHandler::EnableInstant, | |
442 base::Unretained(this))); | |
443 web_ui()->RegisterMessageCallback( | |
444 "disableInstant", | |
445 base::Bind(&BrowserOptionsHandler::DisableInstant, | |
446 base::Unretained(this))); | |
447 web_ui()->RegisterMessageCallback( | |
448 "createProfile", | |
449 base::Bind(&BrowserOptionsHandler::CreateProfile, | |
450 base::Unretained(this))); | |
451 web_ui()->RegisterMessageCallback( | |
452 "createProfileInfo", | |
453 base::Bind(&BrowserOptionsHandler::CreateProfileInfo, | |
454 base::Unretained(this))); | |
455 web_ui()->RegisterMessageCallback( | |
456 "themesReset", | |
457 base::Bind(&BrowserOptionsHandler::ThemesReset, | |
458 base::Unretained(this))); | |
459 #if defined(TOOLKIT_GTK) | |
460 web_ui()->RegisterMessageCallback( | |
461 "themesSetGTK", | |
462 base::Bind(&BrowserOptionsHandler::ThemesSetGTK, | |
463 base::Unretained(this))); | |
464 #endif | |
465 web_ui()->RegisterMessageCallback( | |
466 "selectDownloadLocation", | |
467 base::Bind(&BrowserOptionsHandler::HandleSelectDownloadLocation, | |
468 base::Unretained(this))); | |
469 web_ui()->RegisterMessageCallback( | |
470 "autoOpenFileTypesAction", | |
471 base::Bind(&BrowserOptionsHandler::HandleAutoOpenButton, | |
472 base::Unretained(this))); | |
473 web_ui()->RegisterMessageCallback( | |
474 "defaultFontSizeAction", | |
475 base::Bind(&BrowserOptionsHandler::HandleDefaultFontSize, | |
476 base::Unretained(this))); | |
477 web_ui()->RegisterMessageCallback( | |
478 "defaultZoomFactorAction", | |
479 base::Bind(&BrowserOptionsHandler::HandleDefaultZoomFactor, | |
480 base::Unretained(this))); | |
481 #if !defined(OS_CHROMEOS) | |
482 web_ui()->RegisterMessageCallback( | |
483 "metricsReportingCheckboxAction", | |
484 base::Bind(&BrowserOptionsHandler::HandleMetricsReportingCheckbox, | |
485 base::Unretained(this))); | |
486 #endif | |
487 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
488 web_ui()->RegisterMessageCallback( | |
489 "showManageSSLCertificates", | |
490 base::Bind(&BrowserOptionsHandler::ShowManageSSLCertificates, | |
491 base::Unretained(this))); | |
492 #endif | |
493 web_ui()->RegisterMessageCallback( | |
494 "showCloudPrintManagePage", | |
495 base::Bind(&BrowserOptionsHandler::ShowCloudPrintManagePage, | |
496 base::Unretained(this))); | |
497 #if !defined(OS_CHROMEOS) | |
498 if (cloud_print_connector_ui_enabled_) { | |
499 web_ui()->RegisterMessageCallback( | |
500 "showCloudPrintSetupDialog", | |
501 base::Bind(&BrowserOptionsHandler::ShowCloudPrintSetupDialog, | |
502 base::Unretained(this))); | |
503 web_ui()->RegisterMessageCallback( | |
504 "disableCloudPrintConnector", | |
505 base::Bind(&BrowserOptionsHandler::HandleDisableCloudPrintConnector, | |
506 base::Unretained(this))); | |
507 } | |
508 web_ui()->RegisterMessageCallback( | |
509 "showNetworkProxySettings", | |
510 base::Bind(&BrowserOptionsHandler::ShowNetworkProxySettings, | |
511 base::Unretained(this))); | |
512 #endif | |
513 web_ui()->RegisterMessageCallback( | |
514 "checkRevocationCheckboxAction", | |
515 base::Bind(&BrowserOptionsHandler::HandleCheckRevocationCheckbox, | |
516 base::Unretained(this))); | |
517 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
518 web_ui()->RegisterMessageCallback( | |
519 "backgroundModeAction", | |
520 base::Bind(&BrowserOptionsHandler::HandleBackgroundModeCheckbox, | |
521 base::Unretained(this))); | |
522 #endif | |
523 #if defined(OS_CHROMEOS) | |
524 web_ui()->RegisterMessageCallback( | |
525 "spokenFeedbackChange", | |
526 base::Bind(&BrowserOptionsHandler::SpokenFeedbackChangeCallback, | |
527 base::Unretained(this))); | |
528 web_ui()->RegisterMessageCallback( | |
529 "highContrastChange", | |
530 base::Bind(&BrowserOptionsHandler::HighContrastChangeCallback, | |
531 base::Unretained(this))); | |
532 web_ui()->RegisterMessageCallback( | |
533 "screenMagnifierChange", | |
534 base::Bind(&BrowserOptionsHandler::ScreenMagnifierChangeCallback, | |
535 base::Unretained(this))); | |
536 web_ui()->RegisterMessageCallback( | |
537 "virtualKeyboardChange", | |
538 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback, | |
539 base::Unretained(this))); | |
540 #endif | |
541 } | |
542 | |
543 void BrowserOptionsHandler::OnStateChanged() { | |
544 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", | |
545 *GetSyncStateDictionary()); | |
546 | |
547 SendProfilesInfo(); | |
548 } | |
549 | |
550 void BrowserOptionsHandler::InitializeHandler() { | |
551 Profile* profile = Profile::FromWebUI(web_ui()); | |
552 PrefService* prefs = profile->GetPrefs(); | |
553 | |
554 ProfileSyncService* sync_service( | |
555 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); | |
556 if (sync_service) | |
557 sync_service->AddObserver(this); | |
558 | |
559 // Create our favicon data source. | |
560 ChromeURLDataManager::AddDataSource(profile, | |
561 new FaviconSource(profile, FaviconSource::FAVICON)); | |
562 | |
563 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, | |
564 g_browser_process->local_state(), | |
565 this); | |
566 | |
567 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
568 content::NotificationService::AllSources()); | |
569 #if defined(OS_CHROMEOS) | |
570 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | |
571 content::NotificationService::AllSources()); | |
572 #endif | |
573 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
574 content::Source<ThemeService>( | |
575 ThemeServiceFactory::GetForProfile(profile))); | |
576 | |
577 AddTemplateUrlServiceObserver(); | |
578 | |
579 #if defined(OS_WIN) | |
580 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
581 if (!command_line.HasSwitch(switches::kChromeFrame) && | |
582 !command_line.HasSwitch(switches::kUserDataDir)) { | |
583 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
584 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, | |
585 weak_ptr_factory_for_ui_.GetWeakPtr(), | |
586 weak_ptr_factory_for_file_.GetWeakPtr(), | |
587 profile->GetPath())); | |
588 weak_ptr_factory_for_ui_.DetachFromThread(); | |
589 } | |
590 #endif | |
591 | |
592 #if !defined(OS_CHROMEOS) | |
593 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, | |
594 g_browser_process->local_state(), this); | |
595 cloud_print_connector_email_.Init(prefs::kCloudPrintEmail, prefs, this); | |
596 cloud_print_connector_enabled_.Init(prefs::kCloudPrintProxyEnabled, prefs, | |
597 this); | |
598 #endif | |
599 | |
600 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, | |
601 g_browser_process->local_state(), this); | |
602 | |
603 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
604 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, | |
605 g_browser_process->local_state(), this); | |
606 #endif | |
607 | |
608 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); | |
609 default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); | |
610 default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this); | |
611 #if !defined(OS_CHROMEOS) | |
612 proxy_prefs_.reset( | |
613 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); | |
614 #endif // !defined(OS_CHROMEOS) | |
615 } | |
616 | |
617 void BrowserOptionsHandler::InitializePage() { | |
618 OnTemplateURLServiceChanged(); | |
619 ObserveThemeChanged(); | |
620 OnStateChanged(); | |
621 UpdateDefaultBrowserState(); | |
622 | |
623 SetupMetricsReportingCheckbox(); | |
624 SetupMetricsReportingSettingVisibility(); | |
625 SetupPasswordGenerationSettingVisibility(); | |
626 SetupFontSizeSelector(); | |
627 SetupPageZoomSelector(); | |
628 SetupAutoOpenFileTypes(); | |
629 SetupProxySettingsSection(); | |
630 SetupSSLConfigSettings(); | |
631 #if !defined(OS_CHROMEOS) | |
632 if (cloud_print_connector_ui_enabled_) { | |
633 SetupCloudPrintConnectorSection(); | |
634 RefreshCloudPrintStatusFromService(); | |
635 } else { | |
636 RemoveCloudPrintConnectorSection(); | |
637 } | |
638 #endif | |
639 #if defined(OS_CHROMEOS) | |
640 SetupAccessibilityFeatures(); | |
641 #endif | |
642 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
643 SetupBackgroundModeSettings(); | |
644 #endif | |
645 } | |
646 | |
647 void BrowserOptionsHandler::CheckAutoLaunch( | |
648 base::WeakPtr<BrowserOptionsHandler> weak_this, | |
649 const FilePath& profile_path) { | |
650 #if defined(OS_WIN) | |
651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
652 | |
653 // Auto-launch is not supported for secondary profiles yet. | |
654 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile)) | |
655 return; | |
656 | |
657 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is | |
658 // deleted. | |
659 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
660 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, | |
661 weak_this, | |
662 auto_launch_trial::IsInAutoLaunchGroup(), | |
663 auto_launch_util::AutoStartRequested( | |
664 profile_path.BaseName().value(), | |
665 true, // Window requested. | |
666 FilePath()))); | |
667 #endif | |
668 } | |
669 | |
670 void BrowserOptionsHandler::CheckAutoLaunchCallback( | |
671 bool is_in_auto_launch_group, | |
672 bool will_launch_at_login) { | |
673 #if defined(OS_WIN) | |
674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
675 | |
676 if (is_in_auto_launch_group) { | |
677 web_ui()->RegisterMessageCallback("toggleAutoLaunch", | |
678 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, | |
679 base::Unretained(this))); | |
680 | |
681 base::FundamentalValue enabled(will_launch_at_login); | |
682 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", | |
683 enabled); | |
684 } | |
685 #endif | |
686 } | |
687 | |
688 void BrowserOptionsHandler::UpdateDefaultBrowserState() { | |
689 // Check for side-by-side first. | |
690 if (ShellIntegration::CanSetAsDefaultBrowser() == | |
691 ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { | |
692 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); | |
693 return; | |
694 } | |
695 | |
696 #if defined(OS_MACOSX) | |
697 ShellIntegration::DefaultWebClientState state = | |
698 ShellIntegration::IsDefaultBrowser(); | |
699 int status_string_id; | |
700 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT) | |
701 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; | |
702 else if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT) | |
703 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; | |
704 else | |
705 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; | |
706 | |
707 SetDefaultBrowserUIString(status_string_id); | |
708 #else | |
709 default_browser_worker_->StartCheckIsDefault(); | |
710 #endif | |
711 } | |
712 | |
713 void BrowserOptionsHandler::BecomeDefaultBrowser(const ListValue* args) { | |
714 // If the default browser setting is managed then we should not be able to | |
715 // call this function. | |
716 if (default_browser_policy_.IsManaged()) | |
717 return; | |
718 | |
719 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser")); | |
720 #if defined(OS_MACOSX) | |
721 if (ShellIntegration::SetAsDefaultBrowser()) | |
722 UpdateDefaultBrowserState(); | |
723 #else | |
724 default_browser_worker_->StartSetAsDefault(); | |
725 // Callback takes care of updating UI. | |
726 #endif | |
727 | |
728 // If the user attempted to make Chrome the default browser, then he/she | |
729 // arguably wants to be notified when that changes. | |
730 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | |
731 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); | |
732 } | |
733 | |
734 int BrowserOptionsHandler::StatusStringIdForState( | |
735 ShellIntegration::DefaultWebClientState state) { | |
736 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT) | |
737 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; | |
738 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT) | |
739 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; | |
740 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; | |
741 } | |
742 | |
743 void BrowserOptionsHandler::SetDefaultWebClientUIState( | |
744 ShellIntegration::DefaultWebClientUIState state) { | |
745 int status_string_id; | |
746 if (state == ShellIntegration::STATE_IS_DEFAULT) | |
747 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; | |
748 else if (state == ShellIntegration::STATE_NOT_DEFAULT) | |
749 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; | |
750 else if (state == ShellIntegration::STATE_UNKNOWN) | |
751 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; | |
752 else | |
753 return; // Still processing. | |
754 | |
755 SetDefaultBrowserUIString(status_string_id); | |
756 } | |
757 | |
758 bool BrowserOptionsHandler::IsInteractiveSetDefaultPermitted() { | |
759 return true; // This is UI so we can allow it. | |
760 } | |
761 | |
762 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) { | |
763 scoped_ptr<Value> status_string(Value::CreateStringValue( | |
764 l10n_util::GetStringFUTF16(status_string_id, | |
765 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); | |
766 | |
767 scoped_ptr<Value> is_default(Value::CreateBooleanValue( | |
768 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT)); | |
769 | |
770 scoped_ptr<Value> can_be_default(Value::CreateBooleanValue( | |
771 !default_browser_policy_.IsManaged() && | |
772 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT || | |
773 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT))); | |
774 | |
775 web_ui()->CallJavascriptFunction( | |
776 "BrowserOptions.updateDefaultBrowserState", | |
777 *status_string, *is_default, *can_be_default); | |
778 } | |
779 | |
780 void BrowserOptionsHandler::OnTemplateURLServiceChanged() { | |
781 if (!template_url_service_ || !template_url_service_->loaded()) | |
782 return; | |
783 | |
784 const TemplateURL* default_url = | |
785 template_url_service_->GetDefaultSearchProvider(); | |
786 | |
787 int default_index = 0; | |
788 ListValue search_engines; | |
789 TemplateURLService::TemplateURLVector model_urls( | |
790 template_url_service_->GetTemplateURLs()); | |
791 for (size_t i = 0; i < model_urls.size(); ++i) { | |
792 if (!model_urls[i]->ShowInDefaultList()) | |
793 continue; | |
794 | |
795 DictionaryValue* entry = new DictionaryValue(); | |
796 entry->SetString("name", model_urls[i]->short_name()); | |
797 entry->SetInteger("index", i); | |
798 search_engines.Append(entry); | |
799 if (model_urls[i] == default_url) | |
800 default_index = i; | |
801 } | |
802 | |
803 scoped_ptr<Value> default_value(Value::CreateIntegerValue(default_index)); | |
804 scoped_ptr<Value> default_managed(Value::CreateBooleanValue( | |
805 template_url_service_->is_default_search_managed())); | |
806 | |
807 web_ui()->CallJavascriptFunction("BrowserOptions.updateSearchEngines", | |
808 search_engines, *default_value, | |
809 *default_managed); | |
810 } | |
811 | |
812 void BrowserOptionsHandler::SetDefaultSearchEngine(const ListValue* args) { | |
813 int selected_index = -1; | |
814 if (!ExtractIntegerValue(args, &selected_index)) { | |
815 NOTREACHED(); | |
816 return; | |
817 } | |
818 | |
819 TemplateURLService::TemplateURLVector model_urls( | |
820 template_url_service_->GetTemplateURLs()); | |
821 if (selected_index >= 0 && | |
822 selected_index < static_cast<int>(model_urls.size())) | |
823 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); | |
824 | |
825 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); | |
826 } | |
827 | |
828 void BrowserOptionsHandler::AddTemplateUrlServiceObserver() { | |
829 template_url_service_ = | |
830 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | |
831 if (template_url_service_) { | |
832 template_url_service_->Load(); | |
833 template_url_service_->AddObserver(this); | |
834 } | |
835 } | |
836 | |
837 void BrowserOptionsHandler::Observe( | |
838 int type, | |
839 const content::NotificationSource& source, | |
840 const content::NotificationDetails& details) { | |
841 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { | |
842 ObserveThemeChanged(); | |
843 #if defined(OS_CHROMEOS) | |
844 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { | |
845 UpdateAccountPicture(); | |
846 #endif | |
847 } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
848 std::string* pref_name = content::Details<std::string>(details).ptr(); | |
849 if (*pref_name == prefs::kDefaultBrowserSettingEnabled) { | |
850 UpdateDefaultBrowserState(); | |
851 } else if (*pref_name == prefs::kDownloadExtensionsToOpen) { | |
852 SetupAutoOpenFileTypes(); | |
853 #if !defined(OS_CHROMEOS) | |
854 } else if (proxy_prefs_->IsObserved(*pref_name)) { | |
855 SetupProxySettingsSection(); | |
856 #endif // !defined(OS_CHROMEOS) | |
857 } else if ((*pref_name == prefs::kCloudPrintEmail) || | |
858 (*pref_name == prefs::kCloudPrintProxyEnabled)) { | |
859 #if !defined(OS_CHROMEOS) | |
860 if (cloud_print_connector_ui_enabled_) | |
861 SetupCloudPrintConnectorSection(); | |
862 #endif | |
863 } else if (*pref_name == prefs::kWebKitDefaultFontSize) { | |
864 SetupFontSizeSelector(); | |
865 } else if (*pref_name == prefs::kDefaultZoomLevel) { | |
866 SetupPageZoomSelector(); | |
867 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
868 } else if (*pref_name == prefs::kBackgroundModeEnabled) { | |
869 SetupBackgroundModeSettings(); | |
870 #endif | |
871 } else { | |
872 NOTREACHED(); | |
873 } | |
874 } else if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { | |
875 if (multiprofile_) | |
876 SendProfilesInfo(); | |
877 } else { | |
878 NOTREACHED(); | |
879 } | |
880 } | |
881 | |
882 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | |
883 InstantController::Enable(Profile::FromWebUI(web_ui())); | |
884 } | |
885 | |
886 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | |
887 InstantController::Disable(Profile::FromWebUI(web_ui())); | |
888 } | |
889 | |
890 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { | |
891 #if defined(OS_WIN) | |
892 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
893 return; | |
894 | |
895 bool enable; | |
896 CHECK_EQ(args->GetSize(), 1U); | |
897 CHECK(args->GetBoolean(0, &enable)); | |
898 | |
899 // Make sure we keep track of how many disable and how many enable. | |
900 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); | |
901 Profile* profile = Profile::FromWebUI(web_ui()); | |
902 content::BrowserThread::PostTask( | |
903 content::BrowserThread::FILE, FROM_HERE, | |
904 enable ? base::Bind(&auto_launch_util::EnableForegroundStartAtLogin, | |
905 profile->GetPath().BaseName().value(), FilePath()) : | |
906 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin, | |
907 profile->GetPath().BaseName().value())); | |
908 #endif // OS_WIN | |
909 } | |
910 | |
911 scoped_ptr<ListValue> BrowserOptionsHandler::GetProfilesInfoList() { | |
912 ProfileInfoCache& cache = | |
913 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
914 scoped_ptr<ListValue> profile_info_list(new ListValue); | |
915 FilePath current_profile_path = | |
916 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | |
917 | |
918 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | |
919 DictionaryValue* profile_value = new DictionaryValue(); | |
920 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); | |
921 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); | |
922 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); | |
923 profile_value->SetBoolean("isCurrentProfile", | |
924 profile_path == current_profile_path); | |
925 | |
926 bool is_gaia_picture = | |
927 cache.IsUsingGAIAPictureOfProfileAtIndex(i) && | |
928 cache.GetGAIAPictureOfProfileAtIndex(i); | |
929 if (is_gaia_picture) { | |
930 gfx::Image icon = profiles::GetAvatarIconForWebUI( | |
931 cache.GetAvatarIconOfProfileAtIndex(i), true); | |
932 profile_value->SetString("iconURL", | |
933 web_ui_util::GetImageDataUrl(*icon.ToImageSkia())); | |
934 } else { | |
935 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); | |
936 profile_value->SetString("iconURL", | |
937 cache.GetDefaultAvatarIconUrl(icon_index)); | |
938 } | |
939 | |
940 profile_info_list->Append(profile_value); | |
941 } | |
942 | |
943 return profile_info_list.Pass(); | |
944 } | |
945 | |
946 void BrowserOptionsHandler::SendProfilesInfo() { | |
947 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo", | |
948 *GetProfilesInfoList()); | |
949 } | |
950 | |
951 void BrowserOptionsHandler::CreateProfile(const ListValue* args) { | |
952 // This handler could have been called in managed mode, for example because | |
953 // the user fiddled with the web inspector. Silently return in this case. | |
954 if (!ProfileManager::IsMultipleProfilesEnabled()) | |
955 return; | |
956 string16 name, icon; | |
957 if (args->GetString(0, &name) && args->GetString(1, &icon)) | |
958 ProfileManager::CreateMultiProfileAsync(name, icon); | |
959 else | |
960 ProfileManager::CreateMultiProfileAsync(string16(), string16()); | |
961 } | |
962 | |
963 void BrowserOptionsHandler::CreateProfileInfo(const ListValue* args) { | |
964 DictionaryValue* profile_info = new DictionaryValue(); | |
965 ProfileInfoCache& cache = | |
966 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
967 | |
968 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); | |
969 | |
970 profile_info->SetString("name", cache.ChooseNameForNewProfile(icon_index)); | |
971 profile_info->SetString("iconURL", cache.GetDefaultAvatarIconUrl( | |
972 icon_index)); | |
973 | |
974 web_ui()->CallJavascriptFunction("ManageProfileOverlay.showCreateDialog", | |
975 *profile_info); | |
976 } | |
977 | |
978 void BrowserOptionsHandler::ObserveThemeChanged() { | |
979 Profile* profile = Profile::FromWebUI(web_ui()); | |
980 #if defined(TOOLKIT_GTK) | |
981 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); | |
982 bool is_gtk_theme = theme_service->UsingNativeTheme(); | |
983 base::FundamentalValue gtk_enabled(!is_gtk_theme); | |
984 web_ui()->CallJavascriptFunction("BrowserOptions.setGtkThemeButtonEnabled", | |
985 gtk_enabled); | |
986 #else | |
987 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | |
988 bool is_gtk_theme = false; | |
989 #endif | |
990 | |
991 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); | |
992 base::FundamentalValue enabled(!is_classic_theme); | |
993 web_ui()->CallJavascriptFunction("BrowserOptions.setThemesResetButtonEnabled", | |
994 enabled); | |
995 } | |
996 | |
997 void BrowserOptionsHandler::ThemesReset(const ListValue* args) { | |
998 content::RecordAction(UserMetricsAction("Options_ThemesReset")); | |
999 Profile* profile = Profile::FromWebUI(web_ui()); | |
1000 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); | |
1001 } | |
1002 | |
1003 #if defined(TOOLKIT_GTK) | |
1004 void BrowserOptionsHandler::ThemesSetGTK(const ListValue* args) { | |
1005 content::RecordAction(UserMetricsAction("Options_GtkThemeSet")); | |
1006 Profile* profile = Profile::FromWebUI(web_ui()); | |
1007 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); | |
1008 } | |
1009 #endif | |
1010 | |
1011 #if defined(OS_CHROMEOS) | |
1012 void BrowserOptionsHandler::UpdateAccountPicture() { | |
1013 std::string email = chromeos::UserManager::Get()->GetLoggedInUser().email(); | |
1014 if (!email.empty()) { | |
1015 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture"); | |
1016 base::StringValue email_value(email); | |
1017 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", | |
1018 email_value); | |
1019 } | |
1020 } | |
1021 #endif | |
1022 | |
1023 scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { | |
1024 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); | |
1025 ProfileSyncService* service(ProfileSyncServiceFactory:: | |
1026 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); | |
1027 sync_status->SetBoolean("syncSystemEnabled", !!service); | |
1028 if (!service) | |
1029 return sync_status.Pass(); | |
1030 | |
1031 sync_status->SetBoolean("setupCompleted", | |
1032 service->HasSyncSetupCompleted()); | |
1033 sync_status->SetBoolean("setupInProgress", service->FirstSetupInProgress()); | |
1034 | |
1035 string16 status_label; | |
1036 string16 link_label; | |
1037 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
1038 Profile::FromWebUI(web_ui())); | |
1039 | |
1040 bool status_has_error = sync_ui_util::GetStatusLabels( | |
1041 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == | |
1042 sync_ui_util::SYNC_ERROR; | |
1043 sync_status->SetString("statusText", status_label); | |
1044 sync_status->SetString("actionLinkText", link_label); | |
1045 sync_status->SetBoolean("hasError", status_has_error); | |
1046 | |
1047 sync_status->SetBoolean("managed", service->IsManaged()); | |
1048 sync_status->SetBoolean("hasUnrecoverableError", | |
1049 service->HasUnrecoverableError()); | |
1050 sync_status->SetBoolean( | |
1051 "autoLoginVisible", | |
1052 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) && | |
1053 service->IsSyncEnabledAndLoggedIn() && service->IsSyncTokenAvailable()); | |
1054 | |
1055 return sync_status.Pass(); | |
1056 } | |
1057 | |
1058 void BrowserOptionsHandler::HandleSelectDownloadLocation( | |
1059 const ListValue* args) { | |
1060 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
1061 select_folder_dialog_ = SelectFileDialog::Create( | |
1062 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | |
1063 select_folder_dialog_->SelectFile( | |
1064 SelectFileDialog::SELECT_FOLDER, | |
1065 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), | |
1066 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), | |
1067 NULL, 0, FILE_PATH_LITERAL(""), | |
1068 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | |
1069 } | |
1070 | |
1071 void BrowserOptionsHandler::FileSelected(const FilePath& path, int index, | |
1072 void* params) { | |
1073 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); | |
1074 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
1075 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); | |
1076 } | |
1077 | |
1078 void BrowserOptionsHandler::OnCloudPrintSetupClosed() { | |
1079 #if !defined(OS_CHROMEOS) | |
1080 if (cloud_print_connector_ui_enabled_) | |
1081 SetupCloudPrintConnectorSection(); | |
1082 #endif | |
1083 } | |
1084 | |
1085 #if defined(OS_CHROMEOS) | |
1086 void BrowserOptionsHandler::TouchpadExists(bool exists) { | |
1087 base::FundamentalValue val(exists); | |
1088 web_ui()->CallJavascriptFunction("BrowserOptions.showTouchpadControls", val); | |
1089 } | |
1090 | |
1091 void BrowserOptionsHandler::MouseExists(bool exists) { | |
1092 base::FundamentalValue val(exists); | |
1093 web_ui()->CallJavascriptFunction("BrowserOptions.showMouseControls", val); | |
1094 } | |
1095 #endif | |
1096 | |
1097 void BrowserOptionsHandler::HandleAutoOpenButton(const ListValue* args) { | |
1098 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | |
1099 DownloadManager* manager = BrowserContext::GetDownloadManager( | |
1100 web_ui()->GetWebContents()->GetBrowserContext()); | |
1101 if (manager) | |
1102 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | |
1103 } | |
1104 | |
1105 void BrowserOptionsHandler::HandleMetricsReportingCheckbox( | |
1106 const ListValue* args) { | |
1107 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
1108 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
1109 bool enabled = checked_str == "true"; | |
1110 content::RecordAction( | |
1111 enabled ? | |
1112 UserMetricsAction("Options_MetricsReportingCheckbox_Enable") : | |
1113 UserMetricsAction("Options_MetricsReportingCheckbox_Disable")); | |
1114 bool is_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); | |
1115 enable_metrics_recording_.SetValue(is_enabled); | |
1116 SetupMetricsReportingCheckbox(); | |
1117 #endif | |
1118 } | |
1119 | |
1120 void BrowserOptionsHandler::HandleDefaultFontSize(const ListValue* args) { | |
1121 int font_size; | |
1122 if (ExtractIntegerValue(args, &font_size)) { | |
1123 if (font_size > 0) { | |
1124 default_font_size_.SetValue(font_size); | |
1125 SetupFontSizeSelector(); | |
1126 } | |
1127 } | |
1128 } | |
1129 | |
1130 void BrowserOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { | |
1131 double zoom_factor; | |
1132 if (ExtractDoubleValue(args, &zoom_factor)) { | |
1133 default_zoom_level_.SetValue( | |
1134 WebKit::WebView::zoomFactorToZoomLevel(zoom_factor)); | |
1135 } | |
1136 } | |
1137 | |
1138 void BrowserOptionsHandler::HandleCheckRevocationCheckbox( | |
1139 const ListValue* args) { | |
1140 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
1141 bool enabled = checked_str == "true"; | |
1142 content::RecordAction( | |
1143 enabled ? | |
1144 UserMetricsAction("Options_CheckCertRevocation_Enable") : | |
1145 UserMetricsAction("Options_CheckCertRevocation_Disable")); | |
1146 rev_checking_enabled_.SetValue(enabled); | |
1147 } | |
1148 | |
1149 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
1150 void BrowserOptionsHandler::HandleBackgroundModeCheckbox( | |
1151 const ListValue* args) { | |
1152 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
1153 bool enabled = checked_str == "true"; | |
1154 content::RecordAction( | |
1155 enabled ? | |
1156 UserMetricsAction("Options_BackgroundMode_Enable") : | |
1157 UserMetricsAction("Options_BackgroundMode_Disable")); | |
1158 background_mode_enabled_.SetValue(enabled); | |
1159 } | |
1160 | |
1161 void BrowserOptionsHandler::SetupBackgroundModeSettings() { | |
1162 base::FundamentalValue checked(background_mode_enabled_.GetValue()); | |
1163 PrefService* service = g_browser_process->local_state(); | |
1164 DCHECK(service); | |
1165 const PrefService::Preference* pref = | |
1166 service->FindPreference(prefs::kBackgroundModeEnabled); | |
1167 DCHECK(pref); | |
1168 base::FundamentalValue disabled(!pref->IsUserModifiable()); | |
1169 std::string controlled_by_str; | |
1170 if (pref->IsManaged()) | |
1171 controlled_by_str = "policy"; | |
1172 else if (pref->IsExtensionControlled()) | |
1173 controlled_by_str = "extension"; | |
1174 else if (pref->IsRecommended()) | |
1175 controlled_by_str = "recommended"; | |
1176 base::StringValue controlled_by(controlled_by_str); | |
1177 web_ui()->CallJavascriptFunction( | |
1178 "BrowserOptions.setBackgroundModeCheckboxState", | |
1179 checked, | |
1180 disabled, | |
1181 controlled_by); | |
1182 } | |
1183 #endif | |
1184 | |
1185 #if !defined(OS_CHROMEOS) | |
1186 void BrowserOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { | |
1187 content::RecordAction(UserMetricsAction("Options_ShowProxySettings")); | |
1188 AdvancedOptionsUtilities::ShowNetworkProxySettings( | |
1189 web_ui()->GetWebContents()); | |
1190 } | |
1191 #endif | |
1192 | |
1193 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
1194 void BrowserOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { | |
1195 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); | |
1196 AdvancedOptionsUtilities::ShowManageSSLCertificates( | |
1197 web_ui()->GetWebContents()); | |
1198 } | |
1199 #endif | |
1200 | |
1201 void BrowserOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { | |
1202 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); | |
1203 // Open a new tab in the current window for the management page. | |
1204 Profile* profile = Profile::FromWebUI(web_ui()); | |
1205 OpenURLParams params( | |
1206 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), Referrer(), | |
1207 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | |
1208 web_ui()->GetWebContents()->OpenURL(params); | |
1209 } | |
1210 | |
1211 #if !defined(OS_CHROMEOS) | |
1212 void BrowserOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { | |
1213 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); | |
1214 // Open the connector enable page in the current tab. | |
1215 Profile* profile = Profile::FromWebUI(web_ui()); | |
1216 OpenURLParams params( | |
1217 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( | |
1218 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), | |
1219 Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | |
1220 web_ui()->GetWebContents()->OpenURL(params); | |
1221 } | |
1222 | |
1223 void BrowserOptionsHandler::HandleDisableCloudPrintConnector( | |
1224 const ListValue* args) { | |
1225 content::RecordAction( | |
1226 UserMetricsAction("Options_DisableCloudPrintProxy")); | |
1227 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | |
1228 DisableForUser(); | |
1229 } | |
1230 | |
1231 void BrowserOptionsHandler::RefreshCloudPrintStatusFromService() { | |
1232 if (cloud_print_connector_ui_enabled_) | |
1233 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | |
1234 RefreshStatusFromService(); | |
1235 } | |
1236 | |
1237 void BrowserOptionsHandler::SetupCloudPrintConnectorSection() { | |
1238 Profile* profile = Profile::FromWebUI(web_ui()); | |
1239 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { | |
1240 cloud_print_connector_ui_enabled_ = false; | |
1241 RemoveCloudPrintConnectorSection(); | |
1242 return; | |
1243 } | |
1244 | |
1245 bool cloud_print_connector_allowed = | |
1246 !cloud_print_connector_enabled_.IsManaged() || | |
1247 cloud_print_connector_enabled_.GetValue(); | |
1248 base::FundamentalValue allowed(cloud_print_connector_allowed); | |
1249 | |
1250 std::string email; | |
1251 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && | |
1252 cloud_print_connector_allowed) { | |
1253 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); | |
1254 } | |
1255 base::FundamentalValue disabled(email.empty()); | |
1256 | |
1257 string16 label_str; | |
1258 if (email.empty()) { | |
1259 label_str = l10n_util::GetStringFUTF16( | |
1260 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, | |
1261 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | |
1262 } else { | |
1263 label_str = l10n_util::GetStringFUTF16( | |
1264 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, | |
1265 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), | |
1266 UTF8ToUTF16(email)); | |
1267 } | |
1268 StringValue label(label_str); | |
1269 | |
1270 web_ui()->CallJavascriptFunction( | |
1271 "BrowserOptions.setupCloudPrintConnectorSection", disabled, label, | |
1272 allowed); | |
1273 } | |
1274 | |
1275 void BrowserOptionsHandler::RemoveCloudPrintConnectorSection() { | |
1276 web_ui()->CallJavascriptFunction( | |
1277 "BrowserOptions.removeCloudPrintConnectorSection"); | |
1278 } | |
1279 #endif | |
1280 | |
1281 #if defined(OS_CHROMEOS) | |
1282 void BrowserOptionsHandler::SpokenFeedbackChangeCallback( | |
1283 const ListValue* args) { | |
1284 bool enabled = false; | |
1285 args->GetBoolean(0, &enabled); | |
1286 | |
1287 chromeos::accessibility::EnableSpokenFeedback(enabled, NULL); | |
1288 } | |
1289 | |
1290 void BrowserOptionsHandler::HighContrastChangeCallback(const ListValue* args) { | |
1291 bool enabled = false; | |
1292 args->GetBoolean(0, &enabled); | |
1293 | |
1294 chromeos::accessibility::EnableHighContrast(enabled); | |
1295 } | |
1296 | |
1297 void BrowserOptionsHandler::ScreenMagnifierChangeCallback( | |
1298 const ListValue* args) { | |
1299 bool enabled = false; | |
1300 args->GetBoolean(0, &enabled); | |
1301 | |
1302 chromeos::accessibility::EnableScreenMagnifier(enabled); | |
1303 } | |
1304 | |
1305 void BrowserOptionsHandler::VirtualKeyboardChangeCallback( | |
1306 const ListValue* args) { | |
1307 bool enabled = false; | |
1308 args->GetBoolean(0, &enabled); | |
1309 | |
1310 chromeos::accessibility::EnableVirtualKeyboard(enabled); | |
1311 } | |
1312 | |
1313 void BrowserOptionsHandler::SetupAccessibilityFeatures() { | |
1314 PrefService* pref_service = g_browser_process->local_state(); | |
1315 base::FundamentalValue spoken_feedback_enabled( | |
1316 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled)); | |
1317 web_ui()->CallJavascriptFunction( | |
1318 "BrowserOptions.setSpokenFeedbackCheckboxState", | |
1319 spoken_feedback_enabled); | |
1320 base::FundamentalValue high_contrast_enabled( | |
1321 pref_service->GetBoolean(prefs::kHighContrastEnabled)); | |
1322 web_ui()->CallJavascriptFunction( | |
1323 "BrowserOptions.setHighContrastCheckboxState", | |
1324 high_contrast_enabled); | |
1325 base::FundamentalValue screen_magnifier_enabled( | |
1326 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled)); | |
1327 web_ui()->CallJavascriptFunction( | |
1328 "BrowserOptions.setScreenMagnifierCheckboxState", | |
1329 screen_magnifier_enabled); | |
1330 base::FundamentalValue virtual_keyboard_enabled( | |
1331 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled)); | |
1332 web_ui()->CallJavascriptFunction( | |
1333 "BrowserOptions.setVirtualKeyboardCheckboxState", | |
1334 virtual_keyboard_enabled); | |
1335 } | |
1336 #endif | |
1337 | |
1338 void BrowserOptionsHandler::SetupMetricsReportingCheckbox() { | |
1339 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
1340 base::FundamentalValue checked(enable_metrics_recording_.GetValue()); | |
1341 base::FundamentalValue disabled(enable_metrics_recording_.IsManaged()); | |
1342 web_ui()->CallJavascriptFunction( | |
1343 "BrowserOptions.setMetricsReportingCheckboxState", checked, disabled); | |
1344 #endif | |
1345 } | |
1346 | |
1347 void BrowserOptionsHandler::SetupMetricsReportingSettingVisibility() { | |
1348 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) | |
1349 // Don't show the reporting setting if we are in the guest mode. | |
1350 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | |
1351 base::FundamentalValue visible(false); | |
1352 web_ui()->CallJavascriptFunction( | |
1353 "BrowserOptions.setMetricsReportingSettingVisibility", visible); | |
1354 } | |
1355 #endif | |
1356 } | |
1357 | |
1358 void BrowserOptionsHandler::SetupPasswordGenerationSettingVisibility() { | |
1359 base::FundamentalValue visible( | |
1360 CommandLine::ForCurrentProcess()->HasSwitch( | |
1361 switches::kEnablePasswordGeneration)); | |
1362 web_ui()->CallJavascriptFunction( | |
1363 "BrowserOptions.setPasswordGenerationSettingVisibility", visible); | |
1364 } | |
1365 | |
1366 void BrowserOptionsHandler::SetupFontSizeSelector() { | |
1367 // We're only interested in integer values, so convert to int. | |
1368 base::FundamentalValue font_size(default_font_size_.GetValue()); | |
1369 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", font_size); | |
1370 } | |
1371 | |
1372 void BrowserOptionsHandler::SetupPageZoomSelector() { | |
1373 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
1374 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); | |
1375 double default_zoom_factor = | |
1376 WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level); | |
1377 | |
1378 // Generate a vector of zoom factors from an array of known presets along with | |
1379 // the default factor added if necessary. | |
1380 std::vector<double> zoom_factors = | |
1381 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); | |
1382 | |
1383 // Iterate through the zoom factors and and build the contents of the | |
1384 // selector that will be sent to the javascript handler. | |
1385 // Each item in the list has the following parameters: | |
1386 // 1. Title (string). | |
1387 // 2. Value (double). | |
1388 // 3. Is selected? (bool). | |
1389 ListValue zoom_factors_value; | |
1390 for (std::vector<double>::const_iterator i = zoom_factors.begin(); | |
1391 i != zoom_factors.end(); ++i) { | |
1392 ListValue* option = new ListValue(); | |
1393 double factor = *i; | |
1394 int percent = static_cast<int>(factor * 100 + 0.5); | |
1395 option->Append(Value::CreateStringValue( | |
1396 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); | |
1397 option->Append(Value::CreateDoubleValue(factor)); | |
1398 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); | |
1399 option->Append(Value::CreateBooleanValue(selected)); | |
1400 zoom_factors_value.Append(option); | |
1401 } | |
1402 | |
1403 web_ui()->CallJavascriptFunction( | |
1404 "BrowserOptions.setupPageZoomSelector", zoom_factors_value); | |
1405 } | |
1406 | |
1407 void BrowserOptionsHandler::SetupAutoOpenFileTypes() { | |
1408 // Set the hidden state for the AutoOpenFileTypesResetToDefault button. | |
1409 // We show the button if the user has any auto-open file types registered. | |
1410 DownloadManager* manager = BrowserContext::GetDownloadManager( | |
1411 web_ui()->GetWebContents()->GetBrowserContext()); | |
1412 bool display = manager && | |
1413 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed(); | |
1414 base::FundamentalValue value(display); | |
1415 web_ui()->CallJavascriptFunction( | |
1416 "BrowserOptions.setAutoOpenFileTypesDisplayed", value); | |
1417 } | |
1418 | |
1419 void BrowserOptionsHandler::SetupProxySettingsSection() { | |
1420 #if !defined(OS_CHROMEOS) | |
1421 // Disable the button if proxy settings are managed by a sysadmin or | |
1422 // overridden by an extension. | |
1423 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
1424 const PrefService::Preference* proxy_config = | |
1425 pref_service->FindPreference(prefs::kProxy); | |
1426 bool is_extension_controlled = (proxy_config && | |
1427 proxy_config->IsExtensionControlled()); | |
1428 | |
1429 base::FundamentalValue disabled(proxy_prefs_->IsManaged() || | |
1430 is_extension_controlled); | |
1431 | |
1432 // Get the appropriate info string to describe the button. | |
1433 string16 label_str; | |
1434 if (is_extension_controlled) { | |
1435 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | |
1436 } else { | |
1437 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | |
1438 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
1439 } | |
1440 StringValue label(label_str); | |
1441 | |
1442 web_ui()->CallJavascriptFunction( | |
1443 "BrowserOptions.setupProxySettingsSection", disabled, label); | |
1444 #endif // !defined(OS_CHROMEOS) | |
1445 } | |
1446 | |
1447 void BrowserOptionsHandler::SetupSSLConfigSettings() { | |
1448 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); | |
1449 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); | |
1450 web_ui()->CallJavascriptFunction( | |
1451 "BrowserOptions.setCheckRevocationCheckboxState", checked, disabled); | |
1452 } | |
1453 | |
1454 } // namespace options2 | |
OLD | NEW |