Modernize Track classes' code
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 May 2016 16:37:26 +0000 (16:37 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 May 2016 16:37:26 +0000 (16:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157735

Reviewed by Eric Carlson.

Modernize Track classes' code a bit.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::removeSourceBuffer):
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
* bindings/js/JSTrackCustom.cpp:
(WebCore::toTrack):
(WebCore::toJS):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::audioTrackEnabledChanged):
(WebCore::HTMLMediaElement::textTrackModeChanged):
(WebCore::HTMLMediaElement::videoTrackSelectedChanged):
(WebCore::HTMLMediaElement::textTrackRemoveCues):
(WebCore::HTMLMediaElement::mediaPlayerDidAddTextTrack):
(WebCore::HTMLMediaElement::addAudioTrack):
(WebCore::HTMLMediaElement::addTextTrack):
(WebCore::HTMLMediaElement::addVideoTrack):
(WebCore::HTMLMediaElement::removeAudioTrack):
(WebCore::HTMLMediaElement::removeTextTrack):
(WebCore::HTMLMediaElement::removeVideoTrack):
(WebCore::HTMLMediaElement::forgetResourceSpecificTracks):
(WebCore::HTMLMediaElement::audioTracks):
(WebCore::HTMLMediaElement::textTracks):
(WebCore::HTMLMediaElement::videoTracks):
(WebCore::HTMLMediaElement::didAddTextTrack):
(WebCore::HTMLMediaElement::didRemoveTextTrack):
(WebCore::HTMLMediaElement::setSelectedTextTrack):
(WebCore::HTMLMediaElement::textTrackAddCues): Deleted.
(WebCore::HTMLMediaElement::closeCaptionTracksChanged): Deleted.
* html/HTMLMediaElement.h:
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay):
(WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu):
* html/track/AudioTrack.cpp:
(WebCore::AudioTrack::~AudioTrack):
(WebCore::AudioTrack::setPrivate):
(WebCore::AudioTrack::isValidKind):
(WebCore::AudioTrack::willRemove):
(WebCore::AudioTrack::setEnabled): Deleted.
(WebCore::AudioTrack::updateKindFromPrivate): Deleted.
* html/track/AudioTrack.h:
(isType):
* html/track/AudioTrackList.cpp:
(AudioTrackList::append):
(AudioTrackList::item):
(AudioTrackList::getTrackById):
(AudioTrackList::eventTargetInterface): Deleted.
* html/track/AudioTrackList.h:
* html/track/InbandTextTrack.cpp:
(WebCore::InbandTextTrack::willRemove):
* html/track/TextTrack.cpp:
(WebCore::TextTrack::setKind):
(WebCore::TextTrack::trackIndex):
(WebCore::TextTrack::trackIndexRelativeToRenderedTracks):
(WebCore::TextTrack::setLanguage):
* html/track/TextTrack.h:
(isType):
* html/track/TextTrackList.cpp:
(TextTrackList::getTrackIndex):
(TextTrackList::getTrackIndexRelativeToRenderedTracks):
(TextTrackList::item):
(TextTrackList::getTrackById):
(TextTrackList::invalidateTrackIndexesAfterTrack):
(TextTrackList::append):
(TextTrackList::remove):
(TextTrackList::contains):
* html/track/TextTrackList.h:
* html/track/TrackBase.h:
* html/track/TrackEvent.cpp:
(WebCore::TrackEvent::TrackEvent):
* html/track/TrackEvent.h:
* html/track/TrackListBase.cpp:
(TrackListBase::remove):
(TrackListBase::contains):
(TrackListBase::scheduleTrackEvent):
(TrackListBase::scheduleAddTrackEvent):
(TrackListBase::scheduleRemoveTrackEvent):
* html/track/TrackListBase.h:
* html/track/VideoTrack.cpp:
(WebCore::VideoTrack::willRemove):
(WebCore::VideoTrack::setKind):
(WebCore::VideoTrack::setLanguage):
* html/track/VideoTrack.h:
(isType):
* html/track/VideoTrackList.cpp:
(VideoTrackList::append):
(VideoTrackList::item):
(VideoTrackList::getTrackById):
(VideoTrackList::selectedIndex):
* html/track/VideoTrackList.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200943 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/bindings/js/JSTrackCustom.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/track/AudioTrack.cpp
Source/WebCore/html/track/AudioTrack.h
Source/WebCore/html/track/AudioTrackList.cpp
Source/WebCore/html/track/AudioTrackList.h
Source/WebCore/html/track/InbandTextTrack.cpp
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/html/track/TextTrack.h
Source/WebCore/html/track/TextTrackList.cpp
Source/WebCore/html/track/TextTrackList.h
Source/WebCore/html/track/TrackBase.h
Source/WebCore/html/track/TrackEvent.cpp
Source/WebCore/html/track/TrackEvent.h
Source/WebCore/html/track/TrackListBase.cpp
Source/WebCore/html/track/TrackListBase.h
Source/WebCore/html/track/VideoTrack.cpp
Source/WebCore/html/track/VideoTrack.h
Source/WebCore/html/track/VideoTrackList.cpp
Source/WebCore/html/track/VideoTrackList.h
Source/WebCore/platform/cocoa/WebPlaybackSessionModelMediaElement.mm

index 58cea9c..9bf67f2 100644 (file)
@@ -1,3 +1,102 @@
+2016-05-16  Chris Dumez  <cdumez@apple.com>
+
+        Modernize Track classes' code
+        https://bugs.webkit.org/show_bug.cgi?id=157735
+
+        Reviewed by Eric Carlson.
+
+        Modernize Track classes' code a bit.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::removeSourceBuffer):
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
+        * bindings/js/JSTrackCustom.cpp:
+        (WebCore::toTrack):
+        (WebCore::toJS):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::audioTrackEnabledChanged):
+        (WebCore::HTMLMediaElement::textTrackModeChanged):
+        (WebCore::HTMLMediaElement::videoTrackSelectedChanged):
+        (WebCore::HTMLMediaElement::textTrackRemoveCues):
+        (WebCore::HTMLMediaElement::mediaPlayerDidAddTextTrack):
+        (WebCore::HTMLMediaElement::addAudioTrack):
+        (WebCore::HTMLMediaElement::addTextTrack):
+        (WebCore::HTMLMediaElement::addVideoTrack):
+        (WebCore::HTMLMediaElement::removeAudioTrack):
+        (WebCore::HTMLMediaElement::removeTextTrack):
+        (WebCore::HTMLMediaElement::removeVideoTrack):
+        (WebCore::HTMLMediaElement::forgetResourceSpecificTracks):
+        (WebCore::HTMLMediaElement::audioTracks):
+        (WebCore::HTMLMediaElement::textTracks):
+        (WebCore::HTMLMediaElement::videoTracks):
+        (WebCore::HTMLMediaElement::didAddTextTrack):
+        (WebCore::HTMLMediaElement::didRemoveTextTrack):
+        (WebCore::HTMLMediaElement::setSelectedTextTrack):
+        (WebCore::HTMLMediaElement::textTrackAddCues): Deleted.
+        (WebCore::HTMLMediaElement::closeCaptionTracksChanged): Deleted.
+        * html/HTMLMediaElement.h:
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay):
+        (WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu):
+        * html/track/AudioTrack.cpp:
+        (WebCore::AudioTrack::~AudioTrack):
+        (WebCore::AudioTrack::setPrivate):
+        (WebCore::AudioTrack::isValidKind):
+        (WebCore::AudioTrack::willRemove):
+        (WebCore::AudioTrack::setEnabled): Deleted.
+        (WebCore::AudioTrack::updateKindFromPrivate): Deleted.
+        * html/track/AudioTrack.h:
+        (isType):
+        * html/track/AudioTrackList.cpp:
+        (AudioTrackList::append):
+        (AudioTrackList::item):
+        (AudioTrackList::getTrackById):
+        (AudioTrackList::eventTargetInterface): Deleted.
+        * html/track/AudioTrackList.h:
+        * html/track/InbandTextTrack.cpp:
+        (WebCore::InbandTextTrack::willRemove):
+        * html/track/TextTrack.cpp:
+        (WebCore::TextTrack::setKind):
+        (WebCore::TextTrack::trackIndex):
+        (WebCore::TextTrack::trackIndexRelativeToRenderedTracks):
+        (WebCore::TextTrack::setLanguage):
+        * html/track/TextTrack.h:
+        (isType):
+        * html/track/TextTrackList.cpp:
+        (TextTrackList::getTrackIndex):
+        (TextTrackList::getTrackIndexRelativeToRenderedTracks):
+        (TextTrackList::item):
+        (TextTrackList::getTrackById):
+        (TextTrackList::invalidateTrackIndexesAfterTrack):
+        (TextTrackList::append):
+        (TextTrackList::remove):
+        (TextTrackList::contains):
+        * html/track/TextTrackList.h:
+        * html/track/TrackBase.h:
+        * html/track/TrackEvent.cpp:
+        (WebCore::TrackEvent::TrackEvent):
+        * html/track/TrackEvent.h:
+        * html/track/TrackListBase.cpp:
+        (TrackListBase::remove):
+        (TrackListBase::contains):
+        (TrackListBase::scheduleTrackEvent):
+        (TrackListBase::scheduleAddTrackEvent):
+        (TrackListBase::scheduleRemoveTrackEvent):
+        * html/track/TrackListBase.h:
+        * html/track/VideoTrack.cpp:
+        (WebCore::VideoTrack::willRemove):
+        (WebCore::VideoTrack::setKind):
+        (WebCore::VideoTrack::setLanguage):
+        * html/track/VideoTrack.h:
+        (isType):
+        * html/track/VideoTrackList.cpp:
+        (VideoTrackList::append):
+        (VideoTrackList::item):
+        (VideoTrackList::getTrackById):
+        (VideoTrackList::selectedIndex):
+        * html/track/VideoTrackList.h:
+
 2016-05-16  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         CSSParser.cpp triggers -Wunused-parameter
