| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/BodyStreamBuffer.h" | 5 #include "modules/fetch/BodyStreamBuffer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/V8HiddenValue.h" | 8 #include "bindings/core/v8/V8HiddenValue.h" |
| 9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
| 10 #include "core/dom/DOMTypedArray.h" | 10 #include "core/dom/DOMTypedArray.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/streams/ReadableStreamController.h" | 12 #include "core/streams/ReadableStreamController.h" |
| 13 #include "core/streams/ReadableStreamOperations.h" | 13 #include "core/streams/ReadableStreamOperations.h" |
| 14 #include "modules/fetch/Body.h" | 14 #include "modules/fetch/Body.h" |
| 15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" | 15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" |
| 16 #include "modules/fetch/DataConsumerHandleUtil.h" | 16 #include "modules/fetch/DataConsumerHandleUtil.h" |
| 17 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 17 #include "modules/fetch/ReadableStreamBytesConsumer.h" |
| 18 #include "platform/blob/BlobData.h" | 18 #include "platform/blob/BlobData.h" |
| 19 #include "platform/network/EncodedFormData.h" | 19 #include "platform/network/EncodedFormData.h" |
| 20 #include <memory> | 20 #include <memory> |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 | 23 |
| 24 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo
aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { | 24 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo
aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { |
| 25 WTF_MAKE_NONCOPYABLE(LoaderClient); | 25 WTF_MAKE_NONCOPYABLE(LoaderClient); |
| 26 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); | 26 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
| 27 public: | 27 public: |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (m_madeFromReadableStream) { | 367 if (m_madeFromReadableStream) { |
| 368 ScriptState::Scope scope(m_scriptState.get()); | 368 ScriptState::Scope scope(m_scriptState.get()); |
| 369 // We need to have |reader| alive by some means (as written in | 369 // We need to have |reader| alive by some means (as written in |
| 370 // ReadableStreamDataConsumerHandle). Based on the following facts | 370 // ReadableStreamDataConsumerHandle). Based on the following facts |
| 371 // - This function is used only from tee and startLoading. | 371 // - This function is used only from tee and startLoading. |
| 372 // - This branch cannot be taken when called from tee. | 372 // - This branch cannot be taken when called from tee. |
| 373 // - startLoading makes hasPendingActivity return true while loading. | 373 // - startLoading makes hasPendingActivity return true while loading. |
| 374 // , we don't need to keep the reader explicitly. | 374 // , we don't need to keep the reader explicitly. |
| 375 NonThrowableExceptionState exceptionState; | 375 NonThrowableExceptionState exceptionState; |
| 376 ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.g
et(), stream(), exceptionState); | 376 ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.g
et(), stream(), exceptionState); |
| 377 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio
nContext(), ReadableStreamDataConsumerHandle::create(m_scriptState.get(), reader
)); | 377 return new ReadableStreamBytesConsumer(m_scriptState.get(), reader); |
| 378 } | 378 } |
| 379 // We need to call these before calling closeAndLockAndDisturb. | 379 // We need to call these before calling closeAndLockAndDisturb. |
| 380 const bool isClosed = isStreamClosed(); | 380 const bool isClosed = isStreamClosed(); |
| 381 const bool isErrored = isStreamErrored(); | 381 const bool isErrored = isStreamErrored(); |
| 382 BytesConsumer* consumer = m_consumer.release(); | 382 BytesConsumer* consumer = m_consumer.release(); |
| 383 | 383 |
| 384 closeAndLockAndDisturb(); | 384 closeAndLockAndDisturb(); |
| 385 | 385 |
| 386 if (isClosed) { | 386 if (isClosed) { |
| 387 // Note that the stream cannot be "draining", because it doesn't have | 387 // Note that the stream cannot be "draining", because it doesn't have |
| 388 // the internal buffer. | 388 // the internal buffer. |
| 389 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio
nContext(), createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHan
dle())); | 389 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio
nContext(), createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHan
dle())); |
| 390 } | 390 } |
| 391 if (isErrored) | 391 if (isErrored) |
| 392 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio
nContext(), createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorData
ConsumerHandle())); | 392 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio
nContext(), createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorData
ConsumerHandle())); |
| 393 | 393 |
| 394 DCHECK(consumer); | 394 DCHECK(consumer); |
| 395 consumer->clearClient(); | 395 consumer->clearClient(); |
| 396 return consumer; | 396 return consumer; |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace blink | 399 } // namespace blink |
| OLD | NEW |