Bug 1244768 part 2 - modify media element load algorith; r=jwwang
authorKaku Kuo <tkuo@mozilla.com>
Thu, 18 Aug 2016 20:03:48 +0800
changeset 325496 2a13aa8e9a76aeb83c8a342487b856d0b7857ed0
parent 325495 1b47c134e5e230c267826ae58feeb9774e0fe8ac
child 325497 b8c156c5cff840f28e995caa5c0f5bce9a121fcc
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjwwang
bugs1244768
milestone53.0a1
Bug 1244768 part 2 - modify media element load algorith; r=jwwang 4.8.12.5 https://html.spec.whatwg.org/multipage/embedded-content.html#media-element-load-algorithim The living WHATWG spec has been changed since I implemented this patch. Will update to the latest spec later. MozReview-Commit-ID: 7U1AC2Ua83Z
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1576,16 +1576,24 @@ void HTMLMediaElement::AbortExistingLoad
   }
   // Abort any already-running instance of the resource selection algorithm.
   mLoadWaitStatus = NOT_WAITING;
 
   // Set a new load ID. This will cause events which were enqueued
   // with a different load ID to silently be cancelled.
   mCurrentLoadID++;
 
+  // Immediately reject or resolve the already-dispatched
+  // nsResolveOrRejectPendingPlayPromisesRunners. These runners won't be
+  // executed again later since the mCurrentLoadID had been changed.
+  for (auto& runner : mPendingPlayPromisesRunners) {
+    runner->ResolveOrReject();
+  }
+  mPendingPlayPromisesRunners.Clear();
+
   if (mChannelLoader) {
     mChannelLoader->Cancel();
     mChannelLoader = nullptr;
   }
 
   bool fireTimeUpdate = false;
 
   // We need to remove StreamSizeListener before VideoTracks get emptied.
@@ -1637,17 +1645,20 @@ void HTMLMediaElement::AbortExistingLoad
   mSourcePointer = nullptr;
 
   mTags = nullptr;
 
   if (mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
     NS_ASSERTION(!mDecoder && !mSrcStream, "How did someone setup a new stream/decoder already?");
     // ChangeNetworkState() will call UpdateAudioChannelPlayingState()
     // indirectly which depends on mPaused. So we need to update mPaused first.
-    mPaused = true;
+    if (!mPaused) {
+      mPaused = true;
+      RejectPromises(TakePendingPlayPromises(), NS_ERROR_DOM_MEDIA_ABORT_ERR);
+    }
     ChangeNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY);
     ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING);
 
     //TODO: Apply the rules for text track cue rendering Bug 865407
     if (mTextTrackManager) {
       mTextTrackManager->GetTextTracks()->SetCuesInactive();
     }