index e2849ae..9a54b61 100644 (file)
@@ -584,14 +584,14 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
 
         // 5.3 For each AudioTrack object in the SourceBuffer audioTracks list, run the following steps:
         while (audioTracks->length()) {
-            AudioTrack* track = audioTracks->lastItem();
+            auto& track = *audioTracks->lastItem();
 
             // 5.3.1 Set the sourceBuffer attribute on the AudioTrack object to null.
-            track->setSourceBuffer(nullptr);
+            track.setSourceBuffer(nullptr);
 
             // 5.3.2 If the enabled attribute on the AudioTrack object is true, then set the removed enabled
             // audio track flag to true.
-            if (track->enabled())
+            if (track.enabled())
                 removedEnabledAudioTrack = true;
 
             // 5.3.3 Remove the AudioTrack object from the HTMLMediaElement audioTracks list.
@@ -609,7 +609,7 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
         // 5.4 If the removed enabled audio track flag equals true, then queue a task to fire a simple event
         // named change at the HTMLMediaElement audioTracks list.
         if (removedEnabledAudioTrack)
-            mediaElement()->audioTracks()->scheduleChangeEvent();
+            mediaElement()->audioTracks().scheduleChangeEvent();
     }
 
     // 6. Let SourceBuffer videoTracks list equal the VideoTrackList object returned by sourceBuffer.videoTracks.
@@ -624,14 +624,14 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
 
         // 7.3 For each VideoTrack object in the SourceBuffer videoTracks list, run the following steps:
         while (videoTracks->length()) {
-            VideoTrack* track = videoTracks->lastItem();
+            auto& track = *videoTracks->lastItem();
 
             // 7.3.1 Set the sourceBuffer attribute on the VideoTrack object to null.
-            track->setSourceBuffer(nullptr);
+            track.setSourceBuffer(nullptr);
 
             // 7.3.2 If the selected attribute on the VideoTrack object is true, then set the removed selected
             // video track flag to true.
-            if (track->selected())
+            if (track.selected())
                 removedSelectedVideoTrack = true;
 
             // 7.3.3 Remove the VideoTrack object from the HTMLMediaElement videoTracks list.
@@ -649,7 +649,7 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
         // 7.4 If the removed selected video track flag equals true, then queue a task to fire a simple event
         // named change at the HTMLMediaElement videoTracks list.
         if (removedSelectedVideoTrack)
-            mediaElement()->videoTracks()->scheduleChangeEvent();
+            mediaElement()->videoTracks().scheduleChangeEvent();
     }
 
     // 8. Let SourceBuffer textTracks list equal the TextTrackList object returned by sourceBuffer.textTracks.
@@ -664,14 +664,14 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
 
         // 9.3 For each TextTrack object in the SourceBuffer textTracks list, run the following steps:
         while (textTracks->length()) {
-            TextTrack* track = textTracks->lastItem();
+            auto& track = *textTracks->lastItem();
 
             // 9.3.1 Set the sourceBuffer attribute on the TextTrack object to null.
-            track->setSourceBuffer(nullptr);
+            track.setSourceBuffer(nullptr);
 
             // 9.3.2 If the mode attribute on the TextTrack object is set to "showing" or "hidden", then
             // set the removed enabled text track flag to true.
-            if (track->mode() == TextTrack::Mode::Showing || track->mode() == TextTrack::Mode::Hidden)
+            if (track.mode() == TextTrack::Mode::Showing || track.mode() == TextTrack::Mode::Hidden)
                 removedEnabledTextTrack = true;
 
             // 9.3.3 Remove the TextTrack object from the HTMLMediaElement textTracks list.
@@ -689,7 +689,7 @@ void MediaSource::removeSourceBuffer(SourceBuffer& buffer, ExceptionCode& ec)
         // 9.4 If the removed enabled text track flag equals true, then queue a task to fire a simple event
         // named change at the HTMLMediaElement textTracks list.
         if (removedEnabledTextTrack)
-            mediaElement()->textTracks()->scheduleChangeEvent();
+            mediaElement()->textTracks().scheduleChangeEvent();
     }
     
     
