Diff
Modified: trunk/LayoutTests/ChangeLog (207906 => 207907)
--- trunk/LayoutTests/ChangeLog 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/LayoutTests/ChangeLog 2016-10-26 19:27:20 UTC (rev 207907)
@@ -1,3 +1,15 @@
+2016-10-26 Chris Dumez <[email protected]>
+
+ First parameter to TextTrack.addCue() / removeCue() should not be nullable
+ https://bugs.webkit.org/show_bug.cgi?id=164020
+
+ Reviewed by Eric Carlson.
+
+ Add layout test coverage.
+
+ * media/track/texttrack-addCue-null-expected.txt: Added.
+ * media/track/texttrack-addCue-null.html: Added.
+
2016-10-26 Antoine Quint <[email protected]>
[Modern Media Controls] Media Controller: elapsed and remaining time support
Added: trunk/LayoutTests/media/track/texttrack-addCue-null-expected.txt (0 => 207907)
--- trunk/LayoutTests/media/track/texttrack-addCue-null-expected.txt (rev 0)
+++ trunk/LayoutTests/media/track/texttrack-addCue-null-expected.txt 2016-10-26 19:27:20 UTC (rev 207907)
@@ -0,0 +1,11 @@
+Tests that the parameter to TextTrack.addCue() / removeCue() is not nullable.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS track.addCue(null) threw exception TypeError: Argument 1 ('cue') to TextTrack.addCue must be an instance of TextTrackCue.
+PASS track.removeCue(null) threw exception TypeError: Argument 1 ('cue') to TextTrack.removeCue must be an instance of TextTrackCue.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/media/track/texttrack-addCue-null.html (0 => 207907)
--- trunk/LayoutTests/media/track/texttrack-addCue-null.html (rev 0)
+++ trunk/LayoutTests/media/track/texttrack-addCue-null.html 2016-10-26 19:27:20 UTC (rev 207907)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that the parameter to TextTrack.addCue() / removeCue() is not nullable.");
+var video = document.createElement('video');
+var track = video.addTextTrack('subtitles');
+
+shouldThrowErrorName("track.addCue(null)", "TypeError");
+shouldThrowErrorName("track.removeCue(null)", "TypeError");
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (207906 => 207907)
--- trunk/Source/WebCore/ChangeLog 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/ChangeLog 2016-10-26 19:27:20 UTC (rev 207907)
@@ -1,3 +1,32 @@
+2016-10-26 Chris Dumez <[email protected]>
+
+ First parameter to TextTrack.addCue() / removeCue() should not be nullable
+ https://bugs.webkit.org/show_bug.cgi?id=164020
+
+ Reviewed by Eric Carlson.
+
+ First parameter to TextTrack.addCue() / removeCue() should not be nullable:
+ - https://html.spec.whatwg.org/#texttrack
+
+ Firefox and Chrome agree with the specification.
+
+ Test: media/track/texttrack-addCue-null.html
+
+ * html/track/InbandDataTextTrack.cpp:
+ (WebCore::InbandDataTextTrack::removeDataCue):
+ (WebCore::InbandDataTextTrack::removeCue):
+ * html/track/InbandDataTextTrack.h:
+ * html/track/InbandGenericTextTrack.cpp:
+ (WebCore::InbandGenericTextTrack::addGenericCue):
+ (WebCore::InbandGenericTextTrack::removeGenericCue):
+ (WebCore::InbandGenericTextTrack::removeCue):
+ * html/track/InbandGenericTextTrack.h:
+ * html/track/TextTrack.cpp:
+ (WebCore::TextTrack::addCue):
+ (WebCore::TextTrack::removeCue):
+ * html/track/TextTrack.h:
+ * html/track/TextTrack.idl:
+
2016-10-26 Antoine Quint <[email protected]>
[Modern Media Controls] Media Controller: elapsed and remaining time support
Modified: trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp (207906 => 207907)
--- trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp 2016-10-26 19:27:20 UTC (rev 207907)
@@ -114,18 +114,17 @@
if (iter == m_incompleteCueMap.end())
return;
- RefPtr<DataCue> cue = iter->value;
- if (cue) {
+ if (RefPtr<DataCue> cue = iter->value) {
LOG(Media, "InbandDataTextTrack::removeDataCue removing cue: start=%s, end=%s\n", toString(cue->startTime()).utf8().data(), toString(cue->endTime()).utf8().data());
- removeCue(cue.get());
+ removeCue(*cue);
}
}
-ExceptionOr<void> InbandDataTextTrack::removeCue(TextTrackCue* cue)
+ExceptionOr<void> InbandDataTextTrack::removeCue(TextTrackCue& cue)
{
- ASSERT(cue->cueType() == TextTrackCue::Data);
+ ASSERT(cue.cueType() == TextTrackCue::Data);
- m_incompleteCueMap.remove(const_cast<SerializedPlatformRepresentation*>(toDataCue(cue)->platformValue()));
+ m_incompleteCueMap.remove(const_cast<SerializedPlatformRepresentation*>(toDataCue(&cue)->platformValue()));
return InbandTextTrack::removeCue(cue);
}
Modified: trunk/Source/WebCore/html/track/InbandDataTextTrack.h (207906 => 207907)
--- trunk/Source/WebCore/html/track/InbandDataTextTrack.h 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/InbandDataTextTrack.h 2016-10-26 19:27:20 UTC (rev 207907)
@@ -50,7 +50,7 @@
void addDataCue(InbandTextTrackPrivate*, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation>, const String&) final;
void updateDataCue(InbandTextTrackPrivate*, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation>) final;
void removeDataCue(InbandTextTrackPrivate*, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation>) final;
- ExceptionOr<void> removeCue(TextTrackCue*) final;
+ ExceptionOr<void> removeCue(TextTrackCue&) final;
HashMap<RefPtr<SerializedPlatformRepresentation>, RefPtr<DataCue>> m_incompleteCueMap;
#endif
Modified: trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp (207906 => 207907)
--- trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp 2016-10-26 19:27:20 UTC (rev 207907)
@@ -127,9 +127,9 @@
if (m_cueMap.find(*cueData))
return;
- RefPtr<TextTrackCueGeneric> cue = TextTrackCueGeneric::create(*scriptExecutionContext(), cueData->startTime(), cueData->endTime(), cueData->content());
- updateCueFromCueData(cue.get(), cueData.get());
- if (hasCue(cue.get(), TextTrackCue::IgnoreDuration)) {
+ auto cue = TextTrackCueGeneric::create(*scriptExecutionContext(), cueData->startTime(), cueData->endTime(), cueData->content());
+ updateCueFromCueData(cue.ptr(), cueData.get());
+ if (hasCue(cue.ptr(), TextTrackCue::IgnoreDuration)) {
LOG(Media, "InbandGenericTextTrack::addGenericCue ignoring already added cue: start=%s, end=%s, content=\"%s\"\n", toString(cueData->startTime()).utf8().data(), toString(cueData->endTime()).utf8().data(), cueData->content().utf8().data());
return;
}
@@ -137,7 +137,7 @@
LOG(Media, "InbandGenericTextTrack::addGenericCue added cue: start=%.2f, end=%.2f, content=\"%s\"\n", cueData->startTime().toDouble(), cueData->endTime().toDouble(), cueData->content().utf8().data());
if (cueData->status() != GenericCueData::Complete)
- m_cueMap.add(*cueData, *cue);
+ m_cueMap.add(*cueData, cue);
addCue(WTFMove(cue));
}
@@ -159,17 +159,17 @@
auto* cue = m_cueMap.find(*cueData);
if (cue) {
LOG(Media, "InbandGenericTextTrack::removeGenericCue removing cue: start=%s, end=%s, content=\"%s\"\n", toString(cueData->startTime()).utf8().data(), toString(cueData->endTime()).utf8().data(), cueData->content().utf8().data());
- removeCue(cue);
+ removeCue(*cue);
} else {
LOG(Media, "InbandGenericTextTrack::removeGenericCue UNABLE to find cue: start=%.2f, end=%.2f, content=\"%s\"\n", cueData->startTime().toDouble(), cueData->endTime().toDouble(), cueData->content().utf8().data());
}
}
-ExceptionOr<void> InbandGenericTextTrack::removeCue(TextTrackCue* cue)
+ExceptionOr<void> InbandGenericTextTrack::removeCue(TextTrackCue& cue)
{
auto result = TextTrack::removeCue(cue);
- if (!result.hasException() && cue)
- m_cueMap.remove(*cue);
+ if (!result.hasException())
+ m_cueMap.remove(cue);
return result;
}
Modified: trunk/Source/WebCore/html/track/InbandGenericTextTrack.h (207906 => 207907)
--- trunk/Source/WebCore/html/track/InbandGenericTextTrack.h 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/InbandGenericTextTrack.h 2016-10-26 19:27:20 UTC (rev 207907)
@@ -65,7 +65,7 @@
void addGenericCue(InbandTextTrackPrivate*, PassRefPtr<GenericCueData>) final;
void updateGenericCue(InbandTextTrackPrivate*, GenericCueData*) final;
void removeGenericCue(InbandTextTrackPrivate*, GenericCueData*) final;
- ExceptionOr<void> removeCue(TextTrackCue*) final;
+ ExceptionOr<void> removeCue(TextTrackCue&) final;
PassRefPtr<TextTrackCueGeneric> createCue(PassRefPtr<GenericCueData>);
void updateCueFromCueData(TextTrackCueGeneric*, GenericCueData*);
Modified: trunk/Source/WebCore/html/track/TextTrack.cpp (207906 => 207907)
--- trunk/Source/WebCore/html/track/TextTrack.cpp 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/TextTrack.cpp 2016-10-26 19:27:20 UTC (rev 207907)
@@ -290,11 +290,8 @@
return m_cues->activeCues();
}
-ExceptionOr<void> TextTrack::addCue(RefPtr<TextTrackCue>&& cue)
+ExceptionOr<void> TextTrack::addCue(Ref<TextTrackCue>&& cue)
{
- if (!cue)
- return { };
-
// 4.7.10.12.6 Text tracks exposing in-band metadata
// The UA will use DataCue to expose only text track cue objects that belong to a text track that has a text
// track kind of metadata.
@@ -320,19 +317,16 @@
// 2. Add cue to the method's TextTrack object's text track's text track list of cues.
cue->setTrack(this);
- ensureTextTrackCueList().add(cue);
+ ensureTextTrackCueList().add(cue.ptr());
if (m_client)
- m_client->textTrackAddCue(this, *cue);
+ m_client->textTrackAddCue(this, cue);
return { };
}
-ExceptionOr<void> TextTrack::removeCue(TextTrackCue* cue)
+ExceptionOr<void> TextTrack::removeCue(TextTrackCue& cue)
{
- if (!cue)
- return { };
-
// 4.8.10.12.5 Text track API
// The removeCue(cue) method of TextTrack objects, when invoked, must run the following steps:
@@ -339,16 +333,16 @@
// 1. If the given cue is not currently listed in the method's TextTrack
// object's text track's text track list of cues, then throw a NotFoundError exception.
- if (cue->track() != this)
+ if (cue.track() != this)
return Exception { NOT_FOUND_ERR };
// 2. Remove cue from the method's TextTrack object's text track's text track list of cues.
- if (!m_cues || !m_cues->remove(cue))
+ if (!m_cues || !m_cues->remove(&cue))
return Exception { INVALID_STATE_ERR };
- cue->setTrack(nullptr);
+ cue.setTrack(nullptr);
if (m_client)
- m_client->textTrackRemoveCue(this, *cue);
+ m_client->textTrackRemoveCue(this, cue);
return { };
}
Modified: trunk/Source/WebCore/html/track/TextTrack.h (207906 => 207907)
--- trunk/Source/WebCore/html/track/TextTrack.h 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/TextTrack.h 2016-10-26 19:27:20 UTC (rev 207907)
@@ -100,8 +100,8 @@
void clearClient() override { m_client = nullptr; }
TextTrackClient* client() { return m_client; }
- ExceptionOr<void> addCue(RefPtr<TextTrackCue>&&);
- virtual ExceptionOr<void> removeCue(TextTrackCue*);
+ ExceptionOr<void> addCue(Ref<TextTrackCue>&&);
+ virtual ExceptionOr<void> removeCue(TextTrackCue&);
bool hasCue(TextTrackCue*, TextTrackCue::CueMatchRules = TextTrackCue::MatchAllFields);
Modified: trunk/Source/WebCore/html/track/TextTrack.idl (207906 => 207907)
--- trunk/Source/WebCore/html/track/TextTrack.idl 2016-10-26 19:23:55 UTC (rev 207906)
+++ trunk/Source/WebCore/html/track/TextTrack.idl 2016-10-26 19:27:20 UTC (rev 207907)
@@ -43,9 +43,8 @@
readonly attribute TextTrackCueList? cues;
readonly attribute TextTrackCueList? activeCues;
- // FIXME: cue parameter should not be nullable in addCue and removeCue.
- [MayThrowException] void addCue(TextTrackCue? cue);
- [MayThrowException] void removeCue(TextTrackCue? cue);
+ [MayThrowException] void addCue(TextTrackCue cue);
+ [MayThrowException] void removeCue(TextTrackCue cue);
attribute EventHandler oncuechange;