| 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 55de180d26dac7e71aa32dc4a1eefae4f55066b9..26e3ada761a5880d9fa917960c7aa581dc4ab15d 100644
|
| --- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
|
| +++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
|
| @@ -49,7 +49,7 @@ RemotePlayback::RemotePlayback(HTMLMediaElement& element)
|
| m_state(element.isPlayingRemotely()
|
| ? WebRemotePlaybackState::Connected
|
| : WebRemotePlaybackState::Disconnected),
|
| - m_availability(element.hasRemoteRoutes()),
|
| + m_availability(WebRemotePlaybackAvailability::Unknown),
|
| m_mediaElement(&element) {}
|
|
|
| const AtomicString& RemotePlayback::interfaceName() const {
|
| @@ -141,8 +141,6 @@ ScriptPromise RemotePlayback::cancelWatchAvailability(
|
| }
|
|
|
| ScriptPromise RemotePlayback::prompt(ScriptState* scriptState) {
|
| - // TODO(avayvod): implement steps 5, 8, 9 of the algorithm.
|
| - // https://crbug.com/647441
|
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| ScriptPromise promise = resolver->promise();
|
|
|
| @@ -165,6 +163,22 @@ ScriptPromise RemotePlayback::prompt(ScriptState* scriptState) {
|
| return promise;
|
| }
|
|
|
| + // TODO(avayvod): don't do this check on low-end devices - merge with
|
| + // https://codereview.chromium.org/2475293003
|
| + if (m_availability == WebRemotePlaybackAvailability::DeviceNotAvailable) {
|
| + resolver->reject(DOMException::create(NotFoundError,
|
| + "No remote playback devices found."));
|
| + return promise;
|
| + }
|
| +
|
| + if (m_availability == WebRemotePlaybackAvailability::SourceNotSupported ||
|
| + m_availability == WebRemotePlaybackAvailability::SourceNotCompatible) {
|
| + resolver->reject(DOMException::create(
|
| + NotSupportedError,
|
| + "The currentSrc is not compatible with remote playback"));
|
| + return promise;
|
| + }
|
| +
|
| if (m_state == WebRemotePlaybackState::Disconnected) {
|
| m_promptPromiseResolver = resolver;
|
| m_mediaElement->requestRemotePlayback();
|
| @@ -191,7 +205,7 @@ void RemotePlayback::notifyInitialAvailability(int callbackId) {
|
| if (iter == m_availabilityCallbacks.end())
|
| return;
|
|
|
| - iter->value->call(this, m_availability);
|
| + iter->value->call(this, remotePlaybackAvailable());
|
| }
|
|
|
| void RemotePlayback::stateChanged(WebRemotePlaybackState state) {
|
| @@ -231,13 +245,19 @@ void RemotePlayback::stateChanged(WebRemotePlaybackState state) {
|
| }
|
| }
|
|
|
| -void RemotePlayback::availabilityChanged(bool available) {
|
| - if (m_availability == available)
|
| +void RemotePlayback::availabilityChanged(
|
| + WebRemotePlaybackAvailability availability) {
|
| + if (m_availability == availability)
|
| + return;
|
| +
|
| + bool oldAvailability = remotePlaybackAvailable();
|
| + m_availability = availability;
|
| + bool newAvailability = remotePlaybackAvailable();
|
| + if (newAvailability == oldAvailability)
|
| return;
|
|
|
| - m_availability = available;
|
| for (auto& callback : m_availabilityCallbacks.values())
|
| - callback->call(this, m_availability);
|
| + callback->call(this, newAvailability);
|
| }
|
|
|
| void RemotePlayback::promptCancelled() {
|
| @@ -249,6 +269,10 @@ void RemotePlayback::promptCancelled() {
|
| m_promptPromiseResolver = nullptr;
|
| }
|
|
|
| +bool RemotePlayback::remotePlaybackAvailable() const {
|
| + return m_availability == WebRemotePlaybackAvailability::DeviceAvailable;
|
| +}
|
| +
|
| void RemotePlayback::remotePlaybackDisabled() {
|
| if (m_promptPromiseResolver) {
|
| m_promptPromiseResolver->reject(DOMException::create(
|
|
|