Web Inspector: Add resource initiator column to network panel.
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jul 2011 15:13:34 +0000 (15:13 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jul 2011 15:13:34 +0000 (15:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65105

Reviewed by Pavel Feldman.

Source/WebCore:

Test: http/tests/inspector/network/network-initiator.html

* English.lproj/localizedStrings.js:
* dom/Document.cpp:
(WebCore::Document::scheduleStyleRecalc):
* inspector/Inspector.json:
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willRecalculateStyleImpl):
(WebCore::InspectorInstrumentation::didRecalculateStyleImpl):
(WebCore::InspectorInstrumentation::didScheduleStyleRecalculationImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::didScheduleStyleRecalculation):
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::willSendRequest):
(WebCore::InspectorResourceAgent::didLoadResourceFromMemoryCache):
(WebCore::InspectorResourceAgent::willRecalculateStyle):
(WebCore::InspectorResourceAgent::didRecalculateStyle):
(WebCore::InspectorResourceAgent::didScheduleStyleRecalculation):
(WebCore::InspectorResourceAgent::buildInitiatorObject):
(WebCore::InspectorResourceAgent::InspectorResourceAgent):
* inspector/InspectorResourceAgent.h:
* inspector/front-end/NetworkManager.js:
(WebInspector.NetworkDispatcher.prototype.requestWillBeSent):
(WebInspector.NetworkDispatcher.prototype.resourceLoadedFromMemoryCache):
(WebInspector.NetworkDispatcher.prototype._appendRedirect):
(WebInspector.NetworkDispatcher.prototype._createResource):
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkLogView.prototype._createTable):
(WebInspector.NetworkLogView.prototype._createSortingFunctions):
(WebInspector.NetworkLogView.prototype.switchToDetailedView):
(WebInspector.NetworkLogView.prototype.switchToBriefView):
(WebInspector.NetworkLogView.prototype._toggleGridMode):
(WebInspector.NetworkLogView.prototype._toggleViewingResourceMode):
(WebInspector.NetworkDataGridNode.prototype.createCells):
(WebInspector.NetworkDataGridNode.prototype.refreshResource):
(WebInspector.NetworkDataGridNode.prototype._refreshInitiatorCell):
(WebInspector.NetworkDataGridNode.InitiatorComparator):
* inspector/front-end/networkLogView.css:
(.initiator-column a):

LayoutTests:

