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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/net/net_error_info.h" | 14 #include "chrome/common/net/net_error_info.h" |
15 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
16 #include "extensions/common/extension_icon_set.h" | 16 #include "extensions/common/extension_icon_set.h" |
17 #include "extensions/common/manifest_handlers/icons_handler.h" | 17 #include "extensions/common/manifest_handlers/icons_handler.h" |
18 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "third_party/WebKit/public/platform/WebURLError.h" | 23 #include "third_party/WebKit/public/platform/WebURLError.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/webui/web_ui_util.h" | 25 #include "ui/base/webui/web_ui_util.h" |
26 #include "url/gurl.h" | |
27 | 26 |
28 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
29 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
30 #endif | 29 #endif |
31 | 30 |
32 using blink::WebURLError; | 31 using blink::WebURLError; |
33 | 32 |
34 // Some error pages have no details. | 33 // Some error pages have no details. |
35 const unsigned int kErrorPagesNoDetails = 0; | 34 const unsigned int kErrorPagesNoDetails = 0; |
36 | 35 |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 error_domain == chrome_common_net::kDnsProbeErrorDomain)) | 476 error_domain == chrome_common_net::kDnsProbeErrorDomain)) |
478 return "icon-offline"; | 477 return "icon-offline"; |
479 | 478 |
480 return "icon-generic"; | 479 return "icon-generic"; |
481 } | 480 } |
482 | 481 |
483 } // namespace | 482 } // namespace |
484 | 483 |
485 const char LocalizedError::kHttpErrorDomain[] = "http"; | 484 const char LocalizedError::kHttpErrorDomain[] = "http"; |
486 | 485 |
| 486 LocalizedError::ErrorPageParams::ErrorPageParams() : suggest_reload(false) { |
| 487 } |
| 488 |
| 489 LocalizedError::ErrorPageParams::~ErrorPageParams() { |
| 490 } |
| 491 |
487 void LocalizedError::GetStrings(int error_code, | 492 void LocalizedError::GetStrings(int error_code, |
488 const std::string& error_domain, | 493 const std::string& error_domain, |
489 const GURL& failed_url, | 494 const GURL& failed_url, |
490 bool is_post, | 495 bool is_post, |
491 bool stale_copy_in_cache, | 496 bool stale_copy_in_cache, |
492 const std::string& locale, | 497 const std::string& locale, |
493 const std::string& accept_languages, | 498 const std::string& accept_languages, |
| 499 scoped_ptr<ErrorPageParams> params, |
494 base::DictionaryValue* error_strings) { | 500 base::DictionaryValue* error_strings) { |
495 bool rtl = LocaleIsRTL(); | 501 bool rtl = LocaleIsRTL(); |
496 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 502 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
497 | 503 |
498 // Grab the strings and settings that depend on the error type. Init | 504 // Grab the strings and settings that depend on the error type. Init |
499 // options with default values. | 505 // options with default values. |
500 LocalizedErrorMap options = { | 506 LocalizedErrorMap options = { |
501 0, | 507 0, |
502 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 508 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
503 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 509 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), | 552 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), |
547 accept_languages)); | 553 accept_languages)); |
548 summary->SetString("productName", | 554 summary->SetString("productName", |
549 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 555 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
550 | 556 |
551 error_strings->SetString( | 557 error_strings->SetString( |
552 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); | 558 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); |
553 error_strings->SetString( | 559 error_strings->SetString( |
554 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); | 560 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); |
555 error_strings->Set("summary", summary); | 561 error_strings->Set("summary", summary); |
556 error_strings->SetBoolean("staleCopyInCache", stale_copy_in_cache); | |
557 | |
558 #if defined(OS_CHROMEOS) | |
559 error_strings->SetString( | |
560 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); | |
561 #endif // defined(OS_CHROMEOS) | |
562 | |
563 error_strings->SetBoolean("staleCopyInCache", stale_copy_in_cache); | |
564 | 562 |
565 if (options.details_resource_id != kErrorPagesNoDetails) { | 563 if (options.details_resource_id != kErrorPagesNoDetails) { |
566 error_strings->SetString( | 564 error_strings->SetString( |
567 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 565 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
568 } | 566 } |
569 | 567 |
570 base::string16 error_string; | 568 base::string16 error_string; |
571 if (error_domain == net::kErrorDomain) { | 569 if (error_domain == net::kErrorDomain) { |
572 // Non-internationalized error string, for debugging Chrome itself. | 570 // Non-internationalized error string, for debugging Chrome itself. |
573 std::string ascii_error_string = net::ErrorToString(error_code); | 571 std::string ascii_error_string = net::ErrorToString(error_code); |
574 // Remove the leading "net::" from the returned string. | 572 // Remove the leading "net::" from the returned string. |
575 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 573 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
576 error_string = base::ASCIIToUTF16(ascii_error_string); | 574 error_string = base::ASCIIToUTF16(ascii_error_string); |
577 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { | 575 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
578 std::string ascii_error_string = | 576 std::string ascii_error_string = |
579 chrome_common_net::DnsProbeStatusToString(error_code); | 577 chrome_common_net::DnsProbeStatusToString(error_code); |
580 error_string = base::ASCIIToUTF16(ascii_error_string); | 578 error_string = base::ASCIIToUTF16(ascii_error_string); |
581 } else { | 579 } else { |
582 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); | 580 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
583 error_string = base::IntToString16(error_code); | 581 error_string = base::IntToString16(error_code); |
584 } | 582 } |
585 error_strings->SetString("errorCode", | 583 error_strings->SetString("errorCode", |
586 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); | 584 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
587 | 585 |
588 base::ListValue* suggestions = new base::ListValue(); | 586 // Platform specific information for diagnosing network issues on OSX and |
589 | |
590 // Platform specific instructions for diagnosing network issues on OSX and | |
591 // Windows. | 587 // Windows. |
592 #if defined(OS_MACOSX) || defined(OS_WIN) | 588 #if defined(OS_MACOSX) || defined(OS_WIN) |
593 if (error_domain == net::kErrorDomain && | 589 if (error_domain == net::kErrorDomain && |
594 error_code == net::ERR_INTERNET_DISCONNECTED) { | 590 error_code == net::ERR_INTERNET_DISCONNECTED) { |
595 int platform_string_id = | 591 int platform_string_id = |
596 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; | 592 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; |
597 #if defined(OS_WIN) | 593 #if defined(OS_WIN) |
598 // Different versions of Windows have different instructions. | 594 // Different versions of Windows have different instructions. |
599 base::win::Version windows_version = base::win::GetVersion(); | 595 base::win::Version windows_version = base::win::GetVersion(); |
600 if (windows_version < base::win::VERSION_VISTA) { | 596 if (windows_version < base::win::VERSION_VISTA) { |
601 // XP, XP64, and Server 2003. | 597 // XP, XP64, and Server 2003. |
602 platform_string_id = | 598 platform_string_id = |
603 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; | 599 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; |
604 } else if (windows_version == base::win::VERSION_VISTA) { | 600 } else if (windows_version == base::win::VERSION_VISTA) { |
605 // Vista | 601 // Vista |
606 platform_string_id = | 602 platform_string_id = |
607 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; | 603 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; |
608 } | 604 } |
609 #endif // defined(OS_WIN) | 605 #endif // defined(OS_WIN) |
610 // Lead with the general error description, and suffix with the platform | 606 // Lead with the general error description, and suffix with the platform |
611 // dependent portion of the summary section. | 607 // dependent portion of the summary section. |
612 summary->SetString("msg", | 608 summary->SetString("msg", |
613 l10n_util::GetStringFUTF16( | 609 l10n_util::GetStringFUTF16( |
614 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, | 610 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, |
615 l10n_util::GetStringUTF16(options.summary_resource_id), | 611 l10n_util::GetStringUTF16(options.summary_resource_id), |
616 l10n_util::GetStringUTF16(platform_string_id))); | 612 l10n_util::GetStringUTF16(platform_string_id))); |
617 } | 613 } |
618 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 614 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
619 | 615 |
620 if (options.suggestions & SUGGEST_RELOAD) { | 616 // If no parameters were provided, use the defaults. |
| 617 if (!params) { |
| 618 params.reset(new ErrorPageParams()); |
| 619 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD); |
| 620 } |
| 621 |
| 622 base::ListValue* suggestions = NULL; |
| 623 bool use_default_suggestions = true; |
| 624 if (!params->override_suggestions) { |
| 625 suggestions = new base::ListValue(); |
| 626 } else { |
| 627 suggestions = params->override_suggestions.release(); |
| 628 use_default_suggestions = false; |
| 629 } |
| 630 |
| 631 error_strings->Set("suggestions", suggestions); |
| 632 |
| 633 if (params->search_url.is_valid()) { |
| 634 error_strings->SetString("searchHeader", |
| 635 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH)); |
| 636 error_strings->SetString("searchUrl", params->search_url.spec()); |
| 637 error_strings->SetString("searchTerms", params->search_terms); |
| 638 } |
| 639 |
| 640 // Add the reload suggestion, if needed. |
| 641 if (params->suggest_reload) { |
621 if (!is_post) { | 642 if (!is_post) { |
622 base::DictionaryValue* reload_button = new base::DictionaryValue; | 643 base::DictionaryValue* reload_button = new base::DictionaryValue; |
623 reload_button->SetString("msg", | 644 reload_button->SetString("msg", |
624 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 645 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
625 reload_button->SetString("reloadUrl", failed_url.spec()); | 646 reload_button->SetString("reloadUrl", failed_url.spec()); |
626 error_strings->Set("reload", reload_button); | 647 error_strings->Set("reload", reload_button); |
627 } else { | 648 } else { |
628 // If the page was created by a post, it can't be reloaded in the same | 649 // If the page was created by a post, it can't be reloaded in the same |
629 // way, so just add a suggestion instead. | 650 // way, so just add a suggestion instead. |
630 // TODO(mmenke): Make the reload button bring up the repost confirmation | 651 // TODO(mmenke): Make the reload button bring up the repost confirmation |
631 // dialog for pages resulting from posts. | 652 // dialog for pages resulting from posts. |
632 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue; | 653 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue; |
633 suggest_reload_repost->SetString("header", | 654 suggest_reload_repost->SetString("header", |
634 l10n_util::GetStringUTF16( | 655 l10n_util::GetStringUTF16( |
635 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER)); | 656 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER)); |
636 suggest_reload_repost->SetString("body", | 657 suggest_reload_repost->SetString("body", |
637 l10n_util::GetStringUTF16( | 658 l10n_util::GetStringUTF16( |
638 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY)); | 659 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY)); |
639 suggestions->Append(suggest_reload_repost); | 660 // Add at the front, so it appears before other suggestions, in the case |
| 661 // suggestions are being overridden by |params|. |
| 662 suggestions->Insert(0, suggest_reload_repost); |
640 } | 663 } |
641 } | 664 } |
642 | 665 |
| 666 // If not using the default suggestions, nothing else to do. |
| 667 if (!use_default_suggestions) |
| 668 return; |
| 669 |
| 670 error_strings->SetBoolean("staleCopyInCache", stale_copy_in_cache); |
| 671 |
| 672 #if defined(OS_CHROMEOS) |
| 673 error_strings->SetString( |
| 674 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); |
| 675 #endif // defined(OS_CHROMEOS) |
| 676 |
643 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 677 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
644 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; | 678 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; |
645 suggest_check_connection->SetString("header", | 679 suggest_check_connection->SetString("header", |
646 l10n_util::GetStringUTF16( | 680 l10n_util::GetStringUTF16( |
647 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); | 681 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); |
648 suggest_check_connection->SetString("body", | 682 suggest_check_connection->SetString("body", |
649 l10n_util::GetStringUTF16( | 683 l10n_util::GetStringUTF16( |
650 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); | 684 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); |
651 suggestions->Append(suggest_check_connection); | 685 suggestions->Append(suggest_check_connection); |
652 } | 686 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 learn_more_url = learn_more_url.ReplaceComponents(repl); | 790 learn_more_url = learn_more_url.ReplaceComponents(repl); |
757 | 791 |
758 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; | 792 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; |
759 // There's only a body for this suggestion. | 793 // There's only a body for this suggestion. |
760 suggest_learn_more->SetString("body", | 794 suggest_learn_more->SetString("body", |
761 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 795 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
762 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 796 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
763 suggestions->Append(suggest_learn_more); | 797 suggestions->Append(suggest_learn_more); |
764 } | 798 } |
765 } | 799 } |
766 | |
767 error_strings->Set("suggestions", suggestions); | |
768 } | 800 } |
769 | 801 |
770 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, | 802 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, |
771 bool is_post) { | 803 bool is_post) { |
772 const LocalizedErrorMap* error_map = | 804 const LocalizedErrorMap* error_map = |
773 LookupErrorMap(error.domain.utf8(), error.reason, is_post); | 805 LookupErrorMap(error.domain.utf8(), error.reason, is_post); |
774 if (error_map) | 806 if (error_map) |
775 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 807 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
776 else | 808 else |
777 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 809 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 #if defined(OS_CHROMEOS) | 849 #if defined(OS_CHROMEOS) |
818 GURL learn_more_url(kAppWarningLearnMoreUrl); | 850 GURL learn_more_url(kAppWarningLearnMoreUrl); |
819 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 851 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
820 suggest_learn_more->SetString("msg", | 852 suggest_learn_more->SetString("msg", |
821 l10n_util::GetStringUTF16( | 853 l10n_util::GetStringUTF16( |
822 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 854 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
823 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 855 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
824 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 856 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
825 #endif // defined(OS_CHROMEOS) | 857 #endif // defined(OS_CHROMEOS) |
826 } | 858 } |
OLD | NEW |