OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 } | 55 } |
56 | 56 |
57 String WebVTTParser::collectWord(const String& input, unsigned* position) | 57 String WebVTTParser::collectWord(const String& input, unsigned* position) |
58 { | 58 { |
59 StringBuilder string; | 59 StringBuilder string; |
60 while (*position < input.length() && !isASpace(input[*position])) | 60 while (*position < input.length() && !isASpace(input[*position])) |
61 string.append(input[(*position)++]); | 61 string.append(input[(*position)++]); |
62 return string.toString(); | 62 return string.toString(); |
63 } | 63 } |
64 | 64 |
65 #if ENABLE(WEBVTT_REGIONS) | |
66 float WebVTTParser::parseFloatPercentageValue(const String& value, bool& isValid Setting) | 65 float WebVTTParser::parseFloatPercentageValue(const String& value, bool& isValid Setting) |
67 { | 66 { |
68 // '%' must be present and at the end of the setting value. | 67 // '%' must be present and at the end of the setting value. |
69 if (value.find('%', 1) != value.length() - 1) { | 68 if (value.find('%', 1) != value.length() - 1) { |
70 isValidSetting = false; | 69 isValidSetting = false; |
71 return 0; | 70 return 0; |
72 } | 71 } |
73 | 72 |
74 unsigned position = 0; | 73 unsigned position = 0; |
75 | 74 |
(...skipping 27 matching lines...) Expand all Loading... | |
103 | 102 |
104 bool isFirstValueValid; | 103 bool isFirstValueValid; |
105 float firstCoord = parseFloatPercentageValue(value.substring(0, delimiterOff set), isFirstValueValid); | 104 float firstCoord = parseFloatPercentageValue(value.substring(0, delimiterOff set), isFirstValueValid); |
106 | 105 |
107 bool isSecondValueValid; | 106 bool isSecondValueValid; |
108 float secondCoord = parseFloatPercentageValue(value.substring(delimiterOffse t + 1, value.length() - 1), isSecondValueValid); | 107 float secondCoord = parseFloatPercentageValue(value.substring(delimiterOffse t + 1, value.length() - 1), isSecondValueValid); |
109 | 108 |
110 isValidSetting = isFirstValueValid && isSecondValueValid; | 109 isValidSetting = isFirstValueValid && isSecondValueValid; |
111 return FloatPoint(firstCoord, secondCoord); | 110 return FloatPoint(firstCoord, secondCoord); |
112 } | 111 } |
113 #endif | |
114 | 112 |
115 WebVTTParser::WebVTTParser(WebVTTParserClient* client, ScriptExecutionContext* c ontext) | 113 WebVTTParser::WebVTTParser(WebVTTParserClient* client, ScriptExecutionContext* c ontext) |
116 : m_scriptExecutionContext(context) | 114 : m_scriptExecutionContext(context) |
117 , m_state(Initial) | 115 , m_state(Initial) |
118 , m_currentStartTime(0) | 116 , m_currentStartTime(0) |
119 , m_currentEndTime(0) | 117 , m_currentEndTime(0) |
120 , m_tokenizer(WebVTTTokenizer::create()) | 118 , m_tokenizer(WebVTTTokenizer::create()) |
121 , m_client(client) | 119 , m_client(client) |
122 { | 120 { |
123 } | 121 } |
124 | 122 |
125 void WebVTTParser::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues) | 123 void WebVTTParser::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues) |
126 { | 124 { |
127 outputCues = m_cuelist; | 125 outputCues = m_cuelist; |
128 m_cuelist.clear(); | 126 m_cuelist.clear(); |
129 } | 127 } |
130 | 128 |
131 #if ENABLE(WEBVTT_REGIONS) | |
132 void WebVTTParser::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegions ) | 129 void WebVTTParser::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegions ) |
133 { | 130 { |
134 outputRegions = m_regionList; | 131 outputRegions = m_regionList; |
135 m_regionList.clear(); | 132 m_regionList.clear(); |
136 } | 133 } |
137 #endif | |
138 | 134 |
139 void WebVTTParser::parseBytes(const char* data, unsigned length) | 135 void WebVTTParser::parseBytes(const char* data, unsigned length) |
140 { | 136 { |
141 // 4.8.10.13.3 WHATWG WebVTT Parser algorithm. | 137 // 4.8.10.13.3 WHATWG WebVTT Parser algorithm. |
142 // 1-3 - Initial setup. | 138 // 1-3 - Initial setup. |
143 unsigned position = 0; | 139 unsigned position = 0; |
144 | 140 |
145 while (position < length) { | 141 while (position < length) { |
146 String line = collectNextLine(data, length, &position); | 142 String line = collectNextLine(data, length, &position); |
147 | 143 |
(...skipping 10 matching lines...) Expand all Loading... | |
158 m_client->fileFailedToParse(); | 154 m_client->fileFailedToParse(); |
159 return; | 155 return; |
160 } | 156 } |
161 | 157 |
162 m_state = Header; | 158 m_state = Header; |
163 m_identifierData.clear(); | 159 m_identifierData.clear(); |
164 break; | 160 break; |
165 | 161 |
166 case Header: | 162 case Header: |
167 // 13-18 - Allow a header (comment area) under the WEBVTT line. | 163 // 13-18 - Allow a header (comment area) under the WEBVTT line. |
168 #if ENABLE(WEBVTT_REGIONS) | |
169 if (line.isEmpty()) { | 164 if (line.isEmpty()) { |
170 if (m_client && m_regionList.size()) | 165 if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && m_client & & m_regionList.size()) |
acolwell GONE FROM CHROMIUM
2013/10/04 19:48:20
nit: Can m_regionList.size() be > 0 if the flag is
vcarbune.chromium
2013/10/08 18:07:38
Done.
| |
171 m_client->newRegionsParsed(); | 166 m_client->newRegionsParsed(); |
172 | 167 |
173 m_state = Id; | 168 m_state = Id; |
174 break; | 169 break; |
175 } | 170 } |
176 collectHeader(line); | 171 if (RuntimeEnabledFeatures::webVTTRegionsEnabled()) |
acolwell GONE FROM CHROMIUM
2013/10/04 19:48:20
nit: Do you really need a flag check here? It seem
vcarbune.chromium
2013/10/08 18:07:38
I moved the flag check and inside the function and
| |
172 collectHeader(line); | |
177 | 173 |
178 break; | 174 break; |
179 | 175 |
180 case Metadata: | 176 case Metadata: |
181 #endif | |
182 if (line.isEmpty()) | 177 if (line.isEmpty()) |
183 m_state = Id; | 178 m_state = Id; |
184 break; | 179 break; |
185 | 180 |
186 case Id: | 181 case Id: |
187 // 19-29 - Allow any number of line terminators, then initialize new cue values. | 182 // 19-29 - Allow any number of line terminators, then initialize new cue values. |
188 if (line.isEmpty()) | 183 if (line.isEmpty()) |
189 break; | 184 break; |
190 resetCueValues(); | 185 resetCueValues(); |
191 | 186 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 if (line.length() < fileIdentifierLength) | 219 if (line.length() < fileIdentifierLength) |
225 return false; | 220 return false; |
226 if (line.substring(0, fileIdentifierLength) != "WEBVTT") | 221 if (line.substring(0, fileIdentifierLength) != "WEBVTT") |
227 return false; | 222 return false; |
228 if (line.length() > fileIdentifierLength && line[fileIdentifierLength] != ' ' && line[fileIdentifierLength] != '\t') | 223 if (line.length() > fileIdentifierLength && line[fileIdentifierLength] != ' ' && line[fileIdentifierLength] != '\t') |
229 return false; | 224 return false; |
230 | 225 |
231 return true; | 226 return true; |
232 } | 227 } |
233 | 228 |
234 #if ENABLE(WEBVTT_REGIONS) | |
235 void WebVTTParser::collectHeader(const String& line) | 229 void WebVTTParser::collectHeader(const String& line) |
236 { | 230 { |
237 // 4.1 Extension of WebVTT header parsing (11 - 15) | 231 // 4.1 Extension of WebVTT header parsing (11 - 15) |
238 DEFINE_STATIC_LOCAL(const AtomicString, regionHeaderName, ("Region", AtomicS tring::ConstructFromLiteral)); | 232 DEFINE_STATIC_LOCAL(const AtomicString, regionHeaderName, ("Region", AtomicS tring::ConstructFromLiteral)); |
239 | 233 |
240 // 15.4 If line contains the character ":" (A U+003A COLON), then set metada ta's | 234 // 15.4 If line contains the character ":" (A U+003A COLON), then set metada ta's |
241 // name to the substring of line before the first ":" character and | 235 // name to the substring of line before the first ":" character and |
242 // metadata's value to the substring after this character. | 236 // metadata's value to the substring after this character. |
243 if (!line.contains(":")) | 237 if (!line.contains(":")) |
244 return; | 238 return; |
245 | 239 |
246 unsigned colonPosition = line.find(":"); | 240 unsigned colonPosition = line.find(":"); |
247 m_currentHeaderName = line.substring(0, colonPosition); | 241 m_currentHeaderName = line.substring(0, colonPosition); |
248 | 242 |
249 // 15.5 If metadata's name equals "Region": | 243 // 15.5 If metadata's name equals "Region": |
250 if (m_currentHeaderName == regionHeaderName) { | 244 if (m_currentHeaderName == regionHeaderName) { |
251 m_currentHeaderValue = line.substring(colonPosition + 1, line.length() - 1); | 245 m_currentHeaderValue = line.substring(colonPosition + 1, line.length() - 1); |
252 // 15.5.1 - 15.5.8 Region creation: Let region be a new text track regio n [...] | 246 // 15.5.1 - 15.5.8 Region creation: Let region be a new text track regio n [...] |
253 createNewRegion(); | 247 createNewRegion(); |
254 } | 248 } |
255 } | 249 } |
256 #endif | |
257 | 250 |
258 WebVTTParser::ParseState WebVTTParser::collectCueId(const String& line) | 251 WebVTTParser::ParseState WebVTTParser::collectCueId(const String& line) |
259 { | 252 { |
260 if (line.contains("-->")) | 253 if (line.contains("-->")) |
261 return collectTimingsAndSettings(line); | 254 return collectTimingsAndSettings(line); |
262 m_currentId = line; | 255 m_currentId = line; |
263 return TimingsAndSettings; | 256 return TimingsAndSettings; |
264 } | 257 } |
265 | 258 |
266 WebVTTParser::ParseState WebVTTParser::collectTimingsAndSettings(const String& l ine) | 259 WebVTTParser::ParseState WebVTTParser::collectTimingsAndSettings(const String& l ine) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 | 360 |
368 void WebVTTParser::resetCueValues() | 361 void WebVTTParser::resetCueValues() |
369 { | 362 { |
370 m_currentId = emptyString(); | 363 m_currentId = emptyString(); |
371 m_currentSettings = emptyString(); | 364 m_currentSettings = emptyString(); |
372 m_currentStartTime = 0; | 365 m_currentStartTime = 0; |
373 m_currentEndTime = 0; | 366 m_currentEndTime = 0; |
374 m_currentContent.clear(); | 367 m_currentContent.clear(); |
375 } | 368 } |
376 | 369 |
377 #if ENABLE(WEBVTT_REGIONS) | |
378 void WebVTTParser::createNewRegion() | 370 void WebVTTParser::createNewRegion() |
379 { | 371 { |
380 if (!m_currentHeaderValue.length()) | 372 if (!m_currentHeaderValue.length()) |
381 return; | 373 return; |
382 | 374 |
383 RefPtr<TextTrackRegion> region = TextTrackRegion::create(m_scriptExecutionCo ntext); | 375 RefPtr<TextTrackRegion> region = TextTrackRegion::create(m_scriptExecutionCo ntext); |
384 region->setRegionSettings(m_currentHeaderValue); | 376 region->setRegionSettings(m_currentHeaderValue); |
385 | 377 |
386 // 15.5.10 If the text track list of regions regions contains a region | 378 // 15.5.10 If the text track list of regions regions contains a region |
387 // with the same region identifier value as region, remove that region. | 379 // with the same region identifier value as region, remove that region. |
388 for (size_t i = 0; i < m_regionList.size(); ++i) | 380 for (size_t i = 0; i < m_regionList.size(); ++i) |
389 if (m_regionList[i]->id() == region->id()) { | 381 if (m_regionList[i]->id() == region->id()) { |
390 m_regionList.remove(i); | 382 m_regionList.remove(i); |
391 break; | 383 break; |
392 } | 384 } |
393 | 385 |
394 m_regionList.append(region); | 386 m_regionList.append(region); |
395 } | 387 } |
396 #endif | |
397 | 388 |
398 double WebVTTParser::collectTimeStamp(const String& line, unsigned* position) | 389 double WebVTTParser::collectTimeStamp(const String& line, unsigned* position) |
399 { | 390 { |
400 // 4.8.10.13.3 Collect a WebVTT timestamp. | 391 // 4.8.10.13.3 Collect a WebVTT timestamp. |
401 // 1-4 - Initial checks, let most significant units be minutes. | 392 // 1-4 - Initial checks, let most significant units be minutes. |
402 enum Mode { minutes, hours }; | 393 enum Mode { minutes, hours }; |
403 Mode mode = minutes; | 394 Mode mode = minutes; |
404 if (*position >= line.length() || !isASCIIDigit(line[*position])) | 395 if (*position >= line.length() || !isASCIIDigit(line[*position])) |
405 return malformedTime; | 396 return malformedTime; |
406 | 397 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 unsigned oldPosition = *position; | 557 unsigned oldPosition = *position; |
567 while (*position < length && data[*position] != '\r' && data[*position] != ' \n') | 558 while (*position < length && data[*position] != '\r' && data[*position] != ' \n') |
568 (*position)++; | 559 (*position)++; |
569 String line = String::fromUTF8(data + oldPosition, *position - oldPosition); | 560 String line = String::fromUTF8(data + oldPosition, *position - oldPosition); |
570 skipLineTerminator(data, length, position); | 561 skipLineTerminator(data, length, position); |
571 return line; | 562 return line; |
572 } | 563 } |
573 | 564 |
574 } | 565 } |
575 | 566 |
OLD | NEW |