Web Inspector: OpenResourceDialog should keep its resources list up-to-date
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2016 01:24:47 +0000 (01:24 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2016 01:24:47 +0000 (01:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155321
<rdar://problem/25093890>

Reviewed by Timothy Hatcher.

The Quick Open dialog should listen for resource change events, refreshing
the resource list and current query results as needed.

* UserInterface/Views/OpenResourceDialog.js:
(WebInspector.OpenResourceDialog):
(WebInspector.OpenResourceDialog.prototype.didDismissDialog):
Unregister resource event handlers.

(WebInspector.OpenResourceDialog.prototype.didPresentDialog):
Register resource event handlers and add main frame resources.

(WebInspector.OpenResourceDialog.prototype._addResource):
Add resource to the query controller, if valid. Optionally suppress
the potentially expensive filter update, which is useful when adding
multiple resources at once.

(WebInspector.OpenResourceDialog.prototype._addResourcesForFrame):
Add the entire frame resource tree and update dialog filter.

(WebInspector.OpenResourceDialog.prototype._mainResourceDidChange):
(WebInspector.OpenResourceDialog.prototype._resourceWasAdded):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js

index 3c985a3..71f002d 100644 (file)
@@ -1,3 +1,33 @@
+2016-04-07  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: OpenResourceDialog should keep its resources list up-to-date
+        https://bugs.webkit.org/show_bug.cgi?id=155321
+        <rdar://problem/25093890>
+
+        Reviewed by Timothy Hatcher.
+
+        The Quick Open dialog should listen for resource change events, refreshing
+        the resource list and current query results as needed.
+
+        * UserInterface/Views/OpenResourceDialog.js:
+        (WebInspector.OpenResourceDialog):
+        (WebInspector.OpenResourceDialog.prototype.didDismissDialog):
+        Unregister resource event handlers.
+
+        (WebInspector.OpenResourceDialog.prototype.didPresentDialog):
+        Register resource event handlers and add main frame resources.
+
+        (WebInspector.OpenResourceDialog.prototype._addResource):
+        Add resource to the query controller, if valid. Optionally suppress
+        the potentially expensive filter update, which is useful when adding
+        multiple resources at once.
+
+        (WebInspector.OpenResourceDialog.prototype._addResourcesForFrame):
+        Add the entire frame resource tree and update dialog filter.
+
+        (WebInspector.OpenResourceDialog.prototype._mainResourceDidChange):
+        (WebInspector.OpenResourceDialog.prototype._resourceWasAdded):
+
 2016-04-07  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: ProfileView source links are off by 1 line, worse in pretty printed code
index 37df376..2b01b87 100644 (file)
@@ -120,27 +120,22 @@ WebInspector.OpenResourceDialog = class OpenResourceDialog extends WebInspector.
 
     didDismissDialog()
     {
+        WebInspector.Frame.removeEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
+        WebInspector.Frame.removeEventListener(WebInspector.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
+
         this._queryController.reset();
     }
 
     didPresentDialog()
     {
-        this._inputElement.focus();
-        this._clear();
+        WebInspector.Frame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
+        WebInspector.Frame.addEventListener(WebInspector.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
 
-        let frames = [WebInspector.frameResourceManager.mainFrame];
-        while (frames.length) {
-            let frame = frames.shift();
-            let resources = [frame.mainResource].concat(frame.resources);
-            for (let resource of resources) {
-                if (!this.representedObjectIsValid(resource))
-                    continue;
+        if (WebInspector.frameResourceManager.mainFrame)
+            this._addResourcesForFrame(WebInspector.frameResourceManager.mainFrame);
 
-                this._queryController.addResource(resource);
-            }
-
-            frames = frames.concat(frame.childFrames);
-        }
+        this._inputElement.focus();
+        this._clear();
     }
 
     // Private
@@ -248,6 +243,48 @@ WebInspector.OpenResourceDialog = class OpenResourceDialog extends WebInspector.
 
         this.dismiss(treeElement.representedObject);
     }
+
+    _addResource(resource, suppressFilterUpdate)
+    {
+        if (!this.representedObjectIsValid(resource))
+            return;
+
+        this._queryController.addResource(resource);
+        if (suppressFilterUpdate)
+            return;
+
+        this._updateFilter();
+    }
+
+    _addResourcesForFrame(frame)
+    {
+        const suppressFilterUpdate = true;
+
+        let frames = [frame];
+        while (frames.length) {
+            let currentFrame = frames.shift();
+            let resources = [currentFrame.mainResource].concat(currentFrame.resources);
+            for (let resource of resources)
+                this._addResource(resource, suppressFilterUpdate);
+
+            frames = frames.concat(frame.childFrames);
+        }
+
+        this._updateFilter();
+    }
+
+    _mainResourceDidChange(event)
+    {
+        if (event.target.isMainFrame())
+            this._queryController.reset();
+
+        this._addResource(event.target.mainResource);
+    }
+
+    _resourceWasAdded(event)
+    {
+        this._addResource(event.data.resource);
+    }
 };
 
 WebInspector.OpenResourceDialog.NonEmptyClassName = "non-empty";