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

Side by Side Diff: third_party/WebKit/Source/core/html/track/vtt/VTTParser.cpp

Issue 2685943004: Remove TextTrack.regions and VTTRegionList (Closed)
Patch Set: Rebase Created 3 years, 10 months 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 unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/html/track/vtt/VTTParser.h" 31 #include "core/html/track/vtt/VTTParser.h"
32 32
33 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
34 #include "core/dom/ProcessingInstruction.h" 34 #include "core/dom/ProcessingInstruction.h"
35 #include "core/dom/Text.h" 35 #include "core/dom/Text.h"
36 #include "core/html/track/vtt/VTTElement.h" 36 #include "core/html/track/vtt/VTTElement.h"
37 #include "core/html/track/vtt/VTTRegion.h"
37 #include "core/html/track/vtt/VTTScanner.h" 38 #include "core/html/track/vtt/VTTScanner.h"
38 #include "platform/RuntimeEnabledFeatures.h" 39 #include "platform/RuntimeEnabledFeatures.h"
39 #include "platform/text/SegmentedString.h" 40 #include "platform/text/SegmentedString.h"
40 #include "wtf/text/CharacterNames.h" 41 #include "wtf/text/CharacterNames.h"
41 #include "wtf/text/WTFString.h" 42 #include "wtf/text/WTFString.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 using namespace HTMLNames; 46 using namespace HTMLNames;
46 47
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 m_decoder(TextResourceDecoder::create("text/plain", UTF8Encoding())), 88 m_decoder(TextResourceDecoder::create("text/plain", UTF8Encoding())),
88 m_currentStartTime(0), 89 m_currentStartTime(0),
89 m_currentEndTime(0), 90 m_currentEndTime(0),
90 m_client(client) {} 91 m_client(client) {}
91 92
92 void VTTParser::getNewCues(HeapVector<Member<TextTrackCue>>& outputCues) { 93 void VTTParser::getNewCues(HeapVector<Member<TextTrackCue>>& outputCues) {
93 DCHECK(outputCues.isEmpty()); 94 DCHECK(outputCues.isEmpty());
94 outputCues.swap(m_cueList); 95 outputCues.swap(m_cueList);
95 } 96 }
96 97
97 void VTTParser::getNewRegions(HeapVector<Member<VTTRegion>>& outputRegions) {
98 DCHECK(outputRegions.isEmpty());
99 outputRegions.swap(m_regionList);
100 }
101
102 void VTTParser::parseBytes(const char* data, size_t length) { 98 void VTTParser::parseBytes(const char* data, size_t length) {
103 String textData = m_decoder->decode(data, length); 99 String textData = m_decoder->decode(data, length);
104 m_lineReader.append(textData); 100 m_lineReader.append(textData);
105 parse(); 101 parse();
106 } 102 }
107 103
108 void VTTParser::flush() { 104 void VTTParser::flush() {
109 String textData = m_decoder->flush(); 105 String textData = m_decoder->flush();
110 m_lineReader.append(textData); 106 m_lineReader.append(textData);
111 m_lineReader.setEndOfStream(); 107 m_lineReader.setEndOfStream();
(...skipping 18 matching lines...) Expand all
130 } 126 }
131 127
132 m_state = Header; 128 m_state = Header;
133 break; 129 break;
134 130
135 case Header: 131 case Header:
136 // Steps 10 - 14 - Allow a header (comment area) under the WEBVTT line. 132 // Steps 10 - 14 - Allow a header (comment area) under the WEBVTT line.
137 collectMetadataHeader(line); 133 collectMetadataHeader(line);
138 134
139 if (line.isEmpty()) { 135 if (line.isEmpty()) {
140 if (m_client && m_regionList.size())
141 m_client->newRegionsParsed();
142
143 m_state = Id; 136 m_state = Id;
144 break; 137 break;
145 } 138 }
146 139
147 // Step 15 - Break out of header loop if the line could be a timestamp 140 // Step 15 - Break out of header loop if the line could be a timestamp
148 // line. 141 // line.
149 if (line.contains("-->")) 142 if (line.contains("-->"))
150 m_state = recoverCue(line); 143 m_state = recoverCue(line);
151 144
152 // Step 16 - Line is not the empty string and does not contain "-->". 145 // Step 16 - Line is not the empty string and does not contain "-->".
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // to check for LF here. 207 // to check for LF here.
215 if (maybeSeparator != spaceCharacter && 208 if (maybeSeparator != spaceCharacter &&
216 maybeSeparator != tabulationCharacter) 209 maybeSeparator != tabulationCharacter)
217 return false; 210 return false;
218 } 211 }
219 return true; 212 return true;
220 } 213 }
221 214
222 void VTTParser::collectMetadataHeader(const String& line) { 215 void VTTParser::collectMetadataHeader(const String& line) {
223 // WebVTT header parsing (WebVTT parser algorithm step 12) 216 // WebVTT header parsing (WebVTT parser algorithm step 12)
224 DEFINE_STATIC_LOCAL(const AtomicString, regionHeaderName, ("Region"));
225 217
226 // The only currently supported header is the "Region" header. 218 // The only currently supported header is the "Region" header.
227 if (!RuntimeEnabledFeatures::webVTTRegionsEnabled()) 219 if (!RuntimeEnabledFeatures::webVTTRegionsEnabled())
228 return; 220 return;
229 221
230 // Step 12.4 If line contains the character ":" (A U+003A COLON), then set 222 // Step 12.4 If line contains the character ":" (A U+003A COLON), then set
231 // metadata's name to the substring of line before the first ":" character and 223 // metadata's name to the substring of line before the first ":" character and
232 // metadata's value to the substring after this character. 224 // metadata's value to the substring after this character.
233 size_t colonPosition = line.find(':'); 225 size_t colonPosition = line.find(':');
234 if (colonPosition == kNotFound) 226 if (colonPosition == kNotFound)
235 return; 227 return;
236 228
237 String headerName = line.substring(0, colonPosition); 229 String headerName = line.substring(0, colonPosition);
238 230
239 // Steps 12.5 If metadata's name equals "Region": 231 // Steps 12.5 If metadata's name equals "Region":
240 if (headerName == regionHeaderName) { 232 if (headerName == "Region") {
foolip 2017/02/10 23:31:56 Yeah, that was odd before :)
241 String headerValue = line.substring(colonPosition + 1); 233 String headerValue = line.substring(colonPosition + 1);
242 // Steps 12.5.1 - 12.5.11 Region creation: Let region be a new text track 234 // Steps 12.5.1 - 12.5.11 Region creation: Let region be a new text track
243 // region [...] 235 // region [...]
244 createNewRegion(headerValue); 236 createNewRegion(headerValue);
245 } 237 }
246 } 238 }
247 239
248 VTTParser::ParseState VTTParser::collectCueId(const String& line) { 240 VTTParser::ParseState VTTParser::collectCueId(const String& line) {
249 if (line.contains("-->")) 241 if (line.contains("-->"))
250 return collectTimingsAndSettings(line); 242 return collectTimingsAndSettings(line);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 385 }
394 386
395 void VTTParser::createNewRegion(const String& headerValue) { 387 void VTTParser::createNewRegion(const String& headerValue) {
396 if (headerValue.isEmpty()) 388 if (headerValue.isEmpty())
397 return; 389 return;
398 390
399 // Steps 12.5.1 - 12.5.9 - Construct and initialize a WebVTT Region object. 391 // Steps 12.5.1 - 12.5.9 - Construct and initialize a WebVTT Region object.
400 VTTRegion* region = VTTRegion::create(); 392 VTTRegion* region = VTTRegion::create();
401 region->setRegionSettings(headerValue); 393 region->setRegionSettings(headerValue);
402 394
403 // Step 12.5.10 If the text track list of regions regions contains a region
404 // with the same region identifier value as region, remove that region.
405 for (size_t i = 0; i < m_regionList.size(); ++i) {
406 if (m_regionList[i]->id() == region->id()) {
407 m_regionList.remove(i);
408 break;
409 }
410 }
411
412 // Step 12.5.11
413 m_regionList.push_back(region);
414
415 if (region->id().isEmpty()) 395 if (region->id().isEmpty())
416 return; 396 return;
417 m_regionMap.set(region->id(), region); 397 m_regionMap.set(region->id(), region);
418 } 398 }
419 399
420 bool VTTParser::collectTimeStamp(const String& line, double& timeStamp) { 400 bool VTTParser::collectTimeStamp(const String& line, double& timeStamp) {
421 VTTScanner input(line); 401 VTTScanner input(line);
422 return collectTimeStamp(input, timeStamp); 402 return collectTimeStamp(input, timeStamp);
423 } 403 }
424 404
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 default: 556 default:
577 break; 557 break;
578 } 558 }
579 } 559 }
580 560
581 DEFINE_TRACE(VTTParser) { 561 DEFINE_TRACE(VTTParser) {
582 visitor->trace(m_document); 562 visitor->trace(m_document);
583 visitor->trace(m_client); 563 visitor->trace(m_client);
584 visitor->trace(m_cueList); 564 visitor->trace(m_cueList);
585 visitor->trace(m_regionMap); 565 visitor->trace(m_regionMap);
586 visitor->trace(m_regionList);
587 } 566 }
588 567
589 } // namespace blink 568 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698