Bug 1298594: P2. Fire waiting event when readyState move back to HAVE_CURRENT_DATA. r?jwwang
MozReview-Commit-ID: BpwYY6njXGC
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2877,17 +2877,16 @@ HTMLMediaElement::HTMLMediaElement(alrea
mAllowCasting(false),
mIsCasting(false),
mAudioCaptured(false),
mAudioCapturedByWindow(false),
mPlayingBeforeSeek(false),
mPlayingThroughTheAudioChannelBeforeSeek(false),
mPausedForInactiveDocumentOrChannel(false),
mEventDeliveryPaused(false),
- mWaitingFired(false),
mIsRunningLoadMethod(false),
mIsDoingExplicitLoad(false),
mIsLoadingFromSourceChildren(false),
mDelayingLoadEvent(false),
mIsRunningSelectResource(false),
mHaveQueuedSelectResource(false),
mSuspendedAfterFirstFrame(false),
mAllowSuspendAfterFirstFrame(true),
@@ -4770,21 +4769,16 @@ HTMLMediaElement::UpdateReadyStateIntern
}
if (nextFrameStatus != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
"Next frame not available", this));
if (mFirstFrameLoaded) {
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
}
- if (!mWaitingFired && nextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
- FireTimeUpdate(false);
- DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
- mWaitingFired = true;
- }
return;
}
if (!mFirstFrameLoaded) {
// We haven't yet loaded the first frame, making us unable to determine
// if we have enough valid data at the present stage.
return;
}
@@ -4833,32 +4827,43 @@ void HTMLMediaElement::ChangeReadyState(
return;
}
LOG(LogLevel::Debug, ("%p Ready state changed to %s", this, gReadyStateToString[aState]));
UpdateAudioChannelPlayingState();
// Handle raising of "waiting" event during seek (see 4.8.10.9)
+ // or
+ // 4.8.12.7 Ready states:
+ // "If the previous ready state was HAVE_FUTURE_DATA or more, and the new
+ // ready state is HAVE_CURRENT_DATA or less
+ // If the media element was potentially playing before its readyState
+ // attribute changed to a value lower than HAVE_FUTURE_DATA, and the element
+ // has not ended playback, and playback has not stopped due to errors,
+ // paused for user interaction, or paused for in-band content, the user agent
+ // must queue a task to fire a simple event named timeupdate at the element,
+ // and queue a task to fire a simple event named waiting at the element."
if (mPlayingBeforeSeek &&
mReadyState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
+ } else if (oldState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
+ mReadyState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
+ !Paused() && !Ended() && !mError) {
+ FireTimeUpdate(false);
+ DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
}
if (oldState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
!mLoadedDataFired) {
DispatchAsyncEvent(NS_LITERAL_STRING("loadeddata"));
mLoadedDataFired = true;
}
- if (mReadyState == nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA) {
- mWaitingFired = false;
- }
-
if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
}
CheckAutoplayDataReady();
if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1511,20 +1511,16 @@ protected:
// True iff this element is paused because the document is inactive or has
// been suspended by the audio channel service.
bool mPausedForInactiveDocumentOrChannel;
// True iff event delivery is suspended (mPausedForInactiveDocumentOrChannel must also be true).
bool mEventDeliveryPaused;
- // True if we've reported a "waiting" event since the last
- // readyState change to HAVE_CURRENT_DATA.
- bool mWaitingFired;
-
// True if we're running the "load()" method.
bool mIsRunningLoadMethod;
// True if we're running or waiting to run queued tasks due to an explicit
// call to "load()".
bool mIsDoingExplicitLoad;
// True if we're loading the resource from the child source elements.