Index: third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.cpp |
diff --git a/third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.cpp b/third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.cpp |
index 3512051bf191613a1f4e16497cccfa9af04b78cf..15a4803470a2130d95c6714f60942b265463d471 100644 |
--- a/third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.cpp |
+++ b/third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.cpp |
@@ -4,6 +4,7 @@ |
#include "modules/compositorworker/WindowAnimationWorklet.h" |
+#include "core/dom/Document.h" |
#include "core/frame/LocalDOMWindow.h" |
#include "core/frame/LocalFrame.h" |
#include "modules/compositorworker/AnimationWorklet.h" |
@@ -11,7 +12,7 @@ |
namespace blink { |
WindowAnimationWorklet::WindowAnimationWorklet(LocalDOMWindow& window) |
- : DOMWindowProperty(window.frame()) {} |
+ : ContextLifecycleObserver(window.frame()->document()) {} |
const char* WindowAnimationWorklet::supplementName() { |
return "WindowAnimationWorklet"; |
@@ -30,24 +31,36 @@ WindowAnimationWorklet& WindowAnimationWorklet::from(LocalDOMWindow& window) { |
// static |
Worklet* WindowAnimationWorklet::animationWorklet(DOMWindow& window) { |
- return from(toLocalDOMWindow(window)).animationWorklet(); |
+ return from(toLocalDOMWindow(window)) |
+ .animationWorklet(toLocalDOMWindow(window)); |
} |
-AnimationWorklet* WindowAnimationWorklet::animationWorklet() { |
- if (!m_animationWorklet && frame()) |
- m_animationWorklet = AnimationWorklet::create(frame()); |
+AnimationWorklet* WindowAnimationWorklet::animationWorklet( |
+ LocalDOMWindow& window) { |
+ if (!m_animationWorklet && getExecutionContext()) { |
+ DCHECK(window.frame()); |
+ m_animationWorklet = AnimationWorklet::create(window.frame()); |
+ } |
return m_animationWorklet.get(); |
} |
-void WindowAnimationWorklet::frameDestroyed() { |
- m_animationWorklet.clear(); |
- DOMWindowProperty::frameDestroyed(); |
+// Break the following cycle when the context gets detached. |
+// Otherwise, the worklet object will leak. |
+// |
+// window => window.animationWorklet |
+// => WindowAnimationWorklet |
+// => AnimationWorklet <--- break this reference |
+// => ThreadedWorkletMessagingProxy |
+// => Document |
+// => ... => window |
+void WindowAnimationWorklet::contextDestroyed() { |
+ m_animationWorklet = nullptr; |
} |
DEFINE_TRACE(WindowAnimationWorklet) { |
visitor->trace(m_animationWorklet); |
Supplement<LocalDOMWindow>::trace(visitor); |
- DOMWindowProperty::trace(visitor); |
+ ContextLifecycleObserver::trace(visitor); |
} |
} // namespace blink |