Bug 1244768 part 7 - refactor the Play() and PlayInternal() methods; r=jwwang
authorKaku Kuo <tkuo@mozilla.com>
Mon, 08 Aug 2016 14:52:00 +0800
changeset 325501 23f644a032123cbfa0e332619107ba478202d7a6
parent 325500 ed3195c64abcb14360766eff8f13ae715a4fc756
child 325502 d0869fbb0870ef0ad472ea83ff6e6f4ee48f2c99
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjwwang
bugs1244768
milestone53.0a1
Bug 1244768 part 7 - refactor the Play() and PlayInternal() methods; r=jwwang MozReview-Commit-ID: CP00vERdWMv
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3693,27 +3693,26 @@ void
 HTMLMediaElement::Play(ErrorResult& aRv)
 {
   if (mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked()) {
     // NOTE: for promise-based-play, will return a pending promise here.
     MaybeDoLoad();
     return;
   }
 
-  nsresult rv = PlayInternal();
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-  }
+  PlayInternal(aRv);
 
   UpdateCustomPolicyAfterPlayed();
 }
 
-nsresult
-HTMLMediaElement::PlayInternal()
-{
+void
+HTMLMediaElement::PlayInternal(ErrorResult& aRv)
+{
+  MOZ_ASSERT(!aRv.Failed());
+
   if (!IsAllowedToPlay()) {
     // NOTE: for promise-based-play, will return a rejected promise here.
     return NS_OK;
   }
 
   // Play was not blocked so assume user interacted with the element.
   mHasUserInteraction = true;
 
@@ -3729,17 +3728,18 @@ HTMLMediaElement::PlayInternal()
   // here if we managed to clone an existing decoder.
   if (mDecoder) {
     if (mDecoder->IsEnded()) {
       SetCurrentTime(0);
     }
     if (!mPausedForInactiveDocumentOrChannel) {
       nsresult rv = mDecoder->Play();
       if (NS_FAILED(rv)) {
-        return rv;
+        aRv.Throw(rv);
+        return;
       }
     }
   }
 
   if (mCurrentPlayRangeStart == -1.0) {
     mCurrentPlayRangeStart = CurrentTime();
   }
 
@@ -3769,17 +3769,17 @@ HTMLMediaElement::PlayInternal()
     case nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA:
     case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
       FireTimeUpdate(false);
       DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
       break;
     }
   }
 
-  return NS_OK;
+  return;
 }
 
 void
 HTMLMediaElement::MaybeDoLoad()
 {
   if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
     DoLoad();
   }
@@ -3788,19 +3788,20 @@ HTMLMediaElement::MaybeDoLoad()
 NS_IMETHODIMP HTMLMediaElement::Play()
 {
   if (mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked()) {
     // NOTE: for promise-based-play, will return a pending promise here.
     MaybeDoLoad();
     return NS_OK;
   }
 
-  nsresult rv = PlayInternal();
-  if (NS_FAILED(rv)) {
-    return rv;
+  ErrorResult rv;
+  PlayInternal(rv);
+  if (rv.Failed()) {
+    return rv.StealNSResult();
   }
 
   UpdateCustomPolicyAfterPlayed();
   return NS_OK;
 }
 
 HTMLMediaElement::WakeLockBoolWrapper&
 HTMLMediaElement::WakeLockBoolWrapper::operator=(bool val)
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -805,17 +805,18 @@ protected:
     bool mCapturingDecoder;
     bool mCapturingMediaStream;
 
     // The following members are keeping state for a captured MediaStream.
     TrackID mNextAvailableTrackID;
     nsTArray<Pair<nsString, RefPtr<MediaInputPort>>> mTrackPorts;
   };
 
-  nsresult PlayInternal();
+  // Will make this method return a already_AddRefed<Promise> in next patch.
+  void PlayInternal(ErrorResult& aRv);
 
   /** Use this method to change the mReadyState member, so required
    * events can be fired.
    */
   void ChangeReadyState(nsMediaReadyState aState);
 
   /**
    * Use this method to change the mNetworkState member, so required