* http/tests/inspector/network/network-initiator-expected.txt: Added.
* http/tests/inspector/network/network-initiator.html: Added.
* http/tests/inspector/network/resources/initiator.css: Added.
(.image-background):
(.image-background-2):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91928 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-initiator-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/network-initiator.html [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/resources/initiator.css [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/localizedStrings.js
Source/WebCore/dom/Document.cpp
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.h
Source/WebCore/inspector/front-end/NetworkManager.js
Source/WebCore/inspector/front-end/NetworkPanel.js
Source/WebCore/inspector/front-end/networkLogView.css

index 2a7e4f2..3f8f163 100644 (file)
@@ -1,3 +1,16 @@
+2011-07-28  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Add resource initiator column to network panel.
+        https://bugs.webkit.org/show_bug.cgi?id=65105
+
+        Reviewed by Pavel Feldman.
+
+        * http/tests/inspector/network/network-initiator-expected.txt: Added.
+        * http/tests/inspector/network/network-initiator.html: Added.
+        * http/tests/inspector/network/resources/initiator.css: Added.
+        (.image-background):
+        (.image-background-2):
+
 2011-07-28  Tony Gentilcore  <tonyg@chromium.org>
 
         [chromium] New expectations for r91915
diff --git a/LayoutTests/http/tests/inspector/network/network-initiator-expected.txt b/LayoutTests/http/tests/inspector/network/network-initiator-expected.txt
new file mode 100644 (file)
index 0000000..102cf4b
--- /dev/null
@@ -0,0 +1,18 @@
+CONSOLE MESSAGE: line 34: Done.
+Tests resources initiator for images initiated by IMG tag, static CSS, CSS class added from JavaScript and XHR.
+
+Bug 65105 
+This div has background image set from CSS.
+This div will have background image set from JavaScript.
+Page reloaded.
+http://127.0.0.1:8000/inspector/network/resources/initiator.css: parser
+    http://127.0.0.1:8000/inspector/network/network-initiator.html 3
+http://127.0.0.1:8000/inspector/network/resources/resource.php?type=image&random=1&size=100: parser
+    http://127.0.0.1:8000/inspector/network/network-initiator.html 99
+http://127.0.0.1:8000/inspector/network/resources/resource.php?type=image&random=1&size=200: parser
+    http://127.0.0.1:8000/inspector/network/network-initiator.html 100
+http://127.0.0.1:8000/inspector/network/resources/resource.php?type=image&random=1&size=300: script
+    http://127.0.0.1:8000/inspector/network/network-initiator.html 17
+http://127.0.0.1:8000/inspector/network/resources/resource.php?type=image&random=1&size=400: script
+    http://127.0.0.1:8000/inspector/network/network-initiator.html 29
+
diff --git a/LayoutTests/http/tests/inspector/network/network-initiator.html b/LayoutTests/http/tests/inspector/network/network-initiator.html
new file mode 100644 (file)
index 0000000..4f1c49a
--- /dev/null
@@ -0,0 +1,103 @@
+<html>
+<head>
+<link href="resources/initiator.css" rel="stylesheet" type="text/css">
+<script src="../inspector-test.js"></script>
+<script src="../network-test.js"></script>
+<script>
+
+function addClassToDiv()
+{
+    // We need to setTimeout, to make sure that style recalculation scheduling
+    // is really triggered by adding a class to the div.
+    window.setTimeout(addClassToDivStep2.bind(this), 0);
+}
+
+function addClassToDivStep2()
+{
+    document.getElementById("div-without-class").className = "image-background-2";
+}
+
+function loadData()
+{
+    var xhr = new XMLHttpRequest();
+    xhr.onreadystatechange = function()
+    {
+        if (xhr.readyState === XMLHttpRequest.DONE)
+            resourceLoaded();
+    };
+    xhr.open("GET", "resources/resource.php?type=image&random=1&size=400", true);
+    xhr.send(null);
+}
+
+function resourceLoaded()
+{
+    console.log("Done.");
+}
+
+var test = function()
+{
+    InspectorTest.reloadPage(step1);
+
+    function findResourceByURL(url)
+    {
+        var resources = WebInspector.networkLog.resources;
+        for (var i = 0; i < resources.length; ++i) {
+            if (url.test(resources[i].url))
+                return resources[i];
+        }
+    }
+
+    function step1()
+    {
+        WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, onResource);
+        InspectorTest.evaluateInPage("addClassToDiv()", step2);
+    }
+
+    function onResource(event)
+    {
+        var resource = event.data;
+        if (/size=300/.test(resource.url))
+            step2();
+    }
+
+    function step2()
+    {
+        if (!findResourceByURL(/size=300/))
+            return;
+
+        InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "addMessage", step3);
+        InspectorTest.evaluateInPage("loadData()");
+    }
+
+    function step3()
+    {
+        function dumpInitiator(resource)
+        {
+            var initiator = resource.initiator;
+            InspectorTest.addResult(resource.url + ": " + initiator.type);
+            if (initiator.url)
+                InspectorTest.addResult("    " + initiator.url + " " + initiator.lineNumber);
+            if (initiator.stackTrace)
+                InspectorTest.addResult("    " + initiator.stackTrace[0].url + " " + initiator.stackTrace[0].lineNumber);
+        }
+
+        dumpInitiator(findResourceByURL(/initiator\.css/));
+        dumpInitiator(findResourceByURL(/size=100/));
+        dumpInitiator(findResourceByURL(/size=200/));
+        dumpInitiator(findResourceByURL(/size=300/));
+        dumpInitiator(findResourceByURL(/size=400/));
+
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests resources initiator for images initiated by IMG tag, static CSS, CSS class added from JavaScript and XHR.</p>
+<a href="https://bugs.webkit.org/show_bug.cgi?id=65105">Bug 65105</a>
+<img src="resources/resource.php?type=image&random=1&size=100">
+<div class="image-background">This div has background image set from CSS.</div>
+<div id="div-without-class">This div will have background image set from JavaScript.</div>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/inspector/network/resources/initiator.css b/LayoutTests/http/tests/inspector/network/resources/initiator.css
new file mode 100644 (file)
index 0000000..5c5de78
--- /dev/null
@@ -0,0 +1,8 @@
+.image-background {
+    background-image: url("resource.php?type=image&random=1&size=200");
+}
+
+.image-background-2 {
+    background-image: url("resource.php?type=image&random=1&size=300");
+}
+
index 5375e51..bc33156 100644 (file)
@@ -1,3 +1,50 @@
+2011-07-28  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Add resource initiator column to network panel.
+        https://bugs.webkit.org/show_bug.cgi?id=65105
+
+        Reviewed by Pavel Feldman.
+
+        Test: http/tests/inspector/network/network-initiator.html
+
+        * English.lproj/localizedStrings.js:
+        * dom/Document.cpp:
+        (WebCore::Document::scheduleStyleRecalc):
+        * inspector/Inspector.json:
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willRecalculateStyleImpl):
+        (WebCore::InspectorInstrumentation::didRecalculateStyleImpl):
+        (WebCore::InspectorInstrumentation::didScheduleStyleRecalculationImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::didScheduleStyleRecalculation):
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::willSendRequest):
+        (WebCore::InspectorResourceAgent::didLoadResourceFromMemoryCache):
+        (WebCore::InspectorResourceAgent::willRecalculateStyle):
+        (WebCore::InspectorResourceAgent::didRecalculateStyle):
+        (WebCore::InspectorResourceAgent::didScheduleStyleRecalculation):
+        (WebCore::InspectorResourceAgent::buildInitiatorObject):
+        (WebCore::InspectorResourceAgent::InspectorResourceAgent):
+        * inspector/InspectorResourceAgent.h:
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkDispatcher.prototype.requestWillBeSent):
+        (WebInspector.NetworkDispatcher.prototype.resourceLoadedFromMemoryCache):
+        (WebInspector.NetworkDispatcher.prototype._appendRedirect):
+        (WebInspector.NetworkDispatcher.prototype._createResource):
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkLogView.prototype._createTable):
+        (WebInspector.NetworkLogView.prototype._createSortingFunctions):
+        (WebInspector.NetworkLogView.prototype.switchToDetailedView):
+        (WebInspector.NetworkLogView.prototype.switchToBriefView):
+        (WebInspector.NetworkLogView.prototype._toggleGridMode):
+        (WebInspector.NetworkLogView.prototype._toggleViewingResourceMode):
+        (WebInspector.NetworkDataGridNode.prototype.createCells):
+        (WebInspector.NetworkDataGridNode.prototype.refreshResource):
+        (WebInspector.NetworkDataGridNode.prototype._refreshInitiatorCell):
+        (WebInspector.NetworkDataGridNode.InitiatorComparator):
+        * inspector/front-end/networkLogView.css:
+        (.initiator-column a):
+
 2011-07-28  Rob Buis  <rbuis@rim.com>
 
         Use styling test from ietestcenter fails
