| OLD | NEW |
| 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 "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" | 8 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" |
| 9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 } // anonymous namespace | 41 } // anonymous namespace |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 RemotePlayback* RemotePlayback::create(HTMLMediaElement& element) { | 44 RemotePlayback* RemotePlayback::create(HTMLMediaElement& element) { |
| 45 return new RemotePlayback(element); | 45 return new RemotePlayback(element); |
| 46 } | 46 } |
| 47 | 47 |
| 48 RemotePlayback::RemotePlayback(HTMLMediaElement& element) | 48 RemotePlayback::RemotePlayback(HTMLMediaElement& element) |
| 49 : ActiveScriptWrappable(this), | 49 : ActiveScriptWrappable(this), |
| 50 ContextLifecycleObserver(&element.document()), | |
| 51 m_state(element.isPlayingRemotely() | 50 m_state(element.isPlayingRemotely() |
| 52 ? WebRemotePlaybackState::Connected | 51 ? WebRemotePlaybackState::Connected |
| 53 : WebRemotePlaybackState::Disconnected), | 52 : WebRemotePlaybackState::Disconnected), |
| 54 m_availability(WebRemotePlaybackAvailability::Unknown), | 53 m_availability(WebRemotePlaybackAvailability::Unknown), |
| 55 m_mediaElement(&element) {} | 54 m_mediaElement(&element) {} |
| 56 | 55 |
| 57 const AtomicString& RemotePlayback::interfaceName() const { | 56 const AtomicString& RemotePlayback::interfaceName() const { |
| 58 return EventTargetNames::RemotePlayback; | 57 return EventTargetNames::RemotePlayback; |
| 59 } | 58 } |
| 60 | 59 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 194 } |
| 196 | 195 |
| 197 return promise; | 196 return promise; |
| 198 } | 197 } |
| 199 | 198 |
| 200 String RemotePlayback::state() const { | 199 String RemotePlayback::state() const { |
| 201 return remotePlaybackStateToString(m_state); | 200 return remotePlaybackStateToString(m_state); |
| 202 } | 201 } |
| 203 | 202 |
| 204 bool RemotePlayback::hasPendingActivity() const { | 203 bool RemotePlayback::hasPendingActivity() const { |
| 204 // TODO(haraken): This check should be moved to ActiveScriptWrappable. |
| 205 if (getExecutionContext()->isContextDestroyed()) |
| 206 return false; |
| 205 return hasEventListeners() || !m_availabilityCallbacks.isEmpty() || | 207 return hasEventListeners() || !m_availabilityCallbacks.isEmpty() || |
| 206 m_promptPromiseResolver; | 208 m_promptPromiseResolver; |
| 207 } | 209 } |
| 208 | 210 |
| 209 void RemotePlayback::contextDestroyed() { | |
| 210 m_availabilityCallbacks.clear(); | |
| 211 m_promptPromiseResolver = nullptr; | |
| 212 } | |
| 213 | |
| 214 void RemotePlayback::notifyInitialAvailability(int callbackId) { | 211 void RemotePlayback::notifyInitialAvailability(int callbackId) { |
| 215 // May not find the callback if the website cancels it fast enough. | 212 // May not find the callback if the website cancels it fast enough. |
| 216 auto iter = m_availabilityCallbacks.find(callbackId); | 213 auto iter = m_availabilityCallbacks.find(callbackId); |
| 217 if (iter == m_availabilityCallbacks.end()) | 214 if (iter == m_availabilityCallbacks.end()) |
| 218 return; | 215 return; |
| 219 | 216 |
| 220 iter->value->call(this, remotePlaybackAvailable()); | 217 iter->value->call(this, remotePlaybackAvailable()); |
| 221 } | 218 } |
| 222 | 219 |
| 223 void RemotePlayback::stateChanged(WebRemotePlaybackState state) { | 220 void RemotePlayback::stateChanged(WebRemotePlaybackState state) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 const v8::Persistent<v8::Object>& wrapper) { | 300 const v8::Persistent<v8::Object>& wrapper) { |
| 304 for (auto callback : m_availabilityCallbacks.values()) | 301 for (auto callback : m_availabilityCallbacks.values()) |
| 305 callback->setWrapperReference(isolate, wrapper); | 302 callback->setWrapperReference(isolate, wrapper); |
| 306 } | 303 } |
| 307 | 304 |
| 308 DEFINE_TRACE(RemotePlayback) { | 305 DEFINE_TRACE(RemotePlayback) { |
| 309 visitor->trace(m_availabilityCallbacks); | 306 visitor->trace(m_availabilityCallbacks); |
| 310 visitor->trace(m_promptPromiseResolver); | 307 visitor->trace(m_promptPromiseResolver); |
| 311 visitor->trace(m_mediaElement); | 308 visitor->trace(m_mediaElement); |
| 312 EventTargetWithInlineData::trace(visitor); | 309 EventTargetWithInlineData::trace(visitor); |
| 313 ContextLifecycleObserver::trace(visitor); | |
| 314 } | 310 } |
| 315 | 311 |
| 316 DEFINE_TRACE_WRAPPERS(RemotePlayback) { | 312 DEFINE_TRACE_WRAPPERS(RemotePlayback) { |
| 317 for (auto callback : m_availabilityCallbacks.values()) { | 313 for (auto callback : m_availabilityCallbacks.values()) { |
| 318 visitor->traceWrappers(callback); | 314 visitor->traceWrappers(callback); |
| 319 } | 315 } |
| 320 EventTargetWithInlineData::traceWrappers(visitor); | 316 EventTargetWithInlineData::traceWrappers(visitor); |
| 321 } | 317 } |
| 322 | 318 |
| 323 } // namespace blink | 319 } // namespace blink |
| OLD | NEW |