diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-09 19:49:19 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-09 19:49:19 +0000 |
commit | 5ee3c04ab898137517413dad15c5dbda119bc9cd (patch) | |
tree | 9aecd372a62a4e0843fd216d3450cdced6afb326 /chrome | |
parent | 1372afff134179df33faf084c2d78a044c349f9d (diff) | |
download | chromium_src-5ee3c04ab898137517413dad15c5dbda119bc9cd.zip chromium_src-5ee3c04ab898137517413dad15c5dbda119bc9cd.tar.gz chromium_src-5ee3c04ab898137517413dad15c5dbda119bc9cd.tar.bz2 |
Don't hide asynchronous XHRs from web request handlers
BUG=117002
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11293179
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
3 files changed, 157 insertions, 8 deletions
diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc index bc92e7c..4528e15 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api.cc +++ b/chrome/browser/extensions/api/web_request/web_request_api.cc @@ -1183,6 +1183,7 @@ void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( int tab_id, int window_id, ResourceType::Type resource_type, + bool is_async_request, bool is_request_from_extension, int* extra_info_spec, std::vector<const ExtensionWebRequestEventRouter::EventListener*>* @@ -1221,11 +1222,11 @@ void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( // and therefore prevent the extension from processing the request // handler. This is only a problem for blocking listeners. // http://crbug.com/105656 - bool possibly_synchronous_xhr_from_extension = + bool synchronous_xhr_from_extension = !is_async_request && is_request_from_extension && resource_type == ResourceType::XHR; // Only send webRequest events for URLs the extension has access to. - if (blocking_listener && possibly_synchronous_xhr_from_extension) + if (blocking_listener && synchronous_xhr_from_extension) continue; matching_listeners->push_back(&(*it)); @@ -1262,16 +1263,21 @@ ExtensionWebRequestEventRouter::GetMatchingListeners( bool is_request_from_extension = IsRequestFromExtension(request, extension_info_map); + const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); + // We are conservative here and assume requests are asynchronous in case + // we don't have an info object. We don't want to risk a deadlock. + bool is_async_request = !info || info->IsAsync(); + GetMatchingListenersImpl( profile, extension_info_map, false, event_name, url, - tab_id, window_id, resource_type, is_request_from_extension, - extra_info_spec, &matching_listeners); + tab_id, window_id, resource_type, is_async_request, + is_request_from_extension, extra_info_spec, &matching_listeners); void* cross_profile = GetCrossProfile(profile); if (cross_profile) { GetMatchingListenersImpl( cross_profile, extension_info_map, true, event_name, url, tab_id, - window_id, resource_type, is_request_from_extension, extra_info_spec, - &matching_listeners); + window_id, resource_type, is_async_request, is_request_from_extension, + extra_info_spec, &matching_listeners); } return matching_listeners; diff --git a/chrome/browser/extensions/api/web_request/web_request_api.h b/chrome/browser/extensions/api/web_request/web_request_api.h index 780e9d7..49834ab 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api.h +++ b/chrome/browser/extensions/api/web_request/web_request_api.h @@ -310,6 +310,7 @@ class ExtensionWebRequestEventRouter int tab_id, int window_id, ResourceType::Type resource_type, + bool is_async_request, bool is_request_from_extension, int* extra_info_spec, std::vector<const ExtensionWebRequestEventRouter::EventListener*>* diff --git a/chrome/test/data/extensions/api_test/webrequest/test_blocking.js b/chrome/test/data/extensions/api_test/webrequest/test_blocking.js index 9c5925d..cbed9a2 100644 --- a/chrome/test/data/extensions/api_test/webrequest/test_blocking.js +++ b/chrome/test/data/extensions/api_test/webrequest/test_blocking.js @@ -518,8 +518,9 @@ runTests([ }); }, - // Checks that XHR requests from ourself are invisible to blocking handlers. - function xhrsFromOurselfAreInvisible() { + // Checks that synchronous XHR requests from ourself are invisible to blocking + // handlers. + function syncXhrsFromOurselfAreInvisible() { expect( [ // events { label: "a-onBeforeRequest", @@ -628,4 +629,145 @@ runTests([ navigateAndWait(getURL("complexLoad/b.jpg")); }); }, + + // Checks that asynchronous XHR requests from ourself are visible to blocking + // handlers. + function asyncXhrsFromOurselfAreVisible() { + expect( + [ // events + { label: "a-onBeforeRequest", + event: "onBeforeRequest", + details: { + url: getURL("simpleLoad/a.html"), + frameUrl: getURL("simpleLoad/a.html") + } + }, + { label: "a-onResponseStarted", + event: "onResponseStarted", + details: { + url: getURL("simpleLoad/a.html"), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.1 200 OK", + // Request to chrome-extension:// url has no IP. + } + }, + { label: "a-onCompleted", + event: "onCompleted", + details: { + url: getURL("simpleLoad/a.html"), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.1 200 OK", + // Request to chrome-extension:// url has no IP. + } + }, + { + label: "x-onBeforeRequest", + event: "onBeforeRequest", + details: { + url: getURLHttpXHRData(), + tabId: 1, + type: "xmlhttprequest", + frameUrl: "unknown frame URL", + } + }, + { + label: "x-onBeforeSendHeaders", + event: "onBeforeSendHeaders", + details: { + url: getURLHttpXHRData(), + tabId: 1, + type: "xmlhttprequest", + } + }, + { label: "x-onSendHeaders", + event: "onSendHeaders", + details: { + url: getURLHttpXHRData(), + tabId: 1, + type: "xmlhttprequest", + } + }, + { label: "x-onResponseStarted", + event: "onResponseStarted", + details: { + url: getURLHttpXHRData(), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.0 200 OK", + tabId: 1, + type: "xmlhttprequest", + ip: "127.0.0.1", + // Request to chrome-extension:// url has no IP. + } + }, + { + label: "x-onHeadersReceived", + event: "onHeadersReceived", + details: { + url: getURLHttpXHRData(), + tabId: 1, + type: "xmlhttprequest", + statusLine: "HTTP/1.0 200 OK", + } + }, + { label: "x-onCompleted", + event: "onCompleted", + details: { + url: getURLHttpXHRData(), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.0 200 OK", + tabId: 1, + type: "xmlhttprequest", + ip: "127.0.0.1", + // Request to chrome-extension:// url has no IP. + } + }, + { label: "b-onBeforeRequest", + event: "onBeforeRequest", + details: { + url: getURL("complexLoad/b.jpg"), + frameUrl: getURL("complexLoad/b.jpg") + } + }, + { label: "b-onResponseStarted", + event: "onResponseStarted", + details: { + url: getURL("complexLoad/b.jpg"), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.1 200 OK", + // Request to chrome-extension:// url has no IP. + } + }, + { label: "b-onCompleted", + event: "onCompleted", + details: { + url: getURL("complexLoad/b.jpg"), + statusCode: 200, + fromCache: false, + statusLine: "HTTP/1.1 200 OK", + // Request to chrome-extension:// url has no IP. + } + }, + ], + [ // event order + ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted", + "x-onBeforeRequest", "x-onBeforeSendHeaders", "x-onSendHeaders", + "x-onHeadersReceived", "x-onResponseStarted", "x-onCompleted"], + ["a-onCompleted", "x-onBeforeRequest", + "b-onBeforeRequest", "b-onResponseStarted", "b-onCompleted"] + ], + {urls: ["<all_urls>"]}, ["blocking"]); + // Check the page content for our modified User-Agent string. + navigateAndWait(getURL("simpleLoad/a.html"), function() { + var req = new XMLHttpRequest(); + var asynchronous = true; + req.open("GET", getURLHttpXHRData(), asynchronous); + req.send(null); + navigateAndWait(getURL("complexLoad/b.jpg")); + }); + }, ]); |