index 00c5122..93dcb47 100644 (file)
Binary files a/Source/WebCore/English.lproj/localizedStrings.js and b/Source/WebCore/English.lproj/localizedStrings.js differ
index 34a3481..fd2886e 100644 (file)
@@ -1457,6 +1457,8 @@ void Document::scheduleStyleRecalc()
     invalidateAccessKeyMap();
     
     m_styleRecalcTimer.startOneShot(0);
+
+    InspectorInstrumentation::didScheduleStyleRecalculation(this);
 }
 
 void Document::unscheduleStyleRecalc()
index 5d0d9e6..2235e43 100644 (file)
                     { "name": "text", "type": "string", "description": "Message text." },
                     { "name": "networkIdentifier", "type": "integer", "optional": true, "description": "Identifier of the network request associated with the console message." },
                     { "name": "parameters", "type": "array", "items": { "$ref": "Runtime.RemoteObject" }, "description": "Message parameters in case of the formatted message." },
-                    { "name": "stackTrace", "type": "array", "optional": true, "items": { "$ref": "CallFrame" }, "description": "Call frames for assert and error messages." }
+                    { "name": "stackTrace", "$ref": "StackTrace", "description": "Stack trace for assert and error messages." },
                 ]
             },
             {
                     { "name": "lineNumber", "type": "string", "description": "JavaScript source line number." },
                     { "name": "columnNumber", "type": "string", "description": "JavaScript source column number." }
                 ]
