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