| 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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 int error_code) { | 479 int error_code) { |
| 479 if ((error_code == net::ERR_INTERNET_DISCONNECTED && | 480 if ((error_code == net::ERR_INTERNET_DISCONNECTED && |
| 480 error_domain == net::kErrorDomain) || | 481 error_domain == net::kErrorDomain) || |
| 481 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET && | 482 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET && |
| 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 // Adds a suggestion to reload the page. Depending on whether the request was | |
| 489 // a post or not, either updates |error_strings| to show a reload button or | |
| 490 // |suggestions| to suggest reloading without a button. | |
| 491 void AddReloadSuggestion(const GURL& failed_url, | |
| 492 bool is_post, | |
| 493 base::DictionaryValue* error_strings, | |
| 494 base::ListValue* suggestions) { | |
| 495 if (!is_post) { | |
| 496 base::DictionaryValue* reload_button = new base::DictionaryValue; | |
| 497 reload_button->SetString("msg", | |
| 498 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | |
| 499 reload_button->SetString("reloadUrl", failed_url.spec()); | |
| 500 error_strings->Set("reload", reload_button); | |
| 501 } else { | |
| 502 // If the page was created by a post, it can't be reloaded in the same | |
| 503 // way, so just add a suggestion instead. | |
| 504 // TODO(mmenke): Make the reload button bring up the repost confirmation | |
| 505 // dialog for pages resulting from posts. | |
| 506 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue; | |
| 507 suggest_reload_repost->SetString("header", | |
| 508 l10n_util::GetStringUTF16( | |
| 509 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER)); | |
| 510 suggest_reload_repost->SetString("body", | |
| 511 l10n_util::GetStringUTF16( | |
| 512 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY)); | |
| 513 // Add at the front, so it appears before other suggestions, in the case | |
| 514 // suggestions are being overridden by |params|. | |
| 515 suggestions->Insert(0, suggest_reload_repost); | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 // Updaes |error_strings| according to the information contained in |params|. | |
| 520 void ApplyParamsToErrorStrings( | |
| 521 const GURL& failed_url, | |
| 522 bool is_post, | |
| 523 scoped_ptr<LocalizedError::ErrorPageParams> params, | |
| 524 base::DictionaryValue* error_strings) { | |
| 525 base::ListValue* suggestions = params->override_suggestions.release(); | |
| 526 if (params->suggest_reload) | |
| 527 AddReloadSuggestion(failed_url, is_post, error_strings, suggestions); | |
| 528 error_strings->Set("suggestions", suggestions); | |
| 529 | |
| 530 if (params->search_url.is_valid()) { | |
| 531 error_strings->SetString("searchHeader", | |
| 532 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH)); | |
| 533 error_strings->SetString("searchUrl", params->search_url.spec()); | |
| 534 error_strings->SetString("searchTerms", params->search_terms); | |
| 535 } | |
| 536 } | |
| 537 | |
| 538 } // namespace | 489 } // namespace |
| 539 | 490 |
| 540 const char LocalizedError::kHttpErrorDomain[] = "http"; | 491 const char LocalizedError::kHttpErrorDomain[] = "http"; |
| 541 | 492 |
| 542 LocalizedError::ErrorPageParams::ErrorPageParams() : suggest_reload(false) { | |
| 543 } | |
| 544 | |
| 545 LocalizedError::ErrorPageParams::~ErrorPageParams() { | |
| 546 } | |
| 547 | |
| 548 void LocalizedError::GetStrings(int error_code, | 493 void LocalizedError::GetStrings(int error_code, |
| 549 const std::string& error_domain, | 494 const std::string& error_domain, |
| 550 const GURL& failed_url, | 495 const GURL& failed_url, |
| 551 bool is_post, | 496 bool is_post, |
| 552 bool stale_copy_in_cache, | 497 bool stale_copy_in_cache, |
| 553 const std::string& locale, | 498 const std::string& locale, |
| 554 const std::string& accept_languages, | 499 const std::string& accept_languages, |
| 555 scoped_ptr<ErrorPageParams> params, | |
| 556 base::DictionaryValue* error_strings) { | 500 base::DictionaryValue* error_strings) { |
| 557 bool rtl = LocaleIsRTL(); | 501 bool rtl = LocaleIsRTL(); |
| 558 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 502 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
| 559 | 503 |
| 560 // 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 |
| 561 // options with default values. | 505 // options with default values. |
| 562 LocalizedErrorMap options = { | 506 LocalizedErrorMap options = { |
| 563 0, | 507 0, |
| 564 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 508 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 565 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 509 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), | 552 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), |
| 609 accept_languages)); | 553 accept_languages)); |
| 610 summary->SetString("productName", | 554 summary->SetString("productName", |
| 611 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 555 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 612 | 556 |
| 613 error_strings->SetString( | 557 error_strings->SetString( |
| 614 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); | 558 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); |
| 615 error_strings->SetString( | 559 error_strings->SetString( |
| 616 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); | 560 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); |
| 617 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) |
| 618 | 568 |
| 619 if (options.details_resource_id != kErrorPagesNoDetails) { | 569 if (options.details_resource_id != kErrorPagesNoDetails) { |
| 620 error_strings->SetString( | 570 error_strings->SetString( |
| 621 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 571 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
| 622 } | 572 } |
| 623 | 573 |
| 624 base::string16 error_string; | 574 base::string16 error_string; |
| 625 if (error_domain == net::kErrorDomain) { | 575 if (error_domain == net::kErrorDomain) { |
| 626 // Non-internationalized error string, for debugging Chrome itself. | 576 // Non-internationalized error string, for debugging Chrome itself. |
| 627 std::string ascii_error_string = net::ErrorToString(error_code); | 577 std::string ascii_error_string = net::ErrorToString(error_code); |
| 628 // Remove the leading "net::" from the returned string. | 578 // Remove the leading "net::" from the returned string. |
| 629 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 579 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
| 630 error_string = base::ASCIIToUTF16(ascii_error_string); | 580 error_string = base::ASCIIToUTF16(ascii_error_string); |
| 631 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { | 581 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 632 std::string ascii_error_string = | 582 std::string ascii_error_string = |
| 633 chrome_common_net::DnsProbeStatusToString(error_code); | 583 chrome_common_net::DnsProbeStatusToString(error_code); |
| 634 error_string = base::ASCIIToUTF16(ascii_error_string); | 584 error_string = base::ASCIIToUTF16(ascii_error_string); |
| 635 } else { | 585 } else { |
| 636 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); | 586 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
| 637 error_string = base::IntToString16(error_code); | 587 error_string = base::IntToString16(error_code); |
| 638 } | 588 } |
| 639 error_strings->SetString("errorCode", | 589 error_strings->SetString("errorCode", |
| 640 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); | 590 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
| 641 | 591 |
| 642 // Platform specific information for diagnosing network issues on OSX and | 592 base::ListValue* suggestions = new base::ListValue(); |
| 593 |
| 594 // Platform specific instructions for diagnosing network issues on OSX and |
| 643 // Windows. | 595 // Windows. |
| 644 #if defined(OS_MACOSX) || defined(OS_WIN) | 596 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 645 if (error_domain == net::kErrorDomain && | 597 if (error_domain == net::kErrorDomain && |
| 646 error_code == net::ERR_INTERNET_DISCONNECTED) { | 598 error_code == net::ERR_INTERNET_DISCONNECTED) { |
| 647 int platform_string_id = | 599 int platform_string_id = |
| 648 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; | 600 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; |
| 649 #if defined(OS_WIN) | 601 #if defined(OS_WIN) |
| 650 // Different versions of Windows have different instructions. | 602 // Different versions of Windows have different instructions. |
| 651 base::win::Version windows_version = base::win::GetVersion(); | 603 base::win::Version windows_version = base::win::GetVersion(); |
| 652 if (windows_version < base::win::VERSION_VISTA) { | 604 if (windows_version < base::win::VERSION_VISTA) { |
| 653 // XP, XP64, and Server 2003. | 605 // XP, XP64, and Server 2003. |
| 654 platform_string_id = | 606 platform_string_id = |
| 655 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; | 607 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; |
| 656 } else if (windows_version == base::win::VERSION_VISTA) { | 608 } else if (windows_version == base::win::VERSION_VISTA) { |
| 657 // Vista | 609 // Vista |
| 658 platform_string_id = | 610 platform_string_id = |
| 659 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; | 611 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; |
| 660 } | 612 } |
| 661 #endif // defined(OS_WIN) | 613 #endif // defined(OS_WIN) |
| 662 // Lead with the general error description, and suffix with the platform | 614 // Lead with the general error description, and suffix with the platform |
| 663 // dependent portion of the summary section. | 615 // dependent portion of the summary section. |
| 664 summary->SetString("msg", | 616 summary->SetString("msg", |
| 665 l10n_util::GetStringFUTF16( | 617 l10n_util::GetStringFUTF16( |
| 666 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, | 618 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, |
| 667 l10n_util::GetStringUTF16(options.summary_resource_id), | 619 l10n_util::GetStringUTF16(options.summary_resource_id), |
| 668 l10n_util::GetStringUTF16(platform_string_id))); | 620 l10n_util::GetStringUTF16(platform_string_id))); |
| 669 } | 621 } |
| 670 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 622 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
| 671 | 623 |
| 672 // If there are |params|, just apply them, and there's nothing else to do. | 624 if (options.suggestions & SUGGEST_RELOAD) { |
| 673 if (params) { | 625 if (!is_post) { |
| 674 ApplyParamsToErrorStrings(failed_url, is_post, params.Pass(), | 626 base::DictionaryValue* reload_button = new base::DictionaryValue; |
| 675 error_strings); | 627 reload_button->SetString("msg", |
| 676 return; | 628 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
| 629 reload_button->SetString("reloadUrl", failed_url.spec()); |
| 630 error_strings->Set("reload", reload_button); |
| 631 } else { |
| 632 // If the page was created by a post, it can't be reloaded in the same |
| 633 // way, so just add a suggestion instead. |
| 634 // TODO(mmenke): Make the reload button bring up the repost confirmation |
| 635 // dialog for pages resulting from posts. |
| 636 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue; |
| 637 suggest_reload_repost->SetString("header", |
| 638 l10n_util::GetStringUTF16( |
| 639 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER)); |
| 640 suggest_reload_repost->SetString("body", |
| 641 l10n_util::GetStringUTF16( |
| 642 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY)); |
| 643 suggestions->Append(suggest_reload_repost); |
| 644 } |
| 677 } | 645 } |
| 678 | 646 |
| 679 error_strings->SetBoolean("staleCopyInCache", stale_copy_in_cache); | |
| 680 | |
| 681 #if defined(OS_CHROMEOS) | |
| 682 error_strings->SetString( | |
| 683 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); | |
| 684 #endif // defined(OS_CHROMEOS) | |
| 685 | |
| 686 base::ListValue* suggestions = new base::ListValue(); | |
| 687 | |
| 688 if (options.suggestions & SUGGEST_RELOAD) | |
| 689 AddReloadSuggestion(failed_url, is_post, error_strings, suggestions); | |
| 690 | |
| 691 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 647 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
| 692 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; | 648 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; |
| 693 suggest_check_connection->SetString("header", | 649 suggest_check_connection->SetString("header", |
| 694 l10n_util::GetStringUTF16( | 650 l10n_util::GetStringUTF16( |
| 695 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); | 651 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); |
| 696 suggest_check_connection->SetString("body", | 652 suggest_check_connection->SetString("body", |
| 697 l10n_util::GetStringUTF16( | 653 l10n_util::GetStringUTF16( |
| 698 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); | 654 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); |
| 699 suggestions->Append(suggest_check_connection); | 655 suggestions->Append(suggest_check_connection); |
| 700 } | 656 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 learn_more_url = learn_more_url.ReplaceComponents(repl); | 760 learn_more_url = learn_more_url.ReplaceComponents(repl); |
| 805 | 761 |
| 806 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; | 762 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; |
| 807 // There's only a body for this suggestion. | 763 // There's only a body for this suggestion. |
| 808 suggest_learn_more->SetString("body", | 764 suggest_learn_more->SetString("body", |
| 809 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 765 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 810 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 766 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 811 suggestions->Append(suggest_learn_more); | 767 suggestions->Append(suggest_learn_more); |
| 812 } | 768 } |
| 813 } | 769 } |
| 770 |
| 771 error_strings->Set("suggestions", suggestions); |
| 814 } | 772 } |
| 815 | 773 |
| 816 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, | 774 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, |
| 817 bool is_post) { | 775 bool is_post) { |
| 818 const LocalizedErrorMap* error_map = | 776 const LocalizedErrorMap* error_map = |
| 819 LookupErrorMap(error.domain.utf8(), error.reason, is_post); | 777 LookupErrorMap(error.domain.utf8(), error.reason, is_post); |
| 820 if (error_map) | 778 if (error_map) |
| 821 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 779 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
| 822 else | 780 else |
| 823 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 781 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 #if defined(OS_CHROMEOS) | 821 #if defined(OS_CHROMEOS) |
| 864 GURL learn_more_url(kAppWarningLearnMoreUrl); | 822 GURL learn_more_url(kAppWarningLearnMoreUrl); |
| 865 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 823 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
| 866 suggest_learn_more->SetString("msg", | 824 suggest_learn_more->SetString("msg", |
| 867 l10n_util::GetStringUTF16( | 825 l10n_util::GetStringUTF16( |
| 868 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 826 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 869 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 827 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 870 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 828 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 871 #endif // defined(OS_CHROMEOS) | 829 #endif // defined(OS_CHROMEOS) |
| 872 } | 830 } |
| OLD | NEW |