| 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 #ifndef BodyStreamBuffer_h | 5 #ifndef BodyStreamBuffer_h |
| 6 #define BodyStreamBuffer_h | 6 #define BodyStreamBuffer_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/streams/ReadableByteStream.h" | |
| 12 #include "core/streams/ReadableByteStreamReader.h" | |
| 13 #include "core/streams/UnderlyingSource.h" | |
| 14 #include "core/streams/UnderlyingSourceBase.h" | 11 #include "core/streams/UnderlyingSourceBase.h" |
| 15 #include "modules/ModulesExport.h" | 12 #include "modules/ModulesExport.h" |
| 16 #include "modules/fetch/FetchDataConsumerHandle.h" | 13 #include "modules/fetch/FetchDataConsumerHandle.h" |
| 17 #include "modules/fetch/FetchDataLoader.h" | 14 #include "modules/fetch/FetchDataLoader.h" |
| 18 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 19 #include "public/platform/WebDataConsumerHandle.h" | 16 #include "public/platform/WebDataConsumerHandle.h" |
| 20 #include <memory> | 17 #include <memory> |
| 21 | 18 |
| 22 namespace blink { | 19 namespace blink { |
| 23 | 20 |
| 24 class EncodedFormData; | 21 class EncodedFormData; |
| 25 class ScriptState; | 22 class ScriptState; |
| 26 | 23 |
| 27 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi
c UnderlyingSource, public WebDataConsumerHandle::Client { | 24 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi
c WebDataConsumerHandle::Client { |
| 28 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); | 25 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); |
| 29 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); | 26 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); |
| 30 public: | 27 public: |
| 31 // Needed because we have to release |m_reader| promptly. | 28 // Needed because we have to release |m_reader| promptly. |
| 32 EAGERLY_FINALIZE(); | 29 EAGERLY_FINALIZE(); |
| 33 // |handle| cannot be null and cannot be locked. | 30 // |handle| cannot be null and cannot be locked. |
| 34 // This function must be called with entering an appropriate V8 context. | 31 // This function must be called with entering an appropriate V8 context. |
| 35 BodyStreamBuffer(ScriptState*, std::unique_ptr<FetchDataConsumerHandle> /* h
andle */); | 32 BodyStreamBuffer(ScriptState*, std::unique_ptr<FetchDataConsumerHandle> /* h
andle */); |
| 36 // |ReadableStreamOperations::isReadableStream(stream)| must hold. | 33 // |ReadableStreamOperations::isReadableStream(stream)| must hold. |
| 37 // This function must be called with entering an appropriate V8 context. | 34 // This function must be called with entering an appropriate V8 context. |
| 38 BodyStreamBuffer(ScriptState*, ScriptValue stream); | 35 BodyStreamBuffer(ScriptState*, ScriptValue stream); |
| 39 | 36 |
| 40 ScriptValue stream(); | 37 ScriptValue stream(); |
| 41 | 38 |
| 42 // Callable only when neither locked nor disturbed. | 39 // Callable only when neither locked nor disturbed. |
| 43 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re
ader::BlobSizePolicy); | 40 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re
ader::BlobSizePolicy); |
| 44 PassRefPtr<EncodedFormData> drainAsFormData(); | 41 PassRefPtr<EncodedFormData> drainAsFormData(); |
| 45 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */); | 42 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */); |
| 46 void tee(BodyStreamBuffer**, BodyStreamBuffer**); | 43 void tee(BodyStreamBuffer**, BodyStreamBuffer**); |
| 47 | 44 |
| 48 // UnderlyingSource | |
| 49 void pullSource() override; | |
| 50 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; | |
| 51 | |
| 52 // UnderlyingSourceBase | 45 // UnderlyingSourceBase |
| 53 ScriptPromise pull(ScriptState*) override; | 46 ScriptPromise pull(ScriptState*) override; |
| 54 ScriptPromise cancel(ScriptState*, ScriptValue reason) override; | 47 ScriptPromise cancel(ScriptState*, ScriptValue reason) override; |
| 55 bool hasPendingActivity() const override; | 48 bool hasPendingActivity() const override; |
| 56 void stop() override; | 49 void stop() override; |
| 57 | 50 |
| 58 // WebDataConsumerHandle::Client | 51 // WebDataConsumerHandle::Client |
| 59 void didGetReadable() override; | 52 void didGetReadable() override; |
| 60 | 53 |
| 61 bool isStreamReadable(); | 54 bool isStreamReadable(); |
| 62 bool isStreamClosed(); | 55 bool isStreamClosed(); |
| 63 bool isStreamErrored(); | 56 bool isStreamErrored(); |
| 64 bool isStreamLocked(); | 57 bool isStreamLocked(); |
| 65 bool isStreamDisturbed(); | 58 bool isStreamDisturbed(); |
| 66 void closeAndLockAndDisturb(); | 59 void closeAndLockAndDisturb(); |
| 67 ScriptState* scriptState() { return m_scriptState.get(); } | 60 ScriptState* scriptState() { return m_scriptState.get(); } |
| 68 | 61 |
| 69 DEFINE_INLINE_TRACE() | 62 DEFINE_INLINE_TRACE() |
| 70 { | 63 { |
| 71 visitor->trace(m_stream); | |
| 72 visitor->trace(m_loader); | 64 visitor->trace(m_loader); |
| 73 UnderlyingSourceBase::trace(visitor); | 65 UnderlyingSourceBase::trace(visitor); |
| 74 UnderlyingSource::trace(visitor); | |
| 75 } | 66 } |
| 76 | 67 |
| 77 private: | 68 private: |
| 78 class LoaderClient; | 69 class LoaderClient; |
| 79 | 70 |
| 80 void close(); | 71 void close(); |
| 81 void error(); | 72 void error(); |
| 82 void processData(); | 73 void processData(); |
| 83 void endLoading(); | 74 void endLoading(); |
| 84 void stopLoading(); | 75 void stopLoading(); |
| 85 std::unique_ptr<FetchDataConsumerHandle> releaseHandle(); | 76 std::unique_ptr<FetchDataConsumerHandle> releaseHandle(); |
| 86 | 77 |
| 87 RefPtr<ScriptState> m_scriptState; | 78 RefPtr<ScriptState> m_scriptState; |
| 88 std::unique_ptr<FetchDataConsumerHandle> m_handle; | 79 std::unique_ptr<FetchDataConsumerHandle> m_handle; |
| 89 std::unique_ptr<FetchDataConsumerHandle::Reader> m_reader; | 80 std::unique_ptr<FetchDataConsumerHandle::Reader> m_reader; |
| 90 Member<ReadableByteStream> m_stream; | |
| 91 // We need this member to keep it alive while loading. | 81 // We need this member to keep it alive while loading. |
| 92 Member<FetchDataLoader> m_loader; | 82 Member<FetchDataLoader> m_loader; |
| 93 bool m_streamNeedsMore = false; | 83 bool m_streamNeedsMore = false; |
| 94 bool m_madeFromReadableStream; | 84 bool m_madeFromReadableStream; |
| 95 }; | 85 }; |
| 96 | 86 |
| 97 } // namespace blink | 87 } // namespace blink |
| 98 | 88 |
| 99 #endif // BodyStreamBuffer_h | 89 #endif // BodyStreamBuffer_h |
| OLD | NEW |