index 70d01e4..2e50a6b 100644 (file)
@@ -1035,7 +1035,7 @@ void SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment(SourceBuff
             // FIXME: Implement steps 5.2.1-5.2.8.1 as per Editor's Draft 09 January 2015, and reorder this
             // 5.2.1 Let new audio track be a new AudioTrack object.
             // 5.2.2 Generate a unique ID and assign it to the id property on new video track.
-            RefPtr<AudioTrack> newAudioTrack = AudioTrack::create(this, audioTrackPrivate);
+            auto newAudioTrack = AudioTrack::create(this, audioTrackPrivate);
             newAudioTrack->setSourceBuffer(this);
 
             // 5.2.3 If audioTracks.length equals 0, then run the following steps:
@@ -1051,13 +1051,13 @@ void SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment(SourceBuff
             // 5.2.5 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at the AudioTrackList object
             // referenced by the audioTracks attribute on this SourceBuffer object.
-            audioTracks()->append(newAudioTrack);
+            audioTracks()->append(newAudioTrack.copyRef());
 
             // 5.2.6 Add new audio track to the audioTracks attribute on the HTMLMediaElement.
             // 5.2.7 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at the AudioTrackList object
             // referenced by the audioTracks attribute on the HTMLMediaElement.
-            m_source->mediaElement()->audioTracks()->append(newAudioTrack);
+            m_source->mediaElement()->audioTracks().append(newAudioTrack.copyRef());
 
             // 5.2.8 Create a new track buffer to store coded frames for this track.
             ASSERT(!m_trackBufferMap.contains(newAudioTrack->id()));
@@ -1076,7 +1076,7 @@ void SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment(SourceBuff
             // FIXME: Implement steps 5.3.1-5.3.8.1 as per Editor's Draft 09 January 2015, and reorder this
             // 5.3.1 Let new video track be a new VideoTrack object.
             // 5.3.2 Generate a unique ID and assign it to the id property on new video track.
-            RefPtr<VideoTrack> newVideoTrack = VideoTrack::create(this, videoTrackPrivate);
+            auto newVideoTrack = VideoTrack::create(this, videoTrackPrivate);
             newVideoTrack->setSourceBuffer(this);
 
             // 5.3.3 If videoTracks.length equals 0, then run the following steps:
@@ -1092,13 +1092,13 @@ void SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment(SourceBuff
             // 5.3.5 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at the VideoTrackList object
             // referenced by the videoTracks attribute on this SourceBuffer object.
-            videoTracks()->append(newVideoTrack);
+            videoTracks()->append(newVideoTrack.copyRef());
 
             // 5.3.6 Add new video track to the videoTracks attribute on the HTMLMediaElement.
             // 5.3.7 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at the VideoTrackList object
             // referenced by the videoTracks attribute on the HTMLMediaElement.
-            m_source->mediaElement()->videoTracks()->append(newVideoTrack);
+            m_source->mediaElement()->videoTracks().append(newVideoTrack.copyRef());
 
             // 5.3.8 Create a new track buffer to store coded frames for this track.
             ASSERT(!m_trackBufferMap.contains(newVideoTrack->id()));
@@ -1128,13 +1128,13 @@ void SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment(SourceBuff
             // 5.4.4 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at textTracks attribute on this
             // SourceBuffer object.
-            textTracks()->append(newTextTrack);
+            textTracks()->append(*newTextTrack);
 
             // 5.4.5 Add new text track to the textTracks attribute on the HTMLMediaElement.
             // 5.4.6 Queue a task to fire a trusted event named addtrack, that does not bubble and is
             // not cancelable, and that uses the TrackEvent interface, at the TextTrackList object
             // referenced by the textTracks attribute on the HTMLMediaElement.
-            m_source->mediaElement()->textTracks()->append(newTextTrack);
+            m_source->mediaElement()->textTracks().append(newTextTrack.releaseNonNull());
 
             // 5.4.7 Create a new track buffer to store coded frames for this track.
             ASSERT(!m_trackBufferMap.contains(textTrackPrivate->id()));
index 5d0ada4..865e20d 100644 (file)
@@ -40,7 +40,7 @@ namespace WebCore {
 TrackBase* toTrack(JSValue value)
 {
     if (!value.isObject())
-        return 0;
+        return nullptr;
 
     JSObject* object = asObject(value);
     if (object->inherits(JSTextTrack::info()))
@@ -50,7 +50,7 @@ TrackBase* toTrack(JSValue value)
     if (object->inherits(JSVideoTrack::info()))
         return &jsCast<JSVideoTrack*>(object)->wrapped();
 
-    return 0;
+    return nullptr;
 }
 
 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TrackBase& track)
@@ -62,17 +62,17 @@ JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TrackBase& t
         break;
         
     case TrackBase::AudioTrack:
-        if (auto* wrapper = getCachedWrapper(globalObject->world(), *toAudioTrack(&track)))
+        if (auto* wrapper = getCachedWrapper(globalObject->world(), downcast<AudioTrack>(track)))
             return wrapper;
         return CREATE_DOM_WRAPPER(globalObject, AudioTrack, track);
 
     case TrackBase::VideoTrack:
-        if (auto* wrapper = getCachedWrapper(globalObject->world(), *toVideoTrack(&track)))
+        if (auto* wrapper = getCachedWrapper(globalObject->world(), downcast<VideoTrack>(track)))
             return wrapper;
         return CREATE_DOM_WRAPPER(globalObject, VideoTrack, track);
 
     case TrackBase::TextTrack:
-        if (auto* wrapper = getCachedWrapper(globalObject->world(), *toTextTrack(&track)))
+        if (auto* wrapper = getCachedWrapper(globalObject->world(), downcast<TextTrack>(track)))
             return wrapper;
         return CREATE_DOM_WRAPPER(globalObject, TextTrack, track);
     }
index 359c957..67b402c 100644 (file)
@@ -1739,7 +1739,8 @@ void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track)
 
 void HTMLMediaElement::audioTrackEnabledChanged(AudioTrack* track)
 {
-    if (m_audioTracks && m_audioTracks->contains(track))
+    ASSERT(track);
+    if (m_audioTracks && m_audioTracks->contains(*track))
         m_audioTracks->scheduleChangeEvent();
 }
 
@@ -1769,7 +1770,7 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
 
     configureTextTrackDisplay(AssumeTextTrackVisibilityChanged);
 
-    if (m_textTracks && m_textTracks->contains(track))
+    if (m_textTracks && m_textTracks->contains(*track))
         m_textTracks->scheduleChangeEvent();
 
 #if ENABLE(AVF_CAPTIONS)
@@ -1780,7 +1781,8 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
 
 void HTMLMediaElement::videoTrackSelectedChanged(VideoTrack* track)
 {
-    if (m_videoTracks && m_videoTracks->contains(track))
+    ASSERT(track);
+    if (m_videoTracks && m_videoTracks->contains(*track))
         m_videoTracks->scheduleChangeEvent();
 }
 
@@ -1813,7 +1815,7 @@ void HTMLMediaElement::textTrackAddCues(TextTrack* track, const TextTrackCueList
         textTrackAddCue(track, cues->item(i));
 }
 
-void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList* cues) 
+void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList* cues)
 {
     TrackDisplayUpdateScope scope(this);
     for (size_t i = 0; i < cues->length(); ++i)
@@ -3572,7 +3574,7 @@ void HTMLMediaElement::mediaPlayerDidAddTextTrack(PassRefPtr<InbandTextTrackPriv
     // 9. 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.
-    addTextTrack(textTrack.release());
+    addTextTrack(textTrack.releaseNonNull());
 }
 
 void HTMLMediaElement::mediaPlayerDidAddVideoTrack(PassRefPtr<VideoTrackPrivate> prpTrack)
@@ -3601,12 +3603,12 @@ void HTMLMediaElement::closeCaptionTracksChanged()
         mediaControls()->closedCaptionTracksChanged();
 }
 
-void HTMLMediaElement::addAudioTrack(PassRefPtr<AudioTrack> track)
+void HTMLMediaElement::addAudioTrack(Ref<AudioTrack>&& track)
 {
-    audioTracks()->append(track);
+    audioTracks().append(WTFMove(track));
 }
 
-void HTMLMediaElement::addTextTrack(PassRefPtr<TextTrack> track)
+void HTMLMediaElement::addTextTrack(Ref<TextTrack>&& track)
 {
     if (!m_requireCaptionPreferencesChangedCallbacks) {
         m_requireCaptionPreferencesChangedCallbacks = true;
@@ -3616,34 +3618,34 @@ void HTMLMediaElement::addTextTrack(PassRefPtr<TextTrack> track)
             m_captionDisplayMode = page->group().captionPreferences().captionDisplayMode();
     }
 
-    textTracks()->append(track);
+    textTracks().append(WTFMove(track));
 
     closeCaptionTracksChanged();
 }
 
-void HTMLMediaElement::addVideoTrack(PassRefPtr<VideoTrack> track)
+void HTMLMediaElement::addVideoTrack(Ref<VideoTrack>&& track)
 {
-    videoTracks()->append(track);
+    videoTracks().append(WTFMove(track));
 }
 
-void HTMLMediaElement::removeAudioTrack(AudioTrack* track)
+void HTMLMediaElement::removeAudioTrack(AudioTrack& track)
 {
     m_audioTracks->remove(track);
 }
 
-void HTMLMediaElement::removeTextTrack(TextTrack* track, bool scheduleEvent)
+void HTMLMediaElement::removeTextTrack(TextTrack& track, bool scheduleEvent)
 {
     TrackDisplayUpdateScope scope(this);
-    if (TextTrackCueList* cues = track->cues())
-        textTrackRemoveCues(track, cues);
-    track->clearClient();
+    if (TextTrackCueList* cues = track.cues())
+        textTrackRemoveCues(&track, cues);
+    track.clearClient();
     if (m_textTracks)
         m_textTracks->remove(track, scheduleEvent);
 
     closeCaptionTracksChanged();
 }
 
-void HTMLMediaElement::removeVideoTrack(VideoTrack* track)
+void HTMLMediaElement::removeVideoTrack(VideoTrack& track)
 {
     m_videoTracks->remove(track);
 }
@@ -3651,20 +3653,19 @@ void HTMLMediaElement::removeVideoTrack(VideoTrack* track)
 void HTMLMediaElement::forgetResourceSpecificTracks()
 {
     while (m_audioTracks &&  m_audioTracks->length())
-        removeAudioTrack(m_audioTracks->lastItem());
+        removeAudioTrack(*m_audioTracks->lastItem());
 
     if (m_textTracks) {
         TrackDisplayUpdateScope scope(this);
         for (int i = m_textTracks->length() - 1; i >= 0; --i) {
-            TextTrack* track = m_textTracks->item(i);
-
-            if (track->trackType() == TextTrack::InBand)
+            auto& track = *m_textTracks->item(i);
+            if (track.trackType() == TextTrack::InBand)
                 removeTextTrack(track, false);
         }
     }
 
     while (m_videoTracks &&  m_videoTracks->length())
-        removeVideoTrack(m_videoTracks->lastItem());
+        removeVideoTrack(*m_videoTracks->lastItem());
 }
 
 RefPtr<TextTrack> HTMLMediaElement::addTextTrack(const String& kind, const String& label, const String& language, ExceptionCode& ec)
@@ -3690,7 +3691,7 @@ RefPtr<TextTrack> HTMLMediaElement::addTextTrack(const String& kind, const Strin
     // first append the track to the text track list.
 
     // 6. Add the new text track to the media element's list of text tracks.
-    addTextTrack(textTrack.ptr());
+    addTextTrack(textTrack.copyRef());
 
     // ... its text track readiness state to the text track loaded state ...
     textTrack->setReadinessState(TextTrack::Loaded);
@@ -3701,28 +3702,28 @@ RefPtr<TextTrack> HTMLMediaElement::addTextTrack(const String& kind, const Strin
     return WTFMove(textTrack);
 }
 
-AudioTrackList* HTMLMediaElement::audioTracks()
+AudioTrackList& HTMLMediaElement::audioTracks()
 {
     if (!m_audioTracks)
         m_audioTracks = AudioTrackList::create(this, ActiveDOMObject::scriptExecutionContext());
 
-    return m_audioTracks.get();
+    return *m_audioTracks;
 }
 
-TextTrackList* HTMLMediaElement::textTracks() 
+TextTrackList& HTMLMediaElement::textTracks()
 {
     if (!m_textTracks)
         m_textTracks = TextTrackList::create(this, ActiveDOMObject::scriptExecutionContext());
 
-    return m_textTracks.get();
+    return *m_textTracks;
 }
 
-VideoTrackList* HTMLMediaElement::videoTracks()
+VideoTrackList& HTMLMediaElement::videoTracks()
 {
     if (!m_videoTracks)
         m_videoTracks = VideoTrackList::create(this, ActiveDOMObject::scriptExecutionContext());
 
-    return m_videoTracks.get();
+    return *m_videoTracks;
 }
 
 void HTMLMediaElement::didAddTextTrack(HTMLTrackElement* trackElement)
@@ -3737,7 +3738,7 @@ void HTMLMediaElement::didAddTextTrack(HTMLTrackElement* trackElement)
     if (!textTrack)
         return;
     
-    addTextTrack(textTrack.release());
+    addTextTrack(textTrack.releaseNonNull());
     
     // Do not schedule the track loading until parsing finishes so we don't start before all tracks
     // in the markup have been added.
@@ -3772,7 +3773,7 @@ void HTMLMediaElement::didRemoveTextTrack(HTMLTrackElement* trackElement)
     // When a track element's parent element changes and the old parent was a media element, 
     // then the user agent must remove the track element's corresponding text track from the 
     // media element's list of text tracks.
-    removeTextTrack(textTrack.get());
+    removeTextTrack(*textTrack);
 
     size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get());
     if (index != notFound)
@@ -4002,24 +4003,24 @@ void HTMLMediaElement::visibilityDidChange()
 
 void HTMLMediaElement::setSelectedTextTrack(TextTrack* trackToSelect)
 {
-    TextTrackList* trackList = textTracks();
-    if (!trackList || !trackList->length())
+    TextTrackList& trackList = textTracks();
+    if (!trackList.length())
         return;
 
     if (trackToSelect != TextTrack::captionMenuOffItem() && trackToSelect != TextTrack::captionMenuAutomaticItem()) {
-        if (!trackList->contains(trackToSelect))
+        if (!trackToSelect || !trackList.contains(*trackToSelect))
             return;
         
-        for (int i = 0, length = trackList->length(); i < length; ++i) {
-            TextTrack* track = trackList->item(i);
-            if (!trackToSelect || track != trackToSelect)
-                track->setMode(TextTrack::Mode::Disabled);
+        for (int i = 0, length = trackList.length(); i < length; ++i) {
+            auto& track = *trackList.item(i);
+            if (&track != trackToSelect)
+                track.setMode(TextTrack::Mode::Disabled);
             else
-                track->setMode(TextTrack::Mode::Showing);
+                track.setMode(TextTrack::Mode::Showing);
         }
     } else if (trackToSelect == TextTrack::captionMenuOffItem()) {
-        for (int i = 0, length = trackList->length(); i < length; ++i)
-            trackList->item(i)->setMode(TextTrack::Mode::Disabled);
+        for (int i = 0, length = trackList.length(); i < length; ++i)
+            trackList.item(i)->setMode(TextTrack::Mode::Disabled);
     }
 
     if (!document().page())
index b431b0c..e52e879 100644 (file)
@@ -280,18 +280,18 @@ public:
 #if ENABLE(VIDEO_TRACK)
     RefPtr<TextTrack> addTextTrack(const String& kind, const String& label, const String& language, ExceptionCode&);
 
-    AudioTrackList* audioTracks();
-    TextTrackList* textTracks();
-    VideoTrackList* videoTracks();
+    AudioTrackList& audioTracks();
+    TextTrackList& textTracks();
+    VideoTrackList& videoTracks();
 
     CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
 
-    void addAudioTrack(PassRefPtr<AudioTrack>);
-    void addTextTrack(PassRefPtr<TextTrack>);
-    void addVideoTrack(PassRefPtr<VideoTrack>);
-    void removeAudioTrack(AudioTrack*);
-    void removeTextTrack(TextTrack*, bool scheduleEvent = true);
-    void removeVideoTrack(VideoTrack*);
+    void addAudioTrack(Ref<AudioTrack>&&);
+    void addTextTrack(Ref<TextTrack>&&);
+    void addVideoTrack(Ref<VideoTrack>&&);
+    void removeAudioTrack(AudioTrack&);
+    void removeTextTrack(TextTrack&, bool scheduleEvent = true);
+    void removeVideoTrack(VideoTrack&);
     void forgetResourceSpecificTracks();
     void closeCaptionTracksChanged();
     void notifyMediaPlayerOfTextTrackChanges();
index c9f4a49..2ef0e86 100644 (file)
@@ -734,8 +734,7 @@ void MediaControlClosedCaptionsTrackListElement::updateDisplay()
     if (!mediaElement)
         return;
 
-    TextTrackList* trackList = mediaElement->textTracks();
-    if (!trackList || !trackList->length())
+    if (!mediaElement->textTracks().length())
         return;
 
     rebuildTrackListMenu();
@@ -796,14 +795,14 @@ void MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu()
     if (!mediaElement)
         return;
 
-    TextTrackList* trackList = mediaElement->textTracks();
-    if (!trackList || !trackList->length())
+    TextTrackList& trackList = mediaElement->textTracks();
+    if (!trackList.length())
         return;
 
     if (!document().page())
         return;
     auto& captionPreferences = document().page()->group().captionPreferences();
-    Vector<RefPtr<TextTrack>> tracksForMenu = captionPreferences.sortedTrackListForMenu(trackList);
+    Vector<RefPtr<TextTrack>> tracksForMenu = captionPreferences.sortedTrackListForMenu(&trackList);
 
     auto captionsHeader = document().createElement(h3Tag, ASSERT_NO_EXCEPTION);
     captionsHeader->appendChild(document().createTextNode(textTrackSubtitlesText()));
index 5af4761..8c356f7 100644 (file)
@@ -90,7 +90,7 @@ AudioTrack::AudioTrack(AudioTrackClient* client, PassRefPtr<AudioTrackPrivate> t
 
 AudioTrack::~AudioTrack()
 {
-    m_private->setClient(0);
+    m_private->setClient(nullptr);
 }
 
 void AudioTrack::setPrivate(PassRefPtr<AudioTrackPrivate> trackPrivate)
@@ -101,7 +101,7 @@ void AudioTrack::setPrivate(PassRefPtr<AudioTrackPrivate> trackPrivate)
     if (m_private == trackPrivate)
         return;
 
-    m_private->setClient(0);
+    m_private->setClient(nullptr);
     m_private = trackPrivate;
     m_private->setClient(this);
 
@@ -111,20 +111,12 @@ void AudioTrack::setPrivate(PassRefPtr<AudioTrackPrivate> trackPrivate)
 
 bool AudioTrack::isValidKind(const AtomicString& value) const
 {
-    if (value == alternativeKeyword())
-        return true;
-    if (value == descriptionKeyword())
-        return true;
-    if (value == mainKeyword())
-        return true;
-    if (value == mainDescKeyword())
-        return true;
-    if (value == translationKeyword())
-        return true;
-    if (value == commentaryKeyword())
-        return true;
-
-    return false;
+    return value == alternativeKeyword()
+        || value == descriptionKeyword()
+        || value == mainKeyword()
+        || value == mainDescKeyword()
+        || value == translationKeyword()
+        || value == commentaryKeyword();
 }
 
 void AudioTrack::setEnabled(const bool enabled)
@@ -175,7 +167,7 @@ void AudioTrack::languageChanged(TrackPrivateBase* trackPrivate, const AtomicStr
 void AudioTrack::willRemove(TrackPrivateBase* trackPrivate)
 {
     ASSERT_UNUSED(trackPrivate, trackPrivate == m_private);
-    mediaElement()->removeAudioTrack(this);
+    mediaElement()->removeAudioTrack(*this);
 }
 
 void AudioTrack::updateKindFromPrivate()
index 2f39415..70589c2 100644 (file)
@@ -93,12 +93,10 @@ private:
     RefPtr<AudioTrackPrivate> m_private;
 };
 
-inline AudioTrack* toAudioTrack(TrackBase* track)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(track->type() == TrackBase::AudioTrack);
-    return static_cast<AudioTrack*>(track);
-}
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::AudioTrack)
+    static bool isType(const WebCore::TrackBase& track) { return track.type() == WebCore::TrackBase::AudioTrack; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 6aaa32e..f61ef94 100644 (file)
@@ -43,43 +43,40 @@ AudioTrackList::~AudioTrackList()
 {
 }
 
-void AudioTrackList::append(PassRefPtr<AudioTrack> prpTrack)
+void AudioTrackList::append(Ref<AudioTrack>&& track)
 {
-    RefPtr<AudioTrack> track = prpTrack;
-
     // Insert tracks in the media file order.
     size_t index = track->inbandTrackIndex();
     size_t insertionIndex;
     for (insertionIndex = 0; insertionIndex < m_inbandTracks.size(); ++insertionIndex) {
-        AudioTrack* otherTrack = static_cast<AudioTrack*>(m_inbandTracks[insertionIndex].get());
-        if (otherTrack->inbandTrackIndex() > index)
+        auto& otherTrack = downcast<AudioTrack>(*m_inbandTracks[insertionIndex]);
+        if (otherTrack.inbandTrackIndex() > index)
             break;
     }
-    m_inbandTracks.insert(insertionIndex, track);
+    m_inbandTracks.insert(insertionIndex, track.ptr());
 
 
     ASSERT(!track->mediaElement() || track->mediaElement() == mediaElement());
     track->setMediaElement(mediaElement());
 
-    scheduleAddTrackEvent(track.release());
+    scheduleAddTrackEvent(WTFMove(track));
 }
 
 AudioTrack* AudioTrackList::item(unsigned index) const
 {
     if (index < m_inbandTracks.size())
-        return toAudioTrack(m_inbandTracks[index].get());
-
-    return 0;
+        return downcast<AudioTrack>(m_inbandTracks[index].get());
+    return nullptr;
 }
 
 AudioTrack* AudioTrackList::getTrackById(const AtomicString& id) const
 {
     for (auto& inbandTrack : m_inbandTracks) {
-        AudioTrack* track = toAudioTrack(inbandTrack.get());
-        if (track->id() == id)
-            return track;
+        auto& track = downcast<AudioTrack>(*inbandTrack);
+        if (track.id() == id)
+            return &track;
     }
-    return 0;
+    return nullptr;
 }
 
 EventTargetInterface AudioTrackList::eventTargetInterface() const
index 583bff7..bf2213d 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     AudioTrack* item(unsigned index) const;
     AudioTrack* lastItem() const { return item(length() - 1); }
-    void append(PassRefPtr<AudioTrack>);
+    void append(Ref<AudioTrack>&&);
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const override;
index f062862..e770947 100644 (file)
@@ -189,7 +189,7 @@ void InbandTextTrack::willRemove(TrackPrivateBase* trackPrivate)
     if (!mediaElement())
         return;
     ASSERT_UNUSED(trackPrivate, trackPrivate == m_private);
-    mediaElement()->removeTextTrack(this);
+    mediaElement()->removeTextTrack(*this);
 }
 
 void InbandTextTrack::updateKindFromPrivate()
index 3188781..ab7a2ff 100644 (file)
@@ -193,7 +193,7 @@ void TextTrack::setKind(Kind newKind)
     // 4. Queue a task to fire a simple event named change at the TextTrackList object referenced by
     // the textTracks attribute on the HTMLMediaElement.
     if (mediaElement())
-        mediaElement()->textTracks()->scheduleChangeEvent();
+        mediaElement()->textTracks().scheduleChangeEvent();
 #endif
 
     if (m_client && oldKind != m_kind)
@@ -454,7 +454,7 @@ int TextTrack::trackIndex()
     ASSERT(m_mediaElement);
 
     if (m_trackIndex == invalidTrackIndex)
-        m_trackIndex = m_mediaElement->textTracks()->getTrackIndex(this);
+        m_trackIndex = m_mediaElement->textTracks().getTrackIndex(*this);
 
     return m_trackIndex;
 }
@@ -483,7 +483,7 @@ int TextTrack::trackIndexRelativeToRenderedTracks()
     ASSERT(m_mediaElement);
     
     if (m_renderedTrackIndex == invalidTrackIndex)
-        m_renderedTrackIndex = m_mediaElement->textTracks()->getTrackIndexRelativeToRenderedTracks(this);
+        m_renderedTrackIndex = m_mediaElement->textTracks().getTrackIndexRelativeToRenderedTracks(*this);
     
     return m_renderedTrackIndex;
 }
