Bug 1382574 - part3 : remove HTMLMediaElement::mHasUserInteraction. draft
authorAlastor Wu <alwu@mozilla.com>
Wed, 22 Nov 2017 00:33:23 +0800
changeset 701427 dfc18a19de45ec1d5feae6333f9ce35ef77554d3
parent 701426 9313505821b056bf7c1eb5dae758b3e4a2baf102
child 701430 9329f96a725eb752c9dd179b61fcc8924aba7cfd
child 701738 5d4e15b227dd7a31a3ab065d3f2b6fffdefac41e
child 701742 de85768e98fba967ef4b875d48df2c13f70b6f33
push id90150
push useralwu@mozilla.com
push dateTue, 21 Nov 2017 16:37:52 +0000
bugs1382574
milestone59.0a1
Bug 1382574 - part3 : remove HTMLMediaElement::mHasUserInteraction. We won't need to check the whether the media element is interacted with user for autoplay anymore. MozReview-Commit-ID: 2tll9LtGyVR
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1967,23 +1967,17 @@ NS_IMETHODIMP HTMLMediaElement::Load()
 }
 
 void HTMLMediaElement::DoLoad()
 {
   if (mIsRunningLoadMethod) {
     return;
   }
 
-  // Detect if user has interacted with element so that play will not be
-  // blocked when initiated by a script. This enables sites to capture user
-  // intent to play by calling load() in the click handler of a "catalog
-  // view" of a gallery of videos.
   if (EventStateManager::IsHandlingUserInput()) {
-    mHasUserInteraction = true;
-
     // Mark the channel as urgent-start when autopaly so that it will play the
     // media from src after loading enough resource.
     if (HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
       mUseUrgentStartForChannel = true;
     }
   }
 
   SetPlayedOrSeeked(false);
@@ -2749,22 +2743,16 @@ HTMLMediaElement::Seek(double aTime,
   MOZ_ASSERT(!mozilla::IsNaN(aTime));
 
   RefPtr<Promise> promise = CreateDOMPromise(aRv);
 
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
-  // Detect if user has interacted with element by seeking so that
-  // play will not be blocked when initiated by a script.
-  if (EventStateManager::IsHandlingUserInput()) {
-    mHasUserInteraction = true;
-  }
-
   StopSuspendingAfterFirstFrame();
 
   if (mSrcStream) {
     // do nothing since media streams have an empty Seekable range.
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
     return promise.forget();
   }
 
@@ -4038,17 +4026,16 @@ HTMLMediaElement::HTMLMediaElement(alrea
     mShuttingDown(false),
     mSuspendedForPreloadNone(false),
     mSrcStreamIsPlaying(false),
     mMediaSecurityVerified(false),
     mCORSMode(CORS_NONE),
     mIsEncrypted(false),
     mWaitingForKey(NOT_WAITING_FOR_KEY),
     mDisableVideo(false),
-    mHasUserInteraction(false),
     mFirstFrameLoaded(false),
     mDefaultPlaybackStartPosition(0.0),
     mHasSuspendTaint(false),
     mMediaTracksConstructed(false),
     mVisibilityState(Visibility::UNTRACKED),
     mErrorSink(new ErrorSink(this)),
     mAudioChannelWrapper(new AudioChannelAgentCallback(this))
 {
@@ -4223,19 +4210,16 @@ HTMLMediaElement::PlayInternal(ErrorResu
   // Let promise be a new promise and append promise to the list of pending
   // play promises.
   RefPtr<Promise> promise = CreateDOMPromise(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
   mPendingPlayPromises.AppendElement(promise);
 
-  // Play was not blocked so assume user interacted with the element.
-  mHasUserInteraction = true;
-
   if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE) {
     // The media load algorithm will be initiated by a user interaction.
     // We want to boost the channel priority for better responsiveness.
     // Note this must be done before UpdatePreloadAction() which will
     // update |mPreloadAction|.
     mUseUrgentStartForChannel = true;
   }
 
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1772,20 +1772,16 @@ private:
   TimeDurationAccumulator mPlayTime;
 
   // Total time a video has spent playing while hidden.
   TimeDurationAccumulator mHiddenPlayTime;
 
   // Total time a video has (or would have) spent in video-decode-suspend mode.
   TimeDurationAccumulator mVideoDecodeSuspendTime;
 
-  // Indicates if user has interacted with the element.
-  // Used to block autoplay when disabled.
-  bool mHasUserInteraction;
-
   // True if the first frame has been successfully loaded.
   bool mFirstFrameLoaded;
 
   // Media elements also have a default playback start position, which must
   // initially be set to zero seconds. This time is used to allow the element to
   // be seeked even before the media is loaded.
   double mDefaultPlaybackStartPosition;