Web Inspector: Canvas: rework how Canvas.enable/Canvas.disable is used so that events...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 02:27:35 +0000 (02:27 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 02:27:35 +0000 (02:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195828
<rdar://problem/48941756>

Reviewed by Timothy Hatcher.

* UserInterface/Controllers/CanvasManager.js:
(WI.CanvasManager):
(WI.CanvasManager.prototype.initializeTarget):
(WI.CanvasManager.prototype.enable): Added.
(WI.CanvasManager.prototype.disable): Added.

* UserInterface/Views/CanvasTabContentView.js:
(WI.CanvasTabContentView):
(WI.CanvasTabContentView.prototype.closed): Added.

* UserInterface/Base/Test.js:
(WI.contentLoaded):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js
Source/WebInspectorUI/UserInterface/Test/Test.js
Source/WebInspectorUI/UserInterface/Views/CanvasTabContentView.js

index 29dc77f..d92a734 100644 (file)
@@ -1,5 +1,26 @@
 2019-03-20  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Canvas: rework how Canvas.enable/Canvas.disable is used so that events are not sent when the Canvas tab isn't enabled
+        https://bugs.webkit.org/show_bug.cgi?id=195828
+        <rdar://problem/48941756>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Controllers/CanvasManager.js:
+        (WI.CanvasManager):
+        (WI.CanvasManager.prototype.initializeTarget):
+        (WI.CanvasManager.prototype.enable): Added.
+        (WI.CanvasManager.prototype.disable): Added.
+
+        * UserInterface/Views/CanvasTabContentView.js:
+        (WI.CanvasTabContentView):
+        (WI.CanvasTabContentView.prototype.closed): Added.
+
+        * UserInterface/Base/Test.js:
+        (WI.contentLoaded):
+
+2019-03-20  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Sources: collapsing a section doesn't shrink the space used by that section
         https://bugs.webkit.org/show_bug.cgi?id=196045
 
index e730640..714a529 100644 (file)
@@ -31,17 +31,21 @@ WI.CanvasManager = class CanvasManager extends WI.Object
     {
         super();
 
-        WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
-
+        this._enabled = false;
         this._canvasIdentifierMap = new Map;
         this._shaderProgramIdentifierMap = new Map;
         this._importedRecordings = new Set;
+
+        WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
     }
 
     // Target
 
     initializeTarget(target)
     {
+        if (!this._enabled)
+            return;
+
         if (target.CanvasAgent) {
             target.CanvasAgent.enable();
 
@@ -97,6 +101,32 @@ WI.CanvasManager = class CanvasManager extends WI.Object
         this.dispatchEventToListeners(WI.CanvasManager.Event.RecordingImported, {recording, initiatedByUser: true});
     }
 
+    enable()
+    {
+        console.assert(!this._enabled);
+
+        this._enabled = true;
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
+    disable()
+    {
+        console.assert(this._enabled);
+
+        for (let target of WI.targets) {
+            if (target.CanvasAgent)
+                target.CanvasAgent.disable();
+        }
+
+        this._canvasIdentifierMap.clear();
+        this._shaderProgramIdentifierMap.clear();
+        this._importedRecordings.clear();
+
+        this._enabled = false;
+    }
+
     setRecordingAutoCaptureFrameCount(enabled, count)
     {
         console.assert(!isNaN(count) && count >= 0);
index 9111452..98649f0 100644 (file)
@@ -129,6 +129,9 @@ WI.redirectGlobalAgentsToConnection = function(connection)
 
 WI.contentLoaded = function()
 {
+    // Things that would normally get called by the UI, that we still want to do in tests.
+    WI.canvasManager.enable();
+
     // Signal that the frontend is now ready to receive messages.
     InspectorFrontendAPI.loadCompleted();
 
index f0071ed..58a2ce5 100644 (file)
@@ -58,6 +58,8 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
 
         this.element.addEventListener("dragover", this._handleDragOver.bind(this));
         this.element.addEventListener("drop", this._handleDrop.bind(this));
+
+        WI.canvasManager.enable();
     }
 
     static tabInfo()
@@ -122,6 +124,13 @@ WI.CanvasTabContentView = class CanvasTabContentView extends WI.ContentBrowserTa
         super.hidden();
     }
 
+    closed()
+    {
+        WI.canvasManager.disable();
+
+        super.closed();
+    }
+
     restoreStateFromCookie(cookie)
     {
         // FIXME: implement once <https://webkit.org/b/177606> is complete.