@@ -581,7 +581,7 @@ void TextTrack::setLanguage(const AtomicString& language)
     // 4. Queue a task to fire a simple event named change at the TextTrackList object referenced by
     // the textTracks attribute on the HTMLMediaElement.
     if (mediaElement())
-        mediaElement()->textTracks()->scheduleChangeEvent();
+        mediaElement()->textTracks().scheduleChangeEvent();
 }
 
 #endif
index 7818d22..4ede229 100644 (file)
@@ -173,12 +173,6 @@ private:
     bool m_hasBeenConfigured { false };
 };
 
-inline TextTrack* toTextTrack(TrackBase* track)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(track->type() == TrackBase::TextTrack);
-    return static_cast<TextTrack*>(track);
-}
-
 inline auto TextTrack::mode() const -> Mode
 {
     return m_mode;
@@ -215,4 +209,8 @@ inline void TextTrack::setKindForBindings(Kind kind)
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::TextTrack)
+    static bool isType(const WebCore::TrackBase& track) { return track.type() == WebCore::TrackBase::TextTrack; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index fdbbc49..0ecc0e8 100644 (file)
@@ -51,56 +51,51 @@ unsigned TextTrackList::length() const
     return m_addTrackTracks.size() + m_elementTracks.size() + m_inbandTracks.size();
 }
 
