Bug 1471485 - Ensure autoplay permission promises disconnected if media starts playing. r?jya draft
authorChris Pearce <cpearce@mozilla.com>
Thu, 12 Jul 2018 16:19:25 +1200
changeset 817320 5cfd44ff3abca6c1af9090072e49b49d9170dec3
parent 817319 1cd231e00abe900351eb52be88ce87c592188625
push id116013
push userbmo:cpearce@mozilla.com
push dateThu, 12 Jul 2018 10:39:56 +0000
reviewersjya
bugs1471485
milestone63.0a1
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
dom/html/HTMLMediaElement.cpp
--- 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());