Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,3 +1,18 @@
+2017-08-21 Youenn Fablet <[email protected]>
+
+ [Cache API] Add support for CacheStorage.match
+ https://bugs.webkit.org/show_bug.cgi?id=175747
+
+ Reviewed by Chris Dumez.
+
+ * 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:
+
2017-08-21 Andy Estes <[email protected]>
[Payment Request] Implement the PaymentRequest constructor
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-delete.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -2,9 +2,9 @@
PASS Cache.delete with no arguments
PASS Cache.delete called with a string URL
PASS Cache.delete called with a Request object
-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
-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
+PASS Cache.delete called with a HEAD request
+PASS Cache.delete supports ignoreVary
PASS Cache.delete with a non-existent entry
-FAIL Cache.delete with ignoreSearch option (request with search parameters) assert_equals: undefined : object[0] Attributes differ: status. expected 200 but got 0
-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
+PASS Cache.delete with ignoreSearch option (request with search parameters)
+PASS Cache.delete with ignoreSearch option (when it is specified as false)
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-keys.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -7,7 +7,7 @@
PASS Cache.keys with ignoreSearch option (request with no search parameters)
PASS Cache.keys with ignoreSearch option (request with search parameters)
PASS Cache.keys supports ignoreMethod
-FAIL Cache.keys supports ignoreVary assert_equals: Cache.keys should resolve with an empty array with a mismatched vary. expected 0 but got 1
+PASS Cache.keys supports ignoreVary
PASS Cache.keys with URL containing fragment
PASS Cache.keys with string fragment "http" as query
PASS Cache.keys without parameters
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,22 +1,22 @@
PASS Cache.match with no matching entries
-FAIL Cache.match with URL assert_equals: Cache.match should match by URL. Attributes differ: status. expected 200 but got 0
-FAIL Cache.match with Request assert_equals: Cache.match should match by Request. Attributes differ: status. expected 200 but got 0
-FAIL Cache.match with multiple cache hits assert_equals: Cache.match should match the first cache. Attributes differ: status. expected 200 but got 0
-FAIL Cache.match with new Request assert_equals: Cache.match should match by Request. Attributes differ: status. expected 200 but got 0
+PASS Cache.match with URL
+PASS Cache.match with Request
+PASS Cache.match with multiple cache hits
+PASS Cache.match with new Request
PASS Cache.match with HEAD
-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
-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
-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
-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]"
-FAIL Cache.match with URL containing fragment assert_equals: Cache.match should ignore URL fragment. Attributes differ: status. expected 200 but got 0
+PASS Cache.match with ignoreSearch option (request with no search parameters)
+PASS Cache.match with ignoreSearch option (request with search parameter)
+PASS Cache.match supports ignoreMethod
+PASS Cache.match supports ignoreVary
+PASS Cache.match with URL containing fragment
PASS Cache.match with string fragment "http" as query
-FAIL Cache.match with responses containing "Vary" header assert_true: Cache.match should honor "Vary" header. expected true got false
+PASS Cache.match with responses containing "Vary" header
PASS Cache.match with Request and Response objects with different URLs
PASS Cache.match invoked multiple times for the same Request/Response
PASS Cache.match blob should be sliceable
PASS Cache.match with POST Request
-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
+PASS Cache.match with a non-2xx Response
PASS Cache.match with a network error Response
PASS Cache produces large Responses that can be cloned and read correctly.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-matchAll.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,16 +1,16 @@
PASS Cache.matchAll with no matching entries
-FAIL Cache.matchAll with URL assert_equals: Cache.matchAll should match by URL. : object[0] Attributes differ: status. expected 200 but got 0
-FAIL Cache.matchAll with Request assert_equals: Cache.matchAll should match by Request. : object[0] Attributes differ: status. expected 200 but got 0
-FAIL Cache.matchAll with new Request assert_equals: Cache.matchAll should match by Request. : object[0] Attributes differ: status. expected 200 but got 0
+PASS Cache.matchAll with URL
+PASS Cache.matchAll with Request
+PASS Cache.matchAll with new Request
PASS Cache.matchAll with HEAD
-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
-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
-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
-FAIL Cache.matchAll supports ignoreVary assert_equals: Cache.matchAll should resolve as undefined with a mismatched vary. expected 0 but got 1
-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
+PASS Cache.matchAll with ignoreSearch option (request with no search parameters)
+PASS Cache.matchAll with ignoreSearch option (request with search parameters)
+PASS Cache.matchAll supports ignoreMethod
+PASS Cache.matchAll supports ignoreVary
+PASS Cache.matchAll with URL containing fragment
PASS Cache.matchAll with string fragment "http" as query
-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
-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
-FAIL Cache.matchAll with multiple vary pairs assert_equals: Cache.matchAll should support multiple vary request/response pairs. expected 3 but got 1
+PASS Cache.matchAll without parameters
+PASS Cache.matchAll with responses containing "Vary" header
+PASS Cache.matchAll with multiple vary pairs
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -3,17 +3,17 @@
PASS Cache.put called with Request and Response from fetch()
PASS Cache.put with Request without a body
PASS Cache.put with Response without a body
-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
-FAIL Cache.put with an empty response body assert_equals: Cache.put should store status. expected 200 but got 0
+PASS Cache.put with a Response containing an empty URL
+PASS Cache.put with an empty response body
PASS Cache.put with synthetic 206 response
PASS Cache.put with HTTP 206 response
PASS Cache.put with HTTP 500 response
-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
-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
+FAIL 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"
+FAIL 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"
PASS Cache.put with a string request
PASS Cache.put with an invalid response
PASS Cache.put with a non-HTTP/HTTPS request
-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
+PASS Cache.put with a relative URL
PASS Cache.put with a non-GET request
PASS Cache.put with a null response
PASS Cache.put with a POST request
@@ -21,5 +21,5 @@
PASS getReader() after Cache.put
PASS Cache.put with a VARY:* Response
PASS Cache.put with an embedded VARY:* Response
-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
+PASS Cache.put should store Response.redirect() correctly
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-storage-match.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,13 +1,13 @@
-FAIL CacheStorageMatch with no cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch from one of many caches promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch from one of many caches by name promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch a string request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch a HEAD request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with no cached entry promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with no caches available but name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with empty cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch supports ignoreSearch promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL Cache.match supports ignoreMethod promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch supports ignoreVary promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
+PASS CacheStorageMatch with no cache name provided
+PASS CacheStorageMatch from one of many caches
+PASS CacheStorageMatch from one of many caches by name
+PASS CacheStorageMatch a string request
+PASS CacheStorageMatch a HEAD request
+PASS CacheStorageMatch with no cached entry
+PASS CacheStorageMatch with no caches available but name provided
+PASS CacheStorageMatch with empty cache name provided
+PASS CacheStorageMatch supports ignoreSearch
+PASS Cache.match supports ignoreMethod
+PASS CacheStorageMatch supports ignoreVary
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt (220983 => 220984)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-storage-match.https-expected.txt 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,13 +1,13 @@
-FAIL CacheStorageMatch with no cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch from one of many caches promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch from one of many caches by name promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch a string request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch a HEAD request promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with no cached entry promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with no caches available but name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch with empty cache name provided promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch supports ignoreSearch promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL Cache.match supports ignoreMethod promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
-FAIL CacheStorageMatch supports ignoreVary promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
+PASS CacheStorageMatch with no cache name provided
+PASS CacheStorageMatch from one of many caches
+PASS CacheStorageMatch from one of many caches by name
+PASS CacheStorageMatch a string request
+PASS CacheStorageMatch a HEAD request
+PASS CacheStorageMatch with no cached entry
+PASS CacheStorageMatch with no caches available but name provided
+PASS CacheStorageMatch with empty cache name provided
+PASS CacheStorageMatch supports ignoreSearch
+PASS Cache.match supports ignoreMethod
+PASS CacheStorageMatch supports ignoreVary
Modified: trunk/Source/WebCore/ChangeLog (220983 => 220984)
--- trunk/Source/WebCore/ChangeLog 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/Source/WebCore/ChangeLog 2017-08-21 21:58:58 UTC (rev 220984)
@@ -1,3 +1,36 @@
+2017-08-21 Youenn Fablet <[email protected]>
+
+ [Cache API] Add support for CacheStorage.match
+ https://bugs.webkit.org/show_bug.cgi?id=175747
+
+ Reviewed by Chris Dumez.
+
+ 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):
+
2017-08-21 Dean Jackson <[email protected]>
Persistent WebGL Warning "vertex WARNING: 0:1: extension 'GL_ARB_gpu_shader5' is not supported" in Safari 10.1.2
Modified: trunk/Source/WebCore/Modules/cache/Cache.cpp (220983 => 220984)
--- trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-08-21 21:58:58 UTC (rev 220984)
@@ -51,15 +51,40 @@
void Cache::match(RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
{
- doMatch(WTFMove(info), WTFMove(options), WTFMove(promise), MatchType::OnlyFirst);
+ doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](FetchResponse* result) mutable {
+ if (!result) {
+ promise->resolve();
+ return;
+ }
+ promise->resolve<IDLInterface<FetchResponse>>(*result);
+ });
}
-void Cache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
+void Cache::doMatch(RequestInfo&& info, CacheQueryOptions&& options, MatchCallback&& callback)
{
- doMatch(WTFMove(info), WTFMove(options), WTFMove(promise), MatchType::All);
+ RefPtr<FetchRequest> request;
+ if (WTF::holds_alternative<RefPtr<FetchRequest>>(info)) {
+ request = WTF::get<RefPtr<FetchRequest>>(info).releaseNonNull();
+ if (request->method() != "GET" && !options.ignoreMethod) {
+ callback(nullptr);
+ return;
+ }
+ } else {
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+ request = FetchRequest::create(*scriptExecutionContext(), WTFMove(info), { }).releaseReturnValue();
+ }
+
+ queryCache(request.releaseNonNull(), WTFMove(options), [callback = WTFMove(callback)](const Vector<CacheStorageRecord>& records) mutable {
+ if (records.isEmpty()) {
+ callback(nullptr);
+ return;
+ }
+ callback(records[0].response->cloneForJS().ptr());
+ });
}
-void Cache::doMatch(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise, MatchType matchType)
+void Cache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, MatchAllPromise&& promise)
{
RefPtr<FetchRequest> request;
if (info) {
@@ -66,11 +91,7 @@
if (WTF::holds_alternative<RefPtr<FetchRequest>>(info.value())) {
request = WTF::get<RefPtr<FetchRequest>>(info.value()).releaseNonNull();
if (request->method() != "GET" && !options.ignoreMethod) {
- if (matchType == MatchType::OnlyFirst) {
- promise->resolve();
- return;
- }
- promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(Vector<Ref<FetchResponse>> { });
+ promise.resolve({ });
return;
}
} else {
@@ -81,31 +102,21 @@
}
if (!request) {
- ASSERT(matchType == MatchType::All);
- retrieveRecords([this, promise = WTFMove(promise)]() {
+ retrieveRecords([this, promise = WTFMove(promise)]() mutable {
Vector<Ref<FetchResponse>> responses;
responses.reserveInitialCapacity(m_records.size());
for (auto& record : m_records)
responses.uncheckedAppend(record.response->cloneForJS());
- promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(responses);
+ promise.resolve(responses);
});
return;
}
- queryCache(request.releaseNonNull(), WTFMove(options), [matchType, promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
- if (matchType == MatchType::OnlyFirst) {
- if (records.size()) {
- promise->resolve<IDLInterface<FetchResponse>>(records[0].response->cloneForJS());
- return;
- }
- promise->resolve();
- return;
- }
-
+ queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](const Vector<CacheStorageRecord>& records) mutable {
Vector<Ref<FetchResponse>> responses;
responses.reserveInitialCapacity(records.size());
for (auto& record : records)
responses.uncheckedAppend(record.response->cloneForJS());
- promise->resolve<IDLSequence<IDLInterface<FetchResponse>>>(responses);
+ promise.resolve(responses);
});
}
@@ -305,6 +316,9 @@
ResourceRequest cachedRequest = request.internalRequest();
cachedRequest.setHTTPHeaderFields(request.headers().internalHeaders());
+ ASSERT(!cachedRequest.isNull());
+ ASSERT(!cachedResponse.isNull());
+
return { 0,
request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
Modified: trunk/Source/WebCore/Modules/cache/Cache.h (220983 => 220984)
--- trunk/Source/WebCore/Modules/cache/Cache.h 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/Source/WebCore/Modules/cache/Cache.h 2017-08-21 21:58:58 UTC (rev 220984)
@@ -43,7 +43,9 @@
using KeysPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchRequest>>>;
void match(RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
- void matchAll(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
+
+ using MatchAllPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchResponse>>>;
+ void matchAll(std::optional<RequestInfo>&&, CacheQueryOptions&&, MatchAllPromise&&);
void add(RequestInfo&&, DOMPromiseDeferred<void>&&);
void addAll(Vector<RequestInfo>&&, DOMPromiseDeferred<void>&&);
@@ -54,12 +56,12 @@
const String& name() const { return m_name; }
uint64_t identifier() const { return m_identifier; }
+ using MatchCallback = WTF::Function<void(FetchResponse*)>;
+ void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&);
+
private:
Cache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
- enum class MatchType { All, OnlyFirst };
- void doMatch(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&, MatchType);
-
// ActiveDOMObject
void stop() final;
const char* activeDOMObjectName() const final;
Modified: trunk/Source/WebCore/Modules/cache/CacheStorage.cpp (220983 => 220984)
--- trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-08-21 21:58:58 UTC (rev 220984)
@@ -28,6 +28,7 @@
#include "CacheQueryOptions.h"
#include "JSCache.h"
+#include "JSFetchResponse.h"
#include "ScriptExecutionContext.h"
namespace WebCore {
@@ -46,11 +47,62 @@
return origin ? origin->toString() : String();
}
-void CacheStorage::match(Cache::RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&& promise)
+static void doSequentialMatch(size_t index, Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
{
- promise->reject(Exception { NotSupportedError, ASCIILiteral("Not implemented")});
+ if (index >= caches.size()) {
+ completionHandler(nullptr);
+ return;
+ }
+
+ caches[index]->doMatch(WTFMove(info), WTFMove(options), [caches = WTFMove(caches), info, options, completionHandler = WTFMove(completionHandler), index](FetchResponse* value) mutable {
+ if (value) {
+ completionHandler(value);
+ return;
+ }
+ doSequentialMatch(++index, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
+ });
}
+static inline void startSequentialMatch(Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
+{
+ doSequentialMatch(0, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
+}
+
+static inline Vector<Ref<Cache>> copyCaches(const Vector<Ref<Cache>>& caches)
+{
+ Vector<Ref<Cache>> copy;
+ copy.reserveInitialCapacity(caches.size());
+ for (auto& cache : caches)
+ copy.uncheckedAppend(cache.copyRef());
+ return copy;
+}
+
+void CacheStorage::match(Cache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
+{
+ retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)]() mutable {
+ if (!options.cacheName.isNull()) {
+ auto position = m_caches.findMatching([&](auto& item) { return item->name() == options.cacheName; });
+ if (position != notFound) {
+ m_caches[position]->match(WTFMove(info), WTFMove(options), WTFMove(promise));
+ return;
+ }
+ promise->resolve();
+ return;
+ }
+
+ setPendingActivity(this);
+ startSequentialMatch(copyCaches(m_caches), WTFMove(info), WTFMove(options), [this, promise = WTFMove(promise)](FetchResponse* result) mutable {
+ if (!m_isStopped) {
+ if (!result)
+ promise->resolve();
+ else
+ promise->resolve<IDLInterface<FetchResponse>>(*result);
+ }
+ unsetPendingActivity(this);
+ });
+ });
+}
+
void CacheStorage::has(const String& name, DOMPromiseDeferred<IDLBoolean>&& promise)
{
retrieveCaches([this, name, promise = WTFMove(promise)]() mutable {
Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp (220983 => 220984)
--- trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2017-08-21 21:51:49 UTC (rev 220983)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2017-08-21 21:58:58 UTC (rev 220984)
@@ -281,6 +281,7 @@
lazyInit(CommonFieldsOnly);
m_httpStatusCode = statusCode;
+ m_isNull = false;
// FIXME: Should invalidate or update platform response if present.
}