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

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: Changed RemotePlayback to be ContextLifecycleObserver 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 , ContextLifecycleObserver(&element.document())
51 , m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected) 52 , m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected)
52 , m_availability(element.hasRemoteRoutes()) 53 , m_availability(element.hasRemoteRoutes())
53 , m_mediaElement(&element) 54 , m_mediaElement(&element)
54 { 55 {
55 } 56 }
56 57
57 const AtomicString& RemotePlayback::interfaceName() const 58 const AtomicString& RemotePlayback::interfaceName() const
58 { 59 {
59 return EventTargetNames::RemotePlayback; 60 return EventTargetNames::RemotePlayback;
60 } 61 }
61 62
62 ExecutionContext* RemotePlayback::getExecutionContext() const 63 ExecutionContext* RemotePlayback::getExecutionContext() const
63 { 64 {
64 if (!m_frame) 65 return ContextLifecycleObserver::getExecutionContext();
65 return 0;
66 return m_frame->document();
67 } 66 }
68 67
69 ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState) 68 ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState)
70 { 69 {
71 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
72 ScriptPromise promise = resolver->promise(); 71 ScriptPromise promise = resolver->promise();
73 72
74 // TODO(avayvod): currently the availability is tracked for each media eleme nt 73 // 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 74 // 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 75 // is visible (see https://crbug.com/597281) and has default controls. If th ere's
(...skipping 26 matching lines...) Expand all
103 } 102 }
104 103
105 return promise; 104 return promise;
106 } 105 }
107 106
108 String RemotePlayback::state() const 107 String RemotePlayback::state() const
109 { 108 {
110 return remotePlaybackStateToString(m_state); 109 return remotePlaybackStateToString(m_state);
111 } 110 }
112 111
112 bool RemotePlayback::hasPendingActivity() const
113 {
114 return hasEventListeners()
115 || !m_availabilityObjects.isEmpty()
116 || !m_connectPromiseResolvers.isEmpty();
117 }
118
113 void RemotePlayback::stateChanged(WebRemotePlaybackState state) 119 void RemotePlayback::stateChanged(WebRemotePlaybackState state)
114 { 120 {
115 // We may get a "disconnected" state change while in the "disconnected" 121 // We may get a "disconnected" state change while in the "disconnected"
116 // state if initiated connection fails. So cleanup the promise resolvers 122 // state if initiated connection fails. So cleanup the promise resolvers
117 // before checking if anything changed. 123 // before checking if anything changed.
118 // TODO(avayvod): cleanup this logic when we implementing the "connecting" 124 // TODO(avayvod): cleanup this logic when we implementing the "connecting"
119 // state. 125 // state.
120 if (state != WebRemotePlaybackState::Disconnected) { 126 if (state != WebRemotePlaybackState::Disconnected) {
121 for (auto& resolver : m_connectPromiseResolvers) 127 for (auto& resolver : m_connectPromiseResolvers)
122 resolver->resolve(true); 128 resolver->resolve(true);
(...skipping 13 matching lines...) Expand all
136 void RemotePlayback::availabilityChanged(bool available) 142 void RemotePlayback::availabilityChanged(bool available)
137 { 143 {
138 if (m_availability == available) 144 if (m_availability == available)
139 return; 145 return;
140 146
141 m_availability = available; 147 m_availability = available;
142 for (auto& availabilityObject : m_availabilityObjects) 148 for (auto& availabilityObject : m_availabilityObjects)
143 availabilityObject->availabilityChanged(available); 149 availabilityObject->availabilityChanged(available);
144 } 150 }
145 151
146 void RemotePlayback::connectCancelled() 152 void RemotePlayback::connectCancelled()
haraken 2016/06/03 14:14:36 Not directly related to this CL, I think you need
whywhat 2016/06/03 14:33:45 You mean LifecycleObserver::contextDestroyed() ? D
147 { 153 {
148 for (auto& resolver : m_connectPromiseResolvers) 154 for (auto& resolver : m_connectPromiseResolvers)
149 resolver->resolve(false); 155 resolver->resolve(false);
150 m_connectPromiseResolvers.clear(); 156 m_connectPromiseResolvers.clear();
151 } 157 }
152 158
153 DEFINE_TRACE(RemotePlayback) 159 DEFINE_TRACE(RemotePlayback)
154 { 160 {
155 visitor->trace(m_availabilityObjects); 161 visitor->trace(m_availabilityObjects);
162 visitor->trace(m_connectPromiseResolvers);
156 visitor->trace(m_mediaElement); 163 visitor->trace(m_mediaElement);
157 visitor->trace(m_connectPromiseResolvers);
158 EventTargetWithInlineData::trace(visitor); 164 EventTargetWithInlineData::trace(visitor);
159 DOMWindowProperty::trace(visitor); 165 ContextLifecycleObserver::trace(visitor);
160 } 166 }
161 167
162 } // namespace blink 168 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698