Web Inspector: Initiated section of Resource Details Sidebar should not display as...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:33:59 +0000 (21:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:33:59 +0000 (21:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152907
<rdar://problem/24109927>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-01-08
Reviewed by Timothy Hatcher.

* UserInterface/Models/Resource.js:
(WebInspector.Resource.prototype.addInitiatedResource):
Dispatch an event when the list of initiated resources changes.

* UserInterface/Views/ResourceDetailsSidebarPanel.js:
(WebInspector.ResourceDetailsSidebarPanel.prototype.set resource):
Add/remove event listeners for initiated resources changes to refresh
the related resources section.

(WebInspector.ResourceDetailsSidebarPanel.prototype.refresh):
(WebInspector.ResourceDetailsSidebarPanel.prototype._refreshURL):
(WebInspector.ResourceDetailsSidebarPanel.prototype._refreshRelatedResourcesSection):
Show/hide the related resources section depending on if we have something or not.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/Resource.js
Source/WebInspectorUI/UserInterface/Views/ResourceDetailsSidebarPanel.js

index 3012523..c8291a8 100644 (file)
@@ -1,5 +1,27 @@
 2016-01-08  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Initiated section of Resource Details Sidebar should not display as empty and should update as the list changes
+        https://bugs.webkit.org/show_bug.cgi?id=152907
+        <rdar://problem/24109927>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Models/Resource.js:
+        (WebInspector.Resource.prototype.addInitiatedResource):
+        Dispatch an event when the list of initiated resources changes.
+
+        * UserInterface/Views/ResourceDetailsSidebarPanel.js:
+        (WebInspector.ResourceDetailsSidebarPanel.prototype.set resource):
+        Add/remove event listeners for initiated resources changes to refresh
+        the related resources section.
+
+        (WebInspector.ResourceDetailsSidebarPanel.prototype.refresh):
+        (WebInspector.ResourceDetailsSidebarPanel.prototype._refreshURL):
+        (WebInspector.ResourceDetailsSidebarPanel.prototype._refreshRelatedResourcesSection):
+        Show/hide the related resources section depending on if we have something or not.
+
+2016-01-08  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Uncaught exception: TypeError: this._initiatorSourceCodeLocation.sourceCode.addInitiatedResource is not a function
         https://bugs.webkit.org/show_bug.cgi?id=152905
         <rdar://problem/24109809>
index c2457e8..56d848e 100644 (file)
@@ -230,6 +230,8 @@ WebInspector.Resource = class Resource extends WebInspector.SourceCode
             return;
 
         this._initiatedResources.push(resource);
+
+        this.dispatchEventToListeners(WebInspector.Resource.Event.InitiatedResourcesDidChange);
     }
 
     get parentFrame()
@@ -693,7 +695,8 @@ WebInspector.Resource.Event = {
     TimestampsDidChange: "resource-timestamps-did-change",
     SizeDidChange: "resource-size-did-change",
     TransferSizeDidChange: "resource-transfer-size-did-change",
-    CacheStatusDidChange: "resource-cached-did-change"
+    CacheStatusDidChange: "resource-cached-did-change",
+    InitiatedResourcesDidChange: "resource-initiated-resources-did-change",
 };
 
 // Keep these in sync with the "ResourceType" enum defined by the "Page" domain.
index d8c0c8f..f7fe939 100644 (file)
@@ -157,6 +157,7 @@ WebInspector.ResourceDetailsSidebarPanel = class ResourceDetailsSidebarPanel ext
             this._resource.removeEventListener(WebInspector.Resource.Event.CacheStatusDidChange, this._refreshRequestAndResponse, this);
             this._resource.removeEventListener(WebInspector.Resource.Event.SizeDidChange, this._refreshDecodedSize, this);
             this._resource.removeEventListener(WebInspector.Resource.Event.TransferSizeDidChange, this._refreshTransferSize, this);
+            this._resource.removeEventListener(WebInspector.Resource.Event.InitiatedResourcesDidChange, this._refreshRelatedResourcesSection, this);
         }
 
         this._resource = resource;
