| 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 <memory> |
| 7 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/V8HiddenValue.h" | 9 #include "bindings/core/v8/V8PrivateProperty.h" |
| 9 #include "bindings/core/v8/V8ThrowException.h" | 10 #include "bindings/core/v8/V8ThrowException.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" | 11 #include "core/dom/DOMArrayBuffer.h" |
| 11 #include "core/dom/DOMTypedArray.h" | 12 #include "core/dom/DOMTypedArray.h" |
| 12 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/streams/ReadableStreamController.h" | 14 #include "core/streams/ReadableStreamController.h" |
| 14 #include "core/streams/ReadableStreamOperations.h" | 15 #include "core/streams/ReadableStreamOperations.h" |
| 15 #include "modules/fetch/Body.h" | 16 #include "modules/fetch/Body.h" |
| 16 #include "modules/fetch/ReadableStreamBytesConsumer.h" | 17 #include "modules/fetch/ReadableStreamBytesConsumer.h" |
| 17 #include "platform/blob/BlobData.h" | 18 #include "platform/blob/BlobData.h" |
| 18 #include "platform/network/EncodedFormData.h" | 19 #include "platform/network/EncodedFormData.h" |
| 19 #include <memory> | |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 class BodyStreamBuffer::LoaderClient final | 23 class BodyStreamBuffer::LoaderClient final |
| 24 : public GarbageCollectedFinalized<LoaderClient>, | 24 : public GarbageCollectedFinalized<LoaderClient>, |
| 25 public ContextLifecycleObserver, | 25 public ContextLifecycleObserver, |
| 26 public FetchDataLoader::Client { | 26 public FetchDataLoader::Client { |
| 27 WTF_MAKE_NONCOPYABLE(LoaderClient); | 27 WTF_MAKE_NONCOPYABLE(LoaderClient); |
| 28 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); | 28 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
| 29 | 29 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 m_madeFromReadableStream(false) { | 83 m_madeFromReadableStream(false) { |
| 84 v8::Local<v8::Value> bodyValue = ToV8(this, scriptState); | 84 v8::Local<v8::Value> bodyValue = ToV8(this, scriptState); |
| 85 DCHECK(!bodyValue.IsEmpty()); | 85 DCHECK(!bodyValue.IsEmpty()); |
| 86 DCHECK(bodyValue->IsObject()); | 86 DCHECK(bodyValue->IsObject()); |
| 87 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 87 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
| 88 | 88 |
| 89 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( | 89 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( |
| 90 scriptState, this, | 90 scriptState, this, |
| 91 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0)); | 91 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0)); |
| 92 DCHECK(!readableStream.isEmpty()); | 92 DCHECK(!readableStream.isEmpty()); |
| 93 V8HiddenValue::setHiddenValue( | 93 V8PrivateProperty::getInternalBodyStream(scriptState->isolate()) |
| 94 scriptState, body, | 94 .set(body, readableStream.v8Value()); |
| 95 V8HiddenValue::internalBodyStream(scriptState->isolate()), | |
| 96 readableStream.v8Value()); | |
| 97 m_consumer->setClient(this); | 95 m_consumer->setClient(this); |
| 98 onStateChange(); | 96 onStateChange(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) | 99 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) |
| 102 : UnderlyingSourceBase(scriptState), | 100 : UnderlyingSourceBase(scriptState), |
| 103 m_scriptState(scriptState), | 101 m_scriptState(scriptState), |
| 104 m_madeFromReadableStream(true) { | 102 m_madeFromReadableStream(true) { |
| 105 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); | 103 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); |
| 106 v8::Local<v8::Value> bodyValue = ToV8(this, scriptState); | 104 v8::Local<v8::Value> bodyValue = ToV8(this, scriptState); |
| 107 DCHECK(!bodyValue.IsEmpty()); | 105 DCHECK(!bodyValue.IsEmpty()); |
| 108 DCHECK(bodyValue->IsObject()); | 106 DCHECK(bodyValue->IsObject()); |
| 109 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 107 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
| 110 | 108 |
| 111 V8HiddenValue::setHiddenValue( | 109 V8PrivateProperty::getInternalBodyStream(scriptState->isolate()) |
| 112 scriptState, body, | 110 .set(body, stream.v8Value()); |
| 113 V8HiddenValue::internalBodyStream(scriptState->isolate()), | |
| 114 stream.v8Value()); | |
| 115 } | 111 } |
| 116 | 112 |
| 117 ScriptValue BodyStreamBuffer::stream() { | 113 ScriptValue BodyStreamBuffer::stream() { |
| 118 ScriptState::Scope scope(m_scriptState.get()); | 114 ScriptState::Scope scope(m_scriptState.get()); |
| 119 v8::Local<v8::Value> bodyValue = ToV8(this, m_scriptState.get()); | 115 v8::Local<v8::Value> bodyValue = ToV8(this, m_scriptState.get()); |
| 120 DCHECK(!bodyValue.IsEmpty()); | 116 DCHECK(!bodyValue.IsEmpty()); |
| 121 DCHECK(bodyValue->IsObject()); | 117 DCHECK(bodyValue->IsObject()); |
| 122 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 118 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
| 123 return ScriptValue( | 119 return ScriptValue( |
| 124 m_scriptState.get(), | 120 m_scriptState.get(), |
| 125 V8HiddenValue::getHiddenValue( | 121 V8PrivateProperty::getInternalBodyStream(m_scriptState->isolate()) |
| 126 m_scriptState.get(), body, | 122 .getOrEmpty(body)); |
| 127 V8HiddenValue::internalBodyStream(m_scriptState->isolate()))); | |
| 128 } | 123 } |
| 129 | 124 |
| 130 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle( | 125 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle( |
| 131 BytesConsumer::BlobSizePolicy policy) { | 126 BytesConsumer::BlobSizePolicy policy) { |
| 132 ASSERT(!isStreamLocked()); | 127 ASSERT(!isStreamLocked()); |
| 133 ASSERT(!isStreamDisturbed()); | 128 ASSERT(!isStreamDisturbed()); |
| 134 if (isStreamClosed() || isStreamErrored()) | 129 if (isStreamClosed() || isStreamErrored()) |
| 135 return nullptr; | 130 return nullptr; |
| 136 | 131 |
| 137 if (m_madeFromReadableStream) | 132 if (m_madeFromReadableStream) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 381 } |
| 387 if (isErrored) | 382 if (isErrored) |
| 388 return BytesConsumer::createErrored(BytesConsumer::Error("error")); | 383 return BytesConsumer::createErrored(BytesConsumer::Error("error")); |
| 389 | 384 |
| 390 DCHECK(consumer); | 385 DCHECK(consumer); |
| 391 consumer->clearClient(); | 386 consumer->clearClient(); |
| 392 return consumer; | 387 return consumer; |
| 393 } | 388 } |
| 394 | 389 |
| 395 } // namespace blink | 390 } // namespace blink |
| OLD | NEW |