Hook up the initiator info and show it in the Resource details sidebar.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 19:27:38 +0000 (19:27 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 19:27:38 +0000 (19:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121741

Reviewed by Joseph Pecoraro.

* UserInterface/FrameResourceManager.js:
(WebInspector.FrameResourceManager.prototype.resourceRequestWillBeSent):
(WebInspector.FrameResourceManager.prototype.resourceRequestWasServedFromMemoryCache):
(WebInspector.FrameResourceManager.prototype._addNewResourceToFrame):
(WebInspector.FrameResourceManager.prototype._initiatorSourceCodeLocationFromPayload):
* UserInterface/NetworkObserver.js:
(WebInspector.NetworkObserver.prototype.requestWillBeSent):
(WebInspector.NetworkObserver.prototype.requestServedFromMemoryCache):
* UserInterface/Resource.js:
(WebInspector.Resource):
(WebInspector.Resource.prototype.get initiatorSourceCodeLocation):
* UserInterface/ResourceDetailsSidebarPanel.js:
(WebInspector.ResourceDetailsSidebarPanel):
(WebInspector.ResourceDetailsSidebarPanel.prototype._refreshURL):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/FrameResourceManager.js
Source/WebInspectorUI/UserInterface/NetworkObserver.js
Source/WebInspectorUI/UserInterface/Resource.js
Source/WebInspectorUI/UserInterface/ResourceDetailsSidebarPanel.js

index da300ce..9c79540 100644 (file)
@@ -1,3 +1,26 @@
+2013-09-21  Timothy Hatcher  <timothy@apple.com>
+
+        Hook up the initiator info and show it in the Resource details sidebar.
+
+        https://bugs.webkit.org/show_bug.cgi?id=121741
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/FrameResourceManager.js:
+        (WebInspector.FrameResourceManager.prototype.resourceRequestWillBeSent):
+        (WebInspector.FrameResourceManager.prototype.resourceRequestWasServedFromMemoryCache):
+        (WebInspector.FrameResourceManager.prototype._addNewResourceToFrame):
+        (WebInspector.FrameResourceManager.prototype._initiatorSourceCodeLocationFromPayload):
+        * UserInterface/NetworkObserver.js:
+        (WebInspector.NetworkObserver.prototype.requestWillBeSent):
+        (WebInspector.NetworkObserver.prototype.requestServedFromMemoryCache):
+        * UserInterface/Resource.js:
+        (WebInspector.Resource):
+        (WebInspector.Resource.prototype.get initiatorSourceCodeLocation):
+        * UserInterface/ResourceDetailsSidebarPanel.js:
+        (WebInspector.ResourceDetailsSidebarPanel):
+        (WebInspector.ResourceDetailsSidebarPanel.prototype._refreshURL):
+
 2013-09-20  Timothy Hatcher  <timothy@apple.com>
 
         Parse MIME-types and strip them down to the base type when needed.
index 6a86484..8eefe17 100644 (file)
@@ -173,7 +173,7 @@ WebInspector.FrameResourceManager.prototype = {
             this._mainFrameDidChange(oldMainFrame);
     },
 
-    resourceRequestWillBeSent: function(requestIdentifier, frameIdentifier, loaderIdentifier, request, type, redirectResponse, timestamp)
+    resourceRequestWillBeSent: function(requestIdentifier, frameIdentifier, loaderIdentifier, request, type, redirectResponse, timestamp, initiator)
     {
         // Called from WebInspector.NetworkObserver.
 
@@ -189,8 +189,10 @@ WebInspector.FrameResourceManager.prototype = {
             return;
         }
 
+        var initiatorSourceCodeLocation = this._initiatorSourceCodeLocationFromPayload(initiator);
+
         // This is a new request, make a new resource and add it to the right frame.
-        resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, request.url, type, request.method, request.headers, request.postData, timestamp, null, null);
+        resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, request.url, type, request.method, request.headers, request.postData, timestamp, null, null, initiatorSourceCodeLocation);
 
         // Associate the resource with the requestIdentifier so it can be found in future loading events.
         this._resourceRequestIdentifierMap[requestIdentifier] = resource;
@@ -215,7 +217,7 @@ WebInspector.FrameResourceManager.prototype = {
         resource.markAsCached();
     },
 
-    resourceRequestWasServedFromMemoryCache: function(requestIdentifier, frameIdentifier, loaderIdentifier, cachedResourcePayload, timestamp)
+    resourceRequestWasServedFromMemoryCache: function(requestIdentifier, frameIdentifier, loaderIdentifier, cachedResourcePayload, timestamp, initiator)
     {
         // Called from WebInspector.NetworkObserver.
 
@@ -225,8 +227,10 @@ WebInspector.FrameResourceManager.prototype = {
 
         console.assert(!(requestIdentifier in this._resourceRequestIdentifierMap));
 
+        var initiatorSourceCodeLocation = this._initiatorSourceCodeLocationFromPayload(initiator);
+
         var response = cachedResourcePayload.response;
-        var resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, cachedResourcePayload.url, cachedResourcePayload.type, null, null, timestamp, null, null);
+        var resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, cachedResourcePayload.url, cachedResourcePayload.type, null, null, timestamp, null, null, initiatorSourceCodeLocation);
         resource.markAsCached();
         resource.updateForResponse(cachedResourcePayload.url, response.mimeType, cachedResourcePayload.type, response.headers, response.status, response.statusText, timestamp);
         resource.markAsFinished(timestamp);
@@ -375,7 +379,7 @@ WebInspector.FrameResourceManager.prototype = {
 
     // Private
 
-    _addNewResourceToFrame: function(requestIdentifier, frameIdentifier, loaderIdentifier, url, type, requestMethod, requestHeaders, requestData, timestamp, frameName, frameSecurityOrigin)
+    _addNewResourceToFrame: function(requestIdentifier, frameIdentifier, loaderIdentifier, url, type, requestMethod, requestHeaders, requestData, timestamp, frameName, frameSecurityOrigin, initiatorSourceCodeLocation)
     {
         console.assert(!this._waitingForMainFrameResourceTreePayload);
         if (this._waitingForMainFrameResourceTreePayload)
@@ -391,12 +395,12 @@ WebInspector.FrameResourceManager.prototype = {
             else if (frame.provisionalMainResource && frame.provisionalMainResource.url === url && frame.provisionalLoaderIdentifier === loaderIdentifier)
                 resource = frame.provisionalMainResource;
             else {
-                resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, timestamp);
+                resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, timestamp, initiatorSourceCodeLocation);
                 this._addResourceToFrame(frame, resource);
             }
         } else {
             // This is a new request for a new frame, which is always the main resource.
-            resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, timestamp);
+            resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, timestamp, initiatorSourceCodeLocation);
             frame = new WebInspector.Frame(frameIdentifier, frameName, frameSecurityOrigin, loaderIdentifier, resource);
             this._frameIdentifierMap[frame.id] = frame;
 
