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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 int error_code) { | 478 int error_code) { |
480 if ((error_code == net::ERR_INTERNET_DISCONNECTED && | 479 if ((error_code == net::ERR_INTERNET_DISCONNECTED && |
481 error_domain == net::kErrorDomain) || | 480 error_domain == net::kErrorDomain) || |
482 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET && | 481 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET && |
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 |
| 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 |
489 } // namespace | 538 } // namespace |
490 | 539 |
491 const char LocalizedError::kHttpErrorDomain[] = "http"; | 540 const char LocalizedError::kHttpErrorDomain[] = "http"; |
492 | 541 |
| 542 LocalizedError::ErrorPageParams::ErrorPageParams() : suggest_reload(false) { |
| 543 } |
| 544 |
| 545 LocalizedError::ErrorPageParams::~ErrorPageParams() { |
| 546 } |
| 547 |
493 void LocalizedError::GetStrings(int error_code, | 548 void LocalizedError::GetStrings(int error_code, |
494 const std::string& error_domain, | 549 const std::string& error_domain, |
495 const GURL& failed_url, | 550 const GURL& failed_url, |
496 bool is_post, | 551 bool is_post, |
497 bool stale_copy_in_cache, | 552 bool stale_copy_in_cache, |
498 const std::string& locale, | 553 const std::string& locale, |
499 const std::string& accept_languages, | 554 const std::string& accept_languages, |
| 555 scoped_ptr<ErrorPageParams> params, |
500 base::DictionaryValue* error_strings) { | 556 base::DictionaryValue* error_strings) { |
501 bool rtl = LocaleIsRTL(); | 557 bool rtl = LocaleIsRTL(); |
502 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 558 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
503 | 559 |
504 // Grab the strings and settings that depend on the error type. Init | 560 // Grab the strings and settings that depend on the error type. Init |
505 // options with default values. | 561 // options with default values. |
506 LocalizedErrorMap options = { | 562 LocalizedErrorMap options = { |
507 0, | 563 0, |
508 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 564 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
509 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 565 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), | 608 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(), |
553 accept_languages)); | 609 accept_languages)); |
554 summary->SetString("productName", | 610 summary->SetString("productName", |
555 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 611 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
556 | 612 |
557 error_strings->SetString( | 613 error_strings->SetString( |
558 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); | 614 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); |
559 error_strings->SetString( | 615 error_strings->SetString( |
560 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); | 616 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); |
561 error_strings->Set("summary", summary); | 617 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 | 618 |
569 if (options.details_resource_id != kErrorPagesNoDetails) { | 619 if (options.details_resource_id != kErrorPagesNoDetails) { |
570 error_strings->SetString( | 620 error_strings->SetString( |
571 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 621 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
572 } | 622 } |
573 | 623 |
574 base::string16 error_string; | 624 base::string16 error_string; |
575 if (error_domain == net::kErrorDomain) { | 625 if (error_domain == net::kErrorDomain) { |
576 // Non-internationalized error string, for debugging Chrome itself. | 626 // Non-internationalized error string, for debugging Chrome itself. |
577 std::string ascii_error_string = net::ErrorToString(error_code); | 627 std::string ascii_error_string = net::ErrorToString(error_code); |
578 // Remove the leading "net::" from the returned string. | 628 // Remove the leading "net::" from the returned string. |
579 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 629 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
580 error_string = base::ASCIIToUTF16(ascii_error_string); | 630 error_string = base::ASCIIToUTF16(ascii_error_string); |
581 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { | 631 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
582 std::string ascii_error_string = | 632 std::string ascii_error_string = |
583 chrome_common_net::DnsProbeStatusToString(error_code); | 633 chrome_common_net::DnsProbeStatusToString(error_code); |
584 error_string = base::ASCIIToUTF16(ascii_error_string); | 634 error_string = base::ASCIIToUTF16(ascii_error_string); |
585 } else { | 635 } else { |
586 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); | 636 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
587 error_string = base::IntToString16(error_code); | 637 error_string = base::IntToString16(error_code); |
588 } | 638 } |
589 error_strings->SetString("errorCode", | 639 error_strings->SetString("errorCode", |
590 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); | 640 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
591 | 641 |
592 base::ListValue* suggestions = new base::ListValue(); | 642 // Platform specific information for diagnosing network issues on OSX and |
593 | |
594 // Platform specific instructions for diagnosing network issues on OSX and | |
595 // Windows. | 643 // Windows. |
596 #if defined(OS_MACOSX) || defined(OS_WIN) | 644 #if defined(OS_MACOSX) || defined(OS_WIN) |
597 if (error_domain == net::kErrorDomain && | 645 if (error_domain == net::kErrorDomain && |
598 error_code == net::ERR_INTERNET_DISCONNECTED) { | 646 error_code == net::ERR_INTERNET_DISCONNECTED) { |
599 int platform_string_id = | 647 int platform_string_id = |
600 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; | 648 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM; |
601 #if defined(OS_WIN) | 649 #if defined(OS_WIN) |
602 // Different versions of Windows have different instructions. | 650 // Different versions of Windows have different instructions. |
603 base::win::Version windows_version = base::win::GetVersion(); | 651 base::win::Version windows_version = base::win::GetVersion(); |
604 if (windows_version < base::win::VERSION_VISTA) { | 652 if (windows_version < base::win::VERSION_VISTA) { |
605 // XP, XP64, and Server 2003. | 653 // XP, XP64, and Server 2003. |
606 platform_string_id = | 654 platform_string_id = |
607 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; | 655 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP; |
608 } else if (windows_version == base::win::VERSION_VISTA) { | 656 } else if (windows_version == base::win::VERSION_VISTA) { |
609 // Vista | 657 // Vista |
610 platform_string_id = | 658 platform_string_id = |
611 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; | 659 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA; |
612 } | 660 } |
613 #endif // defined(OS_WIN) | 661 #endif // defined(OS_WIN) |
614 // Lead with the general error description, and suffix with the platform | 662 // Lead with the general error description, and suffix with the platform |
615 // dependent portion of the summary section. | 663 // dependent portion of the summary section. |
616 summary->SetString("msg", | 664 summary->SetString("msg", |
617 l10n_util::GetStringFUTF16( | 665 l10n_util::GetStringFUTF16( |
618 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, | 666 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, |
619 l10n_util::GetStringUTF16(options.summary_resource_id), | 667 l10n_util::GetStringUTF16(options.summary_resource_id), |
620 l10n_util::GetStringUTF16(platform_string_id))); | 668 l10n_util::GetStringUTF16(platform_string_id))); |
621 } | 669 } |
622 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 670 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
623 | 671 |
624 if (options.suggestions & SUGGEST_RELOAD) { | 672 // If there are |params|, just apply them, and there's nothing else to do. |
625 if (!is_post) { | 673 if (params) { |
626 base::DictionaryValue* reload_button = new base::DictionaryValue; | 674 ApplyParamsToErrorStrings(failed_url, is_post, params.Pass(), |
627 reload_button->SetString("msg", | 675 error_strings); |
628 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 676 return; |
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 } | |
645 } | 677 } |
646 | 678 |
| 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 |
647 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 691 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
648 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; | 692 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue; |
649 suggest_check_connection->SetString("header", | 693 suggest_check_connection->SetString("header", |
650 l10n_util::GetStringUTF16( | 694 l10n_util::GetStringUTF16( |
651 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); | 695 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); |
652 suggest_check_connection->SetString("body", | 696 suggest_check_connection->SetString("body", |
653 l10n_util::GetStringUTF16( | 697 l10n_util::GetStringUTF16( |
654 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); | 698 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); |
655 suggestions->Append(suggest_check_connection); | 699 suggestions->Append(suggest_check_connection); |
656 } | 700 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 learn_more_url = learn_more_url.ReplaceComponents(repl); | 804 learn_more_url = learn_more_url.ReplaceComponents(repl); |
761 | 805 |
762 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; | 806 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue; |
763 // There's only a body for this suggestion. | 807 // There's only a body for this suggestion. |
764 suggest_learn_more->SetString("body", | 808 suggest_learn_more->SetString("body", |
765 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 809 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
766 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 810 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
767 suggestions->Append(suggest_learn_more); | 811 suggestions->Append(suggest_learn_more); |
768 } | 812 } |
769 } | 813 } |
770 | |
771 error_strings->Set("suggestions", suggestions); | |
772 } | 814 } |
773 | 815 |
774 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, | 816 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, |
775 bool is_post) { | 817 bool is_post) { |
776 const LocalizedErrorMap* error_map = | 818 const LocalizedErrorMap* error_map = |
777 LookupErrorMap(error.domain.utf8(), error.reason, is_post); | 819 LookupErrorMap(error.domain.utf8(), error.reason, is_post); |
778 if (error_map) | 820 if (error_map) |
779 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 821 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
780 else | 822 else |
781 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 823 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 #if defined(OS_CHROMEOS) | 863 #if defined(OS_CHROMEOS) |
822 GURL learn_more_url(kAppWarningLearnMoreUrl); | 864 GURL learn_more_url(kAppWarningLearnMoreUrl); |
823 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 865 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
824 suggest_learn_more->SetString("msg", | 866 suggest_learn_more->SetString("msg", |
825 l10n_util::GetStringUTF16( | 867 l10n_util::GetStringUTF16( |
826 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 868 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
827 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 869 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
828 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 870 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
829 #endif // defined(OS_CHROMEOS) | 871 #endif // defined(OS_CHROMEOS) |
830 } | 872 } |
OLD | NEW |