Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/ui/webui/options2/advanced_options_handler2.cc

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

Powered by Google App Engine
This is Rietveld 408576698