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