summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 01:59:53 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 01:59:53 +0000
commit9fa242b2b6679e1b05d322d4785262e6716e4738 (patch)
treeae2faba0008e75857f7f020def76efe2296746e4
parent984f08170b1a49deeb7bbb5b8583cb8028c116cd (diff)
downloadchromium_src-9fa242b2b6679e1b05d322d4785262e6716e4738.zip
chromium_src-9fa242b2b6679e1b05d322d4785262e6716e4738.tar.gz
chromium_src-9fa242b2b6679e1b05d322d4785262e6716e4738.tar.bz2
New network error page: Fix resubmit warning when
navigating forward / back to a page generated by a POST that can not be retrieved from the CACHE. This was broken (knowingly) in revision 191712 (https://codereview.chromium.org/12277011/). BUG=174194,226909 Review URL: https://codereview.chromium.org/13811022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194514 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd8
-rw-r--r--chrome/common/localized_error.cc82
-rw-r--r--chrome/common/localized_error.h16
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc21
-rw-r--r--chrome/renderer/net/net_error_helper.cc11
-rw-r--r--chrome/renderer/net/net_error_helper.h1
6 files changed, 79 insertions, 60 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index e755f0e..544bf1f 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -9144,6 +9144,12 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1
</message>
</if>
+ <message name="IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER" desc="When a page fails to load, sometimes we suggest reloading a page. In the case that reloading the page requires resubmitting data to a website, we use this as a header above a short set of instructions.">
+ Reload this webpage.
+ </message>
+ <message name="IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY" desc="When a page fails to load, sometimes we suggest reloading a page. In the case that reloading the page requires resubmitting data to a website, this is displayed below a short header.">
+ Press the reload button to resubmit the data needed to load the page.
+ </message>
<message name="IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER" desc="When a page fails to load, we provide a suggestion that the user try disabling an extension that's blocking it.">
Disable your extensions and then reload this webpage.
</message>
@@ -9679,7 +9685,7 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1
</message>
<message name="IDS_ERRORPAGES_HTTP_POST_WARNING" desc="The error message displayed when the user navigates back or forward to a page which would resubmit post data. They can hit reload to send POST data again and load the page.">
- This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. Press Reload to resend that data and display this page.
+ This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.
</message>
<message name="IDS_ERRORPAGES_APP_WARNING" desc="The error message displayed when the browser can not reach the requested page from an app.">
diff --git a/chrome/common/localized_error.cc b/chrome/common/localized_error.cc
index 0cdd148..f547e34 100644
--- a/chrome/common/localized_error.cc
+++ b/chrome/common/localized_error.cc
@@ -294,6 +294,18 @@ const LocalizedErrorMap net_error_options[] = {
},
};
+// Special error page to be used in the case of navigating back to a page
+// generated by a POST. LocalizedError::HasStrings expects this net error code
+// to also appear in the array above.
+const LocalizedErrorMap repost_error = {
+ net::ERR_CACHE_MISS,
+ IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
+ IDS_HTTP_POST_WARNING_TITLE,
+ IDS_ERRORPAGES_HTTP_POST_WARNING,
+ IDS_ERRORPAGES_DETAILS_CACHE_MISS,
+ SUGGEST_RELOAD,
+};
+
const LocalizedErrorMap http_error_options[] = {
{403,
IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
@@ -365,8 +377,12 @@ const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
}
const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
- int error_code) {
+ int error_code, bool is_post) {
if (error_domain == net::kErrorDomain) {
+ // Display a different page in the special case of navigating through the
+ // history to an uncached page created by a POST.
+ if (is_post && error_code == net::ERR_CACHE_MISS)
+ return &repost_error;
return FindErrorMapInArray(net_error_options,
arraysize(net_error_options),
error_code);
@@ -406,8 +422,9 @@ DictionaryValue* GetStandardMenuItemsText() {
const char LocalizedError::kHttpErrorDomain[] = "http";
void LocalizedError::GetStrings(const WebKit::WebURLError& error,
- DictionaryValue* error_strings,
- const std::string& locale) {
+ bool is_post,
+ const std::string& locale,
+ DictionaryValue* error_strings) {
bool rtl = LocaleIsRTL();
error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
@@ -424,8 +441,8 @@ void LocalizedError::GetStrings(const WebKit::WebURLError& error,
const std::string error_domain = error.domain.utf8();
int error_code = error.reason;
- const LocalizedErrorMap* error_map =
- LookupErrorMap(error_domain, error_code);
+ const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
+ is_post);
if (error_map)
options = *error_map;
@@ -522,11 +539,26 @@ void LocalizedError::GetStrings(const WebKit::WebURLError& error,
#endif // defined(OS_MACOSX) || defined(OS_WIN)
if (options.suggestions & 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 (!is_post) {
+ 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);
+ } else {
+ // If the page was created by a post, it can't be reloaded in the same
+ // way, so just add a suggestion instead.
+ // TODO(mmenke): Make the reload button bring up the repost confirmation
+ // dialog for pages resulting from posts.
+ DictionaryValue* suggest_reload_repost = new DictionaryValue;
+ suggest_reload_repost->SetString("header",
+ l10n_util::GetStringUTF16(
+ IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
+ suggest_reload_repost->SetString("body",
+ l10n_util::GetStringUTF16(
+ IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
+ suggestions->Append(suggest_reload_repost);
+ }
}
if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
@@ -653,9 +685,10 @@ void LocalizedError::GetStrings(const WebKit::WebURLError& error,
error_strings->Set("suggestions", suggestions);
}
-string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error) {
+string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error,
+ bool is_post) {
const LocalizedErrorMap* error_map =
- LookupErrorMap(error.domain.utf8(), error.reason);
+ LookupErrorMap(error.domain.utf8(), error.reason, is_post);
if (error_map)
return l10n_util::GetStringUTF16(error_map->details_resource_id);
else
@@ -664,27 +697,10 @@ string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error) {
bool LocalizedError::HasStrings(const std::string& error_domain,
int error_code) {
- return LookupErrorMap(error_domain, error_code) != NULL;
-}
-
-void LocalizedError::GetFormRepostStrings(const GURL& display_url,
- DictionaryValue* error_strings) {
- bool rtl = LocaleIsRTL();
- error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
-
- string16 failed_url(ASCIIToUTF16(display_url.spec()));
- // URLs are always LTR.
- if (rtl)
- base::i18n::WrapStringWithLTRFormatting(&failed_url);
- error_strings->SetString(
- "title", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
- failed_url));
- error_strings->SetString(
- "heading", l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE));
- DictionaryValue* summary = new DictionaryValue;
- summary->SetString(
- "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_HTTP_POST_WARNING));
- error_strings->Set("summary", summary);
+ // Whether or not the there are strings for an error does not depend on
+ // whether or not the page was be generated by a POST, so just claim it was
+ // not.
+ return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
}
void LocalizedError::GetAppErrorStrings(
diff --git a/chrome/common/localized_error.h b/chrome/common/localized_error.h
index 231d105..69d1d27 100644
--- a/chrome/common/localized_error.h
+++ b/chrome/common/localized_error.h
@@ -29,23 +29,17 @@ class LocalizedError {
// Fills |error_strings| with values to be used to build an error page used
// on HTTP errors, like 404 or connection reset.
static void GetStrings(const WebKit::WebURLError& error,
- base::DictionaryValue* strings,
- const std::string& locale);
+ bool is_post,
+ const std::string& locale,
+ base::DictionaryValue* strings);
// Returns a description of the encountered error.
- static string16 GetErrorDetails(const WebKit::WebURLError& error);
+ static string16 GetErrorDetails(const WebKit::WebURLError& error,
+ bool is_post);
// Returns true if an error page exists for the specified parameters.
static bool HasStrings(const std::string& error_domain, int error_code);
- // Fills |error_strings| with values to be used to build an error page which
- // warns against reposting form data. This is special cased because the form
- // repost "error page" has no real error associated with it, and doesn't have
- // enough strings localized to meaningfully fill the net error template.
- // TODO(mmenke): Get rid of this and merge with GetStrings.
- static void GetFormRepostStrings(const GURL& display_url,
- base::DictionaryValue* error_strings);
-
// Fills |error_strings| with values to be used to build an error page used
// on HTTP errors, like 404 or connection reset, but using information from
// the associated |app| in order to make the error page look like it's more
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index f2c7bbb..6da9edf 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -828,10 +828,6 @@ void ChromeContentRendererClient::GetNavigationErrorStrings(
string16* error_description) {
const GURL failed_url = error.unreachableURL;
const Extension* extension = NULL;
- const bool is_repost =
- error.reason == net::ERR_CACHE_MISS &&
- error.domain == WebString::fromUTF8(net::kErrorDomain) &&
- EqualsASCII(failed_request.httpMethod(), "POST");
if (failed_url.is_valid() &&
!failed_url.SchemeIs(extensions::kExtensionScheme)) {
@@ -839,6 +835,8 @@ void ChromeContentRendererClient::GetNavigationErrorStrings(
ExtensionURLInfo(failed_url));
}
+ bool is_post = EqualsASCII(failed_request.httpMethod(), "POST");
+
if (error_html) {
// Use a local error page.
int resource_id;
@@ -851,12 +849,11 @@ void ChromeContentRendererClient::GetNavigationErrorStrings(
// error messages?
resource_id = IDR_ERROR_APP_HTML;
} else {
- if (is_repost) {
- LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
- } else {
- LocalizedError::GetStrings(error, &error_strings,
- RenderThread::Get()->GetLocale());
- }
+ LocalizedError::GetStrings(
+ error,
+ is_post,
+ RenderThread::Get()->GetLocale(),
+ &error_strings);
resource_id = IDR_NET_ERROR_HTML;
}
@@ -872,8 +869,8 @@ void ChromeContentRendererClient::GetNavigationErrorStrings(
}
if (error_description) {
- if (!extension && !is_repost)
- *error_description = LocalizedError::GetErrorDetails(error);
+ if (!extension)
+ *error_description = LocalizedError::GetErrorDetails(error, is_post);
}
}
diff --git a/chrome/renderer/net/net_error_helper.cc b/chrome/renderer/net/net_error_helper.cc
index 3e7b9ee..e53a906 100644
--- a/chrome/renderer/net/net_error_helper.cc
+++ b/chrome/renderer/net/net_error_helper.cc
@@ -101,7 +101,8 @@ NetErrorHelper::NetErrorHelper(RenderView* render_view)
&NetErrorHelper::TrackerCallback,
base::Unretained(this)))),
dns_error_page_state_(NetErrorTracker::DNS_ERROR_PAGE_NONE),
- updated_error_page_(false) {
+ updated_error_page_(false),
+ is_failed_post_(false) {
}
NetErrorHelper::~NetErrorHelper() {
@@ -113,6 +114,9 @@ void NetErrorHelper::DidStartProvisionalLoad(WebKit::WebFrame* frame) {
void NetErrorHelper::DidFailProvisionalLoad(WebKit::WebFrame* frame,
const WebKit::WebURLError& error) {
+ WebKit::WebDataSource* data_source = frame->provisionalDataSource();
+ const WebKit::WebURLRequest& failed_request = data_source->request();
+ is_failed_post_ = EqualsASCII(failed_request.httpMethod(), "POST");
tracker_.OnFailProvisionalLoad(GetFrameType(frame), GetErrorType(error));
}
@@ -180,8 +184,9 @@ void NetErrorHelper::UpdateErrorPage(DnsProbeResult dns_probe_result) {
DictionaryValue error_strings;
LocalizedError::GetStrings(NetErrorToWebURLError(net_error),
- &error_strings,
- RenderThread::Get()->GetLocale());
+ is_failed_post_,
+ RenderThread::Get()->GetLocale(),
+ &error_strings);
// TODO(ttuttle): Update error page with error_strings.
}
diff --git a/chrome/renderer/net/net_error_helper.h b/chrome/renderer/net/net_error_helper.h
index 4836251..cb33387e 100644
--- a/chrome/renderer/net/net_error_helper.h
+++ b/chrome/renderer/net/net_error_helper.h
@@ -39,6 +39,7 @@ class NetErrorHelper : public content::RenderViewObserver {
NetErrorTracker tracker_;
NetErrorTracker::DnsErrorPageState dns_error_page_state_;
bool updated_error_page_;
+ bool is_failed_post_;
};
#endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_