Web Inspector: Network: support drag/drop for importing
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Apr 2019 01:20:32 +0000 (01:20 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Apr 2019 01:20:32 +0000 (01:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197221

Reviewed by Timothy Hatcher.

* UserInterface/Views/NetworkTabContentView.js:
(WI.NetworkTabContentView.prototype.async.handleFileDrop): Added.
* UserInterface/Views/NetworkTableContentView.js:
(WI.NetworkTableContentView.prototype.processHAR): Added.
(WI.NetworkTableContentView.prototype._importHAR):

* UserInterface/Base/FileUtilities.js:
(WI.FileUtilities.async readText):
Only `await` if the result is a `Promise`.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/FileUtilities.js
Source/WebInspectorUI/UserInterface/Views/NetworkTabContentView.js
Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js

index f622ad2..c72952e 100644 (file)
@@ -1,5 +1,22 @@
 2019-04-23  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Network: support drag/drop for importing
+        https://bugs.webkit.org/show_bug.cgi?id=197221
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/NetworkTabContentView.js:
+        (WI.NetworkTabContentView.prototype.async.handleFileDrop): Added.
+        * UserInterface/Views/NetworkTableContentView.js:
+        (WI.NetworkTableContentView.prototype.processHAR): Added.
+        (WI.NetworkTableContentView.prototype._importHAR):
+
+        * UserInterface/Base/FileUtilities.js:
+        (WI.FileUtilities.async readText):
+        Only `await` if the result is a `Promise`.
+
+2019-04-23  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Uncaught Exception: null is not an object (evaluating 'this.ownerDocument.frameIdentifier')
         https://bugs.webkit.org/show_bug.cgi?id=196420
         <rdar://problem/49444205>
index 486a116..e8ccf54 100644 (file)
@@ -144,7 +144,7 @@ WI.FileUtilities = class FileUtilities {
             }
 
             let promise = callback(result);
-            if (promise)
+            if (promise instanceof Promise)
                 await promise;
         }
     }
index e9b8c4e..b8cd3b5 100644 (file)
@@ -83,6 +83,11 @@ WI.NetworkTabContentView = class NetworkTabContentView extends WI.TabContentView
         super.closed();
     }
 
+    async handleFileDrop(files)
+    {
+        await WI.FileUtilities.readJSON(files, (result) => this._networkTableContentView.processHAR(result));
+    }
+
     // Public
 
     get contentBrowser() { return this._contentBrowser; }
index aa084a1..d6350d2 100644 (file)
@@ -1242,6 +1242,23 @@ WI.NetworkTableContentView = class NetworkTableContentView extends WI.ContentVie
             this._waterfallPopover.resize();
     }
 
+    processHAR(result)
+    {
+        let resources = WI.networkManager.processHAR(result);
+        if (!resources)
+            return;
+
+        let importedCollection = this._addCollection();
+
+        let displayName = WI.UIString("Imported - %s").format(result.filename);
+        this._addCollectionPathComponent(importedCollection, displayName, "network-har-icon");
+
+        this._changeCollection(importedCollection);
+
+        for (let resource of resources)
+            this._insertResourceAndReloadTable(resource);
+    }
+
     handleClearShortcut(event)
     {
         if (!this._isShowingMainCollection())
@@ -2135,21 +2152,7 @@ WI.NetworkTableContentView = class NetworkTableContentView extends WI.ContentVie
 
     _importHAR()
     {
-        WI.FileUtilities.importJSON((result) => {
-            let resources = WI.networkManager.processHAR(result);
-            if (!resources)
-                return;
-
-            let importedCollection = this._addCollection();
-
-            let displayName = WI.UIString("Imported - %s").format(result.filename);
-            this._addCollectionPathComponent(importedCollection, displayName, "network-har-icon");
-
-            this._changeCollection(importedCollection);
-
-            for (let resource of resources)
-                this._insertResourceAndReloadTable(resource);
-        });
+        WI.FileUtilities.importJSON((result) => this.processHAR(result));
     }
 
     _waterfallPopoverContent()