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

Unified Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp

Issue 2480003002: [RemotePlayback] Keep track of source compatibility and reject prompt() correspondingly (Closed)
Patch Set: Fixed failing tests Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 86c69e2d965117b42174b68a91101bc8e12f2349..0ddd46f8b2904f4c58e29ea791b969d5dc2489dc 100644
--- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
+++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
@@ -45,10 +45,7 @@ RemotePlayback* RemotePlayback::create(ScriptState* scriptState,
DCHECK(element.document().frame());
DCHECK(scriptState);
- RemotePlayback* remotePlayback = new RemotePlayback(scriptState, element);
- element.setRemotePlaybackClient(remotePlayback);
-
- return remotePlayback;
+ return new RemotePlayback(scriptState, element);
}
RemotePlayback::RemotePlayback(ScriptState* scriptState,
@@ -58,7 +55,8 @@ RemotePlayback::RemotePlayback(ScriptState* scriptState,
m_state(element.isPlayingRemotely()
? WebRemotePlaybackState::Connected
: WebRemotePlaybackState::Disconnected),
- m_availability(element.hasRemoteRoutes()),
+ m_routeAvailable(false),
+ m_sourceCompatible(false),
m_mediaElement(&element) {}
const AtomicString& RemotePlayback::interfaceName() const {
@@ -175,6 +173,21 @@ ScriptPromise RemotePlayback::prompt() {
return promise;
}
+ // TODO(avayvod): don't do this check on low-end devices - merge with
+ // https://codereview.chromium.org/2475293003
+ if (!m_routeAvailable) {
+ resolver->reject(DOMException::create(NotFoundError,
+ "No remote playback devices found."));
+ return promise;
+ }
+
+ if (!m_sourceCompatible) {
+ 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();
@@ -201,7 +214,7 @@ void RemotePlayback::notifyInitialAvailability(int callbackId) {
if (iter == m_availabilityCallbacks.end())
return;
- iter->value->call(this, m_availability);
+ iter->value->call(this, m_routeAvailable && m_sourceCompatible);
}
void RemotePlayback::stateChanged(WebRemotePlaybackState state) {
@@ -241,13 +254,23 @@ void RemotePlayback::stateChanged(WebRemotePlaybackState state) {
}
}
-void RemotePlayback::availabilityChanged(bool available) {
- if (m_availability == available)
+void RemotePlayback::availabilityChanged(bool isRouteAvailable,
+ bool isSourceCompatible) {
+ if (m_routeAvailable == isRouteAvailable &&
+ m_sourceCompatible == isSourceCompatible) {
+ return;
+ }
+
+ bool oldAvailability = m_routeAvailable && m_sourceCompatible;
+ m_routeAvailable = isRouteAvailable;
+ m_sourceCompatible = isSourceCompatible;
+
+ bool newAvailability = isRouteAvailable && isSourceCompatible;
+ 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() {
@@ -259,6 +282,10 @@ void RemotePlayback::promptCancelled() {
m_promptPromiseResolver = nullptr;
}
+bool RemotePlayback::remotePlaybackAvailable() const {
+ return m_routeAvailable && m_sourceCompatible;
+}
+
void RemotePlayback::remotePlaybackDisabled() {
if (m_promptPromiseResolver) {
m_promptPromiseResolver->reject(DOMException::create(

Powered by Google App Engine
This is Rietveld 408576698