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

Side by Side Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp

Issue 2038573002: [Android, RemotePlayback] Make RemotePlayback classes ActiveScriptWrappable's (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't observe execution context, just return the element's document. Created 4 years, 6 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/remoteplayback/RemotePlayback.h" 5 #include "modules/remoteplayback/RemotePlayback.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "core/dom/DOMException.h" 8 #include "core/dom/DOMException.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/events/Event.h" 10 #include "core/events/Event.h"
(...skipping 29 matching lines...) Expand all
40 { 40 {
41 ASSERT(element.document().frame()); 41 ASSERT(element.document().frame());
42 42
43 RemotePlayback* remotePlayback = new RemotePlayback(element); 43 RemotePlayback* remotePlayback = new RemotePlayback(element);
44 element.setRemotePlaybackClient(remotePlayback); 44 element.setRemotePlaybackClient(remotePlayback);
45 45
46 return remotePlayback; 46 return remotePlayback;
47 } 47 }
48 48
49 RemotePlayback::RemotePlayback(HTMLMediaElement& element) 49 RemotePlayback::RemotePlayback(HTMLMediaElement& element)
50 : DOMWindowProperty(element.document().frame()) 50 : ActiveScriptWrappable(this)
51 , m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected) 51 , m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected)
52 , m_availability(element.hasRemoteRoutes()) 52 , m_availability(element.hasRemoteRoutes())
53 , m_mediaElement(&element) 53 , m_mediaElement(&element)
54 { 54 {
55 } 55 }
56 56
57 const AtomicString& RemotePlayback::interfaceName() const 57 const AtomicString& RemotePlayback::interfaceName() const
58 { 58 {
59 return EventTargetNames::RemotePlayback; 59 return EventTargetNames::RemotePlayback;
60 } 60 }
61 61
62 ExecutionContext* RemotePlayback::getExecutionContext() const 62 ExecutionContext* RemotePlayback::getExecutionContext() const
63 { 63 {
64 if (!m_frame) 64 return &m_mediaElement->document();
65 return 0;
66 return m_frame->document();
67 } 65 }
68 66
69 ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState) 67 ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState)
70 { 68 {
71 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 69 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
72 ScriptPromise promise = resolver->promise(); 70 ScriptPromise promise = resolver->promise();
73 71
74 // TODO(avayvod): currently the availability is tracked for each media eleme nt 72 // TODO(avayvod): currently the availability is tracked for each media eleme nt
75 // as soon as it's created, we probably want to limit that to when the page/ element 73 // as soon as it's created, we probably want to limit that to when the page/ element
76 // is visible (see https://crbug.com/597281) and has default controls. If th ere's 74 // is visible (see https://crbug.com/597281) and has default controls. If th ere's
(...skipping 26 matching lines...) Expand all
103 } 101 }
104 102
105 return promise; 103 return promise;
106 } 104 }
107 105
108 String RemotePlayback::state() const 106 String RemotePlayback::state() const
109 { 107 {
110 return remotePlaybackStateToString(m_state); 108 return remotePlaybackStateToString(m_state);
111 } 109 }
112 110
111 bool RemotePlayback::hasPendingActivity() const
112 {
113 return hasEventListeners()
114 || !m_availabilityObjects.isEmpty()
115 || !m_connectPromiseResolvers.isEmpty();
116 }
117
113 void RemotePlayback::stateChanged(WebRemotePlaybackState state) 118 void RemotePlayback::stateChanged(WebRemotePlaybackState state)
114 { 119 {
115 // We may get a "disconnected" state change while in the "disconnected" 120 // We may get a "disconnected" state change while in the "disconnected"
116 // state if initiated connection fails. So cleanup the promise resolvers 121 // state if initiated connection fails. So cleanup the promise resolvers
117 // before checking if anything changed. 122 // before checking if anything changed.
118 // TODO(avayvod): cleanup this logic when we implementing the "connecting" 123 // TODO(avayvod): cleanup this logic when we implementing the "connecting"
119 // state. 124 // state.
120 if (state != WebRemotePlaybackState::Disconnected) { 125 if (state != WebRemotePlaybackState::Disconnected) {
121 for (auto& resolver : m_connectPromiseResolvers) 126 for (auto& resolver : m_connectPromiseResolvers)
122 resolver->resolve(true); 127 resolver->resolve(true);
(...skipping 23 matching lines...) Expand all
146 void RemotePlayback::connectCancelled() 151 void RemotePlayback::connectCancelled()
147 { 152 {
148 for (auto& resolver : m_connectPromiseResolvers) 153 for (auto& resolver : m_connectPromiseResolvers)
149 resolver->resolve(false); 154 resolver->resolve(false);
150 m_connectPromiseResolvers.clear(); 155 m_connectPromiseResolvers.clear();
151 } 156 }
152 157
153 DEFINE_TRACE(RemotePlayback) 158 DEFINE_TRACE(RemotePlayback)
154 { 159 {
155 visitor->trace(m_availabilityObjects); 160 visitor->trace(m_availabilityObjects);
161 visitor->trace(m_connectPromiseResolvers);
156 visitor->trace(m_mediaElement); 162 visitor->trace(m_mediaElement);
157 visitor->trace(m_connectPromiseResolvers);
158 EventTargetWithInlineData::trace(visitor); 163 EventTargetWithInlineData::trace(visitor);
159 DOMWindowProperty::trace(visitor);
160 } 164 }
161 165
162 } // namespace blink 166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698