Bug 1239899. Part 2 - per spec. await a stable state to pause the element when it is removed from the document. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Fri, 23 Sep 2016 16:16:43 +0800
changeset 316156 a55838bd4bbb5547eaa7ece8a5c0d4e4879579fa
parent 316155 27949d48ec6669996962cb05ae18363ab55eb55f
child 316157 3b0e8c0d02fbb42c01f0372a531d343c4bda0d3c
push id30765
push userphilringnalda@gmail.com
push dateTue, 04 Oct 2016 03:06:46 +0000
treeherdermozilla-central@adb484f84dec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1239899
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1239899. Part 2 - per spec. await a stable state to pause the element when it is removed from the document. r=cpearce MozReview-Commit-ID: BCCWgXmUchU
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3648,26 +3648,31 @@ HTMLMediaElement::ReportTelemetry()
   }
 }
 
 void HTMLMediaElement::UnbindFromTree(bool aDeep,
                                       bool aNullParent)
 {
   mUnboundFromTree = true;
 
-  if (!mPaused && mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
-    Pause();
-  }
-
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 
   if (mDecoder) {
     MOZ_ASSERT(IsHidden());
     mDecoder->NotifyOwnerActivityChanged(false);
   }
+
+  RefPtr<HTMLMediaElement> self(this);
+  nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([self] () {
+    if (self->mUnboundFromTree &&
+        self->mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
+      self->Pause();
+    }
+  });
+  RunInStableState(task);
 }
 
 /* static */
 CanPlayStatus
 HTMLMediaElement::GetCanPlay(const nsAString& aType,
                              DecoderDoctorDiagnostics* aDiagnostics)
 {
   nsContentTypeParser parser(aType);