Commit be820b8e authored by dcheng's avatar dcheng Committed by Commit bot

Use the standard downcasting macros for downcasting TextTrack objects.

Though clusterfuzz uses ubsan now, which should catch bad casts, using
these macros is still the typical convention for Blink code that needs
to downcast.

BUG=none

Review-Url: https://codereview.chromium.org/2617433002
Cr-Commit-Position: refs/heads/master@{#441453}
parent 74ec606e
......@@ -2687,10 +2687,9 @@ void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack) {
if (!m_textTracks)
return;
// This cast is safe because we created the InbandTextTrack with the
// WebInbandTextTrack passed to mediaPlayerDidAddTextTrack.
InbandTextTrack* textTrack =
static_cast<InbandTextTrack*>(webTrack->client());
// This cast is safe because InbandTextTrack is the only concrete
// implementation of WebInbandTextTrackClient.
InbandTextTrack* textTrack = toInbandTextTrack(webTrack->client());
if (!textTrack)
return;
......
......@@ -327,7 +327,7 @@ void CueTimeline::updateActiveCues(double movieTime) {
// simple event named cuechange at the track element as well.
if (track->trackType() == TextTrack::TrackElement) {
HTMLTrackElement* trackElement =
static_cast<LoadableTextTrack*>(track.get())->trackElement();
toLoadableTextTrack(track.get())->trackElement();
DCHECK(trackElement);
mediaElement.scheduleEvent(
createEventWithTarget(EventTypeNames::cuechange, trackElement));
......
......@@ -29,7 +29,7 @@
#include "core/html/track/TextTrack.h"
#include "platform/heap/Handle.h"
#include "public/platform/WebInbandTextTrackClient.h"
#include "wtf/RefPtr.h"
#include "wtf/Assertions.h"
namespace blink {
class WebInbandTextTrack;
......@@ -47,7 +47,7 @@ class InbandTextTrack final : public TextTrack,
void setTrackList(TextTrackList*) override;
private:
InbandTextTrack(WebInbandTextTrack*);
explicit InbandTextTrack(WebInbandTextTrack*);
void addWebVTTCue(double,
double,
......@@ -58,6 +58,10 @@ class InbandTextTrack final : public TextTrack,
WebInbandTextTrack* m_webTrack;
};
// All concrete implementations of WebInbandTextTrackClient are
// InbandTextTracks.
DEFINE_TYPE_CASTS(InbandTextTrack, WebInbandTextTrackClient, track, true, true);
} // namespace blink
#endif
......@@ -28,7 +28,7 @@
#include "core/html/track/TextTrack.h"
#include "platform/heap/Handle.h"
#include "wtf/PassRefPtr.h"
#include "wtf/Assertions.h"
namespace blink {
......@@ -60,6 +60,12 @@ class LoadableTextTrack final : public TextTrack {
Member<HTMLTrackElement> m_trackElement;
};
DEFINE_TYPE_CASTS(LoadableTextTrack,
TextTrack,
track,
track->trackType() == TextTrack::TrackElement,
track.trackType() == TextTrack::TrackElement);
} // namespace blink
#endif // LoadableTextTrack_h
......@@ -47,7 +47,7 @@ unsigned TextTrackList::length() const {
int TextTrackList::getTrackIndex(TextTrack* textTrack) {
if (textTrack->trackType() == TextTrack::TrackElement)
return static_cast<LoadableTextTrack*>(textTrack)->trackElementIndex();
return toLoadableTextTrack(textTrack)->trackElementIndex();
if (textTrack->trackType() == TextTrack::AddTrack)
return m_elementTracks.size() + m_addTrackTracks.find(textTrack);
......@@ -171,7 +171,7 @@ void TextTrackList::append(TextTrack* track) {
m_addTrackTracks.push_back(TraceWrapperMember<TextTrack>(this, track));
} else if (track->trackType() == TextTrack::TrackElement) {
// Insert tracks added for <track> element in tree order.
size_t index = static_cast<LoadableTextTrack*>(track)->trackElementIndex();
size_t index = toLoadableTextTrack(track)->trackElementIndex();
m_elementTracks.insert(index, TraceWrapperMember<TextTrack>(this, track));
} else if (track->trackType() == TextTrack::InBand) {
m_inbandTracks.push_back(TraceWrapperMember<TextTrack>(this, track));
......
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