@@ -436,6 +440,51 @@ WebInspector.FrameResourceManager.prototype = {
         frame.addResource(resource);
     },
 
+    _initiatorSourceCodeLocationFromPayload: function(initiatorPayload)
+    {
+        if (!initiatorPayload)
+            return null;
+
+        var url = null;
+        var lineNumber = NaN;
+        var columnNumber = 0;
+
+        if (initiatorPayload.stackTrace && initiatorPayload.stackTrace.length) {
+            var stackTracePayload = initiatorPayload.stackTrace;
+            for (var i = 0; i < stackTracePayload.length; ++i) {
+                var callFramePayload = stackTracePayload[i];
+                if (!callFramePayload.url || callFramePayload.url === "[native code]")
+                    continue;
+
+                url = callFramePayload.url;
+
+                // The lineNumber is 1-based, but we expect 0-based.
+                lineNumber = callFramePayload.lineNumber - 1;
+
+                columnNumber = callFramePayload.columnNumber;
+
+                break;
+            }
+        } else if (initiatorPayload.url) {
+            url = initiatorPayload.url;
+
+            // The lineNumber is 1-based, but we expect 0-based.
+            lineNumber = initiatorPayload.lineNumber - 1;
+        }
+
+        if (!url || isNaN(lineNumber) || lineNumber < 0)
+            return null;
+
+        var sourceCode = WebInspector.frameResourceManager.resourceForURL(url);
+        if (!sourceCode)
+            sourceCode = WebInspector.debuggerManager.scriptsForURL(url)[0];
+
+        if (!sourceCode)
+            return null;
+
+        return sourceCode.createSourceCodeLocation(lineNumber, columnNumber);
+    },
+
     _processMainFrameResourceTreePayload: function(error, mainFramePayload)
     {
         console.assert(this._waitingForMainFrameResourceTreePayload);
index 7cc0e4e..10da646 100644 (file)
@@ -35,7 +35,7 @@ WebInspector.NetworkObserver.prototype = {
 
     requestWillBeSent: function(requestId, frameId, loaderId, documentURL, request, timestamp, initiator, redirectResponse, type)
     {
-        WebInspector.frameResourceManager.resourceRequestWillBeSent(requestId, frameId, loaderId, request, type, redirectResponse, timestamp);
+        WebInspector.frameResourceManager.resourceRequestWillBeSent(requestId, frameId, loaderId, request, type, redirectResponse, timestamp, initiator);
     },
 
     requestServedFromCache: function(requestId)
@@ -65,7 +65,7 @@ WebInspector.NetworkObserver.prototype = {
 
     requestServedFromMemoryCache: function(requestId, frameId, loaderId, documentURL, timestamp, initiator, resource)
     {
-        WebInspector.frameResourceManager.resourceRequestWasServedFromMemoryCache(requestId, frameId, loaderId, resource, timestamp);
+        WebInspector.frameResourceManager.resourceRequestWasServedFromMemoryCache(requestId, frameId, loaderId, resource, timestamp, initiator);
     },
 
     webSocketWillSendHandshakeRequest: function(requestId, timestamp, request)
index cc01e55..bf3b66c 100644 (file)
@@ -23,7 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.Resource = function(url, mimeType, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, requestSentTimestamp)
+WebInspector.Resource = function(url, mimeType, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, requestSentTimestamp, initiatorSourceCodeLocation)
 {
     WebInspector.SourceCode.call(this);
 
@@ -42,6 +42,7 @@ WebInspector.Resource = function(url, mimeType, type, loaderIdentifier, requestI
     this._requestHeaders = requestHeaders || {};
     this._responseHeaders = {};
     this._parentFrame = null;
+    this._initiatorSourceCodeLocation = initiatorSourceCodeLocation || null;
     this._requestSentTimestamp = requestSentTimestamp || NaN;
     this._responseReceivedTimestamp = NaN;
     this._lastRedirectReceivedTimestamp = NaN;
@@ -201,6 +202,11 @@ WebInspector.Resource.prototype = {
         return WebInspector.displayNameForURL(this._url, this.urlComponents);
     },
 
+    get initiatorSourceCodeLocation()
+    {
+        return this._initiatorSourceCodeLocation;
+    },
+
     get type()
     {
         return this._type;
index 58c2d8b..5b2edf2 100644 (file)
@@ -44,15 +44,18 @@ WebInspector.ResourceDetailsSidebarPanel = function() {
     this._locationQueryStringRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Query String"));
     this._locationFragmentRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Fragment"));
     this._locationFilenameRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Filename"));
+    this._initiatorRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Initiator"));
 
     var firstGroup = [this._locationFullURLRow];
     var secondGroup = [this._locationSchemeRow, this._locationHostRow, this._locationPortRow, this._locationPathRow,
         this._locationQueryStringRow, this._locationFragmentRow, this._locationFilenameRow];
+    var thirdGroup = [this._initiatorRow];
 
     this._fullURLGroup = new WebInspector.DetailsSectionGroup(firstGroup);
     this._locationURLComponentsGroup = new WebInspector.DetailsSectionGroup(secondGroup);
+    this._initiatorGroup = new WebInspector.DetailsSectionGroup(thirdGroup);
 
-    this._locationSection = new WebInspector.DetailsSection("resource-location", WebInspector.UIString("Location"), [this._fullURLGroup, this._locationURLComponentsGroup]);
+    this._locationSection = new WebInspector.DetailsSection("resource-location", WebInspector.UIString("Location"), [this._fullURLGroup, this._locationURLComponentsGroup, this._initiatorGroup]);
 
     this._queryParametersRow = new WebInspector.DetailsSectionDataGridRow(null, WebInspector.UIString("No Query Parameters"));
     this._queryParametersSection = new WebInspector.DetailsSection("resource-query-parameters", WebInspector.UIString("Query Parameters"));
@@ -200,7 +203,10 @@ WebInspector.ResourceDetailsSidebarPanel.prototype = {
 
         var urlComponents = this._resource.urlComponents;
         if (urlComponents.scheme) {
-            this._locationSection.groups = [this._fullURLGroup, this._locationURLComponentsGroup];
+            if (this._resource.initiatorSourceCodeLocation)
+                this._locationSection.groups = [this._fullURLGroup, this._locationURLComponentsGroup, this._initiatorGroup];
+            else
+                this._locationSection.groups = [this._fullURLGroup, this._locationURLComponentsGroup];
 
             this._locationSchemeRow.value = urlComponents.scheme ? urlComponents.scheme : null;
             this._locationHostRow.value = urlComponents.host ? urlComponents.host : null;
@@ -209,8 +215,15 @@ WebInspector.ResourceDetailsSidebarPanel.prototype = {
             this._locationQueryStringRow.value = urlComponents.queryString ? urlComponents.queryString.insertWordBreakCharacters() : null;
             this._locationFragmentRow.value = urlComponents.fragment ? urlComponents.fragment.insertWordBreakCharacters() : null;
             this._locationFilenameRow.value = urlComponents.lastPathComponent ? urlComponents.lastPathComponent.insertWordBreakCharacters() : null;
-        } else
-            this._locationSection.groups = [this._fullURLGroup];
+        } else {
+            if (this._resource.initiatorSourceCodeLocation)
+                this._locationSection.groups = [this._fullURLGroup, this._initiatorGroup];
+            else
+                this._locationSection.groups = [this._fullURLGroup];
+        }
+
+        if (this._resource.initiatorSourceCodeLocation)
+            this._initiatorRow.value = WebInspector.createSourceCodeLocationLink(this._resource.initiatorSourceCodeLocation, true);
 
         if (urlComponents.queryString) {
             // Ensure the "Query Parameters" section is displayed, right after the "Request & Response" section.