bug 1123189 Queue "durationchange" instead of dispatching synchronously r=cpearce
http://www.w3.org/TR/2014/REC-html5-20141028/embedded-content-0.html#offsets-into-the-media-resource
"When the length of the media resource changes to a known value (e.g. from
being unknown to known, or from a previously established length to a new
length) the user agent must queue a task to fire a simple event named
durationchange at the media element."
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -199,17 +199,17 @@ protected:
bool IsCancelled() {
return mElement->GetCurrentLoadID() != mLoadID;
}
nsRefPtr<HTMLMediaElement> mElement;
uint32_t mLoadID;
};
-class nsAsyncEventRunner : public nsMediaEvent
+class HTMLMediaElement::nsAsyncEventRunner : public nsMediaEvent
{
private:
nsString mName;
public:
nsAsyncEventRunner(const nsAString& aName, HTMLMediaElement* aElement) :
nsMediaEvent(aElement), mName(aName)
{
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -212,18 +212,16 @@ public:
virtual void NotifySuspendedByCache(bool aIsSuspended) MOZ_FINAL MOZ_OVERRIDE;
// Called by the media decoder and the video frame to get the
// ImageContainer containing the video data.
virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE;
layers::ImageContainer* GetImageContainer();
// Dispatch events
- using nsGenericHTMLElement::DispatchEvent;
- virtual nsresult DispatchEvent(const nsAString& aName) MOZ_FINAL MOZ_OVERRIDE;
virtual nsresult DispatchAsyncEvent(const nsAString& aName) MOZ_FINAL MOZ_OVERRIDE;
// Dispatch events that were raised while in the bfcache
nsresult DispatchPendingMediaEvents();
// Called by the decoder when some data has been downloaded or
// buffering/seeking has ended. aNextFrameAvailable is true when
// the data for the next frame is available. This method will
@@ -975,16 +973,21 @@ protected:
// in the element's list of text tracks whose text track mode is not disabled
// and whose text track readiness state is loading.
void PopulatePendingTextTrackList();
// Gets a reference to the MediaElement's TextTrackManager. If the
// MediaElement doesn't yet have one then it will create it.
TextTrackManager* GetOrCreateTextTrackManager();
+ class nsAsyncEventRunner;
+ using nsGenericHTMLElement::DispatchEvent;
+ // For nsAsyncEventRunner.
+ nsresult DispatchEvent(const nsAString& aName);
+
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
nsRefPtr<MediaDecoder> mDecoder;
// A reference to the VideoFrameContainer which contains the current frame
// of video to display.
nsRefPtr<VideoFrameContainer> mVideoFrameContainer;
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1248,17 +1248,17 @@ void MediaDecoder::DurationChanged()
mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
// Duration has changed so we should recompute playback rate
UpdatePlaybackRate();
SetInfinite(mDuration == -1);
if (mOwner && oldDuration != mDuration && !IsInfinite()) {
DECODER_LOG("Duration changed to %lld", mDuration);
- mOwner->DispatchEvent(NS_LITERAL_STRING("durationchange"));
+ mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
}
}
void MediaDecoder::SetDuration(double aDuration)
{
MOZ_ASSERT(NS_IsMainThread());
if (mozilla::IsInfinite(aDuration)) {
SetInfinite(true);
--- a/dom/media/MediaDecoderOwner.h
+++ b/dom/media/MediaDecoderOwner.h
@@ -16,19 +16,16 @@ class HTMLMediaElement;
}
class MediaDecoderOwner
{
public:
// Called by the media decoder to indicate that the download is progressing.
virtual void DownloadProgressed() = 0;
- // Dispatch a synchronous event to the decoder owner
- virtual nsresult DispatchEvent(const nsAString& aName) = 0;
-
// Dispatch an asynchronous event to the decoder owner
virtual nsresult DispatchAsyncEvent(const nsAString& aName) = 0;
/**
* Fires a timeupdate event. If aPeriodic is true, the event will only
* be fired if we've not fired a timeupdate event (for any reason) in the
* last 250ms, as required by the spec when the current time is periodically
* increasing during playback.
--- a/dom/media/gtest/MockMediaDecoderOwner.h
+++ b/dom/media/gtest/MockMediaDecoderOwner.h
@@ -8,20 +8,16 @@
#include "MediaDecoderOwner.h"
namespace mozilla
{
class MockMediaDecoderOwner : public MediaDecoderOwner
{
public:
- virtual nsresult DispatchEvent(const nsAString& aName) MOZ_OVERRIDE
- {
- return NS_OK;
- }
virtual nsresult DispatchAsyncEvent(const nsAString& aName) MOZ_OVERRIDE
{
return NS_OK;
}
virtual void FireTimeUpdate(bool aPeriodic) MOZ_OVERRIDE {}
virtual bool GetPaused() MOZ_OVERRIDE { return false; }
virtual void MetadataLoaded(const MediaInfo* aInfo,
nsAutoPtr<const MetadataTags> aTags) MOZ_OVERRIDE