Index: chrome/common/localized_error.cc |
=================================================================== |
--- chrome/common/localized_error.cc (revision 190428) |
+++ 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" |
@@ -21,6 +22,7 @@ |
#include "net/base/net_errors.h" |
#include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/webui/web_ui_util.h" |
#include "webkit/glue/webkit_glue.h" |
#if defined(OS_WIN) |
@@ -29,6 +31,9 @@ |
using WebKit::WebURLError; |
+// Some error pages have no details. |
+#define IDS_ERRORPAGES_DETAILS_NULL 0 |
Nico
2013/03/26 17:56:31
const int?
Also, since this is not a real string
mmenke
2013/03/26 19:22:36
Done.
|
+ |
namespace { |
static const char kRedirectLoopLearnMoreUrl[] = |
@@ -350,53 +355,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,8 +409,10 @@ |
void LocalizedError::GetStrings(const WebKit::WebURLError& error, |
DictionaryValue* error_strings, |
const std::string& locale) { |
- bool rtl = LocaleIsRTL(); |
- error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
+ webui::SetFontAndTextDirection(error_strings); |
+ std::string text_direction; |
+ error_strings->GetString("&textdirection", &text_direction); |
+ bool rtl = (text_direction == "rtl"); |
// Grab the strings and settings that depend on the error type. Init |
// options with default values. |
@@ -461,7 +421,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, |
}; |
@@ -472,12 +432,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 |
@@ -494,6 +448,14 @@ |
options.suggestions = SUGGEST_NONE; |
} |
+ // If there are any suggestions other than reload, populate the suggestion |
+ // 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(UTF8ToUTF16(failed_url.spec())); |
// URLs are always LTR. |
if (rtl) |
@@ -512,12 +474,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) |
@@ -549,11 +531,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) { |