OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/common/localized_error.h" | 5 #include "chrome/common/localized_error.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
15 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
16 #include "components/error_page/common/error_page_params.h" | 18 #include "components/error_page/common/error_page_params.h" |
17 #include "components/error_page/common/net_error_info.h" | 19 #include "components/error_page/common/net_error_info.h" |
18 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
19 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
20 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
21 #include "third_party/WebKit/public/platform/WebURLError.h" | 23 #include "third_party/WebKit/public/platform/WebURLError.h" |
22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/webui/web_ui_util.h" | 25 #include "ui/base/webui/web_ui_util.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 503 } |
502 | 504 |
503 } // namespace | 505 } // namespace |
504 | 506 |
505 const char LocalizedError::kHttpErrorDomain[] = "http"; | 507 const char LocalizedError::kHttpErrorDomain[] = "http"; |
506 | 508 |
507 void LocalizedError::GetStrings(int error_code, | 509 void LocalizedError::GetStrings(int error_code, |
508 const std::string& error_domain, | 510 const std::string& error_domain, |
509 const GURL& failed_url, | 511 const GURL& failed_url, |
510 bool is_post, | 512 bool is_post, |
511 bool show_stale_load_button, | 513 bool stale_copy_in_cache, |
512 const std::string& locale, | 514 const std::string& locale, |
513 const std::string& accept_languages, | 515 const std::string& accept_languages, |
514 scoped_ptr<error_page::ErrorPageParams> params, | 516 scoped_ptr<error_page::ErrorPageParams> params, |
515 base::DictionaryValue* error_strings) { | 517 base::DictionaryValue* error_strings) { |
516 webui::SetLoadTimeDataDefaults(locale, error_strings); | 518 webui::SetLoadTimeDataDefaults(locale, error_strings); |
517 | 519 |
518 // Grab the strings and settings that depend on the error type. Init | 520 // Grab the strings and settings that depend on the error type. Init |
519 // options with default values. | 521 // options with default values. |
520 LocalizedErrorMap options = { | 522 LocalizedErrorMap options = { |
521 0, | 523 0, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // Add at the front, so it appears before other suggestions, in the case | 683 // Add at the front, so it appears before other suggestions, in the case |
682 // suggestions are being overridden by |params|. | 684 // suggestions are being overridden by |params|. |
683 suggestions->Insert(0, suggest_reload_repost); | 685 suggestions->Insert(0, suggest_reload_repost); |
684 } | 686 } |
685 } | 687 } |
686 | 688 |
687 // If not using the default suggestions, nothing else to do. | 689 // If not using the default suggestions, nothing else to do. |
688 if (!use_default_suggestions) | 690 if (!use_default_suggestions) |
689 return; | 691 return; |
690 | 692 |
691 if (show_stale_load_button) { | 693 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
692 base::DictionaryValue* stale_load_button = new base::DictionaryValue; | 694 const std::string& show_saved_copy_value = |
693 stale_load_button->SetString( | 695 command_line->GetSwitchValueASCII(switches::kShowSavedCopy); |
694 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE)); | 696 bool show_saved_copy_primary = (show_saved_copy_value == |
695 stale_load_button->SetString( | 697 switches::kEnableShowSavedCopyPrimary); |
| 698 bool show_saved_copy_secondary = (show_saved_copy_value == |
| 699 switches::kEnableShowSavedCopySecondary); |
| 700 bool show_saved_copy_visible = |
| 701 (stale_copy_in_cache && !is_post && |
| 702 (show_saved_copy_primary || show_saved_copy_secondary)); |
| 703 |
| 704 if (show_saved_copy_visible) { |
| 705 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue; |
| 706 show_saved_copy_button->SetString( |
| 707 "msg", l10n_util::GetStringUTF16( |
| 708 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY)); |
| 709 show_saved_copy_button->SetString( |
696 "title", | 710 "title", |
697 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE_HELP)); | 711 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP)); |
698 error_strings->Set("staleLoadButton", stale_load_button); | 712 if (show_saved_copy_primary) |
| 713 show_saved_copy_button->SetString("primary", "true"); |
| 714 error_strings->Set("showSavedCopyButton", show_saved_copy_button); |
699 } | 715 } |
700 | 716 |
701 #if defined(OS_CHROMEOS) | 717 #if defined(OS_CHROMEOS) |
702 error_strings->SetString( | 718 error_strings->SetString( |
703 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); | 719 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); |
704 #endif // defined(OS_CHROMEOS) | 720 #endif // defined(OS_CHROMEOS) |
705 | 721 |
706 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 722 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
707 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; | 723 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; |
708 suggest_check_connection->SetString("header", | 724 suggest_check_connection->SetString("header", |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 GURL learn_more_url(kAppWarningLearnMoreUrl); | 896 GURL learn_more_url(kAppWarningLearnMoreUrl); |
881 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 897 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
882 suggest_learn_more->SetString("msg", | 898 suggest_learn_more->SetString("msg", |
883 l10n_util::GetStringUTF16( | 899 l10n_util::GetStringUTF16( |
884 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 900 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
885 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 901 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
886 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 902 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
887 #endif // defined(OS_CHROMEOS) | 903 #endif // defined(OS_CHROMEOS) |
888 } | 904 } |
889 #endif | 905 #endif |
OLD | NEW |