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

Side by Side Diff: Source/modules/mediasource/SourceBuffer.cpp

Issue 266453005: Apply TypeChecking to MediaSource IDLs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Undo too eager removal; Fixup test; Mark remove() args unrestricted. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const AtomicString& SourceBuffer::sequenceKeyword() 118 const AtomicString& SourceBuffer::sequenceKeyword()
119 { 119 {
120 DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence", AtomicString: :ConstructFromLiteral)); 120 DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence", AtomicString: :ConstructFromLiteral));
121 return sequence; 121 return sequence;
122 } 122 }
123 123
124 void SourceBuffer::setMode(const AtomicString& newMode, ExceptionState& exceptio nState) 124 void SourceBuffer::setMode(const AtomicString& newMode, ExceptionState& exceptio nState)
125 { 125 {
126 // Section 3.1 On setting mode attribute steps. 126 // Section 3.1 On setting mode attribute steps.
127 // 1. Let new mode equal the new value being assigned to this attribute. 127 // 1. Let new mode equal the new value being assigned to this attribute.
128 // 2. If new mode does not equal "segments" or "sequence", then throw an INV ALID_ACCESS_ERR exception and abort 128 // 2. If this object has been removed from the sourceBuffers attribute of th e parent media source, then throw
129 // these steps.
130 // Step 2 is unnecessary: IDL enforcement prevents this case and should j ust return immediately to script
131 // without calling this method in this case.
132 // 3. If this object has been removed from the sourceBuffers attribute of th e parent media source, then throw
133 // an INVALID_STATE_ERR exception and abort these steps. 129 // an INVALID_STATE_ERR exception and abort these steps.
134 // 4. If the updating attribute equals true, then throw an INVALID_STATE_ERR exception and abort these steps. 130 // 3. If the updating attribute equals true, then throw an INVALID_STATE_ERR exception and abort these steps.
135 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 131 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
136 return; 132 return;
137 133
138 // 5. If the readyState attribute of the parent media source is in the "ende d" state then run the following steps: 134 // 4. If the readyState attribute of the parent media source is in the "ende d" state then run the following steps:
139 // 5.1 Set the readyState attribute of the parent media source to "open" 135 // 4.1 Set the readyState attribute of the parent media source to "open"
140 // 5.2 Queue a task to fire a simple event named sourceopen at the parent me dia source. 136 // 4.2 Queue a task to fire a simple event named sourceopen at the parent me dia source.
141 m_source->openIfInEndedState(); 137 m_source->openIfInEndedState();
142 138
143 // 6. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALI D_STATE_ERR and abort these steps. 139 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALI D_STATE_ERR and abort these steps.
144 // 7. If the new mode equals "sequence", then set the group start timestamp to the highest presentation end timestamp. 140 // 6. If the new mode equals "sequence", then set the group start timestamp to the highest presentation end timestamp.
145 WebSourceBuffer::AppendMode appendMode = WebSourceBuffer::AppendModeSegments ; 141 WebSourceBuffer::AppendMode appendMode = WebSourceBuffer::AppendModeSegments ;
146 if (newMode == sequenceKeyword()) 142 if (newMode == sequenceKeyword())
147 appendMode = WebSourceBuffer::AppendModeSequence; 143 appendMode = WebSourceBuffer::AppendModeSequence;
148 if (!m_webSourceBuffer->setMode(appendMode)) { 144 if (!m_webSourceBuffer->setMode(appendMode)) {
149 exceptionState.throwDOMException(InvalidStateError, "The mode may not be set while the SourceBuffer's append state is 'PARSING_MEDIA_SEGMENT'."); 145 exceptionState.throwDOMException(InvalidStateError, "The mode may not be set while the SourceBuffer's append state is 'PARSING_MEDIA_SEGMENT'.");
150 return; 146 return;
151 } 147 }
152 148
153 // 8. Update the attribute to new mode. 149 // 7. Update the attribute to new mode.
154 m_mode = newMode; 150 m_mode = newMode;
155 } 151 }
156 152
157 PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionState& exceptionState) co nst 153 PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionState& exceptionState) co nst
158 { 154 {
159 // Section 3.1 buffered attribute steps. 155 // Section 3.1 buffered attribute steps.
160 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an 156 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an
161 // InvalidStateError exception and abort these steps. 157 // InvalidStateError exception and abort these steps.
162 if (isRemoved()) { 158 if (isRemoved()) {
163 exceptionState.throwDOMException(InvalidStateError, "This SourceBuffer h as been removed from the parent media source."); 159 exceptionState.throwDOMException(InvalidStateError, "This SourceBuffer h as been removed from the parent media source.");
164 return nullptr; 160 return nullptr;
165 } 161 }
166 162
167 // 2. Return a new static normalized TimeRanges object for the media segment s buffered. 163 // 2. Return a new static normalized TimeRanges object for the media segment s buffered.
168 return TimeRanges::create(m_webSourceBuffer->buffered()); 164 return TimeRanges::create(m_webSourceBuffer->buffered());
169 } 165 }
170 166
171 double SourceBuffer::timestampOffset() const 167 double SourceBuffer::timestampOffset() const
172 { 168 {
173 return m_timestampOffset; 169 return m_timestampOffset;
174 } 170 }
175 171
176 void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionSt ate) 172 void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionSt ate)
177 { 173 {
178 // Enforce throwing an exception on restricted double values. 174 // Enforce throwing an exception on restricted double values.
175 // (Needs TypeChecking=Unrestricted to apply to attributes before it can be
Nils Barth (inactive) 2014/05/01 01:08:46 Could you add a link to the bug here so I can grep
176 // removed.)
179 if (!std::isfinite(offset)) { 177 if (!std::isfinite(offset)) {
180 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(offset )); 178 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(offset ));
181 return; 179 return;
182 } 180 }
183 181
184 // Section 3.1 timestampOffset attribute setter steps. 182 // Section 3.1 timestampOffset attribute setter steps.
185 // 1. Let new timestamp offset equal the new value being assigned to this at tribute. 183 // 1. Let new timestamp offset equal the new value being assigned to this at tribute.
186 // 2. If this object has been removed from the sourceBuffers attribute of th e parent media source, then throw an 184 // 2. If this object has been removed from the sourceBuffers attribute of th e parent media source, then throw an
187 // InvalidStateError exception and abort these steps. 185 // InvalidStateError exception and abort these steps.
188 // 3. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps. 186 // 3. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
(...skipping 17 matching lines...) Expand all
206 } 204 }
207 205
208 double SourceBuffer::appendWindowStart() const 206 double SourceBuffer::appendWindowStart() const
209 { 207 {
210 return m_appendWindowStart; 208 return m_appendWindowStart;
211 } 209 }
212 210
213 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionS tate) 211 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionS tate)
214 { 212 {
215 // Enforce throwing an exception on restricted double values. 213 // Enforce throwing an exception on restricted double values.
214 // (Needs TypeChecking=Unrestricted to apply to attributes before it can be
Nils Barth (inactive) 2014/05/01 01:08:46 http://crbug.com/354298
215 // removed.)
216 if (!std::isfinite(start)) { 216 if (!std::isfinite(start)) {
217 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(start) ); 217 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(start) );
218 return; 218 return;
219 } 219 }
220 220
221 // Section 3.1 appendWindowStart attribute setter steps. 221 // Section 3.1 appendWindowStart attribute setter steps.
222 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an 222 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an
223 // InvalidStateError exception and abort these steps. 223 // InvalidStateError exception and abort these steps.
224 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps. 224 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
225 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 225 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 m_webSourceBuffer->setAppendWindowEnd(end); 268 m_webSourceBuffer->setAppendWindowEnd(end);
269 269
270 // 5. Update the attribute to the new value. 270 // 5. Update the attribute to the new value.
271 m_appendWindowEnd = end; 271 m_appendWindowEnd = end;
272 } 272 }
273 273
274 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& ex ceptionState) 274 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& ex ceptionState)
275 { 275 {
276 // Section 3.2 appendBuffer() 276 // Section 3.2 appendBuffer()
277 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data 277 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
278 // 1. If data is null then throw an InvalidAccessError exception and abort t hese steps.
279 if (!data) {
280 exceptionState.throwDOMException(InvalidAccessError, "The ArrayBuffer pr ovided is invalid.");
281 return;
282 }
283
284 appendBufferInternal(static_cast<const unsigned char*>(data->data()), data-> byteLength(), exceptionState); 278 appendBufferInternal(static_cast<const unsigned char*>(data->data()), data-> byteLength(), exceptionState);
285 } 279 }
286 280
287 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState & exceptionState) 281 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState & exceptionState)
288 { 282 {
289 // Section 3.2 appendBuffer() 283 // Section 3.2 appendBuffer()
290 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data 284 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
291 // 1. If data is null then throw an InvalidAccessError exception and abort t hese steps.
292 if (!data) {
293 exceptionState.throwDOMException(InvalidAccessError, "The ArrayBuffer pr ovided is invalid.");
294 return;
295 }
296
297 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), data->byteLength(), exceptionState); 285 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), data->byteLength(), exceptionState);
298 } 286 }
299 287
300 void SourceBuffer::appendStream(PassRefPtrWillBeRawPtr<Stream> stream, Exception State& exceptionState) 288 void SourceBuffer::appendStream(PassRefPtrWillBeRawPtr<Stream> stream, Exception State& exceptionState)
301 { 289 {
302 m_streamMaxSizeValid = false; 290 m_streamMaxSizeValid = false;
303 appendStreamInternal(stream, exceptionState); 291 appendStreamInternal(stream, exceptionState);
304 } 292 }
305 293
306 void SourceBuffer::appendStream(PassRefPtrWillBeRawPtr<Stream> stream, unsigned long long maxSize, ExceptionState& exceptionState) 294 void SourceBuffer::appendStream(PassRefPtrWillBeRawPtr<Stream> stream, unsigned long long maxSize, ExceptionState& exceptionState)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 event->setTarget(this); 473 event->setTarget(this);
486 474
487 m_asyncEventQueue->enqueueEvent(event.release()); 475 m_asyncEventQueue->enqueueEvent(event.release());
488 } 476 }
489 477
490 void SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size , ExceptionState& exceptionState) 478 void SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size , ExceptionState& exceptionState)
491 { 479 {
492 // Section 3.2 appendBuffer() 480 // Section 3.2 appendBuffer()
493 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data 481 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
494 482
495 // Step 1 is enforced by the caller. 483 // 1. Run the prepare append algorithm.
496 // 2. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an InvalidStateError exception and abort these steps. 484 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-prepare-append
497 // 3. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps. 485 // 1. If this object has been removed from the sourceBuffers attribute of t he parent media source then throw an InvalidStateError exception and abort these steps.
486 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps.
498 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 487 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
499 return; 488 return;
500 489
501 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendBuffer", this); 490 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendBuffer", this);
502 491
503 // 4. If the readyState attribute of the parent media source is in the "ende d" state then run the following steps: ... 492 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ...
504 m_source->openIfInEndedState(); 493 m_source->openIfInEndedState();
505 494
506 // Steps 5-6 495 // Steps 4-5 - end "prepare append" algorithm.
507 496
508 // 7. Add data to the end of the input buffer. 497 // 2. Add data to the end of the input buffer.
509 m_pendingAppendData.append(data, size); 498 m_pendingAppendData.append(data, size);
510 499
511 // 8. Set the updating attribute to true. 500 // 3. Set the updating attribute to true.
512 m_updating = true; 501 m_updating = true;
513 502
514 // 9. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. 503 // 4. Queue a task to fire a simple event named updatestart at this SourceBu ffer object.
515 scheduleEvent(EventTypeNames::updatestart); 504 scheduleEvent(EventTypeNames::updatestart);
516 505
517 // 10. Asynchronously run the buffer append algorithm. 506 // 5. Asynchronously run the buffer append algorithm.
518 m_appendBufferAsyncPartRunner.runAsync(); 507 m_appendBufferAsyncPartRunner.runAsync();
519 508
520 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "w aiting"); 509 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "w aiting");
521 } 510 }
522 511
523 void SourceBuffer::appendBufferAsyncPart() 512 void SourceBuffer::appendBufferAsyncPart()
524 { 513 {
525 ASSERT(m_updating); 514 ASSERT(m_updating);
526 515
527 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "a ppending"); 516 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "a ppending");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 scheduleEvent(EventTypeNames::update); 562 scheduleEvent(EventTypeNames::update);
574 563
575 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object. 564 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object.
576 scheduleEvent(EventTypeNames::updateend); 565 scheduleEvent(EventTypeNames::updateend);
577 } 566 }
578 567
579 void SourceBuffer::appendStreamInternal(PassRefPtrWillBeRawPtr<Stream> stream, E xceptionState& exceptionState) 568 void SourceBuffer::appendStreamInternal(PassRefPtrWillBeRawPtr<Stream> stream, E xceptionState& exceptionState)
580 { 569 {
581 // Section 3.2 appendStream() 570 // Section 3.2 appendStream()
582 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-ma xSize 571 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-ma xSize
583 // 1. If stream is null then throw an InvalidAccessError exception and abort these steps. 572 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.)
584 if (!stream || stream->isNeutered()) { 573 if (stream->isNeutered()) {
585 exceptionState.throwDOMException(InvalidAccessError, stream ? "The strea m provided has been neutered." : "The stream provided is invalid."); 574 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered.");
586 return; 575 return;
587 } 576 }
588 577
589 // 2. Run the prepare append algorithm. 578 // 1. Run the prepare append algorithm.
590 // Section 3.5.4 Prepare Append Algorithm. 579 // Section 3.5.4 Prepare Append Algorithm.
591 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append 580 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append
592 // 1. If this object has been removed from the sourceBuffers attribute of t he parent media source then throw an InvalidStateError exception and abort these steps. 581 // 1. If this object has been removed from the sourceBuffers attribute of t he parent media source then throw an InvalidStateError exception and abort these steps.
593 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. 582 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps.
594 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 583 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
595 return; 584 return;
596 585
597 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); 586 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this);
598 587
599 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... 588 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ...
600 m_source->openIfInEndedState(); 589 m_source->openIfInEndedState();
601 590
602 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffe r. 591 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffe r.
603 592
604 // 3. Set the updating attribute to true. 593 // 2. Set the updating attribute to true.
605 m_updating = true; 594 m_updating = true;
606 595
607 // 4. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. 596 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object.
608 scheduleEvent(EventTypeNames::updatestart); 597 scheduleEvent(EventTypeNames::updatestart);
609 598
610 // 5. Asynchronously run the stream append loop algorithm with stream and ma xSize. 599 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize.
611 600
612 stream->neuter(); 601 stream->neuter();
613 m_loader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadByClient, thi s)); 602 m_loader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadByClient, thi s));
614 m_stream = stream; 603 m_stream = stream;
615 m_appendStreamAsyncPartRunner.runAsync(); 604 m_appendStreamAsyncPartRunner.runAsync();
616 } 605 }
617 606
618 void SourceBuffer::appendStreamAsyncPart() 607 void SourceBuffer::appendStreamAsyncPart()
619 { 608 {
620 ASSERT(m_updating); 609 ASSERT(m_updating);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 appendStreamDone(false); 696 appendStreamDone(false);
708 } 697 }
709 698
710 void SourceBuffer::trace(Visitor* visitor) 699 void SourceBuffer::trace(Visitor* visitor)
711 { 700 {
712 visitor->trace(m_source); 701 visitor->trace(m_source);
713 visitor->trace(m_stream); 702 visitor->trace(m_stream);
714 } 703 }
715 704
716 } // namespace WebCore 705 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698