From 073e501cfce275852b138e41e01136814a39983d Mon Sep 17 00:00:00 2001 From: "mpcomplete@chromium.org" Date: Fri, 21 Oct 2011 22:25:42 +0000 Subject: Use a better error code for when an extension blocks a network request using the webrequest API. BUG=97392 TEST=install a webrequest extension like AdBlock+ experimental and navigate to a URL that is blocked. You should see a descriptive error message. Review URL: http://codereview.chromium.org/8345032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106794 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/generated_resources.grd | 16 ++++++++++++++++ chrome/browser/extensions/extension_webrequest_api.cc | 6 ++---- .../extensions/extension_webrequest_api_unittest.cc | 2 +- chrome/renderer/localized_error.cc | 18 +++++++++++++++++- chrome/renderer/resources/neterror.html | 3 +++ .../extensions/api_test/webrequest/test_blocking.html | 4 ++-- 6 files changed, 41 insertions(+), 8 deletions(-) (limited to 'chrome') diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 96bfaeb..84ea4ce 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6720,6 +6720,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <a jsvalues="href:reloadUrl">Reload</a> this webpage later. + + Disable your extensions and then <a jsvalues="href:reloadUrl">reload</a> this webpage. + Go to the home page of the site: @@ -6836,6 +6839,9 @@ Keep your key file in a safe place. You will need it to create new versions of y $1http://some-unreliable-site.com/ failed to load + + $1http://www.google.com/foo/bar was blocked + This webpage is not available @@ -6878,6 +6884,9 @@ Keep your key file in a safe place. You will need it to create new versions of y Cannot make secure connection because of Kaspersky anti-virus + + This webpage was blocked by an extension + The webpage at <strong jscontent="failedUrl"></strong> might be temporarily down or it may have moved permanently to a new web address. @@ -7253,6 +7262,13 @@ Keep your key file in a safe place. You will need it to create new versions of y Requests to the server have been temporarily throttled. + + A third-party extension has blocked access to this webpage. + + + Requests to the server have been blocked by an extension. + + 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. diff --git a/chrome/browser/extensions/extension_webrequest_api.cc b/chrome/browser/extensions/extension_webrequest_api.cc index 85a9989..616dea4 100644 --- a/chrome/browser/extensions/extension_webrequest_api.cc +++ b/chrome/browser/extensions/extension_webrequest_api.cc @@ -1471,11 +1471,9 @@ void ExtensionWebRequestEventRouter::DecrementBlockCount( request_time_tracker_->SetRequestRedirected(request_id); } - // This signals a failed request to subscribers of onErrorOccurred in case - // a request is cancelled because net::ERR_EMPTY_RESPONSE cannot be - // distinguished from a regular failure. if (blocked_request.callback) { - int rv = canceled ? net::ERR_EMPTY_RESPONSE : net::OK; + // This triggers onErrorOccurred. + int rv = canceled ? net::ERR_BLOCKED_BY_CLIENT : net::OK; net::OldCompletionCallback* callback = blocked_request.callback; // Ensure that request is removed before callback because the callback // might trigger the next event. diff --git a/chrome/browser/extensions/extension_webrequest_api_unittest.cc b/chrome/browser/extensions/extension_webrequest_api_unittest.cc index 1c6a8c4..c1901c2 100644 --- a/chrome/browser/extensions/extension_webrequest_api_unittest.cc +++ b/chrome/browser/extensions/extension_webrequest_api_unittest.cc @@ -286,7 +286,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) { EXPECT_TRUE(!request.is_pending()); EXPECT_EQ(net::URLRequestStatus::FAILED, request.status().status()); - EXPECT_EQ(net::ERR_EMPTY_RESPONSE, request.status().error()); + EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, request.status().error()); EXPECT_EQ(request_url, request.url()); EXPECT_EQ(1U, request.url_chain().size()); EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); diff --git a/chrome/renderer/localized_error.cc b/chrome/renderer/localized_error.cc index ad14e96..a3a30f4 100644 --- a/chrome/renderer/localized_error.cc +++ b/chrome/renderer/localized_error.cc @@ -47,7 +47,8 @@ enum NAV_SUGGESTIONS { SUGGEST_DNS_CONFIG = 1 << 3, SUGGEST_FIREWALL_CONFIG = 1 << 4, SUGGEST_PROXY_CONFIG = 1 << 5, - SUGGEST_LEARNMORE = 1 << 6, + SUGGEST_DISABLE_EXTENSION = 1 << 6, + SUGGEST_LEARNMORE = 1 << 7, }; struct LocalizedErrorMap { @@ -261,6 +262,13 @@ const LocalizedErrorMap net_error_options[] = { IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED, SUGGEST_NONE, }, + {net::ERR_BLOCKED_BY_CLIENT, + IDS_ERRORPAGES_TITLE_BLOCKED, + IDS_ERRORPAGES_HEADING_BLOCKED, + IDS_ERRORPAGES_SUMMARY_BLOCKED, + IDS_ERRORPAGES_DETAILS_BLOCKED, + SUGGEST_DISABLE_EXTENSION, + }, }; const LocalizedErrorMap http_error_options[] = { @@ -593,6 +601,14 @@ void LocalizedError::GetStrings(const WebKit::WebURLError& error, error_strings->Set("suggestionsProxyConfig", suggest_proxy_config); } + if (options.suggestions & SUGGEST_DISABLE_EXTENSION) { + DictionaryValue* suggestion = new DictionaryValue; + suggestion->SetString("msg", + l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION)); + suggestion->SetString("reloadUrl", failed_url_string); + error_strings->Set("suggestionsDisableExtension", suggestion); + } + if (options.suggestions & SUGGEST_LEARNMORE) { GURL learn_more_url; switch (options.error_code) { diff --git a/chrome/renderer/resources/neterror.html b/chrome/renderer/resources/neterror.html index dd456af..ac3172c 100644 --- a/chrome/renderer/resources/neterror.html +++ b/chrome/renderer/resources/neterror.html @@ -178,6 +178,9 @@ if (window.screen.colorDepth >= 24)
  • +
  • + +
  • diff --git a/chrome/test/data/extensions/api_test/webrequest/test_blocking.html b/chrome/test/data/extensions/api_test/webrequest/test_blocking.html index aadb354..8e12ac1 100644 --- a/chrome/test/data/extensions/api_test/webrequest/test_blocking.html +++ b/chrome/test/data/extensions/api_test/webrequest/test_blocking.html @@ -38,7 +38,7 @@ runTests([ details: { url: getURL("complexLoad/b.html"), fromCache: false, - error: "net::ERR_EMPTY_RESPONSE" + error: "net::ERR_BLOCKED_BY_CLIENT" // Request to chrome-extension:// url has no IP. } }, @@ -102,7 +102,7 @@ runTests([ details: { url: getURLHttpSimpleLoad(), fromCache: false, - error: "net::ERR_EMPTY_RESPONSE" + error: "net::ERR_BLOCKED_BY_CLIENT" // Request to chrome-extension:// url has no IP. } }, -- cgit v1.1