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

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/WindowAnimationWorklet.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
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/compositorworker/WindowAnimationWorklet.h" 5 #include "modules/compositorworker/WindowAnimationWorklet.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/compositorworker/AnimationWorklet.h"
11 10
12 namespace blink { 11 namespace blink {
13 12
14 WindowAnimationWorklet::WindowAnimationWorklet(LocalDOMWindow& window)
15 : ContextLifecycleObserver(window.frame()->document()) {}
16
17 const char* WindowAnimationWorklet::supplementName() {
18 return "WindowAnimationWorklet";
19 }
20
21 // static 13 // static
22 WindowAnimationWorklet& WindowAnimationWorklet::from(LocalDOMWindow& window) { 14 AnimationWorklet* WindowAnimationWorklet::animationWorklet(
23 WindowAnimationWorklet* supplement = static_cast<WindowAnimationWorklet*>( 15 LocalDOMWindow& window) {
24 Supplement<LocalDOMWindow>::from(window, supplementName()));
25 if (!supplement) {
26 supplement = new WindowAnimationWorklet(window);
27 provideTo(window, supplementName(), supplement);
28 }
29 return *supplement;
30 }
31
32 // static
33 Worklet* WindowAnimationWorklet::animationWorklet(DOMWindow& window) {
34 if (!window.frame()) 16 if (!window.frame())
35 return nullptr; 17 return nullptr;
36 return from(toLocalDOMWindow(window)) 18 return from(window).m_animationWorklet.get();
37 .animationWorklet(toLocalDOMWindow(window));
38 }
39
40 AnimationWorklet* WindowAnimationWorklet::animationWorklet(
41 LocalDOMWindow& window) {
42 if (!m_animationWorklet && getExecutionContext()) {
43 DCHECK(window.frame());
44 m_animationWorklet = AnimationWorklet::create(window.frame());
45 }
46 return m_animationWorklet.get();
47 } 19 }
48 20
49 // Break the following cycle when the context gets detached. 21 // Break the following cycle when the context gets detached.
50 // Otherwise, the worklet object will leak. 22 // Otherwise, the worklet object will leak.
51 // 23 //
52 // window => window.animationWorklet 24 // window => window.animationWorklet
53 // => WindowAnimationWorklet 25 // => WindowAnimationWorklet
54 // => AnimationWorklet <--- break this reference 26 // => AnimationWorklet <--- break this reference
55 // => ThreadedWorkletMessagingProxy 27 // => ThreadedWorkletMessagingProxy
56 // => Document 28 // => Document
57 // => ... => window 29 // => ... => window
58 void WindowAnimationWorklet::contextDestroyed(ExecutionContext*) { 30 void WindowAnimationWorklet::contextDestroyed(ExecutionContext*) {
59 m_animationWorklet = nullptr; 31 m_animationWorklet = nullptr;
60 } 32 }
61 33
62 DEFINE_TRACE(WindowAnimationWorklet) { 34 DEFINE_TRACE(WindowAnimationWorklet) {
63 visitor->trace(m_animationWorklet); 35 visitor->trace(m_animationWorklet);
64 Supplement<LocalDOMWindow>::trace(visitor); 36 Supplement<LocalDOMWindow>::trace(visitor);
65 ContextLifecycleObserver::trace(visitor); 37 ContextLifecycleObserver::trace(visitor);
66 } 38 }
67 39
40 // static
41 WindowAnimationWorklet& WindowAnimationWorklet::from(LocalDOMWindow& window) {
42 WindowAnimationWorklet* supplement = static_cast<WindowAnimationWorklet*>(
43 Supplement<LocalDOMWindow>::from(window, supplementName()));
44 if (!supplement) {
45 supplement = new WindowAnimationWorklet(window);
46 provideTo(window, supplementName(), supplement);
47 }
48 return *supplement;
49 }
50
51 WindowAnimationWorklet::WindowAnimationWorklet(LocalDOMWindow& window)
52 : ContextLifecycleObserver(window.frame()->document()),
53 m_animationWorklet(AnimationWorklet::create(window.frame())) {
54 DCHECK(getExecutionContext());
55 }
56
57 const char* WindowAnimationWorklet::supplementName() {
58 return "WindowAnimationWorklet";
59 }
60
68 } // namespace blink 61 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698