diff options
Diffstat (limited to 'Source/WebCore/html/track/TrackListBase.cpp')
-rw-r--r-- | Source/WebCore/html/track/TrackListBase.cpp | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/Source/WebCore/html/track/TrackListBase.cpp b/Source/WebCore/html/track/TrackListBase.cpp index 7fb47b68d..ef892cbb5 100644 --- a/Source/WebCore/html/track/TrackListBase.cpp +++ b/Source/WebCore/html/track/TrackListBase.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -46,6 +46,16 @@ TrackListBase::TrackListBase(HTMLMediaElement* element, ScriptExecutionContext* TrackListBase::~TrackListBase() { + clearElement(); +} + +void TrackListBase::clearElement() +{ + m_element = nullptr; + for (auto& track : m_inbandTracks) { + track->setMediaElement(nullptr); + track->clearClient(); + } } Element* TrackListBase::element() const @@ -58,37 +68,36 @@ unsigned TrackListBase::length() const return m_inbandTracks.size(); } -void TrackListBase::remove(TrackBase* track) +void TrackListBase::remove(TrackBase& track, bool scheduleEvent) { - size_t index = m_inbandTracks.find(track); - ASSERT(index != notFound); + size_t index = m_inbandTracks.find(&track); + if (index == notFound) + return; - ASSERT(track->mediaElement() == m_element); - track->setMediaElement(0); + if (track.mediaElement()) { + ASSERT(track.mediaElement() == m_element); + track.setMediaElement(nullptr); + } - RefPtr<TrackBase> trackRef = m_inbandTracks[index]; + Ref<TrackBase> trackRef = *m_inbandTracks[index]; m_inbandTracks.remove(index); - scheduleRemoveTrackEvent(trackRef.release()); + if (scheduleEvent) + scheduleRemoveTrackEvent(WTFMove(trackRef)); } -bool TrackListBase::contains(TrackBase* track) const +bool TrackListBase::contains(TrackBase& track) const { - return m_inbandTracks.find(track) != notFound; + return m_inbandTracks.find(&track) != notFound; } -void TrackListBase::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr<TrackBase> track) +void TrackListBase::scheduleTrackEvent(const AtomicString& eventName, Ref<TrackBase>&& track) { - TrackEventInit initializer; - initializer.track = track; - initializer.bubbles = false; - initializer.cancelable = false; - - m_asyncEventQueue.enqueueEvent(TrackEvent::create(eventName, initializer)); + m_asyncEventQueue.enqueueEvent(TrackEvent::create(eventName, false, false, WTFMove(track))); } -void TrackListBase::scheduleAddTrackEvent(PassRefPtr<TrackBase> track) +void TrackListBase::scheduleAddTrackEvent(Ref<TrackBase>&& track) { // 4.8.10.5 Loading the media resource // ... @@ -108,10 +117,10 @@ void TrackListBase::scheduleAddTrackEvent(PassRefPtr<TrackBase> track) // 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. - scheduleTrackEvent(eventNames().addtrackEvent, track); + scheduleTrackEvent(eventNames().addtrackEvent, WTFMove(track)); } -void TrackListBase::scheduleRemoveTrackEvent(PassRefPtr<TrackBase> track) +void TrackListBase::scheduleRemoveTrackEvent(Ref<TrackBase>&& track) { // 4.8.10.6 Offsets into the media resource // If at any time the user agent learns that an audio or video track has @@ -135,7 +144,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. - scheduleTrackEvent(eventNames().removetrackEvent, track); + scheduleTrackEvent(eventNames().removetrackEvent, WTFMove(track)); } void TrackListBase::scheduleChangeEvent() @@ -148,18 +157,12 @@ void TrackListBase::scheduleChangeEvent() // Whenever a track in a VideoTrackList that was previously not selected is // selected, the user agent must queue a task to fire a simple event named // change at the VideoTrackList object. - - EventInit initializer; - initializer.bubbles = false; - initializer.cancelable = false; - - m_asyncEventQueue.enqueueEvent(Event::create(eventNames().changeEvent, initializer)); + m_asyncEventQueue.enqueueEvent(Event::create(eventNames().changeEvent, false, false)); } bool TrackListBase::isAnyTrackEnabled() const { - for (size_t i = 0; i < m_inbandTracks.size(); ++i) { - TrackBase* track = m_inbandTracks[i].get(); + for (auto& track : m_inbandTracks) { if (track->enabled()) return true; } |