-int TextTrackList::getTrackIndex(TextTrack* textTrack)
+int TextTrackList::getTrackIndex(TextTrack& textTrack)
 {
     if (is<LoadableTextTrack>(textTrack))
-        return downcast<LoadableTextTrack>(*textTrack).trackElementIndex();
+        return downcast<LoadableTextTrack>(textTrack).trackElementIndex();
 
-    if (textTrack->trackType() == TextTrack::AddTrack)
-        return m_elementTracks.size() + m_addTrackTracks.find(textTrack);
+    if (textTrack.trackType() == TextTrack::AddTrack)
+        return m_elementTracks.size() + m_addTrackTracks.find(&textTrack);
 
-    if (textTrack->trackType() == TextTrack::InBand)
-        return m_elementTracks.size() + m_addTrackTracks.size() + m_inbandTracks.find(textTrack);
+    if (textTrack.trackType() == TextTrack::InBand)
+        return m_elementTracks.size() + m_addTrackTracks.size() + m_inbandTracks.find(&textTrack);
 
     ASSERT_NOT_REACHED();
 
     return -1;
 }
 
-int TextTrackList::getTrackIndexRelativeToRenderedTracks(TextTrack *textTrack)
+int TextTrackList::getTrackIndexRelativeToRenderedTracks(TextTracktextTrack)
 {
     // Calculate the "Let n be the number of text tracks whose text track mode is showing and that are in the media element's list of text tracks before track."
     int trackIndex = 0;
 
     for (auto& elementTrack : m_elementTracks) {
-        if (!toTextTrack(elementTrack.get())->isRendered())
+        if (!downcast<TextTrack>(*elementTrack).isRendered())
             continue;
-
-        if (elementTrack == textTrack)
+        if (elementTrack == &textTrack)
             return trackIndex;
         ++trackIndex;
     }
 
     for (auto& addTrack : m_addTrackTracks) {
-        if (!toTextTrack(addTrack.get())->isRendered())
+        if (!downcast<TextTrack>(*addTrack).isRendered())
             continue;
-
-        if (addTrack == textTrack)
+        if (addTrack == &textTrack)
             return trackIndex;
         ++trackIndex;
     }
 
     for (auto& inbandTrack : m_inbandTracks) {
-        if (!toTextTrack(inbandTrack.get())->isRendered())
+        if (!downcast<TextTrack>(*inbandTrack).isRendered())
             continue;
-
-        if (inbandTrack == textTrack)
+        if (inbandTrack == &textTrack)
             return trackIndex;
         ++trackIndex;
     }
-
     ASSERT_NOT_REACHED();
-
     return -1;
 }
 
