Bug 1420488 - part1 : bless media if media has started playing before. r=jwwang

If the media has started playing before, bless it and it would always be allowed
to autoplay.

MozReview-Commit-ID: 4GqMARLXULU

--HG--
extra : rebase_source : 2fdb3937156147755f8e387b1d84311ae1d37ce4
This commit is contained in:
Alastor Wu 2017-11-29 18:59:56 +08:00
Родитель 0436600a3f
Коммит 258e1d56df
3 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -1979,12 +1979,12 @@ void HTMLMediaElement::DoLoad()
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()) {
mHasUserInteractedLoadOrSeek = true;
// 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.
mIsBlessed = 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)) {
@ -2757,7 +2757,7 @@ HTMLMediaElement::Seek(double aTime,
// Detect if user has interacted with element by seeking so that
// play will not be blocked when initiated by a script.
if (EventStateManager::IsHandlingUserInput()) {
mHasUserInteractedLoadOrSeek = true;
mIsBlessed = true;
}
StopSuspendingAfterFirstFrame();
@ -4043,7 +4043,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
mIsEncrypted(false),
mWaitingForKey(NOT_WAITING_FOR_KEY),
mDisableVideo(false),
mHasUserInteractedLoadOrSeek(false),
mFirstFrameLoaded(false),
mDefaultPlaybackStartPosition(0.0),
mHasSuspendTaint(false),
@ -4286,6 +4285,9 @@ HTMLMediaElement::PlayInternal(ErrorResult& aRv)
UpdatePreloadAction();
UpdateSrcMediaStreamPlaying();
// once media start playing, we would always allow it to autoplay
mIsBlessed = true;
// TODO: If the playback has ended, then the user agent must set
// seek to the effective start.

Просмотреть файл

@ -741,11 +741,9 @@ public:
void NotifyCueDisplayStatesChanged();
bool GetAndClearHasUserInteractedLoadOrSeek()
bool IsBlessed() const
{
bool result = mHasUserInteractedLoadOrSeek;
mHasUserInteractedLoadOrSeek = false;
return result;
return mIsBlessed;
}
// A method to check whether we are currently playing.
@ -1785,9 +1783,9 @@ private:
// Total time a video has (or would have) spent in video-decode-suspend mode.
TimeDurationAccumulator mVideoDecodeSuspendTime;
// True if user has called load() or seek() via user input.
// True if user has called load(), seek() or element has started playing before.
// It's *only* use for checking autoplay policy
bool mHasUserInteractedLoadOrSeek;
bool mIsBlessed = false;
// True if the first frame has been successfully loaded.
bool mFirstFrameLoaded;

Просмотреть файл

@ -38,9 +38,8 @@ AutoplayPolicy::IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement)
// TODO : this old way would be removed when user-gestures-needed becomes
// as a default option to block autoplay.
// If user triggers load() or seek() before play(), we would also allow the
// following play().
return aElement->GetAndClearHasUserInteractedLoadOrSeek() ||
// If elelement is blessed, it would always be allowed to play().
return aElement->IsBlessed() ||
EventStateManager::IsHandlingUserInput();
}