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

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: Rebase and address comments. 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
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
47 // 21 //
48 // window => window.audioWorklet 22 // window => window.audioWorklet
49 // => WindowAudioWorklet 23 // => WindowAudioWorklet
50 // => AudioWorklet <--- break this reference 24 // => AudioWorklet <--- break this reference
51 // => ThreadedWorkletMessagingProxy 25 // => ThreadedWorkletMessagingProxy
52 // => Document 26 // => Document
53 // => ... => window 27 // => ... => window
54 void WindowAudioWorklet::contextDestroyed(ExecutionContext*) { 28 void WindowAudioWorklet::contextDestroyed(ExecutionContext*) {
55 m_audioWorklet = nullptr; 29 m_audioWorklet = nullptr;
56 } 30 }
57 31
58 DEFINE_TRACE(WindowAudioWorklet) { 32 DEFINE_TRACE(WindowAudioWorklet) {
59 visitor->trace(m_audioWorklet); 33 visitor->trace(m_audioWorklet);
60 Supplement<LocalDOMWindow>::trace(visitor); 34 Supplement<LocalDOMWindow>::trace(visitor);
61 ContextLifecycleObserver::trace(visitor); 35 ContextLifecycleObserver::trace(visitor);
62 } 36 }
63 37
38 WindowAudioWorklet& WindowAudioWorklet::from(LocalDOMWindow& window) {
39 WindowAudioWorklet* supplement = static_cast<WindowAudioWorklet*>(
40 Supplement<LocalDOMWindow>::from(window, supplementName()));
41 if (!supplement) {
42 supplement = new WindowAudioWorklet(window);
43 provideTo(window, supplementName(), supplement);
44 }
45 return *supplement;
46 }
47
48 WindowAudioWorklet::WindowAudioWorklet(LocalDOMWindow& window)
49 : ContextLifecycleObserver(window.frame()->document()),
50 m_audioWorklet(AudioWorklet::create(window.frame())) {
51 DCHECK(getExecutionContext());
52 }
53
54 const char* WindowAudioWorklet::supplementName() {
55 return "WindowAudioWorklet";
56 }
57
64 } // namespace blink 58 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/WindowAudioWorklet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698