Chromium Code Reviews| Index: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp |
| diff --git a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp |
| index b7f027dc9633f11a389f76155b2e94d484b07471..e0f426e762f7c155e7618bec3282c90e90ec0b8b 100644 |
| --- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp |
| +++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp |
| @@ -10,6 +10,7 @@ |
| #include "core/html/HTMLMediaElement.h" |
| #include "modules/EventTargetModules.h" |
| #include "modules/remoteplayback/RemotePlaybackAvailability.h" |
| +#include "platform/UserGestureIndicator.h" |
| namespace blink { |
| @@ -38,19 +39,17 @@ RemotePlayback* RemotePlayback::create(HTMLMediaElement& element) |
| { |
| ASSERT(element.document().frame()); |
| - RemotePlayback* remotePlayback = new RemotePlayback( |
| - element.document().frame(), |
| - element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected, |
| - element.hasRemoteRoutes()); |
| + RemotePlayback* remotePlayback = new RemotePlayback(element); |
| element.setRemotePlaybackClient(remotePlayback); |
| return remotePlayback; |
| } |
| -RemotePlayback::RemotePlayback(LocalFrame* frame, WebRemotePlaybackState state, bool availability) |
| - : DOMWindowProperty(frame) |
| - , m_state(state) |
| - , m_availability(availability) |
| +RemotePlayback::RemotePlayback(HTMLMediaElement& element) |
| + : DOMWindowProperty(element.document().frame()) |
| + , m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected) |
| + , m_availability(element.hasRemoteRoutes()) |
| + , m_mediaElement(&element) |
| { |
| } |
| @@ -82,6 +81,31 @@ ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState) |
| return promise; |
| } |
| +ScriptPromise RemotePlayback::connect(ScriptState* scriptState) |
| +{ |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + // TODO(avayvod): should we have a flag or reuse the one for the PresentationRequest::start(). |
|
mlamouri (slow - plz ping)
2016/03/24 10:47:06
nit: "a flag to disable user gesture requirement".
whywhat
2016/03/24 16:08:40
Done.
|
| + if (!UserGestureIndicator::processingUserGesture()) { |
| + resolver->reject(DOMException::create(InvalidAccessError, "RemotePlayback::connect() requires user gesture.")); |
| + return promise; |
| + } |
| + |
| + if (!m_mediaElement) { |
| + resolver->reject(DOMException::create(InvalidStateError, "The RemotePlayback is no longer associated with a media element.")); |
| + return promise; |
| + } |
| + |
| + m_connectPromiseResolvers.append(resolver); |
|
mlamouri (slow - plz ping)
2016/03/24 10:47:06
Should you add a TODO that we are only resolving t
whywhat
2016/03/24 16:08:40
We're actually getting a disconnected state change
|
| + if (m_state == WebRemotePlaybackState::Disconnected) |
| + m_mediaElement->requestRemotePlayback(); |
| + else |
| + m_mediaElement->requestRemotePlaybackControl(); |
| + |
| + return promise; |
| +} |
| + |
| String RemotePlayback::state() const |
| { |
| return remotePlaybackStateToString(m_state); |
| @@ -92,6 +116,12 @@ void RemotePlayback::stateChanged(WebRemotePlaybackState state) |
| if (m_state == state) |
| return; |
| + if (state != WebRemotePlaybackState::Disconnected) { |
| + for (auto& resolver : m_connectPromiseResolvers) |
| + resolver->resolve(true); |
| + m_connectPromiseResolvers.clear(); |
| + } |
| + |
| m_state = state; |
| dispatchEvent(Event::create(EventTypeNames::statechange)); |
| } |
| @@ -109,6 +139,8 @@ void RemotePlayback::availabilityChanged(bool available) |
| DEFINE_TRACE(RemotePlayback) |
| { |
| visitor->trace(m_availabilityObjects); |
| + visitor->trace(m_mediaElement); |
| + visitor->trace(m_connectPromiseResolvers); |
| RefCountedGarbageCollectedEventTargetWithInlineData<RemotePlayback>::trace(visitor); |
| DOMWindowProperty::trace(visitor); |
| } |