Bug 1471485 - Ensure autoplay permission promises disconnected if media starts playing. r?jya
We can start playing while we're awaiting a response to an autoplay-media
permission prompt, for example if the user clicks on a play button. In such
cases, it doesn't make sense to keep the autoplay permission request promise
connected in HTMLMediaElement, as since we're playing we'll be resolving the
play() promises and thus we won't be taking action on the autoplay request
promise's result. So we should just disconnect the autoplay permission request
promise if it's connected when we start playing.
MozReview-Commit-ID: 1aiCLXV7Ja9
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -7861,16 +7861,22 @@ HTMLMediaElement::CreateDOMPromise(Error
}
return Promise::Create(win->AsGlobal(), aRv);
}
void
HTMLMediaElement::AsyncResolvePendingPlayPromises()
{
+ // Disconnect requests for permission to play. We're playing either way,
+ // so there's no point keeping the promise connected. Note: the front
+ // end permission prompt code will detect that we've started playing, and
+ // hide the permission prompt.
+ mAutoplayPermissionRequest.DisconnectIfExists();
+
if (mShuttingDown) {
return;
}
nsCOMPtr<nsIRunnable> event = new nsResolveOrRejectPendingPlayPromisesRunner(
this, TakePendingPlayPromises());
mMainThreadEventTarget->Dispatch(event.forget());