Use GenericEventQueue in TrackListBase and reduce code duplication with scheduleTrackEvent()

https://bugs.webkit.org/show_bug.cgi?id=124811

Patch by Brendan Long <b.long@cablelabs.com> on 2013-12-02
Reviewed by Eric Carlson.

Source/WebCore:

No new tests because this is just refactoring.

* html/track/TrackListBase.cpp:
(TrackListBase::TrackListBase): Replace event code with a GenericEventQueue.
(TrackListBase::scheduleTrackEvent): Factor out duplicate code in schedule{Add,Remove}TrackEvent functions.
(TrackListBase::scheduleAddTrackEvent): Same.
(TrackListBase::scheduleRemoveTrackEvent): Same.
(TrackListBase::scheduleChangeEvent): Use GenericEventQueue.
* html/track/TrackListBase.h: Replace event code with GenericEventQueue.

LayoutTests:

* platform/mac/TestExpectations: Unskip onremovetrack test which was fixed a long time ago.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159950 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6f3fc824
2013-12-02 Brendan Long <b.long@cablelabs.com>
Use GenericEventQueue in TrackListBase and reduce code duplication with scheduleTrackEvent()
https://bugs.webkit.org/show_bug.cgi?id=124811
Reviewed by Eric Carlson.
* platform/mac/TestExpectations: Unskip onremovetrack test which was fixed a long time ago.
2013-12-02 Alexey Proskuryakov <ap@apple.com>
Add support for WebCrypto RSA-OAEP
......
......@@ -375,7 +375,6 @@ webkit.org/b/103926 media/track/opera/interfaces/TextTrackCue/text.html [ Skip ]
webkit.org/b/103926 media/track/opera/interfaces/TextTrackCue/vertical.html [ Skip ]
webkit.org/b/103926 media/track/opera/interfaces/TextTrackCueList/getter.html [ Skip ]
webkit.org/b/103926 media/track/opera/interfaces/TextTrackList/getter.html [ Skip ]
webkit.org/b/103926 media/track/opera/interfaces/TextTrackList/onremovetrack.html [ Skip ]
webkit.org/b/103926 media/track/opera/track/track-element/cloneNode.html [ Skip ]
webkit.org/b/103926 media/track/opera/track/track-element/src-clear-cues.html [ Skip ]
webkit.org/b/103926 media/track/opera/track/webvtt/parsing/001.html [ Skip ]
......
2013-12-02 Brendan Long <b.long@cablelabs.com>
Use GenericEventQueue in TrackListBase and reduce code duplication with scheduleTrackEvent()
https://bugs.webkit.org/show_bug.cgi?id=124811
Reviewed by Eric Carlson.
No new tests because this is just refactoring.
* html/track/TrackListBase.cpp:
(TrackListBase::TrackListBase): Replace event code with a GenericEventQueue.
(TrackListBase::scheduleTrackEvent): Factor out duplicate code in schedule{Add,Remove}TrackEvent functions.
(TrackListBase::scheduleAddTrackEvent): Same.
(TrackListBase::scheduleRemoveTrackEvent): Same.
(TrackListBase::scheduleChangeEvent): Use GenericEventQueue.
* html/track/TrackListBase.h: Replace event code with GenericEventQueue.
2013-12-02 Alexey Proskuryakov <ap@apple.com>
Add support for WebCrypto RSA-OAEP
......@@ -39,8 +39,7 @@ using namespace WebCore;
TrackListBase::TrackListBase(HTMLMediaElement* element, ScriptExecutionContext* context)
: m_context(context)
, m_element(element)
, m_pendingEventTimer(this, &TrackListBase::asyncEventTimerFired)
, m_dispatchingEvents(0)
, m_asyncEventQueue(*this)
{
ASSERT(context->isDocument());
}
......@@ -79,6 +78,16 @@ bool TrackListBase::contains(TrackBase* track) const
return m_inbandTracks.find(track) != notFound;
}
void TrackListBase::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr<TrackBase> track)
{
TrackEventInit initializer;
initializer.track = track;
initializer.bubbles = false;
initializer.cancelable = false;
m_asyncEventQueue.enqueueEvent(TrackEvent::create(eventName, initializer));
}
void TrackListBase::scheduleAddTrackEvent(PassRefPtr<TrackBase> track)
{
// 4.8.10.5 Loading the media resource
......@@ -98,17 +107,8 @@ void TrackListBase::scheduleAddTrackEvent(PassRefPtr<TrackBase> track)
// ... then queue a task to fire an event with the name addtrack, that does not
// bubble and is not cancelable, and that uses the TrackEvent interface, with
// the track attribute initialized to the text track's TextTrack object, at
// the media element's textTracks attribute's TextTrackList object.
RefPtr<TrackBase> trackRef = track;
TrackEventInit initializer;
initializer.track = trackRef;
initializer.bubbles = false;
initializer.cancelable = false;
m_pendingEvents.append(TrackEvent::create(eventNames().addtrackEvent, initializer));
if (!m_pendingEventTimer.isActive())
m_pendingEventTimer.startOneShot(0);
// the media element's textTracks attribute's TextTrackList object.
scheduleTrackEvent(eventNames().addtrackEvent, track);
}
void TrackListBase::scheduleRemoveTrackEvent(PassRefPtr<TrackBase> track)
......@@ -135,16 +135,7 @@ void TrackListBase::scheduleRemoveTrackEvent(PassRefPtr<TrackBase> track)
// interface, with the track attribute initialized to the text track's
// TextTrack object, at the media element's textTracks attribute's
// TextTrackList object.
RefPtr<TrackBase> trackRef = track;
TrackEventInit initializer;
initializer.track = trackRef;
initializer.bubbles = false;
initializer.cancelable = false;
m_pendingEvents.append(TrackEvent::create(eventNames().removetrackEvent, initializer));
if (!m_pendingEventTimer.isActive())
m_pendingEventTimer.startOneShot(0);
scheduleTrackEvent(eventNames().removetrackEvent, track);
}
void TrackListBase::scheduleChangeEvent()
......@@ -162,21 +153,7 @@ void TrackListBase::scheduleChangeEvent()
initializer.bubbles = false;
initializer.cancelable = false;
m_pendingEvents.append(Event::create(eventNames().changeEvent, initializer));
if (!m_pendingEventTimer.isActive())
m_pendingEventTimer.startOneShot(0);
}
void TrackListBase::asyncEventTimerFired(Timer<TrackListBase>*)
{
Vector<RefPtr<Event>> pendingEvents;
++m_dispatchingEvents;
m_pendingEvents.swap(pendingEvents);
size_t count = pendingEvents.size();
for (size_t index = 0; index < count; ++index)
dispatchEvent(pendingEvents[index].release(), IGNORE_EXCEPTION);
--m_dispatchingEvents;
m_asyncEventQueue.enqueueEvent(Event::create(eventNames().changeEvent, initializer));
}
bool TrackListBase::isAnyTrackEnabled() const
......
......@@ -30,6 +30,7 @@
#include "EventListener.h"
#include "EventTarget.h"
#include "GenericEventQueue.h"
#include "Timer.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
......@@ -63,8 +64,6 @@ public:
Element* element() const;
HTMLMediaElement* mediaElement() const { return m_element; }
bool isFiringEventListeners() { return m_dispatchingEvents; }
// Needs to be public so tracks can call it
void scheduleChangeEvent();
......@@ -79,20 +78,16 @@ protected:
Vector<RefPtr<TrackBase>> m_inbandTracks;
private:
void scheduleTrackEvent(const AtomicString& eventName, PassRefPtr<TrackBase>);
// EventTarget
virtual void refEventTarget() OVERRIDE FINAL { ref(); }
virtual void derefEventTarget() OVERRIDE FINAL { deref(); }
void asyncEventTimerFired(Timer<TrackListBase>*);
ScriptExecutionContext* m_context;
HTMLMediaElement* m_element;
Vector<RefPtr<Event>> m_pendingEvents;
Timer<TrackListBase> m_pendingEventTimer;
int m_dispatchingEvents;
GenericEventQueue m_asyncEventQueue;
};
} // namespace WebCore
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment