Commit e5b15d20 authored by jochen@chromium.org's avatar jochen@chromium.org

Add support for XMLHttpRequests to the webRequest API

BUG=80230
TEST=api tests

Review URL: http://codereview.chromium.org/7599027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96008 0039d316-1c4b-4281-b951-d872f2087c98
parent c8f5b677
......@@ -57,6 +57,8 @@ static const char* kResourceTypeStrings[] = {
"script",
"image",
"object",
"xmlhttprequest",
"other",
"other",
};
......@@ -67,7 +69,14 @@ static ResourceType::Type kResourceTypeValues[] = {
ResourceType::SCRIPT,
ResourceType::IMAGE,
ResourceType::OBJECT,
ResourceType::XHR,
ResourceType::LAST_TYPE, // represents "other"
// TODO(jochen): We duplicate the last entry, so the array's size is not a
// power of two. If it is, this triggers a bug in gcc 4.4 in Release builds
// (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version
// of gcc with this bug fixed, or the array is changed so this duplicate
// entry is no longer required, this should be removed.
ResourceType::LAST_TYPE,
};
COMPILE_ASSERT(
......
......@@ -4664,7 +4664,7 @@
"type": "array",
"optional": true,
"description": "A list of request types. Requests that cannot match any of the types will be filtered out.",
"items": { "type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "other"] }
"items": { "type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"] }
},
"tabId": { "type": "integer", "optional": true },
"windowId": { "type": "integer", "optional": true }
......@@ -4765,7 +4765,7 @@
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to null if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "other"], "description": "How the requested resource will be used."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when the browser was about to make the request, in milliseconds since the epoch."}
}
}
......
......@@ -2906,7 +2906,7 @@ chrome.windows.onRemoved.addListener(
array of <span><span></span></span>
</span>
<span>string</span>
<span>["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "other"]</span>
<span>["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]</span>
</span>
</span>
)
......@@ -6736,7 +6736,7 @@ chrome.windows.onRemoved.addListener(
array of <span><span></span></span>
</span>
<span>string</span>
<span>["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "other"]</span>
<span>["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]</span>
</span>
</span></span>
</span>
......
......@@ -16,6 +16,10 @@ var URL_ECHO_USER_AGENT =
'http://www.a.com:PORT/echoheader?User-Agent';
var URL_AUTH_REQUIRED =
'http://www.a.com:PORT/auth-basic';
var URL_HTTP_XHR =
'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/xhr/a.html';
var URL_HTTP_XHR_DATA =
'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/xhr/data.json';
function runTests(tests) {
chrome.tabs.getSelected(null, function(tab) {
......@@ -28,6 +32,8 @@ function runTests(tests) {
URL_HTTP_SIMPLE_LOAD_REDIRECT = fixPort(URL_HTTP_SIMPLE_LOAD_REDIRECT);
URL_ECHO_USER_AGENT = fixPort(URL_ECHO_USER_AGENT);
URL_AUTH_REQUIRED = fixPort(URL_AUTH_REQUIRED);
URL_HTTP_XHR = fixPort(URL_HTTP_XHR);
URL_HTTP_XHR_DATA = fixPort(URL_HTTP_XHR_DATA);
chrome.test.runTests(tests);
});
......@@ -382,6 +388,100 @@ runTests([
navigateAndWait(URL_HTTP_SIMPLE_LOAD_REDIRECT);
},
// Navigates to a page to generates an XHR.
function xhrLoad() {
expect(
[ // events
{ label: "onBeforeRequest-1",
event: "onBeforeRequest",
details: {
method: "GET",
tabId: tabId,
type: "main_frame",
url: URL_HTTP_XHR,
frameUrl: URL_HTTP_XHR
}
},
{ label: "onBeforeSendHeaders-1",
event: "onBeforeSendHeaders",
details: {
url: URL_HTTP_XHR,
}
},
{ label: "onSendHeaders-1",
event: "onSendHeaders",
details: {
url: URL_HTTP_XHR,
}
},
{ label: "onResponseStarted-1",
event: "onResponseStarted",
details: {
url: URL_HTTP_XHR,
statusCode: 200,
ip: "127.0.0.1",
fromCache: false,
}
},
{ label: "onCompleted-1",
event: "onCompleted",
details: {
url: URL_HTTP_XHR,
statusCode: 200,
ip: "127.0.0.1",
fromCache: false,
}
},
{ label: "onBeforeRequest-2",
event: "onBeforeRequest",
details: {
method: "GET",
tabId: tabId,
type: "xmlhttprequest",
url: URL_HTTP_XHR_DATA,
frameUrl: URL_HTTP_XHR
}
},
{ label: "onBeforeSendHeaders-2",
event: "onBeforeSendHeaders",
details: {
url: URL_HTTP_XHR_DATA,
}
},
{ label: "onSendHeaders-2",
event: "onSendHeaders",
details: {
url: URL_HTTP_XHR_DATA,
}
},
{ label: "onResponseStarted-2",
event: "onResponseStarted",
details: {
url: URL_HTTP_XHR_DATA,
statusCode: 200,
ip: "127.0.0.1",
fromCache: false,
}
},
{ label: "onCompleted-2",
event: "onCompleted",
details: {
url: URL_HTTP_XHR_DATA,
statusCode: 200,
ip: "127.0.0.1",
fromCache: false,
}
}
],
[ // event order
["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1",
"onResponseStarted-1", "onCompleted-1",
"onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2",
"onResponseStarted-2", "onCompleted-2"] ],
{}, []);
navigateAndWait(URL_HTTP_XHR);
},
// Navigates to a page with subresources.
// TODO(mpcomplete): add multiple subresources; requires support for
// recognizing partial ordering.
......
<html>
<head>
<script>
function sendXHR() {
var req = new XMLHttpRequest();
req.open("GET", "data.json", true);
req.send(null);
}
</script>
</head>
<body onload="sendXHR()"></body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment