Changeset 220984 in webkit


Ignore:
Timestamp:
Aug 21, 2017 2:58:58 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Cache API] Add support for CacheStorage.match
https://bugs.webkit.org/show_bug.cgi?id=175747

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-21
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

  • web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt:
  • web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt:

Source/WebCore:

Covered by rebased tests.

Introducing Cache::doMatch so that CacheStorage can use it.
Make Cache::match use Cache::doMatch as well.

Implementing CacheStorage.match as per spec:

  • If name is provided, query only the cache with the given name.
  • Otherwise pick the first matching response in the caches.

The sequential asynchronous search is done in doSequentialMatch.

Making sure that response with a status code are returning false to isNull.
This allows passing more tests.

  • Modules/cache/Cache.cpp:

(WebCore::Cache::match):
(WebCore::Cache::doMatch):
(WebCore::Cache::matchAll):
(WebCore::toConnectionRecord):

  • Modules/cache/Cache.h:
  • Modules/cache/CacheStorage.cpp:

(WebCore::doSequentialMatch):
(WebCore::copyCaches):
(WebCore::CacheStorage::match):

  • platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::setHTTPStatusCode):

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r220971 r220984  
     12017-08-21  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for CacheStorage.match
     4        https://bugs.webkit.org/show_bug.cgi?id=175747
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt:
     9        * web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt:
     10        * web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt:
     11        * web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt:
     12        * web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
     13        * web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt:
     14        * web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt:
     15
    1162017-08-21  Andy Estes  <aestes@apple.com>
    217
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt

    r220917 r220984  
    33PASS Cache.delete called with a string URL
    44PASS Cache.delete called with a Request object
    5 FAIL Cache.delete called with a HEAD request assert_equals: Cache.delete should leave non-matching response in the cache. Attributes differ: status. expected 200 but got 0
    6 FAIL Cache.delete supports ignoreVary assert_false: Cache.delete should not delete if vary does not match unless ignoreVary is true expected false got true
     5PASS Cache.delete called with a HEAD request
     6PASS Cache.delete supports ignoreVary
    77PASS Cache.delete with a non-existent entry
    8 FAIL Cache.delete with ignoreSearch option (request with search parameters) assert_equals: undefined : object[0] Attributes differ: status. expected 200 but got 0
    9 FAIL Cache.delete with ignoreSearch option (when it is specified as false) assert_equals: undefined : object[0] Attributes differ: status. expected 200 but got 0
     8PASS Cache.delete with ignoreSearch option (request with search parameters)
     9PASS Cache.delete with ignoreSearch option (when it is specified as false)
    1010
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt

    r220917 r220984  
    88PASS Cache.keys with ignoreSearch option (request with search parameters)
    99PASS Cache.keys supports ignoreMethod
    10 FAIL Cache.keys supports ignoreVary assert_equals: Cache.keys should resolve with an empty array with a mismatched vary. expected 0 but got 1
     10PASS Cache.keys supports ignoreVary
    1111PASS Cache.keys with URL containing fragment
    1212PASS Cache.keys with string fragment "http" as query
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt

    r220928 r220984  
    11
    22PASS Cache.match with no matching entries
    3 FAIL Cache.match with URL assert_equals: Cache.match should match by URL. Attributes differ: status. expected 200 but got 0
    4 FAIL Cache.match with Request assert_equals: Cache.match should match by Request. Attributes differ: status. expected 200 but got 0
    5 FAIL Cache.match with multiple cache hits assert_equals: Cache.match should match the first cache. Attributes differ: status. expected 200 but got 0
    6 FAIL Cache.match with new Request assert_equals: Cache.match should match by Request. Attributes differ: status. expected 200 but got 0
     3PASS Cache.match with URL
     4PASS Cache.match with Request
     5PASS Cache.match with multiple cache hits
     6PASS Cache.match with new Request
    77PASS Cache.match with HEAD
    8 FAIL Cache.match with ignoreSearch option (request with no search parameters) assert_true: Cache.match with ignoreSearch should ignore the search parameters of cached request. expected true got false
    9 FAIL Cache.match with ignoreSearch option (request with search parameter) assert_true: Cache.match with ignoreSearch should ignore the search parameters of request. expected true got false
    10 FAIL Cache.match supports ignoreMethod assert_equals: Cache.match with ignoreMethod should ignore the method of request. Attributes differ: status. expected 200 but got 0
    11 FAIL Cache.match supports ignoreVary assert_equals: Cache.match should resolve as undefined with a mismatched vary. expected (undefined) undefined but got (object) object "[object Response]"
    12 FAIL Cache.match with URL containing fragment assert_equals: Cache.match should ignore URL fragment. Attributes differ: status. expected 200 but got 0
     8PASS Cache.match with ignoreSearch option (request with no search parameters)
     9PASS Cache.match with ignoreSearch option (request with search parameter)
     10PASS Cache.match supports ignoreMethod
     11PASS Cache.match supports ignoreVary
     12PASS Cache.match with URL containing fragment
    1313PASS Cache.match with string fragment "http" as query
    14 FAIL Cache.match with responses containing "Vary" header assert_true: Cache.match should honor "Vary" header. expected true got false
     14PASS Cache.match with responses containing "Vary" header
    1515PASS Cache.match with Request and Response objects with different URLs
    1616PASS Cache.match invoked multiple times for the same Request/Response
    1717PASS Cache.match blob should be sliceable
    1818PASS Cache.match with POST Request
    19 FAIL Cache.match with a non-2xx Response assert_equals: Cache.match should return a Response object that has the same properties as a stored non-2xx response. Attributes differ: status. expected 404 but got 0
     19PASS Cache.match with a non-2xx Response
    2020PASS Cache.match with a network error Response
    2121PASS Cache produces large Responses that can be cloned and read correctly.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt

    r220917 r220984  
    11
    22PASS Cache.matchAll with no matching entries
    3 FAIL Cache.matchAll with URL assert_equals: Cache.matchAll should match by URL. : object[0] Attributes differ: status. expected 200 but got 0
    4 FAIL Cache.matchAll with Request assert_equals: Cache.matchAll should match by Request. : object[0] Attributes differ: status. expected 200 but got 0
    5 FAIL Cache.matchAll with new Request assert_equals: Cache.matchAll should match by Request. : object[0] Attributes differ: status. expected 200 but got 0
     3PASS Cache.matchAll with URL
     4PASS Cache.matchAll with Request
     5PASS Cache.matchAll with new Request
    66PASS Cache.matchAll with HEAD
    7 FAIL Cache.matchAll with ignoreSearch option (request with no search parameters) assert_equals: Cache.matchAll with ignoreSearch should ignore the search parameters of cached request. : object[0] Attributes differ: status. expected 200 but got 0
    8 FAIL Cache.matchAll with ignoreSearch option (request with search parameters) assert_equals: Cache.matchAll with ignoreSearch should ignore the search parameters of request. : object[0] Attributes differ: status. expected 200 but got 0
    9 FAIL Cache.matchAll supports ignoreMethod assert_equals: Cache.matchAll with ignoreMethod should ignore the method of request. : object[0] Attributes differ: status. expected 200 but got 0
    10 FAIL Cache.matchAll supports ignoreVary assert_equals: Cache.matchAll should resolve as undefined with a mismatched vary. expected 0 but got 1
    11 FAIL Cache.matchAll with URL containing fragment assert_equals: Cache.matchAll should ignore URL fragment. : object[0] Attributes differ: status. expected 200 but got 0
     7PASS Cache.matchAll with ignoreSearch option (request with no search parameters)
     8PASS Cache.matchAll with ignoreSearch option (request with search parameters)
     9PASS Cache.matchAll supports ignoreMethod
     10PASS Cache.matchAll supports ignoreVary
     11PASS Cache.matchAll with URL containing fragment
    1212PASS Cache.matchAll with string fragment "http" as query
    13 FAIL Cache.matchAll without parameters assert_equals: Cache.matchAll without parameters should match all entries. : object[0] Attributes differ: status. expected 200 but got 0
    14 FAIL Cache.matchAll with responses containing "Vary" header assert_equals: Cache.matchAll should exclude matches if a vary header is missing in the query request, but is present in the cached request. : object[0] Attributes differ: status. expected 200 but got 0
    15 FAIL Cache.matchAll with multiple vary pairs assert_equals: Cache.matchAll should support multiple vary request/response pairs. expected 3 but got 1
     13PASS Cache.matchAll without parameters
     14PASS Cache.matchAll with responses containing "Vary" header
     15PASS Cache.matchAll with multiple vary pairs
    1616
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt

    r220928 r220984  
    44PASS Cache.put with Request without a body
    55PASS Cache.put with Response without a body
    6 FAIL Cache.put with a Response containing an empty URL assert_equals: Cache.put should update the cache with new Request and Response. Attributes differ: status. expected 200 but got 0
    7 FAIL Cache.put with an empty response body assert_equals: Cache.put should store status. expected 200 but got 0
     6PASS Cache.put with a Response containing an empty URL
     7PASS Cache.put with an empty response body
    88PASS Cache.put with synthetic 206 response
    99PASS Cache.put with HTTP 206 response
    1010PASS Cache.put with HTTP 500 response
    11 FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache.put should replace existing response with new response. Attributes differ: status. expected 200 but got 0
    12 FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache.put should replace existing response with new response. Attributes differ: status. expected 200 but got 0
     11FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
     12FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
    1313PASS Cache.put with a string request
    1414PASS Cache.put with an invalid response
    1515PASS Cache.put with a non-HTTP/HTTPS request
    16 FAIL Cache.put with a relative URL assert_equals: Cache.put should accept a relative URL as the request. Attributes differ: status. expected 200 but got 0
     16PASS Cache.put with a relative URL
    1717PASS Cache.put with a non-GET request
    1818PASS Cache.put with a null response
     
    2222PASS Cache.put with a VARY:* Response
    2323PASS Cache.put with an embedded VARY:* Response
    24 FAIL Cache.put should store Response.redirect() correctly assert_equals: Redirect response is reproduced by the Cache API Attributes differ: status. expected 302 but got 0
     24PASS Cache.put should store Response.redirect() correctly
    2525
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt

    r220758 r220984  
    11
    2 FAIL CacheStorageMatch with no cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    3 FAIL CacheStorageMatch from one of many caches promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    4 FAIL CacheStorageMatch from one of many caches by name promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    5 FAIL CacheStorageMatch a string request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    6 FAIL CacheStorageMatch a HEAD request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    7 FAIL CacheStorageMatch with no cached entry promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    8 FAIL CacheStorageMatch with no caches available but name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    9 FAIL CacheStorageMatch with empty cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    10 FAIL CacheStorageMatch supports ignoreSearch promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    11 FAIL Cache.match supports ignoreMethod promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    12 FAIL CacheStorageMatch supports ignoreVary promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
     2PASS CacheStorageMatch with no cache name provided
     3PASS CacheStorageMatch from one of many caches
     4PASS CacheStorageMatch from one of many caches by name
     5PASS CacheStorageMatch a string request
     6PASS CacheStorageMatch a HEAD request
     7PASS CacheStorageMatch with no cached entry
     8PASS CacheStorageMatch with no caches available but name provided
     9PASS CacheStorageMatch with empty cache name provided
     10PASS CacheStorageMatch supports ignoreSearch
     11PASS Cache.match supports ignoreMethod
     12PASS CacheStorageMatch supports ignoreVary
    1313
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt

    r220758 r220984  
    11
    2 FAIL CacheStorageMatch with no cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    3 FAIL CacheStorageMatch from one of many caches promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    4 FAIL CacheStorageMatch from one of many caches by name promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    5 FAIL CacheStorageMatch a string request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    6 FAIL CacheStorageMatch a HEAD request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    7 FAIL CacheStorageMatch with no cached entry promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    8 FAIL CacheStorageMatch with no caches available but name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    9 FAIL CacheStorageMatch with empty cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    10 FAIL CacheStorageMatch supports ignoreSearch promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    11 FAIL Cache.match supports ignoreMethod promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
    12 FAIL CacheStorageMatch supports ignoreVary promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
     2PASS CacheStorageMatch with no cache name provided
     3PASS CacheStorageMatch from one of many caches
     4PASS CacheStorageMatch from one of many caches by name
     5PASS CacheStorageMatch a string request
     6PASS CacheStorageMatch a HEAD request
     7PASS CacheStorageMatch with no cached entry
     8PASS CacheStorageMatch with no caches available but name provided
     9PASS CacheStorageMatch with empty cache name provided
     10PASS CacheStorageMatch supports ignoreSearch
     11PASS Cache.match supports ignoreMethod
     12PASS CacheStorageMatch supports ignoreVary
    1313
  • trunk/Source/WebCore/ChangeLog

    r220983 r220984  
     12017-08-21  Youenn Fablet  <youenn@apple.com>
     2
     3        [Cache API] Add support for CacheStorage.match
     4        https://bugs.webkit.org/show_bug.cgi?id=175747
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by rebased tests.
     9
     10        Introducing Cache::doMatch so that CacheStorage can use it.
     11        Make Cache::match use Cache::doMatch as well.
     12
     13        Implementing CacheStorage.match as per spec:
     14        - If name is provided, query only the cache with the given name.
     15        - Otherwise pick the first matching response in the caches.
     16        The sequential asynchronous search is done in doSequentialMatch.
     17
     18        Making sure that response with a status code are returning false to isNull.
     19        This allows passing more tests.
     20
     21        * Modules/cache/Cache.cpp:
     22        (WebCore::Cache::match):
     23        (WebCore::Cache::doMatch):
     24        (WebCore::Cache::matchAll):
     25        (WebCore::toConnectionRecord):
     26        * Modules/cache/Cache.h:
     27        * Modules/cache/CacheStorage.cpp:
     28        (WebCore::doSequentialMatch):
     29        (WebCore::copyCaches):
     30        (WebCore::CacheStorage::match):
     31        * platform/network/ResourceResponseBase.cpp:
     32        (WebCore::ResourceResponseBase::setHTTPStatusCode):
     33
    1342017-08-21  Dean Jackson  <dino@apple.com>
    235
  • trunk/Source/WebCore/Modules/cache/Cache.cpp

    r220948 r220984  
    5252void Cache::match(RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
    5353{
    54     doMatch(WTFMove(info), WTFMove(options), WTFMove(promise), MatchType::OnlyFirst);
    55 }
    56 
    57 void Cache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
    58 {
    59     doMatch(WTFMove(info), WTFMove(options), WTFMove(promise), MatchType::All);
    60 }
    61 
    62 void Cache::doMatch(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise, MatchType matchType)
     54    doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](FetchResponse* result) mutable {
     55        if (!result) {
     56            promise->resolve();
     57            return;
     58        }
     59        promise->resolve<IDLInterface<FetchResponse>>(*result);
     60    });
     61}
     62
     63void Cache::doMatch(RequestInfo&& info, CacheQueryOptions&& options, MatchCallback&& callback)
     64{
     65    RefPtr<FetchRequest> request;
     66    if (WTF::holds_alternative<RefPtr<FetchRequest>>(info)) {
     67        request = WTF::get<RefPtr<FetchRequest>>(info).releaseNonNull();
     68        if (request->method() != "GET" && !options.ignoreMethod) {
     69            callback(nullptr);
     70            return;
     71        }
     72    } else {
     73        if (UNLIKELY(!scriptExecutionContext()))
     74            return;
     75        request = FetchRequest::create(*scriptExecutionContext(), WTFMove(info), { }).releaseReturnValue();
     76    }
     77
     78    queryCache(request.releaseNonNull(), WTFMove(options), [callback = WTFMove(callback)](const Vector<CacheStorageRecord>& records) mutable {
     79        if (records.isEmpty()) {
     80            callback(nullptr);
     81            return;
     82        }
     83        callback(records[0].response->cloneForJS().ptr());
     84    });
     85}
     86
     87void Cache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, MatchAllPromise&& promise)
    6388{
    6489    RefPtr<FetchRequest> request;
     
    6792            request = WTF::get<RefPtr<FetchRequest>>(info.value()).releaseNonNull();
    6893            if (request->method() != "GET" && !options.ignoreMethod) {
    69                 if (matchType == MatchType::OnlyFirst) {
    70                     promise->resolve();
    71                     return;
    72                 }
    73                 promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(Vector<Ref<FetchResponse>> { });
     94                promise.resolve({ });
    7495                return;
    7596            }
     
    82103
    83104    if (!request) {
    84         ASSERT(matchType == MatchType::All);
    85         retrieveRecords([this, promise = WTFMove(promise)]() {
     105        retrieveRecords([this, promise = WTFMove(promise)]() mutable {
    86106            Vector<Ref<FetchResponse>> responses;
    87107            responses.reserveInitialCapacity(m_records.size());
    88108            for (auto& record : m_records)
    89109                responses.uncheckedAppend(record.response->cloneForJS());
    90             promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(responses);
     110            promise.resolve(responses);
    91111        });
    92112        return;
    93113    }
    94     queryCache(request.releaseNonNull(), WTFMove(options), [matchType, promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
    95         if (matchType == MatchType::OnlyFirst) {
    96             if (records.size()) {
    97                 promise->resolve<IDLInterface<FetchResponse>>(records[0].response->cloneForJS());
    98                 return;
    99             }
    100             promise->resolve();
    101             return;
    102         }
    103 
     114    queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
    104115        Vector<Ref<FetchResponse>> responses;
    105116        responses.reserveInitialCapacity(records.size());
    106117        for (auto& record : records)
    107118            responses.uncheckedAppend(record.response->cloneForJS());
    108         promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(responses);
     119        promise.resolve(responses);
    109120    });
    110121}
     
    306317    cachedRequest.setHTTPHeaderFields(request.headers().internalHeaders());
    307318
     319    ASSERT(!cachedRequest.isNull());
     320    ASSERT(!cachedResponse.isNull());
     321
    308322    return { 0,
    309323        request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
  • trunk/Source/WebCore/Modules/cache/Cache.h

    r220948 r220984  
    4444
    4545    void match(RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
    46     void matchAll(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
     46
     47    using MatchAllPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchResponse>>>;
     48    void matchAll(std::optional<RequestInfo>&&, CacheQueryOptions&&, MatchAllPromise&&);
    4749    void add(RequestInfo&&, DOMPromiseDeferred<void>&&);
    4850
     
    5557    uint64_t identifier() const { return m_identifier; }
    5658
     59    using MatchCallback = WTF::Function<void(FetchResponse*)>;
     60    void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&);
     61
    5762private:
    5863    Cache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
    59 
    60     enum class MatchType { All, OnlyFirst };
    61     void doMatch(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&, MatchType);
    6264
    6365    // ActiveDOMObject
  • trunk/Source/WebCore/Modules/cache/CacheStorage.cpp

    r220863 r220984  
    2929#include "CacheQueryOptions.h"
    3030#include "JSCache.h"
     31#include "JSFetchResponse.h"
    3132#include "ScriptExecutionContext.h"
    3233
     
    4748}
    4849
    49 void CacheStorage::match(Cache::RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&& promise)
    50 {
    51     promise->reject(Exception { NotSupportedError, ASCIILiteral("Not implemented")});
     50static void doSequentialMatch(size_t index, Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
     51{
     52    if (index >= caches.size()) {
     53        completionHandler(nullptr);
     54        return;
     55    }
     56
     57    caches[index]->doMatch(WTFMove(info), WTFMove(options), [caches = WTFMove(caches), info, options, completionHandler = WTFMove(completionHandler), index](FetchResponse* value) mutable {
     58        if (value) {
     59            completionHandler(value);
     60            return;
     61        }
     62        doSequentialMatch(++index, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
     63    });
     64}
     65
     66static inline void startSequentialMatch(Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
     67{
     68    doSequentialMatch(0, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
     69}
     70
     71static inline Vector<Ref<Cache>> copyCaches(const Vector<Ref<Cache>>& caches)
     72{
     73    Vector<Ref<Cache>> copy;
     74    copy.reserveInitialCapacity(caches.size());
     75    for (auto& cache : caches)
     76        copy.uncheckedAppend(cache.copyRef());
     77    return copy;
     78}
     79
     80void CacheStorage::match(Cache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
     81{
     82    retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)]() mutable {
     83        if (!options.cacheName.isNull()) {
     84            auto position = m_caches.findMatching([&](auto& item) { return item->name() == options.cacheName; });
     85            if (position != notFound) {
     86                m_caches[position]->match(WTFMove(info), WTFMove(options), WTFMove(promise));
     87                return;
     88            }
     89            promise->resolve();
     90            return;
     91        }
     92
     93        setPendingActivity(this);
     94        startSequentialMatch(copyCaches(m_caches), WTFMove(info), WTFMove(options), [this, promise = WTFMove(promise)](FetchResponse* result) mutable {
     95            if (!m_isStopped) {
     96                if (!result)
     97                    promise->resolve();
     98                else
     99                    promise->resolve<IDLInterface<FetchResponse>>(*result);
     100            }
     101            unsetPendingActivity(this);
     102        });
     103    });
    52104}
    53105
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp

    r220764 r220984  
    282282
    283283    m_httpStatusCode = statusCode;
     284    m_isNull = false;
    284285
    285286    // FIXME: Should invalidate or update platform response if present.
Note: See TracChangeset for help on using the changeset viewer.