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/cachestorage/Cache.h" | 6 #include "modules/cachestorage/Cache.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (--m_numberOfRemainingOperations != 0) | 196 if (--m_numberOfRemainingOperations != 0) |
197 return; | 197 return; |
198 m_cache->webCache()->dispatchBatch(new CallbackPromiseAdapter<void, Cach
eStorageError>(m_resolver), m_batchOperations); | 198 m_cache->webCache()->dispatchBatch(new CallbackPromiseAdapter<void, Cach
eStorageError>(m_resolver), m_batchOperations); |
199 } | 199 } |
200 | 200 |
201 void onError(DOMException* exception) | 201 void onError(DOMException* exception) |
202 { | 202 { |
203 if (m_completed) | 203 if (m_completed) |
204 return; | 204 return; |
205 m_completed = true; | 205 m_completed = true; |
| 206 m_resolver->reject(exception); |
| 207 } |
206 | 208 |
207 ScriptState* state = m_resolver->scriptState(); | 209 void onError(v8::Local<v8::Value> exception) |
208 ScriptState::Scope scope(state); | 210 { |
209 m_resolver->reject(V8ThrowException::createTypeError(state->isolate(), e
xception->toString())); | 211 if (m_completed) |
| 212 return; |
| 213 m_completed = true; |
| 214 m_resolver->reject(exception); |
210 } | 215 } |
211 | 216 |
212 DEFINE_INLINE_VIRTUAL_TRACE() | 217 DEFINE_INLINE_VIRTUAL_TRACE() |
213 { | 218 { |
214 visitor->trace(m_cache); | 219 visitor->trace(m_cache); |
215 visitor->trace(m_resolver); | 220 visitor->trace(m_resolver); |
216 } | 221 } |
217 | 222 |
218 private: | 223 private: |
219 bool m_completed = false; | 224 bool m_completed = false; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 427 } |
423 | 428 |
424 ScriptPromise Cache::putImpl(ScriptState* scriptState, const HeapVector<Member<R
equest>>& requests, const HeapVector<Member<Response>>& responses) | 429 ScriptPromise Cache::putImpl(ScriptState* scriptState, const HeapVector<Member<R
equest>>& requests, const HeapVector<Member<Response>>& responses) |
425 { | 430 { |
426 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 431 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
427 const ScriptPromise promise = resolver->promise(); | 432 const ScriptPromise promise = resolver->promise(); |
428 BarrierCallbackForPut* barrierCallback = new BarrierCallbackForPut(requests.
size(), this, resolver.get()); | 433 BarrierCallbackForPut* barrierCallback = new BarrierCallbackForPut(requests.
size(), this, resolver.get()); |
429 | 434 |
430 for (size_t i = 0; i < requests.size(); ++i) { | 435 for (size_t i = 0; i < requests.size(); ++i) { |
431 KURL url(KURL(), requests[i]->url()); | 436 KURL url(KURL(), requests[i]->url()); |
432 if (!url.protocolIsInHTTPFamily()) | 437 if (!url.protocolIsInHTTPFamily()) { |
433 return ScriptPromise::reject(scriptState, V8ThrowException::createTy
peError(scriptState->isolate(), "Request scheme '" + url.protocol() + "' is unsu
pported")); | 438 barrierCallback->onError(V8ThrowException::createTypeError(scriptSta
te->isolate(), "Request scheme '" + url.protocol() + "' is unsupported")); |
434 if (requests[i]->method() != "GET") | 439 return promise; |
435 return ScriptPromise::reject(scriptState, V8ThrowException::createTy
peError(scriptState->isolate(), "Request method '" + requests[i]->method() + "'
is unsupported")); | 440 } |
436 if (requests[i]->hasBody() && requests[i]->bodyUsed()) | 441 if (requests[i]->method() != "GET") { |
437 return ScriptPromise::reject(scriptState, V8ThrowException::createTy
peError(scriptState->isolate(), "Request body is already used")); | 442 barrierCallback->onError(V8ThrowException::createTypeError(scriptSta
te->isolate(), "Request method '" + requests[i]->method() + "' is unsupported"))
; |
438 if (responses[i]->hasBody() && responses[i]->bodyUsed()) | 443 return promise; |
439 return ScriptPromise::reject(scriptState, V8ThrowException::createTy
peError(scriptState->isolate(), "Response body is already used")); | 444 } |
| 445 if (requests[i]->hasBody() && requests[i]->bodyUsed()) { |
| 446 barrierCallback->onError(V8ThrowException::createTypeError(scriptSta
te->isolate(), "Request body is already used")); |
| 447 return promise; |
| 448 } |
| 449 if (responses[i]->hasBody() && responses[i]->bodyUsed()) { |
| 450 barrierCallback->onError(V8ThrowException::createTypeError(scriptSta
te->isolate(), "Response body is already used")); |
| 451 return promise; |
| 452 } |
440 | 453 |
441 if (requests[i]->hasBody()) | 454 if (requests[i]->hasBody()) |
442 requests[i]->lockBody(Body::PassBody); | 455 requests[i]->lockBody(Body::PassBody); |
443 if (responses[i]->hasBody()) | 456 if (responses[i]->hasBody()) |
444 responses[i]->lockBody(Body::PassBody); | 457 responses[i]->lockBody(Body::PassBody); |
445 | 458 |
446 if (BodyStreamBuffer* buffer = responses[i]->internalBuffer()) { | 459 if (BodyStreamBuffer* buffer = responses[i]->internalBuffer()) { |
447 if (buffer == responses[i]->buffer() && responses[i]->isBodyConsumed
()) | 460 if (buffer == responses[i]->buffer() && responses[i]->isBodyConsumed
()) |
448 buffer = responses[i]->createDrainingStream(); | 461 buffer = responses[i]->createDrainingStream(); |
449 // If the response body type is stream, read the all data and create | 462 // If the response body type is stream, read the all data and create |
(...skipping 30 matching lines...) Expand all Loading... |
480 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); | 493 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); |
481 return promise; | 494 return promise; |
482 } | 495 } |
483 | 496 |
484 WebServiceWorkerCache* Cache::webCache() const | 497 WebServiceWorkerCache* Cache::webCache() const |
485 { | 498 { |
486 return m_webCache.get(); | 499 return m_webCache.get(); |
487 } | 500 } |
488 | 501 |
489 } // namespace blink | 502 } // namespace blink |
OLD | NEW |