+            },
+            {
+                "id": "StackTrace",
+                "type": "array",
+                "items": { "$ref": "CallFrame" },
+                "description": "Call frames for assert and error messages."
             }
         ],
         "commands": [
                     { "name": "response", "$ref": "ResourceResponse", "description": "Cached response data." },
                     { "name": "bodySize", "type": "number", "description": "Cached response body size." }
                 ]
+            },
+            {
+                "id": "Initiator",
+                "type": "object",
+                "description": "Information about the resource load initiator.",
+                "properties": [
+                    { "name": "type", "type": "string", "enum": ["parser", "script", "other"], "description": "Type of this initiator." },
+                    { "name": "stackTrace", "$ref": "Console.StackTrace", "description": "Initiator JavaScript stack trace, set for Script only." },
+                    { "name": "url", "type": "string", "optional": true, "description": "Initiator URL, set for Parser type only." },
+                    { "name": "lineNumber", "type": "number", "optional": true, "description": "Initiator line number, set for Parser type only." }
+                ]
             }
         ],
         "commands": [
                     { "name": "documentURL", "type": "string", "description": "URL of the document this resource is loaded for." },
                     { "name": "request", "$ref": "ResourceRequest", "description": "Request data." },
                     { "name": "timestamp", "type": "number", "description": "Timestamp." },
-                    { "name": "stackTrace", "type": "array", "items": { "$ref": "Console.CallFrame"}, "description": "JavaScript stack trace upon issuing this request." },
+                    { "name": "initiator", "$ref": "Initiator", "description": "Request initiator." },
+                    { "name": "stackTrace", "$ref": "Console.StackTrace", "description": "JavaScript stack trace upon issuing this request." },
                     { "name": "redirectResponse", "optional": true, "$ref": "ResourceResponse", "description": "Redirect response data." }
                 ]
             },
                     { "name": "loaderId", "type": "string", "description": "Loader identifier." },
                     { "name": "documentURL", "type": "string", "description": "URL of the document this resource is loaded for." },
                     { "name": "timestamp", "type": "number", "description": "Timestamp." },
+                    { "name": "initiator", "$ref": "Initiator", "description": "Request initiator." },
                     { "name": "resource", "$ref": "CachedResource", "description": "Cached resource data." }
                 ]
             },
index 143bce0..c0da311 100644 (file)
@@ -388,6 +388,8 @@ InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImp
         timelineAgent->willRecalculateStyle();
         timelineAgentId = timelineAgent->id();
     }
+    if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
+        resourceAgent->willRecalculateStyle();
     return InspectorInstrumentationCookie(instrumentingAgents, timelineAgentId);
 }
 
@@ -395,6 +397,17 @@ void InspectorInstrumentation::didRecalculateStyleImpl(const InspectorInstrument
 {
     if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
         timelineAgent->didRecalculateStyle();
+    InstrumentingAgents* instrumentingAgents = cookie.first;
+    if (!instrumentingAgents)
+        return;
+    if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
+        resourceAgent->didRecalculateStyle();
+}
+
+void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents* instrumentingAgents, Document* document)
+{
+    if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
+        resourceAgent->didScheduleStyleRecalculation(document);
 }
 
 void InspectorInstrumentation::applyUserAgentOverrideImpl(InstrumentingAgents* instrumentingAgents, String* userAgent)
index db1e71a..4a2b60e 100644 (file)
@@ -113,6 +113,7 @@ public:
     static void didPaint(const InspectorInstrumentationCookie&);
     static InspectorInstrumentationCookie willRecalculateStyle(Document*);
     static void didRecalculateStyle(const InspectorInstrumentationCookie&);
