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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-03-07 21:47:58 +00:00
Родитель 64ab84e0bc
Коммит b441cd934c
2 изменённых файлов: 36 добавлений и 1 удалений

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

@ -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();
}
}));
}

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

@ -1831,6 +1831,11 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// https://w3c.github.io/mediacapture-output/#htmlmediaelement-extensions
// Read/Write from the main thread only.
Pair<nsString, RefPtr<AudioDeviceInfo>> mSink;
// This flag is used to control when the user agent is to show a poster frame
// for a video element instead of showing the video contents.
// https://html.spec.whatwg.org/multipage/media.html#show-poster-flag
bool mShowPoster;
};
// Check if the context is chrome or has the debugger or tabs permission