| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 resolver()->resolve(parsed); | 97 resolver()->resolve(parsed); |
| 98 else | 98 else |
| 99 resolver()->reject(trycatch.Exception()); | 99 resolver()->reject(trycatch.Exception()); |
| 100 } | 100 } |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // namespace | 103 } // namespace |
| 104 | 104 |
| 105 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) | 105 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) |
| 106 { | 106 { |
| 107 if (m_opaque) |
| 108 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); |
| 109 |
| 107 if (bodyUsed()) | 110 if (bodyUsed()) |
| 108 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); | 111 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); |
| 109 | 112 |
| 110 // When the main thread sends a V8::TerminateExecution() signal to a worker | 113 // When the main thread sends a V8::TerminateExecution() signal to a worker |
| 111 // thread, any V8 API on the worker thread starts returning an empty | 114 // thread, any V8 API on the worker thread starts returning an empty |
| 112 // handle. This can happen in Body::readAsync. To avoid the situation, we | 115 // handle. This can happen in Body::readAsync. To avoid the situation, we |
| 113 // first check the ExecutionContext and return immediately if it's already | 116 // first check the ExecutionContext and return immediately if it's already |
| 114 // gone (which means that the V8::TerminateExecution() signal has been sent | 117 // gone (which means that the V8::TerminateExecution() signal has been sent |
| 115 // to this worker thread). | 118 // to this worker thread). |
| 116 if (!scriptState->executionContext()) | 119 if (!scriptState->executionContext()) |
| 117 return ScriptPromise(); | 120 return ScriptPromise(); |
| 118 | 121 |
| 119 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 122 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 120 ScriptPromise promise = resolver->promise(); | 123 ScriptPromise promise = resolver->promise(); |
| 121 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsArrayBuffer(), new BodyArrayBufferConsumer(resolver)); | 124 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsArrayBuffer(), new BodyArrayBufferConsumer(resolver)); |
| 122 return promise; | 125 return promise; |
| 123 } | 126 } |
| 124 | 127 |
| 125 ScriptPromise Body::blob(ScriptState* scriptState) | 128 ScriptPromise Body::blob(ScriptState* scriptState) |
| 126 { | 129 { |
| 130 if (m_opaque) |
| 131 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); |
| 132 |
| 127 if (bodyUsed()) | 133 if (bodyUsed()) |
| 128 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); | 134 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); |
| 129 | 135 |
| 130 // See above comment. | 136 // See above comment. |
| 131 if (!scriptState->executionContext()) | 137 if (!scriptState->executionContext()) |
| 132 return ScriptPromise(); | 138 return ScriptPromise(); |
| 133 | 139 |
| 134 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 135 ScriptPromise promise = resolver->promise(); | 141 ScriptPromise promise = resolver->promise(); |
| 136 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsBlobHandle(mimeType()), new BodyBlobConsumer(resolver)); | 142 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsBlobHandle(mimeType()), new BodyBlobConsumer(resolver)); |
| 137 return promise; | 143 return promise; |
| 138 | 144 |
| 139 } | 145 } |
| 140 | 146 |
| 141 ScriptPromise Body::json(ScriptState* scriptState) | 147 ScriptPromise Body::json(ScriptState* scriptState) |
| 142 { | 148 { |
| 149 if (m_opaque) |
| 150 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); |
| 151 |
| 143 if (bodyUsed()) | 152 if (bodyUsed()) |
| 144 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); | 153 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); |
| 145 | 154 |
| 146 // See above comment. | 155 // See above comment. |
| 147 if (!scriptState->executionContext()) | 156 if (!scriptState->executionContext()) |
| 148 return ScriptPromise(); | 157 return ScriptPromise(); |
| 149 | 158 |
| 150 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 159 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 151 ScriptPromise promise = resolver->promise(); | 160 ScriptPromise promise = resolver->promise(); |
| 152 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsString(), new BodyJsonConsumer(resolver)); | 161 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsString(), new BodyJsonConsumer(resolver)); |
| 153 return promise; | 162 return promise; |
| 154 } | 163 } |
| 155 | 164 |
| 156 ScriptPromise Body::text(ScriptState* scriptState) | 165 ScriptPromise Body::text(ScriptState* scriptState) |
| 157 { | 166 { |
| 167 if (m_opaque) |
| 168 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "The body is opaque.")); |
| 169 |
| 158 if (bodyUsed()) | 170 if (bodyUsed()) |
| 159 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); | 171 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Already read")); |
| 160 | 172 |
| 161 // See above comment. | 173 // See above comment. |
| 162 if (!scriptState->executionContext()) | 174 if (!scriptState->executionContext()) |
| 163 return ScriptPromise(); | 175 return ScriptPromise(); |
| 164 | 176 |
| 165 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 177 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 166 ScriptPromise promise = resolver->promise(); | 178 ScriptPromise promise = resolver->promise(); |
| 167 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsString(), new BodyTextConsumer(resolver)); | 179 bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader:
:createLoaderAsString(), new BodyTextConsumer(resolver)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 return m_bodyPassed || body()->isLocked(); | 191 return m_bodyPassed || body()->isLocked(); |
| 180 } | 192 } |
| 181 | 193 |
| 182 bool Body::hasPendingActivity() const | 194 bool Body::hasPendingActivity() const |
| 183 { | 195 { |
| 184 if (executionContext()->activeDOMObjectsAreStopped()) | 196 if (executionContext()->activeDOMObjectsAreStopped()) |
| 185 return false; | 197 return false; |
| 186 return bodyBuffer()->hasPendingActivity(); | 198 return bodyBuffer()->hasPendingActivity(); |
| 187 } | 199 } |
| 188 | 200 |
| 189 Body::Body(ExecutionContext* context) : ActiveDOMObject(context), m_bodyPassed(f
alse) | 201 Body::Body(ExecutionContext* context) |
| 202 : ActiveDOMObject(context) |
| 203 , m_bodyPassed(false) |
| 204 , m_opaque(false) |
| 190 { | 205 { |
| 191 suspendIfNeeded(); | 206 suspendIfNeeded(); |
| 192 } | 207 } |
| 193 | 208 |
| 194 } // namespace blink | 209 } // namespace blink |
| OLD | NEW |