| 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" |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (error_domain == net::kErrorDomain && | 524 if (error_domain == net::kErrorDomain && |
| 525 error_code == net::ERR_ACCESS_DENIED && | 525 error_code == net::ERR_ACCESS_DENIED && |
| 526 failed_url.scheme() == "file") { | 526 failed_url.scheme() == "file") { |
| 527 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED; | 527 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED; |
| 528 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED; | 528 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED; |
| 529 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED; | 529 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED; |
| 530 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED; | 530 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED; |
| 531 options.suggestions = SUGGEST_NONE; | 531 options.suggestions = SUGGEST_NONE; |
| 532 } | 532 } |
| 533 | 533 |
| 534 string16 failed_url_string(net::FormatUrl( | 534 base::string16 failed_url_string(net::FormatUrl( |
| 535 failed_url, accept_languages, net::kFormatUrlOmitNothing, | 535 failed_url, accept_languages, net::kFormatUrlOmitNothing, |
| 536 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | 536 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); |
| 537 // URLs are always LTR. | 537 // URLs are always LTR. |
| 538 if (rtl) | 538 if (rtl) |
| 539 base::i18n::WrapStringWithLTRFormatting(&failed_url_string); | 539 base::i18n::WrapStringWithLTRFormatting(&failed_url_string); |
| 540 error_strings->SetString("title", | 540 error_strings->SetString("title", |
| 541 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string)); | 541 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string)); |
| 542 error_strings->SetString("heading", | 542 error_strings->SetString("heading", |
| 543 l10n_util::GetStringUTF16(options.heading_resource_id)); | 543 l10n_util::GetStringUTF16(options.heading_resource_id)); |
| 544 | 544 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 562 #if defined(OS_CHROMEOS) | 562 #if defined(OS_CHROMEOS) |
| 563 error_strings->SetString( | 563 error_strings->SetString( |
| 564 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); | 564 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE)); |
| 565 #endif // defined(OS_CHROMEOS) | 565 #endif // defined(OS_CHROMEOS) |
| 566 | 566 |
| 567 if (options.details_resource_id != kErrorPagesNoDetails) { | 567 if (options.details_resource_id != kErrorPagesNoDetails) { |
| 568 error_strings->SetString( | 568 error_strings->SetString( |
| 569 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 569 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
| 570 } | 570 } |
| 571 | 571 |
| 572 string16 error_string; | 572 base::string16 error_string; |
| 573 if (error_domain == net::kErrorDomain) { | 573 if (error_domain == net::kErrorDomain) { |
| 574 // Non-internationalized error string, for debugging Chrome itself. | 574 // Non-internationalized error string, for debugging Chrome itself. |
| 575 std::string ascii_error_string = net::ErrorToString(error_code); | 575 std::string ascii_error_string = net::ErrorToString(error_code); |
| 576 // Remove the leading "net::" from the returned string. | 576 // Remove the leading "net::" from the returned string. |
| 577 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 577 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
| 578 error_string = ASCIIToUTF16(ascii_error_string); | 578 error_string = ASCIIToUTF16(ascii_error_string); |
| 579 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { | 579 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 580 std::string ascii_error_string = | 580 std::string ascii_error_string = |
| 581 chrome_common_net::DnsProbeStatusToString(error_code); | 581 chrome_common_net::DnsProbeStatusToString(error_code); |
| 582 error_string = ASCIIToUTF16(ascii_error_string); | 582 error_string = ASCIIToUTF16(ascii_error_string); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 suggest_learn_more->SetString("body", | 762 suggest_learn_more->SetString("body", |
| 763 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 763 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 764 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 764 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 765 suggestions->Append(suggest_learn_more); | 765 suggestions->Append(suggest_learn_more); |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 | 768 |
| 769 error_strings->Set("suggestions", suggestions); | 769 error_strings->Set("suggestions", suggestions); |
| 770 } | 770 } |
| 771 | 771 |
| 772 string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, | 772 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error, |
| 773 bool is_post) { | 773 bool is_post) { |
| 774 const LocalizedErrorMap* error_map = | 774 const LocalizedErrorMap* error_map = |
| 775 LookupErrorMap(error.domain.utf8(), error.reason, is_post); | 775 LookupErrorMap(error.domain.utf8(), error.reason, is_post); |
| 776 if (error_map) | 776 if (error_map) |
| 777 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 777 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
| 778 else | 778 else |
| 779 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 779 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
| 780 } | 780 } |
| 781 | 781 |
| 782 bool LocalizedError::HasStrings(const std::string& error_domain, | 782 bool LocalizedError::HasStrings(const std::string& error_domain, |
| 783 int error_code) { | 783 int error_code) { |
| 784 // Whether or not the there are strings for an error does not depend on | 784 // Whether or not the there are strings for an error does not depend on |
| 785 // whether or not the page was be generated by a POST, so just claim it was | 785 // whether or not the page was be generated by a POST, so just claim it was |
| 786 // not. | 786 // not. |
| 787 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL; | 787 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL; |
| 788 } | 788 } |
| 789 | 789 |
| 790 void LocalizedError::GetAppErrorStrings( | 790 void LocalizedError::GetAppErrorStrings( |
| 791 const GURL& display_url, | 791 const GURL& display_url, |
| 792 const extensions::Extension* app, | 792 const extensions::Extension* app, |
| 793 base::DictionaryValue* error_strings) { | 793 base::DictionaryValue* error_strings) { |
| 794 DCHECK(app); | 794 DCHECK(app); |
| 795 | 795 |
| 796 bool rtl = LocaleIsRTL(); | 796 bool rtl = LocaleIsRTL(); |
| 797 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 797 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
| 798 | 798 |
| 799 string16 failed_url(ASCIIToUTF16(display_url.spec())); | 799 base::string16 failed_url(ASCIIToUTF16(display_url.spec())); |
| 800 // URLs are always LTR. | 800 // URLs are always LTR. |
| 801 if (rtl) | 801 if (rtl) |
| 802 base::i18n::WrapStringWithLTRFormatting(&failed_url); | 802 base::i18n::WrapStringWithLTRFormatting(&failed_url); |
| 803 error_strings->SetString( | 803 error_strings->SetString( |
| 804 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 804 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 805 failed_url.c_str())); | 805 failed_url.c_str())); |
| 806 | 806 |
| 807 error_strings->SetString("title", app->name()); | 807 error_strings->SetString("title", app->name()); |
| 808 error_strings->SetString( | 808 error_strings->SetString( |
| 809 "icon", | 809 "icon", |
| 810 extensions::IconsInfo::GetIconURL( | 810 extensions::IconsInfo::GetIconURL( |
| 811 app, | 811 app, |
| 812 extension_misc::EXTENSION_ICON_GIGANTOR, | 812 extension_misc::EXTENSION_ICON_GIGANTOR, |
| 813 ExtensionIconSet::MATCH_SMALLER).spec()); | 813 ExtensionIconSet::MATCH_SMALLER).spec()); |
| 814 error_strings->SetString("name", app->name()); | 814 error_strings->SetString("name", app->name()); |
| 815 error_strings->SetString( | 815 error_strings->SetString( |
| 816 "msg", | 816 "msg", |
| 817 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING)); | 817 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING)); |
| 818 | 818 |
| 819 #if defined(OS_CHROMEOS) | 819 #if defined(OS_CHROMEOS) |
| 820 GURL learn_more_url(kAppWarningLearnMoreUrl); | 820 GURL learn_more_url(kAppWarningLearnMoreUrl); |
| 821 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 821 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
| 822 suggest_learn_more->SetString("msg", | 822 suggest_learn_more->SetString("msg", |
| 823 l10n_util::GetStringUTF16( | 823 l10n_util::GetStringUTF16( |
| 824 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 824 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 825 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 825 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 826 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 826 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 827 #endif // defined(OS_CHROMEOS) | 827 #endif // defined(OS_CHROMEOS) |
| 828 } | 828 } |
| OLD | NEW |