Index: third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp |
diff --git a/third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp b/third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp |
index 3f6255407670558bc0608397ac552b11f34816c3..106c562eb847b48de321c2434447897f7327229e 100644 |
--- a/third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp |
+++ b/third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp |
@@ -4,6 +4,7 @@ |
#include "modules/webaudio/WindowAudioWorklet.h" |
+#include "core/dom/Document.h" |
#include "core/frame/LocalDOMWindow.h" |
#include "core/frame/LocalFrame.h" |
#include "modules/webaudio/AudioWorklet.h" |
@@ -11,7 +12,7 @@ |
namespace blink { |
WindowAudioWorklet::WindowAudioWorklet(LocalDOMWindow& window) |
- : DOMWindowProperty(window.frame()) {} |
+ : ContextLifecycleObserver(window.frame()->document()) {} |
const char* WindowAudioWorklet::supplementName() { |
return "WindowAudioWorklet"; |
@@ -28,24 +29,34 @@ WindowAudioWorklet& WindowAudioWorklet::from(LocalDOMWindow& window) { |
} |
Worklet* WindowAudioWorklet::audioWorklet(DOMWindow& window) { |
- return from(toLocalDOMWindow(window)).audioWorklet(); |
+ return from(toLocalDOMWindow(window)).audioWorklet(toLocalDOMWindow(window)); |
} |
-AudioWorklet* WindowAudioWorklet::audioWorklet() { |
- if (!m_audioWorklet && frame()) |
- m_audioWorklet = AudioWorklet::create(frame()); |
+AudioWorklet* WindowAudioWorklet::audioWorklet(LocalDOMWindow& window) { |
+ if (!m_audioWorklet && getExecutionContext()) { |
+ DCHECK(window.frame()); |
+ m_audioWorklet = AudioWorklet::create(window.frame()); |
+ } |
return m_audioWorklet.get(); |
} |
-void WindowAudioWorklet::frameDestroyed() { |
- m_audioWorklet.clear(); |
- DOMWindowProperty::frameDestroyed(); |
+// Break the following cycle when the context gets detached. |
+// Otherwise, the worklet object will leak. |
+// |
+// window => window.audioWorklet |
+// => WindowAudioWorklet |
+// => AudioWorklet <--- break this reference |
+// => ThreadedWorkletMessagingProxy |
+// => Document |
+// => ... => window |
+void WindowAudioWorklet::contextDestroyed() { |
+ m_audioWorklet = nullptr; |
} |
DEFINE_TRACE(WindowAudioWorklet) { |
visitor->trace(m_audioWorklet); |
Supplement<LocalDOMWindow>::trace(visitor); |
- DOMWindowProperty::trace(visitor); |
+ ContextLifecycleObserver::trace(visitor); |
} |
} // namespace blink |