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 "bindings/core/v8/WorkerOrWorkletScriptController.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMTypedArray.h" | 11 #include "core/dom/DOMTypedArray.h" |
11 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
12 #include "core/streams/ReadableStreamController.h" | 13 #include "core/streams/ReadableStreamController.h" |
13 #include "core/streams/ReadableStreamOperations.h" | 14 #include "core/streams/ReadableStreamOperations.h" |
| 15 #include "core/workers/WorkerGlobalScope.h" |
14 #include "modules/fetch/Body.h" | 16 #include "modules/fetch/Body.h" |
15 #include "modules/fetch/DataConsumerHandleUtil.h" | 17 #include "modules/fetch/DataConsumerHandleUtil.h" |
16 #include "modules/fetch/DataConsumerTee.h" | 18 #include "modules/fetch/DataConsumerTee.h" |
17 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 19 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
18 #include "platform/RuntimeEnabledFeatures.h" | 20 #include "platform/RuntimeEnabledFeatures.h" |
19 #include "platform/blob/BlobData.h" | 21 #include "platform/blob/BlobData.h" |
20 #include "platform/network/EncodedFormData.h" | 22 #include "platform/network/EncodedFormData.h" |
21 | 23 |
22 namespace blink { | 24 namespace blink { |
23 | 25 |
| 26 namespace { |
| 27 |
| 28 bool isTerminating(ScriptState* scriptState) |
| 29 { |
| 30 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 31 if (!executionContext) |
| 32 return true; |
| 33 if (!executionContext->isWorkerGlobalScope()) |
| 34 return false; |
| 35 return toWorkerGlobalScope(executionContext)->scriptController()->isExecutio
nTerminating(); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
24 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo
aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { | 40 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo
aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { |
25 WTF_MAKE_NONCOPYABLE(LoaderClient); | 41 WTF_MAKE_NONCOPYABLE(LoaderClient); |
26 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); | 42 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
27 public: | 43 public: |
28 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F
etchDataLoader::Client* client) | 44 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F
etchDataLoader::Client* client) |
29 : ActiveDOMObject(executionContext) | 45 : ActiveDOMObject(executionContext) |
30 , m_buffer(buffer) | 46 , m_buffer(buffer) |
31 , m_client(client) | 47 , m_client(client) |
32 { | 48 { |
33 suspendIfNeeded(); | 49 suspendIfNeeded(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 99 |
84 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat
aConsumerHandle> handle) | 100 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat
aConsumerHandle> handle) |
85 : UnderlyingSourceBase(scriptState) | 101 : UnderlyingSourceBase(scriptState) |
86 , m_scriptState(scriptState) | 102 , m_scriptState(scriptState) |
87 , m_handle(std::move(handle)) | 103 , m_handle(std::move(handle)) |
88 , m_reader(m_handle->obtainReader(this)) | 104 , m_reader(m_handle->obtainReader(this)) |
89 , m_madeFromReadableStream(false) | 105 , m_madeFromReadableStream(false) |
90 { | 106 { |
91 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 107 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
92 ScriptState::Scope scope(scriptState); | 108 ScriptState::Scope scope(scriptState); |
| 109 if (isTerminating(scriptState)) |
| 110 return; |
93 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); | 111 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
94 ASSERT(!bodyValue.IsEmpty()); | 112 if (bodyValue.IsEmpty()) { |
| 113 DCHECK(isTerminating(scriptState)); |
| 114 return; |
| 115 } |
95 ASSERT(bodyValue->IsObject()); | 116 ASSERT(bodyValue->IsObject()); |
96 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 117 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
97 | 118 |
98 ScriptValue readableStream = ReadableStreamOperations::createReadableStr
eam( | 119 ScriptValue readableStream = ReadableStreamOperations::createReadableStr
eam( |
99 scriptState, this, ReadableStreamOperations::createCountQueuingStrat
egy(scriptState, 0)); | 120 scriptState, this, ReadableStreamOperations::createCountQueuingStrat
egy(scriptState, 0)); |
100 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internal
BodyStream(scriptState->isolate()), readableStream.v8Value()); | 121 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internal
BodyStream(scriptState->isolate()), readableStream.v8Value()); |
101 } else { | 122 } else { |
102 m_stream = new ReadableByteStream(this, new ReadableByteStream::StrictSt
rategy); | 123 m_stream = new ReadableByteStream(this, new ReadableByteStream::StrictSt
rategy); |
103 m_stream->didSourceStart(); | 124 m_stream->didSourceStart(); |
104 } | 125 } |
105 } | 126 } |
106 | 127 |
107 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) | 128 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) |
108 : UnderlyingSourceBase(scriptState) | 129 : UnderlyingSourceBase(scriptState) |
109 , m_scriptState(scriptState) | 130 , m_scriptState(scriptState) |
110 , m_madeFromReadableStream(true) | 131 , m_madeFromReadableStream(true) |
111 { | 132 { |
112 ScriptState::Scope scope(scriptState); | 133 ScriptState::Scope scope(scriptState); |
113 DCHECK(RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()); | 134 DCHECK(RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()); |
114 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); | 135 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); |
| 136 if (isTerminating(scriptState)) |
| 137 return; |
115 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); | 138 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
116 DCHECK(!bodyValue.IsEmpty()); | 139 if (bodyValue.IsEmpty()) { |
| 140 DCHECK(isTerminating(scriptState)); |
| 141 return; |
| 142 } |
117 DCHECK(bodyValue->IsObject()); | 143 DCHECK(bodyValue->IsObject()); |
118 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 144 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
119 | 145 |
120 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody
Stream(scriptState->isolate()), stream.v8Value()); | 146 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody
Stream(scriptState->isolate()), stream.v8Value()); |
121 } | 147 } |
122 | 148 |
123 ScriptValue BodyStreamBuffer::stream() | 149 ScriptValue BodyStreamBuffer::stream() |
124 { | 150 { |
125 ScriptState::Scope scope(m_scriptState.get()); | 151 ScriptState::Scope scope(m_scriptState.get()); |
126 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { | 152 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { |
| 153 if (isTerminating(m_scriptState.get())) |
| 154 return ScriptValue(); |
127 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); | 155 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); |
128 ASSERT(!bodyValue.IsEmpty()); | 156 if (bodyValue.IsEmpty()) { |
| 157 DCHECK(isTerminating(m_scriptState.get())); |
| 158 return ScriptValue(); |
| 159 } |
129 ASSERT(bodyValue->IsObject()); | 160 ASSERT(bodyValue->IsObject()); |
130 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 161 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
131 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_
scriptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolat
e()))); | 162 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_
scriptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolat
e()))); |
132 } | 163 } |
133 return ScriptValue(m_scriptState.get(), toV8(m_stream, m_scriptState.get()))
; | 164 return ScriptValue(m_scriptState.get(), toV8(m_stream, m_scriptState.get()))
; |
134 } | 165 } |
135 | 166 |
136 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) | 167 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons
umerHandle::Reader::BlobSizePolicy policy) |
137 { | 168 { |
138 ASSERT(!isStreamLocked()); | 169 ASSERT(!isStreamLocked()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); | 469 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer
Handle()); |
439 } | 470 } |
440 if (isErrored) | 471 if (isErrored) |
441 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); | 472 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD
ataConsumerHandle()); |
442 | 473 |
443 DCHECK(handle); | 474 DCHECK(handle); |
444 return handle; | 475 return handle; |
445 } | 476 } |
446 | 477 |
447 } // namespace blink | 478 } // namespace blink |
OLD | NEW |