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