Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.cpp

Issue 2668753006: Special-case LocalDOMWindow for same-origin access in bindings. (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/webaudio/WindowAudioWorklet.h" 5 #include "modules/webaudio/WindowAudioWorklet.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/LocalDOMWindow.h" 8 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "modules/webaudio/AudioWorklet.h"
11 10
12 namespace blink { 11 namespace blink {
13 12
14 WindowAudioWorklet::WindowAudioWorklet(LocalDOMWindow& window) 13 AudioWorklet* WindowAudioWorklet::audioWorklet(LocalDOMWindow& window) {
15 : ContextLifecycleObserver(window.frame()->document()) {}
16
17 const char* WindowAudioWorklet::supplementName() {
18 return "WindowAudioWorklet";
19 }
20
21 WindowAudioWorklet& WindowAudioWorklet::from(LocalDOMWindow& window) {
22 WindowAudioWorklet* supplement = static_cast<WindowAudioWorklet*>(
23 Supplement<LocalDOMWindow>::from(window, supplementName()));
24 if (!supplement) {
25 supplement = new WindowAudioWorklet(window);
26 provideTo(window, supplementName(), supplement);
27 }
28 return *supplement;
29 }
30
31 Worklet* WindowAudioWorklet::audioWorklet(DOMWindow& window) {
32 if (!window.frame()) 14 if (!window.frame())
33 return nullptr; 15 return nullptr;
34 return from(toLocalDOMWindow(window)).audioWorklet(toLocalDOMWindow(window)); 16 return from(window).m_audioWorklet.get();
35 }
36
37 AudioWorklet* WindowAudioWorklet::audioWorklet(LocalDOMWindow& window) {
38 if (!m_audioWorklet && getExecutionContext()) {
39 DCHECK(window.frame());
40 m_audioWorklet = AudioWorklet::create(window.frame());
41 }
42 return m_audioWorklet.get();
43 } 17 }
44 18
45 // Break the following cycle when the context gets detached. 19 // Break the following cycle when the context gets detached.
46 // Otherwise, the worklet object will leak. 20 // Otherwise, the worklet object will leak.
21 // TODO(dcheng): Why isn't this just all on the Oilpan heap?
47 // 22 //
48 // window => window.audioWorklet 23 // window => window.audioWorklet
49 // => WindowAudioWorklet 24 // => WindowAudioWorklet
50 // => AudioWorklet <--- break this reference 25 // => AudioWorklet <--- break this reference
51 // => ThreadedWorkletMessagingProxy 26 // => ThreadedWorkletMessagingProxy
52 // => Document 27 // => Document
53 // => ... => window 28 // => ... => window
54 void WindowAudioWorklet::contextDestroyed(ExecutionContext*) { 29 void WindowAudioWorklet::contextDestroyed(ExecutionContext*) {
55 m_audioWorklet = nullptr; 30 m_audioWorklet = nullptr;
56 } 31 }
57 32
58 DEFINE_TRACE(WindowAudioWorklet) { 33 DEFINE_TRACE(WindowAudioWorklet) {
59 visitor->trace(m_audioWorklet); 34 visitor->trace(m_audioWorklet);
60 Supplement<LocalDOMWindow>::trace(visitor); 35 Supplement<LocalDOMWindow>::trace(visitor);
61 ContextLifecycleObserver::trace(visitor); 36 ContextLifecycleObserver::trace(visitor);
62 } 37 }
63 38
39 WindowAudioWorklet& WindowAudioWorklet::from(LocalDOMWindow& window) {
40 WindowAudioWorklet* supplement = static_cast<WindowAudioWorklet*>(
41 Supplement<LocalDOMWindow>::from(window, supplementName()));
42 if (!supplement) {
43 supplement = new WindowAudioWorklet(window);
44 provideTo(window, supplementName(), supplement);
45 }
46 return *supplement;
47 }
48
49 WindowAudioWorklet::WindowAudioWorklet(LocalDOMWindow& window)
50 : ContextLifecycleObserver(window.frame()->document()),
51 m_audioWorklet(AudioWorklet::create(window.frame())) {}
52
53 const char* WindowAudioWorklet::supplementName() {
54 return "WindowAudioWorklet";
55 }
56
64 } // namespace blink 57 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698