Commit b0817711 authored by allada's avatar allada Committed by Commit bot
Browse files

[Devtools] Fixed websocket initiators

BUG=457811
R=dgozman

Review-Url: https://codereview.chromium.org/2094903002
Cr-Commit-Position: refs/heads/master@{#402313}
parent 5a31215e
Initiator for Websockets check fixes http://crbug.com/457811
Test started
Network agent enabled
Initiator Type: script
Stack #0
functionName: createSocket
url: initiator.html
lineNumber: 9
<!DOCTYPE html>
<html>
<head>
<script src="../../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script>
var ws;
function createSocket()
{
ws = new WebSocket("ws://localhost:8080/echo");
}
function test()
{
InspectorTest.eventHandler["Network.webSocketCreated"] = onWebSocketCreated;
function enableNetwork()
{
InspectorTest.log("Test started");
InspectorTest.sendCommand("Network.enable", {}, didEnableNetwork);
}
function didEnableNetwork(messageObject)
{
if (messageObject.error) {
InspectorTest.log("FAIL: Couldn't enable network agent" + messageObject.error.message);
InspectorTest.completeTest();
return;
}
InspectorTest.log("Network agent enabled");
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "createSocket()"});
}
function onWebSocketCreated(event)
{
var initiator = event.params.initiator;
InspectorTest.log("");
InspectorTest.log("Initiator Type: " + initiator.type);
var stackTrace = initiator.stack;
for (var i = 0; i < stackTrace.callFrames.length; ++i) {
var frame = stackTrace.callFrames[i];
InspectorTest.log("Stack #" + i);
if (frame.lineNumber) {
InspectorTest.log(" functionName: " + frame.functionName);
InspectorTest.log(" url: " + cleanUrl(frame.url));
InspectorTest.log(" lineNumber: " + frame.lineNumber);
break;
}
}
InspectorTest.completeTest();
}
function cleanUrl(url)
{
url = url.match(/\/[^\/]+$/);
if (url.length)
return url[0].substr(1);
return url;
}
enableNetwork();
}
</script>
</head>
<body onload="runTest();">
<p>Initiator for Websockets check fixes http://crbug.com/457811</p>
</body>
......@@ -819,9 +819,18 @@ std::unique_ptr<protocol::Network::Initiator> InspectorNetworkAgent::buildInitia
.setType(protocol::Network::Initiator::TypeEnum::Other).build();
}
void InspectorNetworkAgent::didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&)
void InspectorNetworkAgent::didCreateWebSocket(Document* document, unsigned long identifier, const KURL& requestURL, const String&)
{
frontend()->webSocketCreated(IdentifiersFactory::requestId(identifier), urlWithoutFragment(requestURL).getString());
std::unique_ptr<protocol::Runtime::StackTrace> currentStackTrace = SourceLocation::capture(document)->buildInspectorObject();
if (!currentStackTrace) {
frontend()->webSocketCreated(IdentifiersFactory::requestId(identifier), urlWithoutFragment(requestURL).getString());
return;
}
std::unique_ptr<protocol::Network::Initiator> initiatorObject = protocol::Network::Initiator::create()
.setType(protocol::Network::Initiator::TypeEnum::Script).build();
initiatorObject->setStack(std::move(currentStackTrace));
frontend()->webSocketCreated(IdentifiersFactory::requestId(identifier), urlWithoutFragment(requestURL).getString(), std::move(initiatorObject));
}
void InspectorNetworkAgent::willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest* request)
......
......@@ -1404,7 +1404,8 @@
"description": "Fired upon WebSocket creation.",
"parameters": [
{ "name": "requestId", "$ref": "RequestId", "description": "Request identifier." },
{ "name": "url", "type": "string", "description": "WebSocket request URL." }
{ "name": "url", "type": "string", "description": "WebSocket request URL." },
{ "name": "initiator", "$ref": "Initiator", "optional": true, "description": "Request initiator." }
],
"hidden": true
},
......
......@@ -456,11 +456,11 @@ WebInspector.NetworkDispatcher.prototype = {
* @override
* @param {!NetworkAgent.RequestId} requestId
* @param {string} requestURL
* @param {!NetworkAgent.Initiator=} initiator
*/
webSocketCreated: function(requestId, requestURL)
webSocketCreated: function(requestId, requestURL, initiator)
{
// FIXME: WebSocket MUST have initiator info.
var networkRequest = new WebInspector.NetworkRequest(this._manager._target, requestId, requestURL, "", "", "", null);
var networkRequest = new WebInspector.NetworkRequest(this._manager._target, requestId, requestURL, "", "", "", initiator || null);
networkRequest.setResourceType(WebInspector.resourceTypes.WebSocket);
this._startNetworkRequest(networkRequest);
},
......
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