@@ -114,17 +109,17 @@ TextTrack* TextTrackList::item(unsigned index) const
     // resource), in the order defined by the media resource's format specification.
 
     if (index < m_elementTracks.size())
-        return toTextTrack(m_elementTracks[index].get());
+        return downcast<TextTrack>(m_elementTracks[index].get());
 
     index -= m_elementTracks.size();
     if (index < m_addTrackTracks.size())
-        return toTextTrack(m_addTrackTracks[index].get());
+        return downcast<TextTrack>(m_addTrackTracks[index].get());
 
     index -= m_addTrackTracks.size();
     if (index < m_inbandTracks.size())
-        return toTextTrack(m_inbandTracks[index].get());
+        return downcast<TextTrack>(m_inbandTracks[index].get());
 
-    return 0;
+    return nullptr;
 }
 
 TextTrack* TextTrackList::getTrackById(const AtomicString& id)
@@ -134,110 +129,122 @@ TextTrack* TextTrackList::getTrackById(const AtomicString& id)
     // TextTrackList object whose id IDL attribute would return a value equal
     // to the value of the id argument.
     for (unsigned i = 0; i < length(); ++i) {
-        TextTrack* track = item(i);
-        if (track->id() == id)
-            return track;
+        auto& track = *item(i);
+        if (track.id() == id)
+            return &track;
     }
 
     // When no tracks match the given argument, the method must return null.
     return nullptr;
 }
 
-void TextTrackList::invalidateTrackIndexesAfterTrack(TextTrack* track)
+void TextTrackList::invalidateTrackIndexesAfterTrack(TextTrack& track)
 {
-    Vector<RefPtr<TrackBase>>* tracks = 0;
+    Vector<RefPtr<TrackBase>>* tracks = nullptr;
 
-    if (track->trackType() == TextTrack::TrackElement) {
+    switch (track.trackType()) {
+    case TextTrack::TrackElement:
         tracks = &m_elementTracks;
         for (auto& addTrack : m_addTrackTracks)
-            toTextTrack(addTrack.get())->invalidateTrackIndex();
+            downcast<TextTrack>(addTrack.get())->invalidateTrackIndex();
         for (auto& inbandTrack : m_inbandTracks)
-            toTextTrack(inbandTrack.get())->invalidateTrackIndex();
-    } else if (track->trackType() == TextTrack::AddTrack) {
+            downcast<TextTrack>(inbandTrack.get())->invalidateTrackIndex();
+        break;
+    case TextTrack::AddTrack:
         tracks = &m_addTrackTracks;
         for (auto& inbandTrack : m_inbandTracks)
-            toTextTrack(inbandTrack.get())->invalidateTrackIndex();
-    } else if (track->trackType() == TextTrack::InBand)
+            downcast<TextTrack>(inbandTrack.get())->invalidateTrackIndex();
+        break;
+    case TextTrack::InBand:
         tracks = &m_inbandTracks;
-    else
+        break;
+    default:
         ASSERT_NOT_REACHED();
+    }
 
-    size_t index = tracks->find(track);
+    size_t index = tracks->find(&track);
     if (index == notFound)
         return;
 
     for (size_t i = index; i < tracks->size(); ++i)
-        toTextTrack(tracks->at(index).get())->invalidateTrackIndex();
+        downcast<TextTrack>(*tracks->at(index)).invalidateTrackIndex();
 }
 
