OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/options/advanced_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/advanced_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 const ListValue* args) { | 399 const ListValue* args) { |
400 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | 400 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); |
401 bool enabled = checked_str == "true"; | 401 bool enabled = checked_str == "true"; |
402 UserMetrics::RecordAction(enabled ? | 402 UserMetrics::RecordAction(enabled ? |
403 UserMetricsAction("Options_BackgroundMode_Enable") : | 403 UserMetricsAction("Options_BackgroundMode_Enable") : |
404 UserMetricsAction("Options_BackgroundMode_Disable")); | 404 UserMetricsAction("Options_BackgroundMode_Disable")); |
405 background_mode_enabled_.SetValue(enabled); | 405 background_mode_enabled_.SetValue(enabled); |
406 } | 406 } |
407 | 407 |
408 void AdvancedOptionsHandler::SetupBackgroundModeSettings() { | 408 void AdvancedOptionsHandler::SetupBackgroundModeSettings() { |
409 FundamentalValue checked(background_mode_enabled_.GetValue()); | 409 base::FundamentalValue checked(background_mode_enabled_.GetValue()); |
410 web_ui_->CallJavascriptFunction( | 410 web_ui_->CallJavascriptFunction( |
411 "options.AdvancedOptions.SetBackgroundModeCheckboxState", checked); | 411 "options.AdvancedOptions.SetBackgroundModeCheckboxState", checked); |
412 } | 412 } |
413 #endif | 413 #endif |
414 | 414 |
415 #if !defined(OS_CHROMEOS) | 415 #if !defined(OS_CHROMEOS) |
416 void AdvancedOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { | 416 void AdvancedOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { |
417 UserMetrics::RecordAction(UserMetricsAction("Options_ShowProxySettings")); | 417 UserMetrics::RecordAction(UserMetricsAction("Options_ShowProxySettings")); |
418 AdvancedOptionsUtilities::ShowNetworkProxySettings(web_ui_->tab_contents()); | 418 AdvancedOptionsUtilities::ShowNetworkProxySettings(web_ui_->tab_contents()); |
419 } | 419 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { | 463 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { |
464 if (!CloudPrintProxyServiceFactory::GetForProfile(web_ui_->GetProfile())) { | 464 if (!CloudPrintProxyServiceFactory::GetForProfile(web_ui_->GetProfile())) { |
465 cloud_print_proxy_ui_enabled_ = false; | 465 cloud_print_proxy_ui_enabled_ = false; |
466 RemoveCloudPrintProxySection(); | 466 RemoveCloudPrintProxySection(); |
467 return; | 467 return; |
468 } | 468 } |
469 | 469 |
470 bool cloud_print_proxy_allowed = | 470 bool cloud_print_proxy_allowed = |
471 !cloud_print_proxy_enabled_.IsManaged() || | 471 !cloud_print_proxy_enabled_.IsManaged() || |
472 cloud_print_proxy_enabled_.GetValue(); | 472 cloud_print_proxy_enabled_.GetValue(); |
473 FundamentalValue allowed(cloud_print_proxy_allowed); | 473 base::FundamentalValue allowed(cloud_print_proxy_allowed); |
474 | 474 |
475 std::string email; | 475 std::string email; |
476 if (web_ui_->GetProfile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && | 476 if (web_ui_->GetProfile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && |
477 cloud_print_proxy_allowed) { | 477 cloud_print_proxy_allowed) { |
478 email = web_ui_->GetProfile()->GetPrefs()->GetString( | 478 email = web_ui_->GetProfile()->GetPrefs()->GetString( |
479 prefs::kCloudPrintEmail); | 479 prefs::kCloudPrintEmail); |
480 } | 480 } |
481 FundamentalValue disabled(email.empty()); | 481 base::FundamentalValue disabled(email.empty()); |
482 | 482 |
483 string16 label_str; | 483 string16 label_str; |
484 if (email.empty()) { | 484 if (email.empty()) { |
485 label_str = l10n_util::GetStringUTF16( | 485 label_str = l10n_util::GetStringUTF16( |
486 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL); | 486 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL); |
487 } else { | 487 } else { |
488 label_str = l10n_util::GetStringFUTF16( | 488 label_str = l10n_util::GetStringFUTF16( |
489 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, UTF8ToUTF16(email)); | 489 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, UTF8ToUTF16(email)); |
490 } | 490 } |
491 StringValue label(label_str); | 491 StringValue label(label_str); |
492 | 492 |
493 web_ui_->CallJavascriptFunction( | 493 web_ui_->CallJavascriptFunction( |
494 "options.AdvancedOptions.SetupCloudPrintProxySection", | 494 "options.AdvancedOptions.SetupCloudPrintProxySection", |
495 disabled, label, allowed); | 495 disabled, label, allowed); |
496 } | 496 } |
497 | 497 |
498 void AdvancedOptionsHandler::RemoveCloudPrintProxySection() { | 498 void AdvancedOptionsHandler::RemoveCloudPrintProxySection() { |
499 web_ui_->CallJavascriptFunction( | 499 web_ui_->CallJavascriptFunction( |
500 "options.AdvancedOptions.RemoveCloudPrintProxySection"); | 500 "options.AdvancedOptions.RemoveCloudPrintProxySection"); |
501 } | 501 } |
502 | 502 |
503 #endif | 503 #endif |
504 | 504 |
505 void AdvancedOptionsHandler::SetupMetricsReportingCheckbox() { | 505 void AdvancedOptionsHandler::SetupMetricsReportingCheckbox() { |
506 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | 506 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
507 FundamentalValue checked(enable_metrics_recording_.GetValue()); | 507 base::FundamentalValue checked(enable_metrics_recording_.GetValue()); |
508 FundamentalValue disabled(enable_metrics_recording_.IsManaged()); | 508 base::FundamentalValue disabled(enable_metrics_recording_.IsManaged()); |
509 web_ui_->CallJavascriptFunction( | 509 web_ui_->CallJavascriptFunction( |
510 "options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, | 510 "options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, |
511 disabled); | 511 disabled); |
512 #endif | 512 #endif |
513 } | 513 } |
514 | 514 |
515 void AdvancedOptionsHandler::SetupMetricsReportingSettingVisibility() { | 515 void AdvancedOptionsHandler::SetupMetricsReportingSettingVisibility() { |
516 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) | 516 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) |
517 // Don't show the reporting setting if we are in the guest mode. | 517 // Don't show the reporting setting if we are in the guest mode. |
518 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | 518 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { |
519 FundamentalValue visible(false); | 519 base::FundamentalValue visible(false); |
520 web_ui_->CallJavascriptFunction( | 520 web_ui_->CallJavascriptFunction( |
521 "options.AdvancedOptions.SetMetricsReportingSettingVisibility", | 521 "options.AdvancedOptions.SetMetricsReportingSettingVisibility", |
522 visible); | 522 visible); |
523 } | 523 } |
524 #endif | 524 #endif |
525 } | 525 } |
526 | 526 |
527 void AdvancedOptionsHandler::SetupFontSizeLabel() { | 527 void AdvancedOptionsHandler::SetupFontSizeLabel() { |
528 // We're only interested in integer values, so convert to int. | 528 // We're only interested in integer values, so convert to int. |
529 FundamentalValue font_size(default_font_size_.GetValue()); | 529 base::FundamentalValue font_size(default_font_size_.GetValue()); |
530 web_ui_->CallJavascriptFunction( | 530 web_ui_->CallJavascriptFunction( |
531 "options.AdvancedOptions.SetFontSize", font_size); | 531 "options.AdvancedOptions.SetFontSize", font_size); |
532 } | 532 } |
533 | 533 |
534 void AdvancedOptionsHandler::SetupDownloadLocationPath() { | 534 void AdvancedOptionsHandler::SetupDownloadLocationPath() { |
535 StringValue value(default_download_location_.GetValue().value()); | 535 StringValue value(default_download_location_.GetValue().value()); |
536 // In case allow_file_selection_dialogs_ is false, we will not display any | 536 // In case allow_file_selection_dialogs_ is false, we will not display any |
537 // file-selection dialogs but show an InfoBar. That is why we can disable | 537 // file-selection dialogs but show an InfoBar. That is why we can disable |
538 // the DownloadLocationPath-Chooser right-away. | 538 // the DownloadLocationPath-Chooser right-away. |
539 FundamentalValue disabled(default_download_location_.IsManaged() || | 539 base::FundamentalValue disabled(default_download_location_.IsManaged() || |
540 !allow_file_selection_dialogs_.GetValue()); | 540 !allow_file_selection_dialogs_.GetValue()); |
541 web_ui_->CallJavascriptFunction( | 541 web_ui_->CallJavascriptFunction( |
542 "options.AdvancedOptions.SetDownloadLocationPath", value, disabled); | 542 "options.AdvancedOptions.SetDownloadLocationPath", value, disabled); |
543 } | 543 } |
544 | 544 |
545 void AdvancedOptionsHandler::SetupPromptForDownload() { | 545 void AdvancedOptionsHandler::SetupPromptForDownload() { |
546 FundamentalValue checked(ask_for_save_location_.GetValue()); | 546 base::FundamentalValue checked(ask_for_save_location_.GetValue()); |
547 // If either the DownloadDirectory is managed or if file-selection dialogs are | 547 // If either the DownloadDirectory is managed or if file-selection dialogs are |
548 // disallowed then |ask_for_save_location_| must currently be false and cannot | 548 // disallowed then |ask_for_save_location_| must currently be false and cannot |
549 // be changed. | 549 // be changed. |
550 FundamentalValue disabled(default_download_location_.IsManaged() || | 550 base::FundamentalValue disabled(default_download_location_.IsManaged() || |
551 !allow_file_selection_dialogs_.GetValue()); | 551 !allow_file_selection_dialogs_.GetValue()); |
552 web_ui_->CallJavascriptFunction( | 552 web_ui_->CallJavascriptFunction( |
553 "options.AdvancedOptions.SetPromptForDownload", checked, disabled); | 553 "options.AdvancedOptions.SetPromptForDownload", checked, disabled); |
554 } | 554 } |
555 | 555 |
556 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { | 556 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { |
557 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. | 557 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. |
558 // We enable the button if the user has any auto-open file types registered. | 558 // We enable the button if the user has any auto-open file types registered. |
559 DownloadManager* manager = web_ui_->GetProfile()->GetDownloadManager(); | 559 DownloadManager* manager = web_ui_->GetProfile()->GetDownloadManager(); |
560 bool disabled = !(manager && manager->download_prefs()->IsAutoOpenUsed()); | 560 bool disabled = !(manager && manager->download_prefs()->IsAutoOpenUsed()); |
561 FundamentalValue value(disabled); | 561 base::FundamentalValue value(disabled); |
562 web_ui_->CallJavascriptFunction( | 562 web_ui_->CallJavascriptFunction( |
563 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); | 563 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); |
564 } | 564 } |
565 | 565 |
566 void AdvancedOptionsHandler::SetupProxySettingsSection() { | 566 void AdvancedOptionsHandler::SetupProxySettingsSection() { |
567 // Disable the button if proxy settings are managed by a sysadmin or | 567 // Disable the button if proxy settings are managed by a sysadmin or |
568 // overridden by an extension. | 568 // overridden by an extension. |
569 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 569 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
570 const PrefService::Preference* proxy_config = | 570 const PrefService::Preference* proxy_config = |
571 pref_service->FindPreference(prefs::kProxy); | 571 pref_service->FindPreference(prefs::kProxy); |
572 bool is_extension_controlled = (proxy_config && | 572 bool is_extension_controlled = (proxy_config && |
573 proxy_config->IsExtensionControlled()); | 573 proxy_config->IsExtensionControlled()); |
574 | 574 |
575 FundamentalValue disabled(proxy_prefs_->IsManaged() || | 575 base::FundamentalValue disabled(proxy_prefs_->IsManaged() || |
576 is_extension_controlled); | 576 is_extension_controlled); |
577 | 577 |
578 // Get the appropriate info string to describe the button. | 578 // Get the appropriate info string to describe the button. |
579 string16 label_str; | 579 string16 label_str; |
580 if (is_extension_controlled) { | 580 if (is_extension_controlled) { |
581 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | 581 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); |
582 } else { | 582 } else { |
583 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | 583 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, |
584 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 584 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
585 } | 585 } |
586 StringValue label(label_str); | 586 StringValue label(label_str); |
587 | 587 |
588 web_ui_->CallJavascriptFunction( | 588 web_ui_->CallJavascriptFunction( |
589 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); | 589 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); |
590 } | 590 } |
OLD | NEW |