Bug 1311904 - move |mOwner->FirstFrameLoaded()| to the bottom of FirstFrameLoaded() to prevent shutdown from happening in the middle of FirstFrameLoaded(). draft
authorJW Wang <jwwang@mozilla.com>
Fri, 21 Oct 2016 14:27:27 +0800
changeset 428555 923b5a6d5146c6be187ee5a160fdafcb9ce11ace
parent 428554 71cf0cec3c84d3a88cc6806c9aef46b17443e472
child 534763 9bbea64a161c68b86dc3f3b131fbf89febfdf41e
push id33342
push userjwwang@mozilla.com
push dateMon, 24 Oct 2016 08:21:57 +0000
bugs1311904
milestone52.0a1
Bug 1311904 - move |mOwner->FirstFrameLoaded()| to the bottom of FirstFrameLoaded() to prevent shutdown from happening in the middle of FirstFrameLoaded(). MozReview-Commit-ID: FnRsGMhxeZV
dom/media/MediaDecoder.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -992,34 +992,37 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr
 
   DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d",
               aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
               aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant);
 
   mInfo = aInfo.forget();
 
   Invalidate();
-  if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
-    mOwner->FirstFrameLoaded();
-  }
 
   // This can run cache callbacks.
   mResource->EnsureCacheUpToDate();
 
   // The element can run javascript via events
   // before reaching here, so only change the
   // state if we're still set to the original
   // loading state.
   if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) {
     ChangeState(mNextState);
   }
 
   // Run NotifySuspendedStatusChanged now to give us a chance to notice
   // that autoplay should run.
   NotifySuspendedStatusChanged();
+
+  // mOwner->FirstFrameLoaded() might call us back. Put it at the bottom of
+  // this function to avoid unexpected shutdown from reentrant calls.
+  if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
+    mOwner->FirstFrameLoaded();
+  }
 }
 
 void
 MediaDecoder::NetworkError()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!IsShutdown());
   mOwner->NetworkError();