-void TextTrackList::append(PassRefPtr<TextTrack> prpTrack)
+void TextTrackList::append(Ref<TextTrack>&& track)
 {
-    RefPtr<TextTrack> track = prpTrack;
-
     if (track->trackType() == TextTrack::AddTrack)
-        m_addTrackTracks.append(track);
-    else if (is<LoadableTextTrack>(*track)) {
+        m_addTrackTracks.append(track.ptr());
+    else if (is<LoadableTextTrack>(track.get())) {
         // Insert tracks added for <track> element in tree order.
-        size_t index = downcast<LoadableTextTrack>(*track).trackElementIndex();
-        m_elementTracks.insert(index, track);
+        size_t index = downcast<LoadableTextTrack>(track.get()).trackElementIndex();
+        m_elementTracks.insert(index, track.ptr());
     } else if (track->trackType() == TextTrack::InBand) {
         // Insert tracks added for in-band in the media file order.
-        size_t index = static_cast<InbandTextTrack*>(track.get())->inbandTrackIndex();
-        m_inbandTracks.insert(index, track);
+        size_t index = downcast<InbandTextTrack>(track.get()).inbandTrackIndex();
+        m_inbandTracks.insert(index, track.ptr());
     } else
         ASSERT_NOT_REACHED();
 
-    invalidateTrackIndexesAfterTrack(track.get());
+    invalidateTrackIndexesAfterTrack(track);
 
     ASSERT(!track->mediaElement() || track->mediaElement() == mediaElement());
     track->setMediaElement(mediaElement());
 
-    scheduleAddTrackEvent(track.release());
+    scheduleAddTrackEvent(WTFMove(track));
 }
 
-void TextTrackList::remove(TrackBase* track, bool scheduleEvent)
+void TextTrackList::remove(TrackBase& track, bool scheduleEvent)
 {
-    TextTrack* textTrack = toTextTrack(track);
-    Vector<RefPtr<TrackBase>>* tracks = 0;
-    if (textTrack->trackType() == TextTrack::TrackElement)
+    auto& textTrack = downcast<TextTrack>(track);
+    Vector<RefPtr<TrackBase>>* tracks = nullptr;
+    switch (textTrack.trackType()) {
+    case TextTrack::TrackElement:
         tracks = &m_elementTracks;
-    else if (textTrack->trackType() == TextTrack::AddTrack)
+        break;
+    case TextTrack::AddTrack:
         tracks = &m_addTrackTracks;
-    else if (textTrack->trackType() == TextTrack::InBand)
+        break;
+    case TextTrack::InBand:
         tracks = &m_inbandTracks;
-    else
+        break;
+    default:
         ASSERT_NOT_REACHED();
+    }
 
-    size_t index = tracks->find(track);
+    size_t index = tracks->find(&track);
     if (index == notFound)
         return;
 
     invalidateTrackIndexesAfterTrack(textTrack);
 
-    ASSERT(!track->mediaElement() || track->mediaElement() == element());
-    track->setMediaElement(0);
+    ASSERT(!track.mediaElement() || track.mediaElement() == element());
+    track.setMediaElement(nullptr);
 
-    RefPtr<TrackBase> trackRef = (*tracks)[index];
+    Ref<TrackBase> trackRef = *(*tracks)[index];
     tracks->remove(index);
 
     if (scheduleEvent)
-        scheduleRemoveTrackEvent(trackRef.release());
+        scheduleRemoveTrackEvent(WTFMove(trackRef));
 }
 
-bool TextTrackList::contains(TrackBase* track) const
+bool TextTrackList::contains(TrackBase& track) const
 {
-    const Vector<RefPtr<TrackBase>>* tracks = 0;
-    TextTrack::TextTrackType type = toTextTrack(track)->trackType();
-    if (type == TextTrack::TrackElement)
+    const Vector<RefPtr<TrackBase>>* tracks = nullptr;
+    switch (downcast<TextTrack>(track).trackType()) {
+    case TextTrack::TrackElement:
         tracks = &m_elementTracks;
-    else if (type == TextTrack::AddTrack)
+        break;
+    case TextTrack::AddTrack:
         tracks = &m_addTrackTracks;
-    else if (type == TextTrack::InBand)
+        break;
+    case TextTrack::InBand:
         tracks = &m_inbandTracks;
-    else
+        break;
+    default:
         ASSERT_NOT_REACHED();
+    }
     
-    return tracks->find(track) != notFound;
+    return tracks->find(&track) != notFound;
 }
 
 EventTargetInterface TextTrackList::eventTargetInterface() const
index 041e218..9297855 100644 (file)
@@ -43,16 +43,16 @@ public:
     virtual ~TextTrackList();
 
     unsigned length() const override;
-    int getTrackIndex(TextTrack*);
-    int getTrackIndexRelativeToRenderedTracks(TextTrack*);
-    bool contains(TrackBase*) const override;
+    int getTrackIndex(TextTrack&);
+    int getTrackIndexRelativeToRenderedTracks(TextTrack&);
+    bool contains(TrackBase&) const override;
 
     TextTrack* item(unsigned index) const;
     TextTrack* getTrackById(const AtomicString&);
     TextTrack* lastItem() const { return item(length() - 1); }
 
-    void append(PassRefPtr<TextTrack>);
-    void remove(TrackBase*, bool scheduleEvent = true) override;
+    void append(Ref<TextTrack>&&);
+    void remove(TrackBase&, bool scheduleEvent = true) override;
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const override;
@@ -60,7 +60,7 @@ public:
 private:
     TextTrackList(HTMLMediaElement*, ScriptExecutionContext*);
 
-    void invalidateTrackIndexesAfterTrack(TextTrack*);
+    void invalidateTrackIndexesAfterTrack(TextTrack&);
 
     Vector<RefPtr<TrackBase>> m_addTrackTracks;
     Vector<RefPtr<TrackBase>> m_elementTracks;
index f75678f..d6c5e48 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "EventTarget.h"
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
index 815625f..434ed4c 100644 (file)
@@ -33,9 +33,9 @@
 
 namespace WebCore {
 
-TrackEvent::TrackEvent(const AtomicString& type, bool canBubble, bool cancelable, RefPtr<TrackBase>&& track)
+TrackEvent::TrackEvent(const AtomicString& type, bool canBubble, bool cancelable, Ref<TrackBase>&& track)
     : Event(type, canBubble, cancelable)
-    , m_track(track)
+    , m_track(WTFMove(track))
 {
 }
 
index 466d9f8..8aeffcd 100644 (file)
@@ -41,7 +41,7 @@ class TrackEvent final : public Event {
 public:
     virtual ~TrackEvent();
 
-    static Ref<TrackEvent> create(const AtomicString& type, bool canBubble, bool cancelable, RefPtr<TrackBase>&& track)
+    static Ref<TrackEvent> create(const AtomicString& type, bool canBubble, bool cancelable, Ref<TrackBase>&& track)
     {
         return adoptRef(*new TrackEvent(type, canBubble, cancelable, WTFMove(track)));
     }
@@ -56,7 +56,7 @@ public:
     TrackBase* track() const { return m_track.get(); }
 
 private:
-    TrackEvent(const AtomicString& type, bool canBubble, bool cancelable, RefPtr<TrackBase>&&);
+    TrackEvent(const AtomicString& type, bool canBubble, bool cancelable, Ref<TrackBase>&&);
     TrackEvent(const AtomicString& type, const TrackEventInit& initializer);
 
     RefPtr<TrackBase> m_track;
index f234671..dbed3aa 100644 (file)
@@ -58,33 +58,33 @@ unsigned TrackListBase::length() const
     return m_inbandTracks.size();
 }
 
-void TrackListBase::remove(TrackBase* track, bool scheduleEvent)
+void TrackListBase::remove(TrackBase& track, bool scheduleEvent)
 {
-    size_t index = m_inbandTracks.find(track);
+    size_t index = m_inbandTracks.find(&track);
     ASSERT(index != notFound);
 
-    ASSERT(track->mediaElement() == m_element);
-    track->setMediaElement(0);
+    ASSERT(track.mediaElement() == m_element);
+    track.setMediaElement(nullptr);
 
-    RefPtr<TrackBase> trackRef = m_inbandTracks[index];
+    Ref<TrackBase> trackRef = *m_inbandTracks[index];
 
     m_inbandTracks.remove(index);
 
     if (scheduleEvent)
-        scheduleRemoveTrackEvent(trackRef.release());
+        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)
 {
-    m_asyncEventQueue.enqueueEvent(TrackEvent::create(eventName, false, false, track));
+    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
     // ...
@@ -104,10 +104,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
@@ -131,7 +131,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()
index bd6410d..e2e18d0 100644 (file)
@@ -47,8 +47,8 @@ public:
     virtual ~TrackListBase();
 
     virtual unsigned length() const;
-    virtual bool contains(TrackBase*) const;
-    virtual void remove(TrackBase*, bool scheduleEvent = true);
+    virtual bool contains(TrackBase&) const;
+    virtual void remove(TrackBase&, bool scheduleEvent = true);
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const override = 0;
@@ -68,13 +68,13 @@ public:
 protected:
     TrackListBase(HTMLMediaElement*, ScriptExecutionContext*);
 
-    void scheduleAddTrackEvent(PassRefPtr<TrackBase>);
-    void scheduleRemoveTrackEvent(PassRefPtr<TrackBase>);
+    void scheduleAddTrackEvent(Ref<TrackBase>&&);
+    void scheduleRemoveTrackEvent(Ref<TrackBase>&&);
 
     Vector<RefPtr<TrackBase>> m_inbandTracks;
 
 private:
-    void scheduleTrackEvent(const AtomicString& eventName, PassRefPtr<TrackBase>);
+    void scheduleTrackEvent(const AtomicString& eventName, Ref<TrackBase>&&);
 
     // EventTarget
     void refEventTarget() final { ref(); }
index be29688..f80bc10 100644 (file)
@@ -175,7 +175,7 @@ void VideoTrack::languageChanged(TrackPrivateBase* trackPrivate, const AtomicStr
 void VideoTrack::willRemove(TrackPrivateBase* trackPrivate)
 {
     ASSERT_UNUSED(trackPrivate, trackPrivate == m_private);
-    mediaElement()->removeVideoTrack(this);
+    mediaElement()->removeVideoTrack(*this);
 }
 
 #if ENABLE(MEDIA_SOURCE)
@@ -197,7 +197,7 @@ void VideoTrack::setKind(const AtomicString& kind)
 
     // 4. Queue a task to fire a simple event named change at the VideoTrackList object referenced by
     // the videoTracks attribute on the HTMLMediaElement.
-    mediaElement()->videoTracks()->scheduleChangeEvent();
+    mediaElement()->videoTracks().scheduleChangeEvent();
 }
 
 void VideoTrack::setLanguage(const AtomicString& language)
@@ -217,8 +217,7 @@ void VideoTrack::setLanguage(const AtomicString& language)
 
     // 4. Queue a task to fire a simple event named change at the VideoTrackList object referenced by
     // the videoTracks attribute on the HTMLMediaElement.
-    if (mediaElement()->videoTracks())
-        mediaElement()->videoTracks()->scheduleChangeEvent();
+    mediaElement()->videoTracks().scheduleChangeEvent();
 }
 #endif
 
index 5c71f5f..e143c09 100644 (file)
@@ -102,12 +102,10 @@ private:
     RefPtr<VideoTrackPrivate> m_private;
 };
 
-inline VideoTrack* toVideoTrack(TrackBase* track)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(track->type() == TrackBase::VideoTrack);
-    return static_cast<VideoTrack*>(track);
-}
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::VideoTrack)
+    static bool isType(const WebCore::TrackBase& track) { return track.type() == WebCore::TrackBase::VideoTrack; }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 426b2a0..1599578 100644 (file)
@@ -43,54 +43,50 @@ VideoTrackList::~VideoTrackList()
 {
 }
 
