Bug 1302350 - part6 : ensure loading process doens't be interrupted even media element can't be played. r=jwwang
authorAlastor Wu <alwu@mozilla.com>
Wed, 02 Nov 2016 14:22:35 +0800
changeset 347486 10d414508e1798890cbe04007a726c80a6dc7514
parent 347485 d94c3a6c1ad6785940c861225b6394c9e51ca3d4
child 347487 e8e4733d6c482328d14a7798bff3711800a0b762
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1302350
milestone52.0a1
Bug 1302350 - part6 : ensure loading process doens't be interrupted even media element can't be played. r=jwwang We don't want to stop the loading process even we canceled the play operation. MozReview-Commit-ID: FyPqBlDKYo0
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3026,16 +3026,17 @@ HTMLMediaElement::NotifyXPCOMShutdown()
 {
   ShutdownDecoder();
 }
 
 void
 HTMLMediaElement::Play(ErrorResult& aRv)
 {
   if (!IsAllowedToPlay()) {
+    MaybeDoLoad();
     return;
   }
 
   nsresult rv = PlayInternal();
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
   }
 }
@@ -3044,19 +3045,17 @@ nsresult
 HTMLMediaElement::PlayInternal()
 {
   // Play was not blocked so assume user interacted with the element.
   mHasUserInteraction = true;
 
   StopSuspendingAfterFirstFrame();
   SetPlayedOrSeeked(true);
 
-  if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
-    DoLoad();
-  }
+  MaybeDoLoad();
   if (mSuspendedForPreloadNone) {
     ResumeLoad(PRELOAD_ENOUGH);
   }
 
   // Even if we just did Load() or ResumeLoad(), we could already have a decoder
   // here if we managed to clone an existing decoder.
   if (mDecoder) {
     if (mDecoder->IsEnded()) {
@@ -3112,19 +3111,28 @@ HTMLMediaElement::PlayInternal()
       DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
       break;
     }
   }
 
   return NS_OK;
 }
 
+void
+HTMLMediaElement::MaybeDoLoad()
+{
+  if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
+    DoLoad();
+  }
+}
+
 NS_IMETHODIMP HTMLMediaElement::Play()
 {
   if (!IsAllowedToPlay()) {
+    MaybeDoLoad();
     return NS_OK;
   }
 
   return PlayInternal();
 }
 
 HTMLMediaElement::WakeLockBoolWrapper&
 HTMLMediaElement::WakeLockBoolWrapper::operator=(bool val)
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1267,16 +1267,19 @@ protected:
   void ResumeFromAudioChannelBlocked();
 
   bool IsSuspendedByAudioChannel() const;
   void SetAudioChannelSuspended(SuspendTypes aSuspend);
 
   // A method to check whether the media element is allowed to start playback.
   bool IsAllowedToPlay();
 
+  // If the network state is empty and then we would trigger DoLoad().
+  void MaybeDoLoad();
+
   // True if the tab which media element belongs to has been to foreground at
   // least once or activated by manually clicking the unblocking tab icon.
   bool IsTabActivated() const;
 
   bool IsAudible() const;
   bool HaveFailedWithSourceNotSupportedError() const;
 
   void OpenUnsupportedMediaWithExtenalAppIfNeeded();