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/Body.h" | 5 #include "modules/fetch/Body.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "bindings/core/v8/V8ArrayBuffer.h" | 9 #include "bindings/core/v8/V8ArrayBuffer.h" |
10 #include "bindings/core/v8/V8ThrowException.h" | 10 #include "bindings/core/v8/V8ThrowException.h" |
11 #include "core/dom/DOMArrayBuffer.h" | 11 #include "core/dom/DOMArrayBuffer.h" |
12 #include "core/dom/DOMTypedArray.h" | 12 #include "core/dom/DOMTypedArray.h" |
13 #include "core/fileapi/Blob.h" | 13 #include "core/fileapi/Blob.h" |
14 #include "core/frame/UseCounter.h" | |
15 #include "modules/fetch/BodyStreamBuffer.h" | 14 #include "modules/fetch/BodyStreamBuffer.h" |
16 #include "modules/fetch/FetchDataLoader.h" | 15 #include "modules/fetch/FetchDataLoader.h" |
17 #include "public/platform/WebDataConsumerHandle.h" | 16 #include "public/platform/WebDataConsumerHandle.h" |
18 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
19 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
20 #include <memory> | 19 #include <memory> |
21 | 20 |
22 namespace blink { | 21 namespace blink { |
23 | 22 |
24 namespace { | 23 namespace { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 promise = resolver->promise(); | 191 promise = resolver->promise(); |
193 if (bodyBuffer()) { | 192 if (bodyBuffer()) { |
194 bodyBuffer()->startLoading(FetchDataLoader::createLoaderAsString(), | 193 bodyBuffer()->startLoading(FetchDataLoader::createLoaderAsString(), |
195 new BodyTextConsumer(resolver)); | 194 new BodyTextConsumer(resolver)); |
196 } else { | 195 } else { |
197 resolver->resolve(String()); | 196 resolver->resolve(String()); |
198 } | 197 } |
199 return promise; | 198 return promise; |
200 } | 199 } |
201 | 200 |
202 ScriptValue Body::bodyWithUseCounter(ScriptState* scriptState) { | 201 ScriptValue Body::body(ScriptState* scriptState) { |
203 UseCounter::count(getExecutionContext(), UseCounter::FetchBodyStream); | |
204 if (!bodyBuffer()) | 202 if (!bodyBuffer()) |
205 return ScriptValue::createNull(scriptState); | 203 return ScriptValue::createNull(scriptState); |
206 ScriptValue stream = bodyBuffer()->stream(); | 204 ScriptValue stream = bodyBuffer()->stream(); |
207 ASSERT(stream.getScriptState() == scriptState); | 205 ASSERT(stream.getScriptState() == scriptState); |
208 return stream; | 206 return stream; |
209 } | 207 } |
210 | 208 |
211 bool Body::bodyUsed() { | 209 bool Body::bodyUsed() { |
212 return bodyBuffer() && bodyBuffer()->isStreamDisturbed(); | 210 return bodyBuffer() && bodyBuffer()->isStreamDisturbed(); |
213 } | 211 } |
(...skipping 14 matching lines...) Expand all Loading... |
228 | 226 |
229 ScriptPromise Body::rejectInvalidConsumption(ScriptState* scriptState) { | 227 ScriptPromise Body::rejectInvalidConsumption(ScriptState* scriptState) { |
230 if (isBodyLocked() || bodyUsed()) | 228 if (isBodyLocked() || bodyUsed()) |
231 return ScriptPromise::reject( | 229 return ScriptPromise::reject( |
232 scriptState, V8ThrowException::createTypeError(scriptState->isolate(), | 230 scriptState, V8ThrowException::createTypeError(scriptState->isolate(), |
233 "Already read")); | 231 "Already read")); |
234 return ScriptPromise(); | 232 return ScriptPromise(); |
235 } | 233 } |
236 | 234 |
237 } // namespace blink | 235 } // namespace blink |
OLD | NEW |