-void VideoTrackList::append(PassRefPtr<VideoTrack> prpTrack)
+void VideoTrackList::append(Ref<VideoTrack>&& track)
 {
-    RefPtr<VideoTrack> track = prpTrack;
-
     // Insert tracks in the media file order.
     size_t index = track->inbandTrackIndex();
     size_t insertionIndex;
     for (insertionIndex = 0; insertionIndex < m_inbandTracks.size(); ++insertionIndex) {
-        VideoTrack* otherTrack = static_cast<VideoTrack*>(m_inbandTracks[insertionIndex].get());
-        if (otherTrack->inbandTrackIndex() > index)
+        auto& otherTrack = downcast<VideoTrack>(*m_inbandTracks[insertionIndex]);
+        if (otherTrack.inbandTrackIndex() > index)
             break;
     }
-    m_inbandTracks.insert(insertionIndex, track);
+    m_inbandTracks.insert(insertionIndex, track.ptr());
 
     ASSERT(!track->mediaElement() || track->mediaElement() == mediaElement());
     track->setMediaElement(mediaElement());
 
-    scheduleAddTrackEvent(track.release());
+    scheduleAddTrackEvent(WTFMove(track));
 }
 
 VideoTrack* VideoTrackList::item(unsigned index) const
 {
     if (index < m_inbandTracks.size())
-        return toVideoTrack(m_inbandTracks[index].get());
-
-    return 0;
+        return downcast<VideoTrack>(m_inbandTracks[index].get());
+    return nullptr;
 }
 
 VideoTrack* VideoTrackList::getTrackById(const AtomicString& id) const
 {
     for (auto& inbandTracks : m_inbandTracks) {
-        VideoTrack* track = toVideoTrack(inbandTracks.get());
-        if (track->id() == id)
-            return track;
+        auto& track = downcast<VideoTrack>(*inbandTracks);
+        if (track.id() == id)
+            return &track;
     }
-    return 0;
+    return nullptr;
 }
 
-long VideoTrackList::selectedIndex() const
+int VideoTrackList::selectedIndex() const
 {
     // 4.8.10.10.1 AudioTrackList and VideoTrackList objects
     // The VideoTrackList.selectedIndex attribute must return the index of the
     // currently selected track, if any. If the VideoTrackList object does not
     // currently represent any tracks, or if none of the tracks are selected,
     // it must instead return −1.
-    for (size_t i = 0; i < length(); ++i) {
-        VideoTrack* track = toVideoTrack(m_inbandTracks[i].get());
-        if (track->selected())
+    for (unsigned i = 0; i < length(); ++i) {
+        if (downcast<VideoTrack>(*m_inbandTracks[i]).selected())
             return i;
     }
     return -1;
index f6d9d45..bc4e050 100644 (file)
@@ -43,11 +43,11 @@ public:
     virtual ~VideoTrackList();
 
     VideoTrack* getTrackById(const AtomicString&) const;
-    long selectedIndex() const;
+    int selectedIndex() const;
 
     VideoTrack* item(unsigned) const;
     VideoTrack* lastItem() const { return item(length() - 1); }
-    void append(PassRefPtr<VideoTrack>);
+    void append(Ref<VideoTrack>&&);
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const override;
index 80d6b82..a4c6fa3 100644 (file)
@@ -259,15 +259,12 @@ void WebPlaybackSessionModelMediaElement::updateLegibleOptions()
     if (!m_mediaElement)
         return;
 
-    AudioTrackList* audioTrackList = m_mediaElement->audioTracks();
-    TextTrackList* trackList = m_mediaElement->textTracks();
-
-    if ((!trackList && !audioTrackList) || !m_mediaElement->document().page())
+    if (!m_mediaElement->document().page())
         return;
 
     auto& captionPreferences = m_mediaElement->document().page()->group().captionPreferences();
-    m_legibleTracksForMenu = captionPreferences.sortedTrackListForMenu(trackList);
-    m_audioTracksForMenu = captionPreferences.sortedTrackListForMenu(audioTrackList);
+    m_legibleTracksForMenu = captionPreferences.sortedTrackListForMenu(&m_mediaElement->textTracks());
+    m_audioTracksForMenu = captionPreferences.sortedTrackListForMenu(&m_mediaElement->audioTracks());
 
     m_playbackSessionInterface->setAudioMediaSelectionOptions(audioMediaSelectionOptions(), audioMediaSelectedIndex());
     m_playbackSessionInterface->setLegibleMediaSelectionOptions(legibleMediaSelectionOptions(), legibleMediaSelectedIndex());