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 "core/dom/DOMArrayBuffer.h" | 7 #include "core/dom/DOMArrayBuffer.h" |
8 #include "core/dom/DOMTypedArray.h" | 8 #include "core/dom/DOMTypedArray.h" |
9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
10 #include "modules/fetch/DataConsumerHandleUtil.h" | 10 #include "modules/fetch/DataConsumerHandleUtil.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 BodyStreamBuffer::BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> handle) | 76 BodyStreamBuffer::BodyStreamBuffer(PassOwnPtr<FetchDataConsumerHandle> handle) |
77 : m_handle(handle) | 77 : m_handle(handle) |
78 , m_reader(m_handle->obtainReader(this)) | 78 , m_reader(m_handle->obtainReader(this)) |
79 , m_stream(new ReadableByteStream(this, new ReadableByteStream::StrictStrate
gy)) | 79 , m_stream(new ReadableByteStream(this, new ReadableByteStream::StrictStrate
gy)) |
80 , m_streamNeedsMore(false) | 80 , m_streamNeedsMore(false) |
81 { | 81 { |
82 m_stream->didSourceStart(); | 82 m_stream->didSourceStart(); |
83 } | 83 } |
84 | 84 |
85 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) | 85 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(ExecutionCont
ext* executionContext, FetchDataConsumerHandle::Reader::BlobSizePolicy policy) |
86 { | 86 { |
87 ASSERT(!isStreamLocked()); | 87 ASSERT(!isStreamLocked()); |
88 m_stream->setIsDisturbed(); | 88 ASSERT(!isStreamDisturbed()); |
89 if (isStreamClosed() || isStreamErrored()) | 89 if (isStreamClosed() || isStreamErrored()) |
90 return nullptr; | 90 return nullptr; |
91 | 91 |
92 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); | 92 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); |
93 if (blobDataHandle) { | 93 if (blobDataHandle) { |
| 94 NonThrowableExceptionState exceptionState; |
| 95 m_stream->getBytesReader(executionContext, exceptionState); |
| 96 m_stream->setIsDisturbed(); |
94 close(); | 97 close(); |
95 return blobDataHandle.release(); | 98 return blobDataHandle.release(); |
96 } | 99 } |
97 return nullptr; | 100 return nullptr; |
98 } | 101 } |
99 | 102 |
100 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() | 103 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData(ExecutionContext*
executionContext) |
101 { | 104 { |
102 ASSERT(!isStreamLocked()); | 105 ASSERT(!isStreamLocked()); |
103 m_stream->setIsDisturbed(); | 106 ASSERT(!isStreamDisturbed()); |
104 if (isStreamClosed() || isStreamErrored()) | 107 if (isStreamClosed() || isStreamErrored()) |
105 return nullptr; | 108 return nullptr; |
106 | 109 |
107 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); | 110 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); |
108 if (formData) { | 111 if (formData) { |
| 112 NonThrowableExceptionState exceptionState; |
| 113 m_stream->getBytesReader(executionContext, exceptionState); |
| 114 m_stream->setIsDisturbed(); |
109 close(); | 115 close(); |
110 return formData.release(); | 116 return formData.release(); |
111 } | 117 } |
112 return nullptr; | 118 return nullptr; |
113 } | 119 } |
114 | 120 |
115 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) | 121 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle(ExecutionCon
text* executionContext) |
116 { | 122 { |
117 ASSERT(!isStreamLocked()); | 123 ASSERT(!isStreamLocked()); |
| 124 ASSERT(!isStreamDisturbed()); |
118 m_reader = nullptr; | 125 m_reader = nullptr; |
119 m_stream->setIsDisturbed(); | 126 m_stream->setIsDisturbed(); |
120 TrackExceptionState exceptionState; | 127 NonThrowableExceptionState exceptionState; |
121 m_stream->getBytesReader(executionContext, exceptionState); | 128 m_stream->getBytesReader(executionContext, exceptionState); |
122 | 129 |
123 if (isStreamClosed()) | 130 if (isStreamClosed()) |
124 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); | 131 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); |
125 if (isStreamErrored()) | 132 if (isStreamErrored()) |
126 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); | 133 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); |
127 | 134 |
128 ASSERT(m_handle); | 135 ASSERT(m_handle); |
129 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); | 136 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); |
130 close(); | 137 close(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 273 |
267 void BodyStreamBuffer::stopLoading() | 274 void BodyStreamBuffer::stopLoading() |
268 { | 275 { |
269 if (!m_loader) | 276 if (!m_loader) |
270 return; | 277 return; |
271 m_loader->cancel(); | 278 m_loader->cancel(); |
272 m_loader = nullptr; | 279 m_loader = nullptr; |
273 } | 280 } |
274 | 281 |
275 } // namespace blink | 282 } // namespace blink |
OLD | NEW |