| Index: Source/core/html/track/TrackBaseList.cpp
|
| diff --git a/Source/core/html/track/TrackBaseList.cpp b/Source/core/html/track/TrackBaseList.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9281d7e03b700cdf923d2829f1ebafca29751f97
|
| --- /dev/null
|
| +++ b/Source/core/html/track/TrackBaseList.cpp
|
| @@ -0,0 +1,127 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "core/html/track/TrackBaseList.h"
|
| +
|
| +#include "core/events/GenericEventQueue.h"
|
| +#include "core/html/track/TrackBase.h"
|
| +#include "core/html/track/TrackEvent.h"
|
| +#include "platform/Logging.h"
|
| +
|
| +namespace WebCore {
|
| +
|
| +TrackBaseList::TrackBaseList(HTMLMediaElement* mediaElement)
|
| + : ActiveDOMObject(mediaElement->executionContext())
|
| + , m_shutdown(false)
|
| + , m_asyncEventQueue(GenericEventQueue::create(this))
|
| +{
|
| + ASSERT(mediaElement);
|
| +}
|
| +
|
| +TrackBaseList::~TrackBaseList()
|
| +{
|
| + ASSERT(m_shutdown);
|
| + ASSERT(m_tracks.isEmpty());
|
| +}
|
| +
|
| +void TrackBaseList::shutdown()
|
| +{
|
| + m_shutdown = true;
|
| + removeAll();
|
| + m_asyncEventQueue->close();
|
| +}
|
| +
|
| +TrackBase* TrackBaseList::getByIndex(unsigned index) const
|
| +{
|
| + if (index >= m_tracks.size())
|
| + return 0;
|
| +
|
| + return m_tracks[index].get();
|
| +}
|
| +
|
| +TrackBase* TrackBaseList::getById(const AtomicString& id) const
|
| +{
|
| + for (unsigned i = 0; i < m_tracks.size(); ++i) {
|
| + if (m_tracks[i]->id() == id)
|
| + return m_tracks[i].get();
|
| + }
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +unsigned TrackBaseList::getIndex(const AtomicString& id) const
|
| +{
|
| + for (unsigned i = 0; i < m_tracks.size(); ++i) {
|
| + if (m_tracks[i]->id() == id)
|
| + return i;
|
| + }
|
| +
|
| + ASSERT_NOT_REACHED();
|
| + return 0;
|
| +}
|
| +
|
| +ExecutionContext* TrackBaseList::executionContext() const
|
| +{
|
| + return ActiveDOMObject::executionContext();
|
| +}
|
| +
|
| +bool TrackBaseList::hasPendingActivity() const
|
| +{
|
| + return !m_shutdown || m_asyncEventQueue->hasPendingEvents() || ActiveDOMObject::hasPendingActivity();
|
| +}
|
| +
|
| +void TrackBaseList::stop()
|
| +{
|
| + shutdown();
|
| +}
|
| +
|
| +void TrackBaseList::add(TrackBase* track)
|
| +{
|
| + m_tracks.append(track);
|
| +
|
| + scheduleTrackEvent(EventTypeNames::addtrack, track);
|
| +}
|
| +
|
| +void TrackBaseList::remove(const String& id)
|
| +{
|
| + for (unsigned i = 0; i < m_tracks.size(); ++i) {
|
| + if (m_tracks[i]->id() == id) {
|
| + m_tracks[i]->setMediaElement(0);
|
| + scheduleTrackEvent(EventTypeNames::removetrack, m_tracks[i]);
|
| + m_tracks.remove(i);
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| +void TrackBaseList::removeAll()
|
| +{
|
| + for (unsigned i = 0; i < m_tracks.size(); ++i)
|
| + m_tracks[i]->setMediaElement(0);
|
| +
|
| + m_tracks.clear();
|
| +}
|
| +
|
| +void TrackBaseList::scheduleChangeEvent()
|
| +{
|
| + WTF_LOG(Media, "TrackBaseList::scheduleChangeEvent() : %p", this);
|
| + EventInit initializer;
|
| + initializer.bubbles = false;
|
| + initializer.cancelable = false;
|
| + m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initializer));
|
| +}
|
| +
|
| +void TrackBaseList::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr<TrackBase> track)
|
| +{
|
| + WTF_LOG(Media, "TrackBaseList::scheduleTrackEvent(%s) : %p", eventName.string().ascii().data(), this);
|
| + TrackEventInit initializer;
|
| + initializer.track = track;
|
| + initializer.bubbles = false;
|
| + initializer.cancelable = false;
|
| +
|
| + m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer));
|
| +}
|
| +
|
| +}
|
|
|