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" | |
10 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
11 #include "core/dom/DOMTypedArray.h" | 10 #include "core/dom/DOMTypedArray.h" |
12 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
13 #include "core/streams/ReadableStreamController.h" | 12 #include "core/streams/ReadableStreamController.h" |
14 #include "core/streams/ReadableStreamOperations.h" | 13 #include "core/streams/ReadableStreamOperations.h" |
15 #include "core/workers/WorkerGlobalScope.h" | |
16 #include "modules/fetch/Body.h" | 14 #include "modules/fetch/Body.h" |
17 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" | 15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" |
18 #include "modules/fetch/DataConsumerHandleUtil.h" | 16 #include "modules/fetch/DataConsumerHandleUtil.h" |
19 #include "modules/fetch/DataConsumerTee.h" | 17 #include "modules/fetch/DataConsumerTee.h" |
20 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" | 18 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
21 #include "platform/blob/BlobData.h" | 19 #include "platform/blob/BlobData.h" |
22 #include "platform/network/EncodedFormData.h" | 20 #include "platform/network/EncodedFormData.h" |
23 #include <memory> | 21 #include <memory> |
24 | 22 |
25 namespace blink { | 23 namespace blink { |
26 | 24 |
27 namespace { | |
28 | |
29 bool isTerminating(ScriptState* scriptState) | |
30 { | |
31 ExecutionContext* executionContext = scriptState->getExecutionContext(); | |
32 if (!executionContext) | |
33 return true; | |
34 if (!executionContext->isWorkerGlobalScope()) | |
35 return false; | |
36 return toWorkerGlobalScope(executionContext)->scriptController()->isExecutio nTerminating(); | |
37 } | |
38 | |
39 } // namespace | |
40 | |
41 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { | 25 class BodyStreamBuffer::LoaderClient final : public GarbageCollectedFinalized<Lo aderClient>, public ActiveDOMObject, public FetchDataLoader::Client { |
42 WTF_MAKE_NONCOPYABLE(LoaderClient); | 26 WTF_MAKE_NONCOPYABLE(LoaderClient); |
43 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); | 27 USING_GARBAGE_COLLECTED_MIXIN(LoaderClient); |
44 public: | 28 public: |
45 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F etchDataLoader::Client* client) | 29 LoaderClient(ExecutionContext* executionContext, BodyStreamBuffer* buffer, F etchDataLoader::Client* client) |
46 : ActiveDOMObject(executionContext) | 30 : ActiveDOMObject(executionContext) |
47 , m_buffer(buffer) | 31 , m_buffer(buffer) |
48 , m_client(client) | 32 , m_client(client) |
49 { | 33 { |
50 suspendIfNeeded(); | 34 suspendIfNeeded(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 Member<FetchDataLoader::Client> m_client; | 82 Member<FetchDataLoader::Client> m_client; |
99 }; | 83 }; |
100 | 84 |
101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, std::unique_ptr<Fet chDataConsumerHandle> handle) | 85 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, std::unique_ptr<Fet chDataConsumerHandle> handle) |
102 : UnderlyingSourceBase(scriptState) | 86 : UnderlyingSourceBase(scriptState) |
103 , m_scriptState(scriptState) | 87 , m_scriptState(scriptState) |
104 , m_handle(std::move(handle)) | 88 , m_handle(std::move(handle)) |
105 , m_reader(m_handle->obtainFetchDataReader(this)) | 89 , m_reader(m_handle->obtainFetchDataReader(this)) |
106 , m_madeFromReadableStream(false) | 90 , m_madeFromReadableStream(false) |
107 { | 91 { |
108 if (isTerminating(scriptState)) { | 92 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
93 if (bodyValue.IsEmpty()) { | |
109 m_reader = nullptr; | 94 m_reader = nullptr; |
110 m_handle = nullptr; | 95 m_handle = nullptr; |
111 return; | 96 return; |
112 } | |
113 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); | |
114 if (bodyValue.IsEmpty()) { | |
115 DCHECK(isTerminating(scriptState)); | |
116 m_reader = nullptr; | |
117 m_handle = nullptr; | |
118 return; | |
119 } | 97 } |
120 DCHECK(bodyValue->IsObject()); | 98 DCHECK(bodyValue->IsObject()); |
121 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 99 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
122 | 100 |
123 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( | 101 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( |
124 scriptState, this, ReadableStreamOperations::createCountQueuingStrategy( scriptState, 0)); | 102 scriptState, this, ReadableStreamOperations::createCountQueuingStrategy( scriptState, 0)); |
125 if (isTerminating(scriptState)) { | |
126 m_reader = nullptr; | |
127 m_handle = nullptr; | |
128 return; | |
129 } | |
130 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), readableStream.v8Value()); | 103 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), readableStream.v8Value()); |
131 } | 104 } |
132 | 105 |
133 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) | 106 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) |
134 : UnderlyingSourceBase(scriptState) | 107 : UnderlyingSourceBase(scriptState) |
135 , m_scriptState(scriptState) | 108 , m_scriptState(scriptState) |
136 , m_madeFromReadableStream(true) | 109 , m_madeFromReadableStream(true) |
137 { | 110 { |
138 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); | 111 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); |
139 if (isTerminating(scriptState)) | 112 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); |
113 if (bodyValue.IsEmpty()) | |
haraken
2016/08/22 04:35:39
I recently changed toV8 so that it never returns a
yhirano
2016/08/22 06:22:13
+1
nhiroki
2016/08/22 06:57:46
Removed the empty checks in this CL.
| |
140 return; | 114 return; |
141 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); | |
142 if (bodyValue.IsEmpty()) { | |
143 DCHECK(isTerminating(scriptState)); | |
144 return; | |
145 } | |
146 DCHECK(bodyValue->IsObject()); | 115 DCHECK(bodyValue->IsObject()); |
147 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 116 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
148 | 117 |
149 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), stream.v8Value()); | 118 V8HiddenValue::setHiddenValue(scriptState, body, V8HiddenValue::internalBody Stream(scriptState->isolate()), stream.v8Value()); |
150 } | 119 } |
151 | 120 |
152 ScriptValue BodyStreamBuffer::stream() | 121 ScriptValue BodyStreamBuffer::stream() |
153 { | 122 { |
154 ScriptState::Scope scope(m_scriptState.get()); | 123 ScriptState::Scope scope(m_scriptState.get()); |
155 if (isTerminating(m_scriptState.get())) | 124 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); |
125 if (bodyValue.IsEmpty()) | |
156 return ScriptValue(); | 126 return ScriptValue(); |
157 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); | |
158 if (bodyValue.IsEmpty()) { | |
159 DCHECK(isTerminating(m_scriptState.get())); | |
160 return ScriptValue(); | |
161 } | |
162 DCHECK(bodyValue->IsObject()); | 127 DCHECK(bodyValue->IsObject()); |
163 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); | 128 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); |
164 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_scri ptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolate()) )); | 129 return ScriptValue(m_scriptState.get(), V8HiddenValue::getHiddenValue(m_scri ptState.get(), body, V8HiddenValue::internalBodyStream(m_scriptState->isolate()) )); |
165 } | 130 } |
166 | 131 |
167 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons umerHandle::Reader::BlobSizePolicy policy) | 132 PassRefPtr<BlobDataHandle> BodyStreamBuffer::drainAsBlobDataHandle(FetchDataCons umerHandle::Reader::BlobSizePolicy policy) |
168 { | 133 { |
169 ASSERT(!isStreamLocked()); | 134 ASSERT(!isStreamLocked()); |
170 ASSERT(!isStreamDisturbed()); | 135 ASSERT(!isStreamDisturbed()); |
171 if (isStreamClosed() || isStreamErrored()) | 136 if (isStreamClosed() || isStreamErrored()) |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle()); | 385 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle()); |
421 } | 386 } |
422 if (isErrored) | 387 if (isErrored) |
423 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle()); | 388 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle()); |
424 | 389 |
425 DCHECK(handle); | 390 DCHECK(handle); |
426 return handle; | 391 return handle; |
427 } | 392 } |
428 | 393 |
429 } // namespace blink | 394 } // namespace blink |
OLD | NEW |