+    static void didScheduleStyleRecalculation(Document*);
 
     static void applyUserAgentOverride(Frame*, String*);
     static void willSendRequest(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
@@ -241,6 +242,7 @@ private:
     static void didPaintImpl(const InspectorInstrumentationCookie&);
     static InspectorInstrumentationCookie willRecalculateStyleImpl(InstrumentingAgents*);
     static void didRecalculateStyleImpl(const InspectorInstrumentationCookie&);
+    static void didScheduleStyleRecalculationImpl(InstrumentingAgents*, Document*);
 
     static void applyUserAgentOverrideImpl(InstrumentingAgents*, String*);
     static void willSendRequestImpl(InstrumentingAgents*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
@@ -665,6 +667,15 @@ inline void InspectorInstrumentation::didRecalculateStyle(const InspectorInstrum
 #endif
 }
 
+inline void InspectorInstrumentation::didScheduleStyleRecalculation(Document* document)
+{
+#if ENABLE(INSPECTOR)
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
+        didScheduleStyleRecalculationImpl(instrumentingAgents, document);
+#endif
+}
+
 inline void InspectorInstrumentation::applyUserAgentOverride(Frame* frame, String* userAgent)
 {
 #if ENABLE(INSPECTOR)
index f07a7c8..ea3cef9 100644 (file)
@@ -60,6 +60,7 @@
 #include "ResourceResponse.h"
 #include "ScriptCallStack.h"
 #include "ScriptCallStackFactory.h"
+#include "ScriptableDocumentParser.h"
 #include "WebSocketHandshakeRequest.h"
 #include "WebSocketHandshakeResponse.h"
 
@@ -231,7 +232,8 @@ void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL
         callStackValue = callStack->buildInspectorArray();
     else
         callStackValue = InspectorArray::create();
-    m_frontend->requestWillBeSent(resourceId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), loader->url().string(), buildObjectForResourceRequest(request), currentTime(), callStackValue, buildObjectForResourceResponse(redirectResponse));
+    RefPtr<InspectorObject> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0);
+    m_frontend->requestWillBeSent(resourceId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), loader->url().string(), buildObjectForResourceRequest(request), currentTime(), initiatorObject, callStackValue, buildObjectForResourceResponse(redirectResponse));
 }
 
 void InspectorResourceAgent::markResourceAsCached(unsigned long identifier)
@@ -314,8 +316,9 @@ void InspectorResourceAgent::didLoadResourceFromMemoryCache(DocumentLoader* load
     String resourceId = IdentifiersFactory::resourceId(identifier);
     m_resourcesData->resourceCreated(resourceId, loaderId);
     m_resourcesData->addCachedResource(resourceId, resource);
+    RefPtr<InspectorObject> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0);
 
-    m_frontend->resourceLoadedFromMemoryCache(resourceId, frameId, loaderId, loader->url().string(), currentTime(), buildObjectForCachedResource(*resource));
+    m_frontend->resourceLoadedFromMemoryCache(resourceId, frameId, loaderId, loader->url().string(), currentTime(), initiatorObject, buildObjectForCachedResource(*resource));
 }
 
 void InspectorResourceAgent::setInitialScriptContent(unsigned long identifier, const String& sourceString)
@@ -349,6 +352,49 @@ void InspectorResourceAgent::applyUserAgentOverride(String* userAgent)
         *userAgent = m_userAgentOverride;
 }
 
+void InspectorResourceAgent::willRecalculateStyle()
+{
+    m_isRecalculatingStyle = true;
+}
+
+void InspectorResourceAgent::didRecalculateStyle()
+{
+    m_isRecalculatingStyle = false;
+    m_styleRecalculationInitiator = nullptr;
+}
+
+void InspectorResourceAgent::didScheduleStyleRecalculation(Document* document)
+{
+    if (!m_styleRecalculationInitiator)
+        m_styleRecalculationInitiator = buildInitiatorObject(document);
+}
+
+PassRefPtr<InspectorObject> InspectorResourceAgent::buildInitiatorObject(Document* document)
+{
+    RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture, true);
+    if (stackTrace && stackTrace->size() > 0) {
+        RefPtr<InspectorObject> initiatorObject = InspectorObject::create();
+        initiatorObject->setString("type", "script");
+        initiatorObject->setArray("stackTrace", stackTrace->buildInspectorArray());
+        return initiatorObject;
+    }
+
+    if (document && document->scriptableDocumentParser()) {
+        RefPtr<InspectorObject> initiatorObject = InspectorObject::create();
+        initiatorObject->setString("type", "parser");
+        initiatorObject->setString("url", document->url().string());
+        initiatorObject->setNumber("lineNumber", document->scriptableDocumentParser()->lineNumber() + 1);
+        return initiatorObject;
+    }
+
+    if (m_isRecalculatingStyle && m_styleRecalculationInitiator)
+        return m_styleRecalculationInitiator;
+
+    RefPtr<InspectorObject> initiatorObject = InspectorObject::create();
+    initiatorObject->setString("type", "other");
+    return initiatorObject;
+}
+
 #if ENABLE(WEB_SOCKETS)
 
 // FIXME: More this into the front-end?
