| 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 "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
| 10 #include "core/dom/DOMTypedArray.h" | 10 #include "core/dom/DOMTypedArray.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) | 117 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) |
| 118 { | 118 { |
| 119 ASSERT(!isStreamLocked()); | 119 ASSERT(!isStreamLocked()); |
| 120 ASSERT(!isStreamDisturbed()); | 120 ASSERT(!isStreamDisturbed()); |
| 121 if (isStreamClosed() || isStreamErrored()) | 121 if (isStreamClosed() || isStreamErrored()) |
| 122 return nullptr; | 122 return nullptr; |
| 123 | 123 |
| 124 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); | 124 RefPtr<BlobDataHandle> blobDataHandle = m_reader->drainAsBlobDataHandle(poli
cy); |
| 125 if (blobDataHandle) { | 125 if (blobDataHandle) { |
| 126 lockAndDisturb(); | 126 closeAndLockAndDisturb(); |
| 127 close(); | |
| 128 return blobDataHandle.release(); | 127 return blobDataHandle.release(); |
| 129 } | 128 } |
| 130 return nullptr; | 129 return nullptr; |
| 131 } | 130 } |
| 132 | 131 |
| 133 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() | 132 PassRefPtr<EncodedFormData> BodyStreamBuffer::drainAsFormData() |
| 134 { | 133 { |
| 135 ASSERT(!isStreamLocked()); | 134 ASSERT(!isStreamLocked()); |
| 136 ASSERT(!isStreamDisturbed()); | 135 ASSERT(!isStreamDisturbed()); |
| 137 if (isStreamClosed() || isStreamErrored()) | 136 if (isStreamClosed() || isStreamErrored()) |
| 138 return nullptr; | 137 return nullptr; |
| 139 | 138 |
| 140 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); | 139 RefPtr<EncodedFormData> formData = m_reader->drainAsFormData(); |
| 141 if (formData) { | 140 if (formData) { |
| 142 lockAndDisturb(); | 141 closeAndLockAndDisturb(); |
| 143 close(); | |
| 144 return formData.release(); | 142 return formData.release(); |
| 145 } | 143 } |
| 146 return nullptr; | 144 return nullptr; |
| 147 } | 145 } |
| 148 | 146 |
| 149 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle() | 147 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle() |
| 150 { | 148 { |
| 151 ASSERT(!isStreamLocked()); | 149 ASSERT(!isStreamLocked()); |
| 152 ASSERT(!isStreamDisturbed()); | 150 ASSERT(!isStreamDisturbed()); |
| 153 lockAndDisturb(); | 151 // We need to call these before calling closeAndLockAndDisturb. |
| 152 const bool isClosed = isStreamClosed(); |
| 153 const bool isErrored = isStreamErrored(); |
| 154 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); |
| 154 | 155 |
| 155 if (isStreamClosed()) | 156 closeAndLockAndDisturb(); |
| 157 |
| 158 if (isClosed) { |
| 159 // Note that the stream cannot be "draining", because it doesn't have |
| 160 // the internal buffer. |
| 156 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); | 161 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); |
| 157 if (isStreamErrored()) | 162 } |
| 163 if (isErrored) |
| 158 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); | 164 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); |
| 159 | 165 |
| 160 ASSERT(m_handle); | 166 ASSERT(handle); |
| 161 OwnPtr<FetchDataConsumerHandle> handle = m_handle.release(); | |
| 162 close(); | |
| 163 return handle.release(); | 167 return handle.release(); |
| 164 } | 168 } |
| 165 | 169 |
| 166 void BodyStreamBuffer::startLoading(FetchDataLoader* loader, FetchDataLoader::Cl
ient* client) | 170 void BodyStreamBuffer::startLoading(FetchDataLoader* loader, FetchDataLoader::Cl
ient* client) |
| 167 { | 171 { |
| 168 ASSERT(!m_loader); | 172 ASSERT(!m_loader); |
| 169 ASSERT(m_scriptState->contextIsValid()); | 173 ASSERT(m_scriptState->contextIsValid()); |
| 170 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(); | 174 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle(); |
| 171 m_loader = loader; | 175 m_loader = loader; |
| 172 loader->start(handle.get(), new LoaderClient(m_scriptState->getExecutionCont
ext(), this, client)); | 176 loader->start(handle.get(), new LoaderClient(m_scriptState->getExecutionCont
ext(), this, client)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 288 |
| 285 bool BodyStreamBuffer::isStreamDisturbed() | 289 bool BodyStreamBuffer::isStreamDisturbed() |
| 286 { | 290 { |
| 287 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 291 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
| 288 ScriptState::Scope scope(m_scriptState.get()); | 292 ScriptState::Scope scope(m_scriptState.get()); |
| 289 return ReadableStreamOperations::isDisturbed(m_scriptState.get(), stream
()); | 293 return ReadableStreamOperations::isDisturbed(m_scriptState.get(), stream
()); |
| 290 } | 294 } |
| 291 return m_stream->isDisturbed(); | 295 return m_stream->isDisturbed(); |
| 292 } | 296 } |
| 293 | 297 |
| 294 void BodyStreamBuffer::setDisturbed() | 298 void BodyStreamBuffer::closeAndLockAndDisturb() |
| 295 { | 299 { |
| 296 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 300 if (isStreamReadable()) { |
| 297 ScriptState::Scope scope(m_scriptState.get()); | 301 // Note that the stream cannot be "draining", because it doesn't have |
| 298 ReadableStreamOperations::setDisturbed(m_scriptState.get(), stream()); | 302 // the internal buffer. |
| 299 } else { | 303 close(); |
| 300 m_stream->setIsDisturbed(); | |
| 301 } | 304 } |
| 302 } | |
| 303 | 305 |
| 304 void BodyStreamBuffer::lockAndDisturb() | |
| 305 { | |
| 306 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 306 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
| 307 ScriptState::Scope scope(m_scriptState.get()); | 307 ScriptState::Scope scope(m_scriptState.get()); |
| 308 NonThrowableExceptionState exceptionState; | 308 NonThrowableExceptionState exceptionState; |
| 309 ReadableStreamOperations::getReader(m_scriptState.get(), stream(), excep
tionState); | 309 ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.g
et(), stream(), exceptionState); |
| 310 ReadableStreamOperations::setDisturbed(m_scriptState.get(), stream()); | 310 ReadableStreamOperations::read(m_scriptState.get(), reader); |
| 311 } else { | 311 } else { |
| 312 NonThrowableExceptionState exceptionState; | 312 NonThrowableExceptionState exceptionState; |
| 313 m_stream->getBytesReader(m_scriptState->getExecutionContext(), exception
State); | 313 m_stream->getBytesReader(m_scriptState->getExecutionContext(), exception
State); |
| 314 m_stream->setIsDisturbed(); | 314 m_stream->setIsDisturbed(); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void BodyStreamBuffer::close() | 318 void BodyStreamBuffer::close() |
| 319 { | 319 { |
| 320 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) | 320 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 378 |
| 379 void BodyStreamBuffer::stopLoading() | 379 void BodyStreamBuffer::stopLoading() |
| 380 { | 380 { |
| 381 if (!m_loader) | 381 if (!m_loader) |
| 382 return; | 382 return; |
| 383 m_loader->cancel(); | 383 m_loader->cancel(); |
| 384 m_loader = nullptr; | 384 m_loader = nullptr; |
| 385 } | 385 } |
| 386 | 386 |
| 387 } // namespace blink | 387 } // namespace blink |
| OLD | NEW |