Commit ce6ec84a authored by ahmetemiremir's avatar ahmetemiremir Committed by Commit bot

DevTools: Show redirects from navigator.sendBeacon()

BUG=672258

Review-Url: https://codereview.chromium.org/2586063002
Cr-Commit-Position: refs/heads/master@{#442880}
parent f812e777
...@@ -31,6 +31,20 @@ InspectorTest.evaluateInInspectedPage = function(expression, callback) ...@@ -31,6 +31,20 @@ InspectorTest.evaluateInInspectedPage = function(expression, callback)
InspectorTest.sendCommand("Runtime.evaluate", { expression: expression }, callback); InspectorTest.sendCommand("Runtime.evaluate", { expression: expression }, callback);
} }
InspectorTest.parseURL = function(url)
{
var result = {};
var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
if (!match)
return result;
result.scheme = match[1].toLowerCase();
result.host = match[2];
result.port = match[3];
result.path = match[4] || "/";
result.fragment = match[5];
return result;
}
} }
var outputElement; var outputElement;
......
Tests that redirect from navigator.sendBeacon() is recorded.
Request Sent: /inspector-protocol/resources/ping-redirect.php
Request Sent: /inspector-protocol/resources/ping-redirected-page.html
Redirect Source: /inspector-protocol/resources/ping-redirect.php
<html>
<head>
<script src="inspector-protocol-test.js"></script>
<script>
function sendBeacon()
{
navigator.sendBeacon("resources/ping-redirect.php", "foo");
}
function test()
{
var requestSent = 0;
InspectorTest.eventHandler["Network.requestWillBeSent"] = onRequestWillBeSent;
enableNetwork();
function enableNetwork()
{
InspectorTest.sendCommandOrDie("Network.enable", {}, didEnableNetwork);
}
function didEnableNetwork()
{
InspectorTest.evaluateInPage("sendBeacon()");
}
function onRequestWillBeSent(event)
{
requestSent++;
var params = event.params;
InspectorTest.log("Request Sent: " + InspectorTest.parseURL(params.request.url).path);
if (requestSent == 2) {
var redirectSource = "";
if (params.redirectResponse)
redirectSource = InspectorTest.parseURL(params.redirectResponse.url).path;
InspectorTest.log("Redirect Source: " + redirectSource);
InspectorTest.completeTest();
}
}
}
</script>
</head>
<body onload="runTest()">
<p>Tests that redirect from navigator.sendBeacon() is recorded.</p>
</body>
</html>
<?php
header('HTTP/1.1 307 Temporary Redirect');
header('Expires: Thu, 01 Dec 2003 16:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Location: ping-redirected-page.html');
?>
...@@ -222,6 +222,7 @@ class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, ...@@ -222,6 +222,7 @@ class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>,
String m_url; String m_url;
unsigned long m_identifier; unsigned long m_identifier;
SelfKeepAlive<PingLoaderImpl> m_keepAlive; SelfKeepAlive<PingLoaderImpl> m_keepAlive;
AtomicString m_initiator;
bool m_isBeacon; bool m_isBeacon;
...@@ -239,6 +240,7 @@ PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, ...@@ -239,6 +240,7 @@ PingLoaderImpl::PingLoaderImpl(LocalFrame* frame,
m_url(request.url()), m_url(request.url()),
m_identifier(createUniqueIdentifier()), m_identifier(createUniqueIdentifier()),
m_keepAlive(this), m_keepAlive(this),
m_initiator(initiator),
m_isBeacon(isBeacon), m_isBeacon(isBeacon),
m_origin(frame->document()->getSecurityOrigin()), m_origin(frame->document()->getSecurityOrigin()),
m_corsMode(IsCORSEnabled) { m_corsMode(IsCORSEnabled) {
...@@ -293,42 +295,47 @@ void PingLoaderImpl::dispose() { ...@@ -293,42 +295,47 @@ void PingLoaderImpl::dispose() {
bool PingLoaderImpl::willFollowRedirect( bool PingLoaderImpl::willFollowRedirect(
WebURLRequest& passedNewRequest, WebURLRequest& passedNewRequest,
const WebURLResponse& passedRedirectResponse) { const WebURLResponse& passedRedirectResponse) {
if (!m_isBeacon) if (m_isBeacon && m_corsMode == IsCORSEnabled) {
return true; DCHECK(passedNewRequest.allowStoredCredentials());
if (m_corsMode == NotCORSEnabled) ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
return true; const ResourceResponse& redirectResponse(
passedRedirectResponse.toResourceResponse());
DCHECK(passedNewRequest.allowStoredCredentials());
DCHECK(!newRequest.isNull());
ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); DCHECK(!redirectResponse.isNull());
const ResourceResponse& redirectResponse(
passedRedirectResponse.toResourceResponse()); String errorDescription;
ResourceLoaderOptions options;
DCHECK(!newRequest.isNull()); // TODO(tyoshino): Save updated data in options.securityOrigin and pass it
DCHECK(!redirectResponse.isNull()); // on the next time.
if (!CrossOriginAccessControl::handleRedirect(
String errorDescription; m_origin, newRequest, redirectResponse, AllowStoredCredentials,
ResourceLoaderOptions options; options, errorDescription)) {
// TODO(tyoshino): Save updated data in options.securityOrigin and pass it if (frame()) {
// on the next time. if (frame()->document()) {
if (!CrossOriginAccessControl::handleRedirect( frame()->document()->addConsoleMessage(ConsoleMessage::create(
m_origin, newRequest, redirectResponse, AllowStoredCredentials, JSMessageSource, ErrorMessageLevel, errorDescription));
options, errorDescription)) { }
if (frame()) {
if (frame()->document()) {
frame()->document()->addConsoleMessage(ConsoleMessage::create(
JSMessageSource, ErrorMessageLevel, errorDescription));
} }
} // Cancel the load and self destruct.
// Cancel the load and self destruct. dispose();
dispose();
return false; return false;
}
} }
// FIXME: http://crbug.com/427429 is needed to correctly propagate updates of // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of
// Origin: following this successful redirect. // Origin: following this successful redirect.
if (frame() && frame()->document()) {
FetchInitiatorInfo initiatorInfo;
initiatorInfo.name = m_initiator;
FetchContext& fetchContext = frame()->document()->fetcher()->context();
fetchContext.dispatchWillSendRequest(
m_identifier, passedNewRequest.toMutableResourceRequest(),
passedRedirectResponse.toResourceResponse(), initiatorInfo);
}
return true; return true;
} }
......
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