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/options/advanced_options_handler.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/bind.h" | |
11 #include "base/bind_helpers.h" | |
12 #include "base/command_line.h" | |
13 #include "base/utf_string_conversions.h" | |
14 #include "base/values.h" | |
15 #include "chrome/browser/browser_process.h" | |
16 #include "chrome/browser/chrome_page_zoom.h" | |
17 #include "chrome/browser/download/download_prefs.h" | |
18 #include "chrome/browser/prefs/pref_service.h" | |
19 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | |
20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | |
21 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | |
22 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | |
23 #include "chrome/browser/profiles/profile.h" | |
24 #include "chrome/browser/service/service_process_control.h" | |
25 #include "chrome/browser/ui/options/options_util.h" | |
26 #include "chrome/common/chrome_notification_types.h" | |
27 #include "chrome/common/chrome_switches.h" | |
28 #include "chrome/common/pref_names.h" | |
29 #include "chrome/common/url_constants.h" | |
30 #include "content/public/browser/download_manager.h" | |
31 #include "content/public/browser/notification_details.h" | |
32 #include "content/public/browser/notification_types.h" | |
33 #include "content/public/browser/user_metrics.h" | |
34 #include "content/public/browser/web_contents.h" | |
35 #include "content/public/browser/web_contents_view.h" | |
36 #include "content/public/common/page_zoom.h" | |
37 #include "grit/chromium_strings.h" | |
38 #include "grit/generated_resources.h" | |
39 #include "grit/locale_settings.h" | |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
41 #include "ui/base/l10n/l10n_util.h" | |
42 | |
43 #if !defined(OS_CHROMEOS) | |
44 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" | |
45 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" | |
46 #endif | |
47 | |
48 using content::DownloadManager; | |
49 using content::OpenURLParams; | |
50 using content::Referrer; | |
51 using content::UserMetricsAction; | |
52 | |
53 AdvancedOptionsHandler::AdvancedOptionsHandler() { | |
54 | |
55 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) | |
56 // On Windows, we need the PDF plugin which is only guaranteed to exist on | |
57 // Google Chrome builds. Use a command-line switch for Windows non-Google | |
58 // Chrome builds. | |
59 cloud_print_connector_ui_enabled_ = | |
60 CommandLine::ForCurrentProcess()->HasSwitch( | |
61 switches::kEnableCloudPrintProxy); | |
62 #elif(!defined(OS_CHROMEOS)) | |
63 // Always enabled for Mac, Linux and Google Chrome Windows builds. | |
64 // Never enabled for Chrome OS, we don't even need to indicate it. | |
65 cloud_print_connector_ui_enabled_ = true; | |
66 #endif | |
67 } | |
68 | |
69 AdvancedOptionsHandler::~AdvancedOptionsHandler() { | |
70 // There may be pending file dialogs, we need to tell them that we've gone | |
71 // away so they don't try and call back to us. | |
72 if (select_folder_dialog_.get()) | |
73 select_folder_dialog_->ListenerDestroyed(); | |
74 } | |
75 | |
76 void AdvancedOptionsHandler::GetLocalizedValues( | |
77 DictionaryValue* localized_strings) { | |
78 DCHECK(localized_strings); | |
79 | |
80 static OptionsStringResource resources[] = { | |
81 { "downloadLocationGroupName", | |
82 IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME }, | |
83 { "downloadLocationChangeButton", | |
84 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON }, | |
85 { "downloadLocationBrowseTitle", | |
86 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE }, | |
87 { "downloadLocationBrowseWindowTitle", | |
88 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_WINDOW_TITLE }, | |
89 { "downloadLocationAskForSaveLocation", | |
90 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION }, | |
91 { "autoOpenFileTypesInfo", | |
92 IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, | |
93 { "autoOpenFileTypesResetToDefault", | |
94 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, | |
95 { "translateEnableTranslate", | |
96 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, | |
97 { "certificatesManageButton", | |
98 IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, | |
99 { "proxiesLabel", | |
100 IDS_OPTIONS_PROXIES_LABEL }, | |
101 #if !defined(OS_CHROMEOS) | |
102 { "proxiesConfigureButton", | |
103 IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON }, | |
104 #endif | |
105 { "safeBrowsingEnableProtection", | |
106 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION }, | |
107 { "sslGroupDescription", | |
108 IDS_OPTIONS_SSL_GROUP_DESCRIPTION }, | |
109 { "sslCheckRevocation", | |
110 IDS_OPTIONS_SSL_CHECKREVOCATION }, | |
111 { "networkPredictionEnabledDescription", | |
112 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, | |
113 { "privacyContentSettingsButton", | |
114 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON }, | |
115 { "privacyClearDataButton", | |
116 IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, | |
117 { "linkDoctorPref", | |
118 IDS_OPTIONS_LINKDOCTOR_PREF }, | |
119 { "spellingPref", | |
120 IDS_OPTIONS_SPELLING_PREF }, | |
121 { "suggestPref", | |
122 IDS_OPTIONS_SUGGEST_PREF }, | |
123 { "tabsToLinksPref", | |
124 IDS_OPTIONS_TABS_TO_LINKS_PREF }, | |
125 { "fontSettingsInfo", | |
126 IDS_OPTIONS_FONTSETTINGS_INFO }, | |
127 { "defaultZoomFactorLabel", | |
128 IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, | |
129 { "defaultFontSizeLabel", | |
130 IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, | |
131 { "fontSizeLabelVerySmall", | |
132 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, | |
133 { "fontSizeLabelSmall", | |
134 IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, | |
135 { "fontSizeLabelMedium", | |
136 IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, | |
137 { "fontSizeLabelLarge", | |
138 IDS_OPTIONS_FONT_SIZE_LABEL_LARGE }, | |
139 { "fontSizeLabelVeryLarge", | |
140 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE }, | |
141 { "fontSizeLabelCustom", | |
142 IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM }, | |
143 { "fontSettingsCustomizeFontsButton", | |
144 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON }, | |
145 { "languageAndSpellCheckSettingsButton", | |
146 IDS_OPTIONS_LANGUAGE_AND_SPELLCHECK_BUTTON }, | |
147 { "advancedSectionTitlePrivacy", | |
148 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, | |
149 { "advancedSectionTitleContent", | |
150 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, | |
151 { "advancedSectionTitleSecurity", | |
152 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY }, | |
153 { "advancedSectionTitleNetwork", | |
154 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, | |
155 { "advancedSectionTitleTranslate", | |
156 IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE }, | |
157 { "translateEnableTranslate", | |
158 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, | |
159 { "enableLogging", | |
160 IDS_OPTIONS_ENABLE_LOGGING }, | |
161 { "improveBrowsingExperience", | |
162 IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE }, | |
163 { "disableWebServices", | |
164 IDS_OPTIONS_DISABLE_WEB_SERVICES }, | |
165 { "advancedSectionTitleCloudPrint", | |
166 IDS_GOOGLE_CLOUD_PRINT }, | |
167 #if !defined(OS_CHROMEOS) | |
168 { "cloudPrintConnectorEnabledManageButton", | |
169 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_MANAGE_BUTTON}, | |
170 { "cloudPrintConnectorEnablingButton", | |
171 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON }, | |
172 #endif | |
173 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
174 { "advancedSectionTitleBackground", | |
175 IDS_OPTIONS_ADVANCED_SECTION_TITLE_BACKGROUND }, | |
176 { "backgroundModeCheckbox", | |
177 IDS_OPTIONS_BACKGROUND_ENABLE_BACKGROUND_MODE }, | |
178 #endif | |
179 }; | |
180 | |
181 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
182 RegisterCloudPrintStrings(localized_strings); | |
183 RegisterTitle(localized_strings, "advancedPage", | |
184 IDS_OPTIONS_ADVANCED_TAB_LABEL); | |
185 | |
186 localized_strings->SetString("privacyLearnMoreURL", | |
187 chrome::kPrivacyLearnMoreURL); | |
188 | |
189 #if defined(OS_CHROMEOS) | |
190 localized_strings->SetString("cloudPrintLearnMoreURL", | |
191 chrome::kCloudPrintLearnMoreURL); | |
192 #endif | |
193 } | |
194 | |
195 void AdvancedOptionsHandler::RegisterCloudPrintStrings( | |
196 DictionaryValue* localized_strings) { | |
197 #if defined(OS_CHROMEOS) | |
198 localized_strings->SetString("cloudPrintChromeosOptionLabel", | |
199 l10n_util::GetStringFUTF16( | |
200 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, | |
201 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
202 localized_strings->SetString("cloudPrintChromeosOptionButton", | |
203 l10n_util::GetStringFUTF16( | |
204 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON, | |
205 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
206 #else | |
207 localized_strings->SetString("cloudPrintConnectorDisabledLabel", | |
208 l10n_util::GetStringFUTF16( | |
209 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, | |
210 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
211 localized_strings->SetString("cloudPrintConnectorDisabledButton", | |
212 l10n_util::GetStringFUTF16( | |
213 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON, | |
214 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
215 localized_strings->SetString("cloudPrintConnectorEnabledButton", | |
216 l10n_util::GetStringFUTF16( | |
217 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON, | |
218 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | |
219 #endif | |
220 } | |
221 | |
222 void AdvancedOptionsHandler::InitializeHandler() { | |
223 DCHECK(web_ui()); | |
224 SetupMetricsReportingCheckbox(); | |
225 SetupMetricsReportingSettingVisibility(); | |
226 SetupFontSizeSelector(); | |
227 SetupPageZoomSelector(); | |
228 SetupAutoOpenFileTypesDisabledAttribute(); | |
229 SetupProxySettingsSection(); | |
230 SetupSSLConfigSettings(); | |
231 #if !defined(OS_CHROMEOS) | |
232 if (cloud_print_connector_ui_enabled_) { | |
233 SetupCloudPrintConnectorSection(); | |
234 RefreshCloudPrintStatusFromService(); | |
235 } else { | |
236 RemoveCloudPrintConnectorSection(); | |
237 } | |
238 #endif | |
239 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
240 SetupBackgroundModeSettings(); | |
241 #endif | |
242 | |
243 } | |
244 | |
245 void AdvancedOptionsHandler::RegisterMessages() { | |
246 // Register for preferences that we need to observe manually. These have | |
247 // special behaviors that aren't handled by the standard prefs UI. | |
248 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | |
249 #if !defined(OS_CHROMEOS) | |
250 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, | |
251 g_browser_process->local_state(), this); | |
252 cloud_print_connector_email_.Init(prefs::kCloudPrintEmail, prefs, this); | |
253 cloud_print_connector_enabled_.Init(prefs::kCloudPrintProxyEnabled, | |
254 prefs, | |
255 this); | |
256 #endif | |
257 | |
258 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, | |
259 g_browser_process->local_state(), this); | |
260 | |
261 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
262 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, | |
263 g_browser_process->local_state(), | |
264 this); | |
265 #endif | |
266 | |
267 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); | |
268 default_font_size_.Init(prefs::kWebKitGlobalDefaultFontSize, prefs, this); | |
269 default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this); | |
270 #if !defined(OS_CHROMEOS) | |
271 proxy_prefs_.reset( | |
272 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); | |
273 #endif // !defined(OS_CHROMEOS) | |
274 | |
275 // Setup handlers specific to this panel. | |
276 web_ui()->RegisterMessageCallback("selectDownloadLocation", | |
277 base::Bind(&AdvancedOptionsHandler::HandleSelectDownloadLocation, | |
278 base::Unretained(this))); | |
279 web_ui()->RegisterMessageCallback("autoOpenFileTypesAction", | |
280 base::Bind(&AdvancedOptionsHandler::HandleAutoOpenButton, | |
281 base::Unretained(this))); | |
282 web_ui()->RegisterMessageCallback("defaultFontSizeAction", | |
283 base::Bind(&AdvancedOptionsHandler::HandleDefaultFontSize, | |
284 base::Unretained(this))); | |
285 web_ui()->RegisterMessageCallback("defaultZoomFactorAction", | |
286 base::Bind(&AdvancedOptionsHandler::HandleDefaultZoomFactor, | |
287 base::Unretained(this))); | |
288 #if !defined(OS_CHROMEOS) | |
289 web_ui()->RegisterMessageCallback("metricsReportingCheckboxAction", | |
290 base::Bind(&AdvancedOptionsHandler::HandleMetricsReportingCheckbox, | |
291 base::Unretained(this))); | |
292 #endif | |
293 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
294 web_ui()->RegisterMessageCallback("showManageSSLCertificates", | |
295 base::Bind(&AdvancedOptionsHandler::ShowManageSSLCertificates, | |
296 base::Unretained(this))); | |
297 #endif | |
298 web_ui()->RegisterMessageCallback("showCloudPrintManagePage", | |
299 base::Bind(&AdvancedOptionsHandler::ShowCloudPrintManagePage, | |
300 base::Unretained(this))); | |
301 #if !defined(OS_CHROMEOS) | |
302 if (cloud_print_connector_ui_enabled_) { | |
303 web_ui()->RegisterMessageCallback("showCloudPrintSetupDialog", | |
304 base::Bind(&AdvancedOptionsHandler::ShowCloudPrintSetupDialog, | |
305 base::Unretained(this))); | |
306 web_ui()->RegisterMessageCallback("disableCloudPrintConnector", | |
307 base::Bind(&AdvancedOptionsHandler::HandleDisableCloudPrintConnector, | |
308 base::Unretained(this))); | |
309 } | |
310 web_ui()->RegisterMessageCallback("showNetworkProxySettings", | |
311 base::Bind(&AdvancedOptionsHandler::ShowNetworkProxySettings, | |
312 base::Unretained(this))); | |
313 #endif | |
314 web_ui()->RegisterMessageCallback("checkRevocationCheckboxAction", | |
315 base::Bind(&AdvancedOptionsHandler::HandleCheckRevocationCheckbox, | |
316 base::Unretained(this))); | |
317 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
318 web_ui()->RegisterMessageCallback("backgroundModeAction", | |
319 base::Bind(&AdvancedOptionsHandler::HandleBackgroundModeCheckbox, | |
320 base::Unretained(this))); | |
321 #endif | |
322 } | |
323 | |
324 void AdvancedOptionsHandler::Observe( | |
325 int type, | |
326 const content::NotificationSource& source, | |
327 const content::NotificationDetails& details) { | |
328 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
329 std::string* pref_name = content::Details<std::string>(details).ptr(); | |
330 if (*pref_name == prefs::kDownloadExtensionsToOpen) { | |
331 SetupAutoOpenFileTypesDisabledAttribute(); | |
332 #if !defined(OS_CHROMEOS) | |
333 } else if (proxy_prefs_->IsObserved(*pref_name)) { | |
334 SetupProxySettingsSection(); | |
335 #endif // !defined(OS_CHROMEOS) | |
336 } else if ((*pref_name == prefs::kCloudPrintEmail) || | |
337 (*pref_name == prefs::kCloudPrintProxyEnabled)) { | |
338 #if !defined(OS_CHROMEOS) | |
339 if (cloud_print_connector_ui_enabled_) | |
340 SetupCloudPrintConnectorSection(); | |
341 #endif | |
342 } else if (*pref_name == prefs::kWebKitGlobalDefaultFontSize) { | |
343 SetupFontSizeSelector(); | |
344 } else if (*pref_name == prefs::kDefaultZoomLevel) { | |
345 SetupPageZoomSelector(); | |
346 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
347 } else if (*pref_name == prefs::kBackgroundModeEnabled) { | |
348 SetupBackgroundModeSettings(); | |
349 #endif | |
350 } | |
351 } | |
352 } | |
353 | |
354 void AdvancedOptionsHandler::HandleSelectDownloadLocation( | |
355 const ListValue* args) { | |
356 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
357 select_folder_dialog_ = SelectFileDialog::Create(this); | |
358 select_folder_dialog_->SelectFile( | |
359 SelectFileDialog::SELECT_FOLDER, | |
360 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), | |
361 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), | |
362 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), | |
363 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | |
364 } | |
365 | |
366 void AdvancedOptionsHandler::FileSelected(const FilePath& path, int index, | |
367 void* params) { | |
368 content::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); | |
369 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
370 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); | |
371 } | |
372 | |
373 void AdvancedOptionsHandler::OnCloudPrintSetupClosed() { | |
374 #if !defined(OS_CHROMEOS) | |
375 if (cloud_print_connector_ui_enabled_) | |
376 SetupCloudPrintConnectorSection(); | |
377 #endif | |
378 } | |
379 | |
380 void AdvancedOptionsHandler::HandleAutoOpenButton(const ListValue* args) { | |
381 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | |
382 DownloadManager* manager = | |
383 web_ui()->GetWebContents()->GetBrowserContext()->GetDownloadManager(); | |
384 if (manager) | |
385 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | |
386 } | |
387 | |
388 void AdvancedOptionsHandler::HandleMetricsReportingCheckbox( | |
389 const ListValue* args) { | |
390 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
391 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
392 bool enabled = checked_str == "true"; | |
393 content::RecordAction( | |
394 enabled ? | |
395 UserMetricsAction("Options_MetricsReportingCheckbox_Enable") : | |
396 UserMetricsAction("Options_MetricsReportingCheckbox_Disable")); | |
397 bool is_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); | |
398 enable_metrics_recording_.SetValue(is_enabled); | |
399 SetupMetricsReportingCheckbox(); | |
400 #endif | |
401 } | |
402 | |
403 void AdvancedOptionsHandler::HandleDefaultFontSize(const ListValue* args) { | |
404 int font_size; | |
405 if (ExtractIntegerValue(args, &font_size)) { | |
406 if (font_size > 0) { | |
407 default_font_size_.SetValue(font_size); | |
408 SetupFontSizeSelector(); | |
409 } | |
410 } | |
411 } | |
412 | |
413 void AdvancedOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { | |
414 double zoom_factor; | |
415 if (ExtractDoubleValue(args, &zoom_factor)) { | |
416 default_zoom_level_.SetValue( | |
417 WebKit::WebView::zoomFactorToZoomLevel(zoom_factor)); | |
418 } | |
419 } | |
420 | |
421 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( | |
422 const ListValue* args) { | |
423 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
424 bool enabled = checked_str == "true"; | |
425 content::RecordAction( | |
426 enabled ? | |
427 UserMetricsAction("Options_CheckCertRevocation_Enable") : | |
428 UserMetricsAction("Options_CheckCertRevocation_Disable")); | |
429 rev_checking_enabled_.SetValue(enabled); | |
430 } | |
431 | |
432 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
433 void AdvancedOptionsHandler::HandleBackgroundModeCheckbox( | |
434 const ListValue* args) { | |
435 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
436 bool enabled = checked_str == "true"; | |
437 content::RecordAction( | |
438 enabled ? | |
439 UserMetricsAction("Options_BackgroundMode_Enable") : | |
440 UserMetricsAction("Options_BackgroundMode_Disable")); | |
441 background_mode_enabled_.SetValue(enabled); | |
442 } | |
443 | |
444 void AdvancedOptionsHandler::SetupBackgroundModeSettings() { | |
445 base::FundamentalValue checked(background_mode_enabled_.GetValue()); | |
446 PrefService* service = g_browser_process->local_state(); | |
447 DCHECK(service); | |
448 const PrefService::Preference* pref = | |
449 service->FindPreference(prefs::kBackgroundModeEnabled); | |
450 DCHECK(pref); | |
451 base::FundamentalValue disabled(!pref->IsUserModifiable()); | |
452 std::string controlled_by_str; | |
453 if (pref->IsManaged()) | |
454 controlled_by_str = "policy"; | |
455 else if (pref->IsExtensionControlled()) | |
456 controlled_by_str = "extension"; | |
457 else if (pref->IsRecommended()) | |
458 controlled_by_str = "recommended"; | |
459 base::StringValue controlled_by(controlled_by_str); | |
460 web_ui()->CallJavascriptFunction( | |
461 "options.AdvancedOptions.SetBackgroundModeCheckboxState", | |
462 checked, | |
463 disabled, | |
464 controlled_by); | |
465 } | |
466 #endif | |
467 | |
468 #if !defined(OS_CHROMEOS) | |
469 void AdvancedOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { | |
470 content::RecordAction(UserMetricsAction("Options_ShowProxySettings")); | |
471 AdvancedOptionsUtilities::ShowNetworkProxySettings( | |
472 web_ui()->GetWebContents()); | |
473 } | |
474 #endif | |
475 | |
476 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
477 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { | |
478 content::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); | |
479 AdvancedOptionsUtilities::ShowManageSSLCertificates( | |
480 web_ui()->GetWebContents()); | |
481 } | |
482 #endif | |
483 | |
484 void AdvancedOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { | |
485 content::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); | |
486 // Open a new tab in the current window for the management page. | |
487 Profile* profile = Profile::FromWebUI(web_ui()); | |
488 OpenURLParams params( | |
489 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), Referrer(), | |
490 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | |
491 web_ui()->GetWebContents()->OpenURL(params); | |
492 } | |
493 | |
494 #if !defined(OS_CHROMEOS) | |
495 void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { | |
496 content::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); | |
497 // Open the connector enable page in the current tab. | |
498 Profile* profile = Profile::FromWebUI(web_ui()); | |
499 OpenURLParams params( | |
500 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( | |
501 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), | |
502 Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | |
503 web_ui()->GetWebContents()->OpenURL(params); | |
504 } | |
505 | |
506 void AdvancedOptionsHandler::HandleDisableCloudPrintConnector( | |
507 const ListValue* args) { | |
508 content::RecordAction( | |
509 UserMetricsAction("Options_DisableCloudPrintProxy")); | |
510 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | |
511 DisableForUser(); | |
512 } | |
513 | |
514 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { | |
515 if (cloud_print_connector_ui_enabled_) | |
516 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | |
517 RefreshStatusFromService(); | |
518 } | |
519 | |
520 void AdvancedOptionsHandler::SetupCloudPrintConnectorSection() { | |
521 Profile* profile = Profile::FromWebUI(web_ui()); | |
522 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { | |
523 cloud_print_connector_ui_enabled_ = false; | |
524 RemoveCloudPrintConnectorSection(); | |
525 return; | |
526 } | |
527 | |
528 bool cloud_print_connector_allowed = | |
529 !cloud_print_connector_enabled_.IsManaged() || | |
530 cloud_print_connector_enabled_.GetValue(); | |
531 base::FundamentalValue allowed(cloud_print_connector_allowed); | |
532 | |
533 std::string email; | |
534 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && | |
535 cloud_print_connector_allowed) { | |
536 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); | |
537 } | |
538 base::FundamentalValue disabled(email.empty()); | |
539 | |
540 string16 label_str; | |
541 if (email.empty()) { | |
542 label_str = l10n_util::GetStringFUTF16( | |
543 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, | |
544 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | |
545 } else { | |
546 label_str = l10n_util::GetStringFUTF16( | |
547 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, | |
548 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), | |
549 UTF8ToUTF16(email)); | |
550 } | |
551 StringValue label(label_str); | |
552 | |
553 web_ui()->CallJavascriptFunction( | |
554 "options.AdvancedOptions.SetupCloudPrintConnectorSection", | |
555 disabled, label, allowed); | |
556 } | |
557 | |
558 void AdvancedOptionsHandler::RemoveCloudPrintConnectorSection() { | |
559 web_ui()->CallJavascriptFunction( | |
560 "options.AdvancedOptions.RemoveCloudPrintConnectorSection"); | |
561 } | |
562 | |
563 #endif | |
564 | |
565 void AdvancedOptionsHandler::SetupMetricsReportingCheckbox() { | |
566 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
567 base::FundamentalValue checked(enable_metrics_recording_.GetValue()); | |
568 base::FundamentalValue disabled(enable_metrics_recording_.IsManaged()); | |
569 web_ui()->CallJavascriptFunction( | |
570 "options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, | |
571 disabled); | |
572 #endif | |
573 } | |
574 | |
575 void AdvancedOptionsHandler::SetupMetricsReportingSettingVisibility() { | |
576 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) | |
577 // Don't show the reporting setting if we are in the guest mode. | |
578 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | |
579 base::FundamentalValue visible(false); | |
580 web_ui()->CallJavascriptFunction( | |
581 "options.AdvancedOptions.SetMetricsReportingSettingVisibility", | |
582 visible); | |
583 } | |
584 #endif | |
585 } | |
586 | |
587 void AdvancedOptionsHandler::SetupFontSizeSelector() { | |
588 // We're only interested in integer values, so convert to int. | |
589 base::FundamentalValue font_size(default_font_size_.GetValue()); | |
590 web_ui()->CallJavascriptFunction( | |
591 "options.AdvancedOptions.SetFontSize", font_size); | |
592 } | |
593 | |
594 void AdvancedOptionsHandler::SetupPageZoomSelector() { | |
595 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
596 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); | |
597 double default_zoom_factor = | |
598 WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level); | |
599 | |
600 // Generate a vector of zoom factors from an array of known presets along with | |
601 // the default factor added if necessary. | |
602 std::vector<double> zoom_factors = | |
603 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); | |
604 | |
605 // Iterate through the zoom factors and and build the contents of the | |
606 // selector that will be sent to the javascript handler. | |
607 // Each item in the list has the following parameters: | |
608 // 1. Title (string). | |
609 // 2. Value (double). | |
610 // 3. Is selected? (bool). | |
611 ListValue zoom_factors_value; | |
612 for (std::vector<double>::const_iterator i = zoom_factors.begin(); | |
613 i != zoom_factors.end(); ++i) { | |
614 ListValue* option = new ListValue(); | |
615 double factor = *i; | |
616 int percent = static_cast<int>(factor * 100 + 0.5); | |
617 option->Append(Value::CreateStringValue( | |
618 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); | |
619 option->Append(Value::CreateDoubleValue(factor)); | |
620 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); | |
621 option->Append(Value::CreateBooleanValue(selected)); | |
622 zoom_factors_value.Append(option); | |
623 } | |
624 | |
625 web_ui()->CallJavascriptFunction( | |
626 "options.AdvancedOptions.SetupPageZoomSelector", zoom_factors_value); | |
627 } | |
628 | |
629 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { | |
630 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. | |
631 // We enable the button if the user has any auto-open file types registered. | |
632 DownloadManager* manager = | |
633 web_ui()->GetWebContents()->GetBrowserContext()->GetDownloadManager(); | |
634 bool disabled = !(manager && | |
635 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed()); | |
636 base::FundamentalValue value(disabled); | |
637 web_ui()->CallJavascriptFunction( | |
638 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); | |
639 } | |
640 | |
641 void AdvancedOptionsHandler::SetupProxySettingsSection() { | |
642 #if !defined(OS_CHROMEOS) | |
643 // Disable the button if proxy settings are managed by a sysadmin or | |
644 // overridden by an extension. | |
645 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
646 const PrefService::Preference* proxy_config = | |
647 pref_service->FindPreference(prefs::kProxy); | |
648 bool is_extension_controlled = (proxy_config && | |
649 proxy_config->IsExtensionControlled()); | |
650 | |
651 base::FundamentalValue disabled(proxy_prefs_->IsManaged() || | |
652 is_extension_controlled); | |
653 | |
654 // Get the appropriate info string to describe the button. | |
655 string16 label_str; | |
656 if (is_extension_controlled) { | |
657 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | |
658 } else { | |
659 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | |
660 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
661 } | |
662 StringValue label(label_str); | |
663 | |
664 web_ui()->CallJavascriptFunction( | |
665 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); | |
666 #endif // !defined(OS_CHROMEOS) | |
667 } | |
668 | |
669 void AdvancedOptionsHandler::SetupSSLConfigSettings() { | |
670 { | |
671 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); | |
672 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); | |
673 web_ui()->CallJavascriptFunction( | |
674 "options.AdvancedOptions.SetCheckRevocationCheckboxState", checked, | |
675 disabled); | |
676 } | |
677 } | |
OLD | NEW |