Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Unified Diff: Source/core/html/track/WebVTTParser.cpp

Issue 59453002: Add a flushing mechanism for the WebVTTParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Even more binary Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/track/WebVTTParser.h ('k') | Source/core/loader/TextTrackLoader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/track/WebVTTParser.cpp
diff --git a/Source/core/html/track/WebVTTParser.cpp b/Source/core/html/track/WebVTTParser.cpp
index 00d026ef9438332e5ee4d329440f1235e372ced8..98de87c2ece687ec98ce5e3a7927be7dccc1d623 100644
--- a/Source/core/html/track/WebVTTParser.cpp
+++ b/Source/core/html/track/WebVTTParser.cpp
@@ -135,7 +135,18 @@ void WebVTTParser::getNewRegions(Vector<RefPtr<VTTRegion> >& outputRegions)
void WebVTTParser::parseBytes(const char* data, unsigned length)
{
String textData = m_decoder->decode(data, length);
+ parse(textData);
+}
+
+void WebVTTParser::flush()
+{
+ String textData = m_decoder->flush();
+ parse(textData);
+ flushPendingCue();
+}
+void WebVTTParser::parse(const String& textData)
+{
// 4.8.10.13.3 WHATWG WebVTT Parser algorithm.
// 1-3 - Initial setup.
unsigned position = 0;
@@ -191,7 +202,7 @@ void WebVTTParser::parseBytes(const char* data, unsigned length)
case CueText:
// 41-53 - Collect the cue text, create a cue, and add it to the output.
- m_state = collectCueText(line, position >= textData.length());
+ m_state = collectCueText(line);
break;
case BadCue:
@@ -202,6 +213,13 @@ void WebVTTParser::parseBytes(const char* data, unsigned length)
}
}
+void WebVTTParser::flushPendingCue()
+{
+ // If we're in the CueText state when we run out of data, we emit the pending cue.
+ if (m_state == CueText)
+ createNewCue();
+}
+
bool WebVTTParser::hasRequiredFileIdentifier(const String& line)
{
// A WebVTT file identifier consists of an optional BOM character,
@@ -281,7 +299,7 @@ WebVTTParser::ParseState WebVTTParser::collectTimingsAndSettings(const String& l
return CueText;
}
-WebVTTParser::ParseState WebVTTParser::collectCueText(const String& line, bool isAtEnd)
+WebVTTParser::ParseState WebVTTParser::collectCueText(const String& line)
{
if (line.isEmpty()) {
createNewCue();
@@ -291,9 +309,6 @@ WebVTTParser::ParseState WebVTTParser::collectCueText(const String& line, bool i
m_currentContent.append("\n");
m_currentContent.append(line);
- if (isAtEnd)
- createNewCue();
-
return CueText;
}
« no previous file with comments | « Source/core/html/track/WebVTTParser.h ('k') | Source/core/loader/TextTrackLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698