@@ -527,6 +573,7 @@ InspectorResourceAgent::InspectorResourceAgent(InstrumentingAgents* instrumentin
     , m_state(state)
     , m_resourcesData(adoptPtr(new NetworkResourcesData()))
     , m_loadingXHRSynchronously(false)
+    , m_isRecalculatingStyle(false)
 {
     if (isBackgroundEventsCollectionEnabled()) {
         initializeBackgroundCollection();
index 4ad40bc..12c5506 100644 (file)
@@ -104,6 +104,13 @@ public:
 
     void applyUserAgentOverride(String* userAgent);
 
+    // FIXME: InspectorResourceAgent should now be aware of style recalculation.
+    void willRecalculateStyle();
+    void didRecalculateStyle();
+    void didScheduleStyleRecalculation(Document*);
+
+    PassRefPtr<InspectorObject> buildInitiatorObject(Document*);
+
 #if ENABLE(WEB_SOCKETS)
     void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
     void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
@@ -147,6 +154,10 @@ private:
     String m_userAgentOverride;
     OwnPtr<NetworkResourcesData> m_resourcesData;
     bool m_loadingXHRSynchronously;
+
+    // FIXME: InspectorResourceAgent should now be aware of style recalculation.
+    RefPtr<InspectorObject> m_styleRecalculationInitiator;
+    bool m_isRecalculatingStyle;
 };
 
 } // namespace WebCore
index 90b8c2b..4a889d3 100644 (file)
@@ -131,7 +131,7 @@ WebInspector.NetworkDispatcher.prototype = {
         return response && !response.status && !response.mimeType && !Object.keys(response.headers).length;
     },
 
-    requestWillBeSent: function(identifier, frameId, loaderId, documentURL, request, time, stackTrace, redirectResponse)
+    requestWillBeSent: function(identifier, frameId, loaderId, documentURL, request, time, initiator, stackTrace, redirectResponse)
     {
         var resource = this._inflightResourcesById[identifier];
         if (resource) {
@@ -141,7 +141,7 @@ WebInspector.NetworkDispatcher.prototype = {
             this.responseReceived(identifier, time, "Other", redirectResponse);
             resource = this._appendRedirect(identifier, time, request.url);
         } else
-            resource = this._createResource(identifier, frameId, loaderId, request.url, documentURL, stackTrace);
+            resource = this._createResource(identifier, frameId, loaderId, request.url, documentURL, initiator, stackTrace);
         resource.hasNetworkData = true;
         this._updateResourceWithRequest(resource, request);
         resource.startTime = time;
@@ -212,9 +212,9 @@ WebInspector.NetworkDispatcher.prototype = {
         this._finishResource(resource, time);
     },
 
-    resourceLoadedFromMemoryCache: function(identifier, frameId, loaderId, documentURL, time, cachedResource)
+    resourceLoadedFromMemoryCache: function(identifier, frameId, loaderId, documentURL, time, initiator, cachedResource)
     {
-        var resource = this._createResource(identifier, frameId, loaderId, cachedResource.url, documentURL);
+        var resource = this._createResource(identifier, frameId, loaderId, cachedResource.url, documentURL, initiator);
         this._updateResourceWithCachedResource(resource, cachedResource);
         resource.cached = true;
         resource.requestMethod = "GET";
@@ -286,7 +286,7 @@ WebInspector.NetworkDispatcher.prototype = {
         delete originalResource.redirects;
         this._finishResource(originalResource, time);
         var newResource = this._createResource(identifier, originalResource.frameId, originalResource.loaderId,
-             redirectURL, originalResource.documentURL, originalResource.stackTrace);
+             redirectURL, originalResource.documentURL, originalResource.initiator, originalResource.stackTrace);
         newResource.redirects = previousRedirects.concat(originalResource);
         return newResource;
     },
@@ -317,11 +317,12 @@ WebInspector.NetworkDispatcher.prototype = {
         this._manager.dispatchEventToListeners(eventType, resource);
     },
 
-    _createResource: function(identifier, frameId, loaderId, url, documentURL, stackTrace)
+    _createResource: function(identifier, frameId, loaderId, url, documentURL, initiator, stackTrace)
     {
         var resource = new WebInspector.Resource(identifier, url, loaderId);
         resource.documentURL = documentURL;
         resource.frameId = frameId;
+        resource.initiator = initiator;
         resource.stackTrace = stackTrace;
         return resource;
     }
index 03a9602..ea7a2e1 100644 (file)
@@ -143,7 +143,7 @@ WebInspector.NetworkLogView.prototype = {
 
     _createTable: function()
     {
-        var columns = {name: {}, method: {}, status: {}, type: {}, size: {}, time: {}, timeline: {}};
+        var columns = {name: {}, method: {}, status: {}, type: {}, initiator: {}, size: {}, time: {}, timeline: {}};
         columns.name.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Name"), WebInspector.UIString("Path"));
         columns.name.sortable = true;
         columns.name.width = "20%";
@@ -161,6 +161,10 @@ WebInspector.NetworkLogView.prototype = {
         columns.type.sortable = true;
         columns.type.width = "6%";
 
+        columns.initiator.title = WebInspector.UIString("Initiator");
+        columns.initiator.sortable = true;
+        columns.initiator.width = "10%";
+
         columns.size.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Size"), WebInspector.UIString("Content"));
         columns.size.sortable = true;
         columns.size.width = "6%";
@@ -173,7 +177,7 @@ WebInspector.NetworkLogView.prototype = {
 
         columns.timeline.title = "";
         columns.timeline.sortable = false;
-        columns.timeline.width = "50%";
+        columns.timeline.width = "40%";
         columns.timeline.sort = "ascending";
 
         this._dataGrid = new WebInspector.DataGrid(columns);
@@ -251,6 +255,7 @@ WebInspector.NetworkLogView.prototype = {
         this._sortingFunctions.method = WebInspector.NetworkDataGridNode.ResourcePropertyComparator.bind(null, "method", false);
         this._sortingFunctions.status = WebInspector.NetworkDataGridNode.ResourcePropertyComparator.bind(null, "statusCode", false);
         this._sortingFunctions.type = WebInspector.NetworkDataGridNode.ResourcePropertyComparator.bind(null, "mimeType", false);
+        this._sortingFunctions.initiator = WebInspector.NetworkDataGridNode.InitiatorComparator;
         this._sortingFunctions.size = WebInspector.NetworkDataGridNode.SizeComparator;
         this._sortingFunctions.time = WebInspector.NetworkDataGridNode.ResourcePropertyComparator.bind(null, "duration", false);
         this._sortingFunctions.timeline = WebInspector.NetworkDataGridNode.ResourcePropertyComparator.bind(null, "startTime", false);
@@ -800,6 +805,7 @@ WebInspector.NetworkLogView.prototype = {
         this._dataGrid.showColumn("method");
         this._dataGrid.showColumn("status");
         this._dataGrid.showColumn("type");
+        this._dataGrid.showColumn("initiator");
         this._dataGrid.showColumn("size");
         this._dataGrid.showColumn("time");
         this._dataGrid.showColumn("timeline");
@@ -809,9 +815,10 @@ WebInspector.NetworkLogView.prototype = {
         widths.method = 6;
         widths.status = 6;
         widths.type = 6;
+        widths.initiator = 10;
         widths.size = 6;
         widths.time = 6;
-        widths.timeline = 50;
+        widths.timeline = 40;
 
         this._dataGrid.applyColumnWidthsMap(widths);
     },
@@ -823,6 +830,7 @@ WebInspector.NetworkLogView.prototype = {
         this._dataGrid.hideColumn("method");
         this._dataGrid.hideColumn("status");
         this._dataGrid.hideColumn("type");
+        this._dataGrid.hideColumn("initiator");
         this._dataGrid.hideColumn("size");
         this._dataGrid.hideColumn("time");
         this._dataGrid.hideColumn("timeline");
@@ -891,6 +899,7 @@ WebInspector.NetworkLogView.prototype = {
         this._dataGrid.showColumn("method");
         this._dataGrid.showColumn("status");
         this._dataGrid.showColumn("type");
+        this._dataGrid.showColumn("initiator");
         this._dataGrid.showColumn("size");
         this._dataGrid.showColumn("time");
 
@@ -899,9 +908,10 @@ WebInspector.NetworkLogView.prototype = {
         widths.method = 6;
         widths.status = 6;
         widths.type = 6;
+        widths.initiator = 10;
         widths.size = 6;
         widths.time = 6;
-        widths.timeline = 50;
+        widths.timeline = 40;
 
         this._dataGrid.showColumn("timeline");
         this._dataGrid.applyColumnWidthsMap(widths);
@@ -918,6 +928,7 @@ WebInspector.NetworkLogView.prototype = {
         this._dataGrid.hideColumn("method");
         this._dataGrid.hideColumn("status");
         this._dataGrid.hideColumn("type");
+        this._dataGrid.hideColumn("initiator");
         this._dataGrid.hideColumn("size");
         this._dataGrid.hideColumn("time");
         this._dataGrid.hideColumn("timeline");
@@ -1724,6 +1735,7 @@ WebInspector.NetworkDataGridNode.prototype = {
         this._methodCell = this._createDivInTD("method");
         this._statusCell = this._createDivInTD("status");
         this._typeCell = this._createDivInTD("type");
+        this._initiatorCell = this._createDivInTD("initiator");
         this._sizeCell = this._createDivInTD("size");
         this._timeCell = this._createDivInTD("time");
         this._createTimelineCell();
@@ -1816,6 +1828,7 @@ WebInspector.NetworkDataGridNode.prototype = {
 
         this._refreshStatusCell();
         this._refreshTypeCell();
+        this._refreshInitiatorCell();
         this._refreshSizeCell();
         this._refreshTimeCell();
 
@@ -1917,6 +1930,28 @@ WebInspector.NetworkDataGridNode.prototype = {
         }
     },
 
+    _refreshInitiatorCell: function()
+    {
+        var initiator = this._resource.initiator;
+        if (!initiator || initiator.type === "other") {
+            this._initiatorCell.addStyleClass("network-dim-cell");
+            this._initiatorCell.setTextAndTitle(WebInspector.UIString("Other"));
+        } else {
+            this._initiatorCell.removeStyleClass("network-dim-cell");
+            this._initiatorCell.removeChildren();
+            if (initiator.type === "script") {
+                var topFrame = initiator.stackTrace[0];
+                this._initiatorCell.title = topFrame.url + ":" + topFrame.lineNumber;
+                this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(topFrame.url, "scripts", topFrame.lineNumber));
+                this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Script"));
+            } else { // initiator.type === "parser"
+                this._initiatorCell.title = initiator.url + ":" + initiator.lineNumber;
+                this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(initiator.url, "resources", initiator.lineNumber));
+                this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Parser"));
+            }
+        }
+    },
+
     _refreshSizeCell: function()
     {
         if (this._resource.cached) {
@@ -2073,6 +2108,21 @@ WebInspector.NetworkDataGridNode.SizeComparator = function(a, b)
     return a._resource.resourceSize - b._resource.resourceSize;
 }
 
+WebInspector.NetworkDataGridNode.InitiatorComparator = function(a, b)
+{
+    if (!a._resource.initiator || a._resource.initiator.type === "Other")
+        return -1;
+    if (!b._resource.initiator || b._resource.initiator.type === "Other")
+        return 1;
+
+    if (a._resource.initiator.url < b._resource.initiator.url)
+        return -1;
+    if (a._resource.initiator.url > b._resource.initiator.url)
+        return 1;
+
+    return a._resource.initiator.lineNumber - b._resource.initiator.lineNumber;
+}
+
 WebInspector.NetworkDataGridNode.ResourcePropertyComparator = function(propertyName, revert, a, b)
 {
     var aValue = a._resource[propertyName];
index 6b4f61b..eab591d 100644 (file)
@@ -89,6 +89,7 @@
 .network-log-grid td.method-column,
 .network-log-grid td.status-column,
 .network-log-grid td.type-column,
+.network-log-grid td.initiator-column,
 .network-log-grid td.size-column,
 .network-log-grid td.time-column {
     background-color: rgba(0, 0, 0, 0.07);
     color: gray;
 }
 
+.initiator-column a {
+    color: inherit;
+}
+
 .network-log-grid tr.selected .network-cell-subtitle {
     color: white;
 }