Web Inspector: Canvas: unbinding a canvas should always remove the agent as an observer
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2019 18:08:03 +0000 (18:08 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2019 18:08:03 +0000 (18:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196324
<rdar://problem/49357109>

Reviewed by Matt Baker.

No change in functionality.

* html/CanvasBase.cpp:
(WebCore::CanvasBase::notifyObserversCanvasChanged):
(WebCore::CanvasBase::notifyObserversCanvasResized):
(WebCore::CanvasBase::notifyObserversCanvasDestroyed):

* inspector/agents/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::frameNavigated):
(WebCore::InspectorCanvasAgent::bindCanvas):
(WebCore::InspectorCanvasAgent::unbindCanvas):

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

Source/WebCore/ChangeLog
Source/WebCore/html/CanvasBase.cpp
Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp

index 93414cc..2f842fb 100644 (file)
@@ -1,3 +1,23 @@
+2019-03-28  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Canvas: unbinding a canvas should always remove the agent as an observer
+        https://bugs.webkit.org/show_bug.cgi?id=196324
+        <rdar://problem/49357109>
+
+        Reviewed by Matt Baker.
+
+        No change in functionality.
+
+        * html/CanvasBase.cpp:
+        (WebCore::CanvasBase::notifyObserversCanvasChanged):
+        (WebCore::CanvasBase::notifyObserversCanvasResized):
+        (WebCore::CanvasBase::notifyObserversCanvasDestroyed):
+
+        * inspector/agents/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::frameNavigated):
+        (WebCore::InspectorCanvasAgent::bindCanvas):
+        (WebCore::InspectorCanvasAgent::unbindCanvas):
+
 2019-03-28  Alicia Boya GarcĂ­a  <aboya@igalia.com>
 
         [MSE][GStreamer] Remove dead code in MediaPlayerPrivateGStreamer::doSeek()
index a8ae80a..bb22039 100644 (file)
@@ -31,6 +31,7 @@
 #include "Element.h"
 #include "FloatRect.h"
 #include "InspectorInstrumentation.h"
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -69,13 +70,13 @@ void CanvasBase::removeObserver(CanvasObserver& observer)
 
 void CanvasBase::notifyObserversCanvasChanged(const FloatRect& rect)
 {
-    for (auto& observer : m_observers)
+    for (auto& observer : copyToVector(m_observers))
         observer->canvasChanged(*this, rect);
 }
 
 void CanvasBase::notifyObserversCanvasResized()
 {
-    for (auto& observer : m_observers)
+    for (auto& observer : copyToVector(m_observers))
         observer->canvasResized(*this);
 }
 
@@ -83,7 +84,7 @@ void CanvasBase::notifyObserversCanvasDestroyed()
 {
     ASSERT(!m_didNotifyObserversCanvasDestroyed);
 
-    for (auto& observer : m_observers)
+    for (auto& observer : copyToVector(m_observers))
         observer->canvasDestroyed(*this);
 
     m_observers.clear();
index d087b05..9367a4e 100644 (file)
@@ -378,8 +378,6 @@ void InspectorCanvasAgent::frameNavigated(Frame& frame)
     }
 
     for (auto* inspectorCanvas : inspectorCanvases) {
-        inspectorCanvas->context().canvasBase().removeObserver(*this);
-
         String identifier = unbindCanvas(*inspectorCanvas);
         m_frontendDispatcher->canvasRemoved(identifier);
     }
@@ -647,11 +645,11 @@ void InspectorCanvasAgent::clearCanvasData()
 
 InspectorCanvas& InspectorCanvasAgent::bindCanvas(CanvasRenderingContext& context, bool captureBacktrace)
 {
-    context.canvasBase().addObserver(*this);
-
     auto inspectorCanvas = InspectorCanvas::create(context);
     m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), inspectorCanvas.copyRef());
 
+    inspectorCanvas->context().canvasBase().addObserver(*this);
+
     m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
 
 #if ENABLE(WEBGL)
@@ -682,6 +680,8 @@ String InspectorCanvasAgent::unbindCanvas(InspectorCanvas& inspectorCanvas)
         unbindProgram(*inspectorProgram);
 #endif
 
+    inspectorCanvas.context().canvasBase().removeObserver(*this);
+
     String identifier = inspectorCanvas.identifier();
     m_identifierToInspectorCanvas.remove(identifier);