Chromium Code Reviews| Index: chrome/common/localized_error.cc |
| =================================================================== |
| --- chrome/common/localized_error.cc (revision 184561) |
| +++ chrome/common/localized_error.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include "base/i18n/rtl.h" |
| #include "base/logging.h" |
| #include "base/string16.h" |
| +#include "base/string_util.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/values.h" |
| @@ -28,6 +29,9 @@ |
| using WebKit::WebURLError; |
| +// Some error pages have no details. |
| +#define IDS_ERRORPAGES_DETAILS_NULL 0 |
| + |
| namespace { |
| static const char kRedirectLoopLearnMoreUrl[] = |
| @@ -340,53 +344,6 @@ |
| }, |
| }; |
| -const char* HttpErrorToString(int status_code) { |
| - switch (status_code) { |
| - case 403: |
| - return "Forbidden"; |
| - case 410: |
| - return "Gone"; |
| - case 500: |
| - return "Internal Server Error"; |
| - case 501: |
| - return "Not Implemented"; |
| - case 502: |
| - return "Bad Gateway"; |
| - case 503: |
| - return "Service Unavailable"; |
| - case 504: |
| - return "Gateway Timeout"; |
| - case 505: |
| - return "HTTP Version Not Supported"; |
| - default: |
| - return ""; |
| - } |
| -} |
| - |
| -string16 GetErrorDetailsString(const std::string& error_domain, |
| - int error_code, |
| - const string16& details) { |
| - int error_page_template; |
| - const char* error_string; |
| - if (error_domain == net::kErrorDomain) { |
| - error_page_template = IDS_ERRORPAGES_DETAILS_TEMPLATE; |
| - error_string = net::ErrorToString(error_code); |
| - DCHECK(error_code < 0); // Net error codes are negative. |
| - error_code = -error_code; |
| - } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
| - error_page_template = IDS_ERRORPAGES_HTTP_DETAILS_TEMPLATE; |
| - error_string = HttpErrorToString(error_code); |
| - } else { |
| - NOTREACHED(); |
| - return string16(); |
| - } |
| - return l10n_util::GetStringFUTF16( |
| - error_page_template, |
| - base::IntToString16(error_code), |
| - ASCIIToUTF16(error_string), |
| - details); |
| -} |
| - |
| const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps, |
| size_t num_maps, |
| int error_code) { |
| @@ -451,7 +408,7 @@ |
| IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, |
| - IDS_ERRORPAGES_DETAILS_UNKNOWN, |
| + IDS_ERRORPAGES_DETAILS_NULL, |
| SUGGEST_NONE, |
| }; |
| @@ -462,12 +419,6 @@ |
| if (error_map) |
| options = *error_map; |
| - if (options.suggestions != SUGGEST_NONE) { |
| - error_strings->SetString( |
| - "suggestionsHeading", |
| - l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HEADING)); |
| - } |
| - |
| const GURL failed_url = error.unreachableURL; |
| // If we got "access denied" but the url was a file URL, then we say it was a |
| @@ -484,6 +435,14 @@ |
| options.suggestions = SUGGEST_NONE; |
| } |
| + // If there are any suggestions other than reload, popuplate the suggestion |
|
eroman
2013/02/27 02:26:16
typo: populate
mmenke
2013/02/27 02:43:01
Done.
|
| + // heading (reload has a button, rather than a suggestion in the list). |
| + if ((options.suggestions & ~SUGGEST_RELOAD) != SUGGEST_NONE) { |
| + error_strings->SetString( |
| + "suggestionsHeading", |
| + l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HEADING)); |
| + } |
| + |
| string16 failed_url_string(ASCIIToUTF16(failed_url.spec())); |
| // URLs are always LTR. |
| if (rtl) |
| @@ -502,12 +461,32 @@ |
| summary->SetString("hostName", failed_url.host()); |
| summary->SetString("productName", |
| l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| + |
| + error_strings->SetString( |
| + "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE)); |
| + error_strings->SetString( |
| + "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS)); |
| error_strings->Set("summary", summary); |
| - string16 details = l10n_util::GetStringUTF16(options.details_resource_id); |
| - error_strings->SetString("details", |
| - GetErrorDetailsString(error_domain, error_code, details)); |
| + if (options.details_resource_id != IDS_ERRORPAGES_DETAILS_NULL) { |
| + error_strings->SetString( |
| + "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
| + } |
| + string16 error_string; |
| + if (error_domain == net::kErrorDomain) { |
| + // Non-internationalized error string, for debugging Chrome itself. |
| + std::string ascii_error_string = net::ErrorToString(error_code); |
| + // Remove the leading "net::" from the returned string. |
| + RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
| + error_string = ASCIIToUTF16(ascii_error_string); |
| + } else { |
| + DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
| + error_string = base::IntToString16(error_code); |
| + } |
| + error_strings->SetString("errorCode", |
| + l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
| + |
| // Platform specific instructions for diagnosing network issues on OSX and |
| // Windows. |
| #if defined(OS_MACOSX) || defined(OS_WIN) |
| @@ -539,11 +518,11 @@ |
| #endif // defined(OS_MACOSX) || defined(OS_WIN) |
| if (options.suggestions & SUGGEST_RELOAD) { |
| - DictionaryValue* suggest_reload = new DictionaryValue; |
| - suggest_reload->SetString("msg", |
| - l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_RELOAD)); |
| - suggest_reload->SetString("reloadUrl", failed_url_string); |
| - error_strings->Set("suggestionsReload", suggest_reload); |
| + DictionaryValue* reload_button = new DictionaryValue; |
| + reload_button->SetString("msg", |
| + l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
| + reload_button->SetString("reloadUrl", failed_url_string); |
| + error_strings->Set("reload", reload_button); |
| } |
| if (options.suggestions & SUGGEST_HOSTNAME) { |