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