Bug 1302350 - part6 : ensure loading process doens't be interrupted even media element can't be played. draft
authorAlastor Wu <alwu@mozilla.com>
Wed, 02 Nov 2016 14:22:35 +0800
changeset 432492 6f9d37bc5130f4858d52b550d71996c422555ce2
parent 432491 a635e5212548e657cc7f9b1e577f0d81c16d373b
child 535666 a449bbd8d3b5da6fbdb6fbc8551cf9f54e0fe151
push id34328
push useralwu@mozilla.com
push dateWed, 02 Nov 2016 06:23:00 +0000
bugs1302350
milestone52.0a1
Bug 1302350 - part6 : ensure loading process doens't be interrupted even media element can't be played. 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
@@ -2997,16 +2997,17 @@ HTMLMediaElement::NotifyXPCOMShutdown()
 {
   ShutdownDecoder();
 }
 
 void
 HTMLMediaElement::Play(ErrorResult& aRv)
 {
   if (!IsAllowedToPlay()) {
+    MaybeDoLoad();
     return;
   }
 
   nsresult rv = PlayInternal();
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
   }
 }
@@ -3015,19 +3016,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()) {
@@ -3083,19 +3082,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
@@ -1260,16 +1260,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();