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" | |
9 #include "bindings/core/v8/ScriptValue.h" | |
10 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
11 #include "core/streams/ReadableByteStream.h" | 9 #include "core/streams/ReadableByteStream.h" |
12 #include "core/streams/ReadableByteStreamReader.h" | 10 #include "core/streams/ReadableByteStreamReader.h" |
13 #include "core/streams/UnderlyingSource.h" | 11 #include "core/streams/UnderlyingSource.h" |
14 #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 "wtf/OwnPtr.h" | 17 #include "wtf/OwnPtr.h" |
21 #include "wtf/PassOwnPtr.h" | 18 #include "wtf/PassOwnPtr.h" |
22 | 19 |
23 namespace blink { | 20 namespace blink { |
24 | 21 |
25 class EncodedFormData; | 22 class EncodedFormData; |
26 class ScriptState; | 23 class ExecutionContext; |
27 | 24 |
28 class MODULES_EXPORT BodyStreamBuffer final : public UnderlyingSourceBase, publi
c UnderlyingSource, public WebDataConsumerHandle::Client { | 25 class MODULES_EXPORT BodyStreamBuffer final : public GarbageCollectedFinalized<B
odyStreamBuffer>, public UnderlyingSource, public WebDataConsumerHandle::Client
{ |
29 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); | 26 WTF_MAKE_NONCOPYABLE(BodyStreamBuffer); |
30 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); | 27 USING_GARBAGE_COLLECTED_MIXIN(BodyStreamBuffer); |
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 public: | 30 public: |
34 // |handle| cannot be null and cannot be locked. | 31 // |handle| cannot be null and cannot be locked. |
35 BodyStreamBuffer(ScriptState*, PassOwnPtr<FetchDataConsumerHandle> /* handle
*/); | 32 explicit BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> /* handle */); |
36 | 33 |
37 ScriptValue stream(); | 34 ReadableByteStream* stream() { return m_stream; } |
38 | 35 |
39 // Callable only when neither locked nor disturbed. | 36 // Callable only when neither locked nor disturbed. |
40 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(FetchDataConsumerHandle::Re
ader::BlobSizePolicy); | 37 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(ExecutionContext*, FetchDat
aConsumerHandle::Reader::BlobSizePolicy); |
41 PassRefPtr<EncodedFormData> drainAsFormData(); | 38 PassRefPtr<EncodedFormData> drainAsFormData(ExecutionContext*); |
42 void startLoading(FetchDataLoader*, FetchDataLoader::Client* /* client */); | 39 void startLoading(ExecutionContext*, FetchDataLoader*, FetchDataLoader::Clie
nt* /* client */); |
43 | 40 |
44 // Callable only when not locked. Returns a non-null handle. | 41 // Callable only when not locked. Returns a non-null handle. |
45 // There is no means to "return" the handle to the body buffer: Calling | 42 // There is no means to "return" the handle to the body buffer: Calling |
46 // this function locks, disturbs and closes the stream and no one will | 43 // this function locks, disturbs and closes the stream and no one will |
47 // not be able to get any information from the stream and this buffer after | 44 // not be able to get any information from the stream and this buffer after |
48 // that. | 45 // that. |
49 PassOwnPtr<FetchDataConsumerHandle> releaseHandle(); | 46 PassOwnPtr<FetchDataConsumerHandle> releaseHandle(ExecutionContext*); |
50 | 47 |
51 bool hasPendingActivity() const; | 48 bool hasPendingActivity() const; |
52 void stop(); | 49 void stop(); |
53 | 50 |
54 // UnderlyingSource | 51 // UnderlyingSource |
55 void pullSource() override; | 52 void pullSource() override; |
56 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; | 53 ScriptPromise cancelSource(ScriptState*, ScriptValue reason) override; |
57 | 54 |
58 // UnderlyingSourceBase | |
59 ScriptPromise pull(ScriptState*) override; | |
60 ScriptPromise cancel(ScriptState*, ScriptValue reason) override; | |
61 | |
62 // WebDataConsumerHandle::Client | 55 // WebDataConsumerHandle::Client |
63 void didGetReadable() override; | 56 void didGetReadable() override; |
64 | 57 |
65 bool isStreamReadable(); | 58 bool isStreamReadable() const; |
66 bool isStreamClosed(); | 59 bool isStreamClosed() const; |
67 bool isStreamErrored(); | 60 bool isStreamErrored() const; |
68 bool isStreamLocked(); | 61 bool isStreamLocked() const; |
69 bool isStreamDisturbed(); | 62 bool isStreamDisturbed() const; |
70 void setDisturbed(); | |
71 | 63 |
72 DEFINE_INLINE_TRACE() | 64 DEFINE_INLINE_TRACE() |
73 { | 65 { |
74 visitor->trace(m_stream); | 66 visitor->trace(m_stream); |
75 visitor->trace(m_loader); | 67 visitor->trace(m_loader); |
76 UnderlyingSourceBase::trace(visitor); | |
77 UnderlyingSource::trace(visitor); | 68 UnderlyingSource::trace(visitor); |
78 } | 69 } |
79 | 70 |
80 private: | 71 private: |
81 class LoaderClient; | 72 class LoaderClient; |
82 | |
83 void lockAndDisturb(); | |
84 void close(); | 73 void close(); |
85 void error(); | 74 void error(); |
86 void processData(); | 75 void processData(); |
87 void endLoading(); | 76 void endLoading(); |
88 void stopLoading(); | 77 void stopLoading(); |
89 | 78 |
90 RefPtr<ScriptState> m_scriptState; | |
91 OwnPtr<FetchDataConsumerHandle> m_handle; | 79 OwnPtr<FetchDataConsumerHandle> m_handle; |
92 OwnPtr<FetchDataConsumerHandle::Reader> m_reader; | 80 OwnPtr<FetchDataConsumerHandle::Reader> m_reader; |
93 Member<ReadableByteStream> m_stream; | 81 Member<ReadableByteStream> m_stream; |
94 // We need this member to keep it alive while loading. | 82 // We need this member to keep it alive while loading. |
95 Member<FetchDataLoader> m_loader; | 83 Member<FetchDataLoader> m_loader; |
96 bool m_streamNeedsMore = false; | 84 bool m_streamNeedsMore; |
97 }; | 85 }; |
98 | 86 |
99 } // namespace blink | 87 } // namespace blink |
100 | 88 |
101 #endif // BodyStreamBuffer_h | 89 #endif // BodyStreamBuffer_h |
OLD | NEW |