| 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 "bindings/core/v8/V8ThrowException.h" | 9 #include "bindings/core/v8/V8ThrowException.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
| 11 #include "core/dom/DOMTypedArray.h" | 11 #include "core/dom/DOMTypedArray.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/streams/ReadableStreamController.h" | 13 #include "core/streams/ReadableStreamController.h" |
| 14 #include "core/streams/ReadableStreamOperations.h" | 14 #include "core/streams/ReadableStreamOperations.h" |
| 15 #include "modules/fetch/Body.h" | 15 #include "modules/fetch/Body.h" |
| 16 #include "modules/fetch/ReadableStreamBytesConsumer.h" | 16 #include "modules/fetch/ReadableStreamBytesConsumer.h" |
| 17 #include "platform/blob/BlobData.h" | 17 #include "platform/blob/BlobData.h" |
| 18 #include "platform/network/EncodedFormData.h" | 18 #include "platform/network/EncodedFormData.h" |
| 19 #include <memory> | 19 #include <memory> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 class BodyStreamBuffer::LoaderClient final | 23 class BodyStreamBuffer::LoaderClient final |
| 24 : public GarbageCollectedFinalized<LoaderClient>, | 24 : public GarbageCollectedFinalized<LoaderClient>, |
| 25 public SuspendableObject, | 25 public ContextLifecycleObserver, |
| 26 public FetchDataLoader::Client { | 26 public FetchDataLoader::Client { |
| 27 WTF_MAKE_NONCOPYABLE(LoaderClient); | 27 WTF_MAKE_NONCOPYABLE(LoaderClient); |
| 28 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); | 28 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
| 29 | 29 |
| 30 public: | 30 public: |
| 31 LoaderClient(ExecutionContext* executionContext, | 31 LoaderClient(ExecutionContext* executionContext, |
| 32 BodyStreamBuffer* buffer, | 32 BodyStreamBuffer* buffer, |
| 33 FetchDataLoader::Client* client) | 33 FetchDataLoader::Client* client) |
| 34 : SuspendableObject(executionContext), | 34 : ContextLifecycleObserver(executionContext), |
| 35 m_buffer(buffer), | 35 m_buffer(buffer), |
| 36 m_client(client) { | 36 m_client(client) {} |
| 37 suspendIfNeeded(); | |
| 38 } | |
| 39 | 37 |
| 40 void didFetchDataLoadedBlobHandle( | 38 void didFetchDataLoadedBlobHandle( |
| 41 PassRefPtr<BlobDataHandle> blobDataHandle) override { | 39 PassRefPtr<BlobDataHandle> blobDataHandle) override { |
| 42 m_buffer->endLoading(); | 40 m_buffer->endLoading(); |
| 43 m_client->didFetchDataLoadedBlobHandle(std::move(blobDataHandle)); | 41 m_client->didFetchDataLoadedBlobHandle(std::move(blobDataHandle)); |
| 44 } | 42 } |
| 45 | 43 |
| 46 void didFetchDataLoadedArrayBuffer(DOMArrayBuffer* arrayBuffer) override { | 44 void didFetchDataLoadedArrayBuffer(DOMArrayBuffer* arrayBuffer) override { |
| 47 m_buffer->endLoading(); | 45 m_buffer->endLoading(); |
| 48 m_client->didFetchDataLoadedArrayBuffer(arrayBuffer); | 46 m_client->didFetchDataLoadedArrayBuffer(arrayBuffer); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 } | 57 } |
| 60 | 58 |
| 61 void didFetchDataLoadFailed() override { | 59 void didFetchDataLoadFailed() override { |
| 62 m_buffer->endLoading(); | 60 m_buffer->endLoading(); |
| 63 m_client->didFetchDataLoadFailed(); | 61 m_client->didFetchDataLoadFailed(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 DEFINE_INLINE_TRACE() { | 64 DEFINE_INLINE_TRACE() { |
| 67 visitor->trace(m_buffer); | 65 visitor->trace(m_buffer); |
| 68 visitor->trace(m_client); | 66 visitor->trace(m_client); |
| 69 SuspendableObject::trace(visitor); | 67 ContextLifecycleObserver::trace(visitor); |
| 70 FetchDataLoader::Client::trace(visitor); | 68 FetchDataLoader::Client::trace(visitor); |
| 71 } | 69 } |
| 72 | 70 |
| 73 private: | 71 private: |
| 74 void contextDestroyed() override { m_buffer->stopLoading(); } | 72 void contextDestroyed() override { m_buffer->stopLoading(); } |
| 75 | 73 |
| 76 Member<BodyStreamBuffer> m_buffer; | 74 Member<BodyStreamBuffer> m_buffer; |
| 77 Member<FetchDataLoader::Client> m_client; | 75 Member<FetchDataLoader::Client> m_client; |
| 78 }; | 76 }; |
| 79 | 77 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 384 } |
| 387 if (isErrored) | 385 if (isErrored) |
| 388 return BytesConsumer::createErrored(BytesConsumer::Error("error")); | 386 return BytesConsumer::createErrored(BytesConsumer::Error("error")); |
| 389 | 387 |
| 390 DCHECK(consumer); | 388 DCHECK(consumer); |
| 391 consumer->clearClient(); | 389 consumer->clearClient(); |
| 392 return consumer; | 390 return consumer; |
| 393 } | 391 } |
| 394 | 392 |
| 395 } // namespace blink | 393 } // namespace blink |
| OLD | NEW |