Bug 1531863 - part3 : implement the 'show-poster-flag' for HTMLMediaElement. r=jya

According to the spec [1], implement the `show-poster-flag` which is used to decide whether we need to run `TimeMarchesOn` algorithm under certain situations.

[1] https://html.spec.whatwg.org/multipage/media.html#show-poster-flag

Differential Revision: https://phabricator.services.mozilla.com/D21811
This commit is contained in:
Alastor Wu
2019-03-08 03:06:27 +00:00
parent 77d47ec8d5
commit 50a2ef4283
2 changed files with 36 additions and 1 deletions

View File

@@ -2710,6 +2710,10 @@ already_AddRefed<Promise> HTMLMediaElement::Seek(double aTime,
// aTime should be non-NaN.
MOZ_ASSERT(!mozilla::IsNaN(aTime));
// Seeking step1, Set the media element's show poster flag to false.
// https://html.spec.whatwg.org/multipage/media.html#dom-media-seek
mShowPoster = false;
RefPtr<Promise> promise = CreateDOMPromise(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
@@ -3503,7 +3507,8 @@ HTMLMediaElement::HTMLMediaElement(
mPaused(true, "HTMLMediaElement::mPaused"),
mErrorSink(new ErrorSink(this)),
mAudioChannelWrapper(new AudioChannelAgentCallback(this)),
mSink(MakePair(nsString(), RefPtr<AudioDeviceInfo>())) {
mSink(MakePair(nsString(), RefPtr<AudioDeviceInfo>())),
mShowPoster(IsVideo()) {
MOZ_ASSERT(mMainThreadEventTarget);
MOZ_ASSERT(mAbstractMainThread);
// Please don't add anything to this constructor or the initialization
@@ -3808,6 +3813,12 @@ void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
// 6.2. If the show poster flag is true, set the element's show poster flag
// to false and run the time marches on steps.
if (mShowPoster) {
mShowPoster = false;
if (mTextTrackManager) {
mTextTrackManager->TimeMarchesOn();
}
}
// 6.3. Queue a task to fire a simple event named play at the element.
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
@@ -5583,6 +5594,13 @@ void HTMLMediaElement::ChangeNetworkState(nsMediaNetworkState aState) {
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
}
// According to the resource selection (step2, step9-18), dedicated media
// source failure step (step4) and aborting existing load (step4), set show
// poster flag to true. https://html.spec.whatwg.org/multipage/media.html
if (mNetworkState == NETWORK_NO_SOURCE || mNetworkState == NETWORK_EMPTY) {
mShowPoster = true;
}
// Changing mNetworkState affects AddRemoveSelfReference().
AddRemoveSelfReference();
}
@@ -5668,6 +5686,14 @@ void HTMLMediaElement::CheckAutoplayDataReady() {
SetPlayedOrSeeked(true);
}
// https://html.spec.whatwg.org/multipage/media.html#ready-states:show-poster-flag
if (mShowPoster) {
mShowPoster = false;
if (mTextTrackManager) {
mTextTrackManager->TimeMarchesOn();
}
}
// For blocked media, the event would be pending until it is resumed.
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
@@ -7388,6 +7414,10 @@ void HTMLMediaElement::NotifyTextTrackModeChanged() {
return;
}
GetTextTracks()->CreateAndDispatchChangeEvent();
// https://html.spec.whatwg.org/multipage/media.html#text-track-model:show-poster-flag
if (!mShowPoster) {
mTextTrackManager->TimeMarchesOn();
}
}));
}