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/cachestorage/Cache.h" | 5 #include "modules/cachestorage/Cache.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
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 11 matching lines...) Expand all Loading... | |
22 #include "platform/HTTPNames.h" | 22 #include "platform/HTTPNames.h" |
23 #include "platform/Histogram.h" | 23 #include "platform/Histogram.h" |
24 #include "platform/RuntimeEnabledFeatures.h" | 24 #include "platform/RuntimeEnabledFeatures.h" |
25 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" | 25 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" |
26 #include <memory> | 26 #include <memory> |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 void checkCacheQueryOptions(const CacheQueryOptions& options, ExecutionContext* context) | |
33 { | |
34 if (!RuntimeEnabledFeatures::cacheIgnoreSearchOptionEnabled() && options.ign oreSearch()) | |
35 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni ngMessageLevel, "Cache.match() does not support 'ignoreSearch' option yet. See h ttp://crbug.com/520784")); | |
36 if (options.ignoreMethod()) | |
37 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni ngMessageLevel, "Cache.match() does not support 'ignoreMethod' option yet. See h ttp://crbug.com/482256")); | |
38 if (options.ignoreVary()) | |
39 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni ngMessageLevel, "Cache.match() does not support 'ignoreVary' option yet. See htt p://crbug.com/499216")); | |
40 } | |
41 | |
42 // FIXME: Consider using CallbackPromiseAdapter. | 32 // FIXME: Consider using CallbackPromiseAdapter. |
43 class CacheMatchCallbacks : public WebServiceWorkerCache::CacheMatchCallbacks { | 33 class CacheMatchCallbacks : public WebServiceWorkerCache::CacheMatchCallbacks { |
44 WTF_MAKE_NONCOPYABLE(CacheMatchCallbacks); | 34 WTF_MAKE_NONCOPYABLE(CacheMatchCallbacks); |
45 public: | 35 public: |
46 explicit CacheMatchCallbacks(ScriptPromiseResolver* resolver) | 36 explicit CacheMatchCallbacks(ScriptPromiseResolver* resolver) |
47 : m_resolver(resolver) { } | 37 : m_resolver(resolver) { } |
48 | 38 |
49 void onSuccess(const WebServiceWorkerResponse& webResponse) override | 39 void onSuccess(const WebServiceWorkerResponse& webResponse) override |
50 { | 40 { |
51 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) | 41 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 Request* newRequest = Request::create(scriptState, request.getAsUSVString(), exceptionState); | 450 Request* newRequest = Request::create(scriptState, request.getAsUSVString(), exceptionState); |
461 if (exceptionState.hadException()) | 451 if (exceptionState.hadException()) |
462 return ScriptPromise(); | 452 return ScriptPromise(); |
463 return keysImpl(scriptState, newRequest, options); | 453 return keysImpl(scriptState, newRequest, options); |
464 } | 454 } |
465 | 455 |
466 // static | 456 // static |
467 WebServiceWorkerCache::QueryParams Cache::toWebQueryParams(const CacheQueryOptio ns& options) | 457 WebServiceWorkerCache::QueryParams Cache::toWebQueryParams(const CacheQueryOptio ns& options) |
468 { | 458 { |
469 WebServiceWorkerCache::QueryParams webQueryParams; | 459 WebServiceWorkerCache::QueryParams webQueryParams; |
470 webQueryParams.ignoreSearch = options.ignoreSearch() && RuntimeEnabledFeatur es::cacheIgnoreSearchOptionEnabled(); | 460 webQueryParams.ignoreSearch = options.ignoreSearch() && RuntimeEnabledFeatur es::cacheIgnoreSearchOptionEnabled(); |
nhiroki
2016/08/18 00:05:43
Can you remove cacheIgnoreSearchOptionEnabled() an
jkarlin
2016/08/18 14:08:24
Done.
| |
471 webQueryParams.ignoreMethod = options.ignoreMethod(); | 461 webQueryParams.ignoreMethod = options.ignoreMethod(); |
472 webQueryParams.ignoreVary = options.ignoreVary(); | 462 webQueryParams.ignoreVary = options.ignoreVary(); |
473 webQueryParams.cacheName = options.cacheName(); | 463 webQueryParams.cacheName = options.cacheName(); |
474 return webQueryParams; | 464 return webQueryParams; |
475 } | 465 } |
476 | 466 |
477 Cache::Cache(GlobalFetch::ScopedFetcher* fetcher, std::unique_ptr<WebServiceWork erCache> webCache) | 467 Cache::Cache(GlobalFetch::ScopedFetcher* fetcher, std::unique_ptr<WebServiceWork erCache> webCache) |
478 : m_scopedFetcher(fetcher) | 468 : m_scopedFetcher(fetcher) |
479 , m_webCache(std::move(webCache)) | 469 , m_webCache(std::move(webCache)) |
480 { | 470 { |
481 } | 471 } |
482 | 472 |
483 DEFINE_TRACE(Cache) | 473 DEFINE_TRACE(Cache) |
484 { | 474 { |
485 visitor->trace(m_scopedFetcher); | 475 visitor->trace(m_scopedFetcher); |
486 } | 476 } |
487 | 477 |
488 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options) | 478 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options) |
489 { | 479 { |
490 WebServiceWorkerRequest webRequest; | 480 WebServiceWorkerRequest webRequest; |
491 request->populateWebServiceWorkerRequest(webRequest); | 481 request->populateWebServiceWorkerRequest(webRequest); |
492 checkCacheQueryOptions(options, scriptState->getExecutionContext()); | |
493 | 482 |
494 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 483 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
495 const ScriptPromise promise = resolver->promise(); | 484 const ScriptPromise promise = resolver->promise(); |
496 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { | 485 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { |
497 resolver->resolve(); | 486 resolver->resolve(); |
498 return promise; | 487 return promise; |
499 } | 488 } |
500 m_webCache->dispatchMatch(new CacheMatchCallbacks(resolver), webRequest, toW ebQueryParams(options)); | 489 m_webCache->dispatchMatch(new CacheMatchCallbacks(resolver), webRequest, toW ebQueryParams(options)); |
501 return promise; | 490 return promise; |
502 } | 491 } |
503 | 492 |
504 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState) | 493 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState) |
505 { | 494 { |
506 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 495 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
507 const ScriptPromise promise = resolver->promise(); | 496 const ScriptPromise promise = resolver->promise(); |
508 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), WebS erviceWorkerRequest(), WebServiceWorkerCache::QueryParams()); | 497 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), WebS erviceWorkerRequest(), WebServiceWorkerCache::QueryParams()); |
509 return promise; | 498 return promise; |
510 } | 499 } |
511 | 500 |
512 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState, const Request* reque st, const CacheQueryOptions& options) | 501 ScriptPromise Cache::matchAllImpl(ScriptState* scriptState, const Request* reque st, const CacheQueryOptions& options) |
513 { | 502 { |
514 WebServiceWorkerRequest webRequest; | 503 WebServiceWorkerRequest webRequest; |
515 request->populateWebServiceWorkerRequest(webRequest); | 504 request->populateWebServiceWorkerRequest(webRequest); |
516 checkCacheQueryOptions(options, scriptState->getExecutionContext()); | |
517 | 505 |
518 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 506 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
519 const ScriptPromise promise = resolver->promise(); | 507 const ScriptPromise promise = resolver->promise(); |
520 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { | 508 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { |
521 resolver->resolve(HeapVector<Member<Response>>()); | 509 resolver->resolve(HeapVector<Member<Response>>()); |
522 return promise; | 510 return promise; |
523 } | 511 } |
524 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), webR equest, toWebQueryParams(options)); | 512 m_webCache->dispatchMatchAll(new CacheWithResponsesCallbacks(resolver), webR equest, toWebQueryParams(options)); |
525 return promise; | 513 return promise; |
526 } | 514 } |
(...skipping 18 matching lines...) Expand all Loading... | |
545 } | 533 } |
546 | 534 |
547 return ScriptPromise::all(scriptState, promises).then(FetchResolvedForAdd::c reate(scriptState, this, requests)); | 535 return ScriptPromise::all(scriptState, promises).then(FetchResolvedForAdd::c reate(scriptState, this, requests)); |
548 } | 536 } |
549 | 537 |
550 ScriptPromise Cache::deleteImpl(ScriptState* scriptState, const Request* request , const CacheQueryOptions& options) | 538 ScriptPromise Cache::deleteImpl(ScriptState* scriptState, const Request* request , const CacheQueryOptions& options) |
551 { | 539 { |
552 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1)); | 540 WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1)); |
553 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelet e; | 541 batchOperations[0].operationType = WebServiceWorkerCache::OperationTypeDelet e; |
554 request->populateWebServiceWorkerRequest(batchOperations[0].request); | 542 request->populateWebServiceWorkerRequest(batchOperations[0].request); |
555 checkCacheQueryOptions(options, scriptState->getExecutionContext()); | |
556 batchOperations[0].matchParams = toWebQueryParams(options); | 543 batchOperations[0].matchParams = toWebQueryParams(options); |
557 | 544 |
558 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 545 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
559 const ScriptPromise promise = resolver->promise(); | 546 const ScriptPromise promise = resolver->promise(); |
560 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { | 547 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { |
561 resolver->resolve(false); | 548 resolver->resolve(false); |
562 return promise; | 549 return promise; |
563 } | 550 } |
564 m_webCache->dispatchBatch(new CacheDeleteCallback(resolver), batchOperations ); | 551 m_webCache->dispatchBatch(new CacheDeleteCallback(resolver), batchOperations ); |
565 return promise; | 552 return promise; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 607 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
621 const ScriptPromise promise = resolver->promise(); | 608 const ScriptPromise promise = resolver->promise(); |
622 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), WebServic eWorkerRequest(), WebServiceWorkerCache::QueryParams()); | 609 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), WebServic eWorkerRequest(), WebServiceWorkerCache::QueryParams()); |
623 return promise; | 610 return promise; |
624 } | 611 } |
625 | 612 |
626 ScriptPromise Cache::keysImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options) | 613 ScriptPromise Cache::keysImpl(ScriptState* scriptState, const Request* request, const CacheQueryOptions& options) |
627 { | 614 { |
628 WebServiceWorkerRequest webRequest; | 615 WebServiceWorkerRequest webRequest; |
629 request->populateWebServiceWorkerRequest(webRequest); | 616 request->populateWebServiceWorkerRequest(webRequest); |
630 checkCacheQueryOptions(options, scriptState->getExecutionContext()); | |
631 | 617 |
632 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 618 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
633 const ScriptPromise promise = resolver->promise(); | 619 const ScriptPromise promise = resolver->promise(); |
634 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { | 620 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { |
635 resolver->resolve(HeapVector<Member<Request>>()); | 621 resolver->resolve(HeapVector<Member<Request>>()); |
636 return promise; | 622 return promise; |
637 } | 623 } |
638 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), webReques t, toWebQueryParams(options)); | 624 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), webReques t, toWebQueryParams(options)); |
639 return promise; | 625 return promise; |
640 } | 626 } |
641 | 627 |
642 WebServiceWorkerCache* Cache::webCache() const | 628 WebServiceWorkerCache* Cache::webCache() const |
643 { | 629 { |
644 return m_webCache.get(); | 630 return m_webCache.get(); |
645 } | 631 } |
646 | 632 |
647 } // namespace blink | 633 } // namespace blink |
OLD | NEW |