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/serviceworkers/Cache.h" | 6 #include "modules/serviceworkers/Cache.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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelet
e; | 296 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelet
e; |
297 request->populateWebServiceWorkerRequest(batchOperations[0].request); | 297 request->populateWebServiceWorkerRequest(batchOperations[0].request); |
298 batchOperations[0].matchParams = toWebQueryParams(options); | 298 batchOperations[0].matchParams = toWebQueryParams(options); |
299 | 299 |
300 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 300 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
301 const ScriptPromise promise = resolver->promise(); | 301 const ScriptPromise promise = resolver->promise(); |
302 m_webCache->dispatchBatch(new CacheDeleteCallback(resolver), batchOperations
); | 302 m_webCache->dispatchBatch(new CacheDeleteCallback(resolver), batchOperations
); |
303 return promise; | 303 return promise; |
304 } | 304 } |
305 | 305 |
306 ScriptPromise Cache::putImpl(ScriptState* scriptState, const Request* request, R
esponse* response) | 306 ScriptPromise Cache::putImpl(ScriptState* scriptState, Request* request, Respons
e* response) |
307 { | 307 { |
308 KURL url(KURL(), request->url()); | 308 KURL url(KURL(), request->url()); |
309 if (!url.protocolIsInHTTPFamily()) | 309 if (!url.protocolIsInHTTPFamily()) |
310 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Request scheme '" + url.protocol() + "' is unsuppor
ted")); | 310 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Request scheme '" + url.protocol() + "' is unsuppor
ted")); |
311 if (request->method() != "GET") | 311 if (request->method() != "GET") |
312 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Request method '" + request->method() + "' is unsup
ported")); | 312 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Request method '" + request->method() + "' is unsup
ported")); |
| 313 if (request->hasBody() && request->bodyUsed()) |
| 314 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Request body is already used")); |
| 315 if (response->hasBody() && response->bodyUsed()) |
| 316 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "Response body is already used")); |
| 317 |
| 318 if (request->hasBody()) |
| 319 request->setBodyUsed(); |
| 320 if (response->hasBody()) |
| 321 response->setBodyUsed(); |
313 | 322 |
314 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1)); | 323 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1)); |
315 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut; | 324 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut; |
316 request->populateWebServiceWorkerRequest(batchOperations[0].request); | 325 request->populateWebServiceWorkerRequest(batchOperations[0].request); |
317 response->populateWebServiceWorkerResponse(batchOperations[0].response); | 326 response->populateWebServiceWorkerResponse(batchOperations[0].response); |
318 | 327 |
319 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 328 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
320 const ScriptPromise promise = resolver->promise(); | 329 const ScriptPromise promise = resolver->promise(); |
321 m_webCache->dispatchBatch(new CacheAddOrPutCallbacks(resolver), batchOperati
ons); | 330 m_webCache->dispatchBatch(new CacheAddOrPutCallbacks(resolver), batchOperati
ons); |
322 return promise; | 331 return promise; |
(...skipping 12 matching lines...) Expand all Loading... |
335 WebServiceWorkerRequest webRequest; | 344 WebServiceWorkerRequest webRequest; |
336 request->populateWebServiceWorkerRequest(webRequest); | 345 request->populateWebServiceWorkerRequest(webRequest); |
337 | 346 |
338 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 347 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
339 const ScriptPromise promise = resolver->promise(); | 348 const ScriptPromise promise = resolver->promise(); |
340 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); | 349 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); |
341 return promise; | 350 return promise; |
342 } | 351 } |
343 | 352 |
344 } // namespace blink | 353 } // namespace blink |
OLD | NEW |