@@ -170,6 +171,7 @@ WebInspector.ResourceDetailsSidebarPanel = class ResourceDetailsSidebarPanel ext
             this._resource.addEventListener(WebInspector.Resource.Event.CacheStatusDidChange, this._refreshRequestAndResponse, this);
             this._resource.addEventListener(WebInspector.Resource.Event.SizeDidChange, this._refreshDecodedSize, this);
             this._resource.addEventListener(WebInspector.Resource.Event.TransferSizeDidChange, this._refreshTransferSize, this);
+            this._resource.addEventListener(WebInspector.Resource.Event.InitiatedResourcesDidChange, this._refreshRelatedResourcesSection, this);
         }
 
         this.needsRefresh();
@@ -189,6 +191,7 @@ WebInspector.ResourceDetailsSidebarPanel = class ResourceDetailsSidebarPanel ext
         this._refreshRequestHeaders();
         this._refreshImageSizeSection();
         this._refreshRequestDataSection();
+        this._refreshRelatedResourcesSection();
     }
 
     // Private
@@ -215,6 +218,37 @@ WebInspector.ResourceDetailsSidebarPanel = class ResourceDetailsSidebarPanel ext
             this._locationSection.groups = [this._fullURLGroup, this._relatedResourcesGroup];
         }
 
+        if (urlComponents.queryString) {
+            // Ensure the "Query Parameters" section is displayed, right after the "Request & Response" section.
+            this.contentView.element.insertBefore(this._queryParametersSection.element, this._requestAndResponseSection.element.nextSibling);
+
+            this._queryParametersRow.dataGrid = this._createNameValueDataGrid(parseQueryString(urlComponents.queryString, true));
+        } else {
+            // Hide the "Query Parameters" section if we don't have a query string.
+            var queryParametersSectionElement = this._queryParametersSection.element;
+            if (queryParametersSectionElement.parentNode)
+                queryParametersSectionElement.parentNode.removeChild(queryParametersSectionElement);
+        }
+    }
+
+    _refreshRelatedResourcesSection()
+    {
+        // Hide the section if we don't have anything to show.
+        let groups = this._locationSection.groups;
+        let isSectionVisible = groups.includes(this._relatedResourcesGroup);
+        if (!this._resource.initiatorSourceCodeLocation && !this._resource.initiatedResources.length) {
+            if (isSectionVisible) {
+                groups.remove(this._relatedResourcesGroup);
+                this._locationSection.groups = groups;
+            }
+            return;
+        }
+
+        if (!isSectionVisible) {
+            groups.push(this._relatedResourcesGroup);
+            this._locationSection.groups = groups;
+        }
+
         let initiatorLocation = this._resource.initiatorSourceCodeLocation;
         this._initiatorRow.value = initiatorLocation ? WebInspector.createSourceCodeLocationLink(initiatorLocation, true) : null;
 
@@ -227,18 +261,6 @@ WebInspector.ResourceDetailsSidebarPanel = class ResourceDetailsSidebarPanel ext
             this._initiatedRow.value = resourceLinkContainer;
         } else
             this._initiatedRow.value = null;
-
-        if (urlComponents.queryString) {
-            // Ensure the "Query Parameters" section is displayed, right after the "Request & Response" section.
-            this.contentView.element.insertBefore(this._queryParametersSection.element, this._requestAndResponseSection.element.nextSibling);
-
-            this._queryParametersRow.dataGrid = this._createNameValueDataGrid(parseQueryString(urlComponents.queryString, true));
-        } else {
-            // Hide the "Query Parameters" section if we don't have a query string.
-            var queryParametersSectionElement = this._queryParametersSection.element;
-            if (queryParametersSectionElement.parentNode)
-                queryParametersSectionElement.parentNode.removeChild(queryParametersSectionElement);
-        }
     }
 
     _refreshResourceType()