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

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: . 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());
dcheng 2017/02/01 07:22:59 This helper got moved into the constructor: there'
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.
23 // TODO(dcheng): Why isn't this just all on the Oilpan heap?
dcheng 2017/02/01 07:22:59 Something that might be good to fix... not really
haraken 2017/02/01 08:32:01 I'm not sure how easy it will be to move ThreadedW
dcheng 2017/02/01 18:30:28 OK, removed the TODO. It feels like it's harder th
51 // 24 //
52 // window => window.animationWorklet 25 // window => window.animationWorklet
53 // => WindowAnimationWorklet 26 // => WindowAnimationWorklet
54 // => AnimationWorklet <--- break this reference 27 // => AnimationWorklet <--- break this reference
55 // => ThreadedWorkletMessagingProxy 28 // => ThreadedWorkletMessagingProxy
56 // => Document 29 // => Document
57 // => ... => window 30 // => ... => window
58 void WindowAnimationWorklet::contextDestroyed(ExecutionContext*) { 31 void WindowAnimationWorklet::contextDestroyed(ExecutionContext*) {
59 m_animationWorklet = nullptr; 32 m_animationWorklet = nullptr;
60 } 33 }
61 34
62 DEFINE_TRACE(WindowAnimationWorklet) { 35 DEFINE_TRACE(WindowAnimationWorklet) {
63 visitor->trace(m_animationWorklet); 36 visitor->trace(m_animationWorklet);
64 Supplement<LocalDOMWindow>::trace(visitor); 37 Supplement<LocalDOMWindow>::trace(visitor);
65 ContextLifecycleObserver::trace(visitor); 38 ContextLifecycleObserver::trace(visitor);
66 } 39 }
67 40
41 // static
42 WindowAnimationWorklet& WindowAnimationWorklet::from(LocalDOMWindow& window) {
43 WindowAnimationWorklet* supplement = static_cast<WindowAnimationWorklet*>(
44 Supplement<LocalDOMWindow>::from(window, supplementName()));
45 if (!supplement) {
46 supplement = new WindowAnimationWorklet(window);
47 provideTo(window, supplementName(), supplement);
48 }
49 return *supplement;
50 }
51
52 WindowAnimationWorklet::WindowAnimationWorklet(LocalDOMWindow& window)
53 : ContextLifecycleObserver(window.frame()->document()),
54 m_animationWorklet(AnimationWorklet::create(window.frame())) {}
55
56 const char* WindowAnimationWorklet::supplementName() {
57 return "WindowAnimationWorklet";
58 }
59
68 } // namespace blink 60 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698