| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/Body.h" | 6 #include "modules/fetch/Body.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (bodyBuffer()) { | 185 if (bodyBuffer()) { |
| 186 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoa
der::createLoaderAsString(), new BodyTextConsumer(resolver)); | 186 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoa
der::createLoaderAsString(), new BodyTextConsumer(resolver)); |
| 187 } else { | 187 } else { |
| 188 resolver->resolve(String()); | 188 resolver->resolve(String()); |
| 189 } | 189 } |
| 190 return promise; | 190 return promise; |
| 191 } | 191 } |
| 192 | 192 |
| 193 ReadableByteStream* Body::body() | 193 ReadableByteStream* Body::body() |
| 194 { | 194 { |
| 195 return bodyBuffer() ? bodyBuffer()->stream() : nullptr; |
| 196 } |
| 197 |
| 198 ReadableByteStream* Body::bodyWithUseCounter() |
| 199 { |
| 195 UseCounter::count(executionContext(), UseCounter::FetchBodyStream); | 200 UseCounter::count(executionContext(), UseCounter::FetchBodyStream); |
| 196 return bodyBuffer() ? bodyBuffer()->stream() : nullptr; | 201 return body(); |
| 197 } | 202 } |
| 198 | 203 |
| 199 bool Body::bodyUsed() | 204 bool Body::bodyUsed() |
| 200 { | 205 { |
| 201 return m_bodyPassed || (body() && body()->isLocked()); | 206 return body() && body()->isDisturbed(); |
| 207 } |
| 208 |
| 209 bool Body::isBodyLocked() |
| 210 { |
| 211 return body() && body()->isLocked(); |
| 202 } | 212 } |
| 203 | 213 |
| 204 bool Body::hasPendingActivity() const | 214 bool Body::hasPendingActivity() const |
| 205 { | 215 { |
| 206 if (executionContext()->activeDOMObjectsAreStopped()) | 216 if (executionContext()->activeDOMObjectsAreStopped()) |
| 207 return false; | 217 return false; |
| 208 if (!bodyBuffer()) | 218 if (!bodyBuffer()) |
| 209 return false; | 219 return false; |
| 210 return bodyBuffer()->hasPendingActivity(); | 220 return bodyBuffer()->hasPendingActivity(); |
| 211 } | 221 } |
| 212 | 222 |
| 213 Body::Body(ExecutionContext* context) : ActiveDOMObject(context), m_bodyPassed(f
alse), m_opaque(false) | 223 Body::Body(ExecutionContext* context) : ActiveDOMObject(context), m_opaque(false
) |
| 214 { | 224 { |
| 215 suspendIfNeeded(); | 225 suspendIfNeeded(); |
| 216 } | 226 } |
| 217 | 227 |
| 218 ScriptPromise Body::rejectInvalidConsumption(ScriptState* scriptState) | 228 ScriptPromise Body::rejectInvalidConsumption(ScriptState* scriptState) |
| 219 { | 229 { |
| 220 if (m_opaque) | 230 if (m_opaque) |
| 221 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); | 231 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); |
| 222 if (bodyUsed()) | 232 if (isBodyLocked() || bodyUsed()) |
| 223 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); | 233 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); |
| 224 return ScriptPromise(); | 234 return ScriptPromise(); |
| 225 } | 235 } |
| 226 | 236 |
| 227 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |