Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (221497 => 221498)
--- trunk/Source/WebCore/CMakeLists.txt 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/CMakeLists.txt 2017-09-01 21:47:57 UTC (rev 221498)
@@ -184,7 +184,7 @@
Modules/beacon/NavigatorBeacon.idl
- Modules/cache/Cache.idl
+ Modules/cache/DOMCache.idl
Modules/cache/CacheQueryOptions.idl
Modules/cache/CacheStorage.idl
Modules/cache/DOMWindowCaches.idl
@@ -911,7 +911,7 @@
Modules/beacon/NavigatorBeacon.cpp
- Modules/cache/Cache.cpp
+ Modules/cache/DOMCache.cpp
Modules/cache/CacheStorage.cpp
Modules/cache/CacheStorageConnection.cpp
Modules/cache/DOMCacheEngine.cpp
Modified: trunk/Source/WebCore/ChangeLog (221497 => 221498)
--- trunk/Source/WebCore/ChangeLog 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/ChangeLog 2017-09-01 21:47:57 UTC (rev 221498)
@@ -1,3 +1,71 @@
+2017-09-01 Per Arne Vollan <[email protected]>
+
+ [Win] Compile error, 'Cache' is not declared.
+ https://bugs.webkit.org/show_bug.cgi?id=176062
+
+ Reviewed by Youenn Fablet.
+
+ Rename Cache to DOMCache.
+
+ No new tests, covered by existing tests.
+
+ * DerivedSources.make:
+ * Modules/cache/Cache.cpp: Removed.
+ * Modules/cache/Cache.h: Removed.
+ * Modules/cache/Cache.idl: Removed.
+ * Modules/cache/CacheStorage.cpp:
+ (WebCore::doSequentialMatch):
+ (WebCore::startSequentialMatch):
+ (WebCore::copyCaches):
+ (WebCore::CacheStorage::match):
+ (WebCore::CacheStorage::retrieveCaches):
+ (WebCore::CacheStorage::open):
+ * Modules/cache/CacheStorage.h:
+ * Modules/cache/DOMCache.cpp: Copied from Source/WebCore/Modules/cache/Cache.cpp.
+ (WebCore::DOMCache::DOMCache):
+ (WebCore::DOMCache::~DOMCache):
+ (WebCore::DOMCache::match):
+ (WebCore::DOMCache::doMatch):
+ (WebCore::DOMCache::matchAll):
+ (WebCore::DOMCache::add):
+ (WebCore::DOMCache::requestFromInfo):
+ (WebCore::DOMCache::addAll):
+ (WebCore::DOMCache::put):
+ (WebCore::DOMCache::remove):
+ (WebCore::DOMCache::keys):
+ (WebCore::DOMCache::retrieveRecords):
+ (WebCore::DOMCache::queryCache):
+ (WebCore::DOMCache::queryCacheWithTargetStorage):
+ (WebCore::DOMCache::batchDeleteOperation):
+ (WebCore::DOMCache::batchPutOperation):
+ (WebCore::DOMCache::updateRecords):
+ (WebCore::DOMCache::stop):
+ (WebCore::DOMCache::activeDOMObjectName const):
+ (WebCore::DOMCache::canSuspendForDocumentSuspension const):
+ (WebCore::Cache::Cache): Deleted.
+ (WebCore::Cache::~Cache): Deleted.
+ (WebCore::Cache::match): Deleted.
+ (WebCore::Cache::doMatch): Deleted.
+ (WebCore::Cache::matchAll): Deleted.
+ (WebCore::Cache::add): Deleted.
+ (WebCore::Cache::requestFromInfo): Deleted.
+ (WebCore::Cache::addAll): Deleted.
+ (WebCore::Cache::put): Deleted.
+ (WebCore::Cache::remove): Deleted.
+ (WebCore::Cache::keys): Deleted.
+ (WebCore::Cache::retrieveRecords): Deleted.
+ (WebCore::Cache::queryCache): Deleted.
+ (WebCore::Cache::queryCacheWithTargetStorage): Deleted.
+ (WebCore::Cache::batchDeleteOperation): Deleted.
+ (WebCore::Cache::batchPutOperation): Deleted.
+ (WebCore::Cache::updateRecords): Deleted.
+ (WebCore::Cache::stop): Deleted.
+ (WebCore::Cache::activeDOMObjectName const): Deleted.
+ (WebCore::Cache::canSuspendForDocumentSuspension const): Deleted.
+ * Modules/cache/DOMCache.h: Copied from Source/WebCore/Modules/cache/Cache.h.
+ * Modules/cache/DOMCache.idl: Copied from Source/WebCore/Modules/cache/Cache.idl.
+ * WebCore.xcodeproj/project.pbxproj:
+
2017-09-01 Brady Eidson <[email protected]>
Move ServiceWorkerJob from FetchLoader to ThreadableLoader.
Modified: trunk/Source/WebCore/DerivedSources.make (221497 => 221498)
--- trunk/Source/WebCore/DerivedSources.make 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/DerivedSources.make 2017-09-01 21:47:57 UTC (rev 221498)
@@ -104,7 +104,7 @@
$(WebCore)/Modules/applepay/ApplePayValidateMerchantEvent.idl \
$(WebCore)/Modules/beacon/NavigatorBeacon.idl \
$(WebCore)/Modules/cache/DOMWindowCaches.idl \
- $(WebCore)/Modules/cache/Cache.idl \
+ $(WebCore)/Modules/cache/DOMCache.idl \
$(WebCore)/Modules/cache/CacheQueryOptions.idl \
$(WebCore)/Modules/cache/CacheStorage.idl \
$(WebCore)/Modules/cache/WorkerGlobalScopeCaches.idl \
Deleted: trunk/Source/WebCore/Modules/cache/Cache.cpp (221497 => 221498)
--- trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-09-01 21:47:57 UTC (rev 221498)
@@ -1,561 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "Cache.h"
-
-#include "CacheQueryOptions.h"
-#include "FetchResponse.h"
-#include "HTTPParsers.h"
-#include "JSFetchRequest.h"
-#include "JSFetchResponse.h"
-#include "ScriptExecutionContext.h"
-#include "URL.h"
-
-using namespace WebCore::DOMCacheEngine;
-
-namespace WebCore {
-
-static Record toConnectionRecord(const FetchRequest&, FetchResponse&, ResponseBody&&);
-
-Cache::Cache(ScriptExecutionContext& context, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&& connection)
- : ActiveDOMObject(&context)
- , m_name(WTFMove(name))
- , m_identifier(identifier)
- , m_connection(WTFMove(connection))
-{
- suspendIfNeeded();
-}
-
-Cache::~Cache()
-{
-}
-
-void Cache::match(RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
-{
- doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
- if (result.hasException()) {
- promise->reject(result.releaseException());
- return;
- }
- if (!result.returnValue()) {
- promise->resolve();
- return;
- }
- promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
- });
-}
-
-void Cache::doMatch(RequestInfo&& info, CacheQueryOptions&& options, MatchCallback&& callback)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- auto requestOrException = requestFromInfo(WTFMove(info), options.ignoreMethod);
- if (requestOrException.hasException()) {
- callback(nullptr);
- return;
- }
- auto request = requestOrException.releaseReturnValue();
-
- queryCache(request.get(), WTFMove(options), [callback = WTFMove(callback)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
- if (result.hasException()) {
- callback(result.releaseException());
- return;
- }
- if (result.returnValue().isEmpty()) {
- callback(nullptr);
- return;
- }
- callback(result.returnValue()[0].response->cloneForJS().ptr());
- });
-}
-
-void Cache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, MatchAllPromise&& promise)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- RefPtr<FetchRequest> request;
- if (info) {
- auto requestOrException = requestFromInfo(WTFMove(info.value()), options.ignoreMethod);
- if (requestOrException.hasException()) {
- promise.resolve({ });
- return;
- }
- request = requestOrException.releaseReturnValue();
- }
-
- if (!request) {
- retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
- if (exception) {
- promise.reject(WTFMove(exception.value()));
- return;
- }
- Vector<Ref<FetchResponse>> responses;
- responses.reserveInitialCapacity(m_records.size());
- for (auto& record : m_records)
- responses.uncheckedAppend(record.response->cloneForJS());
- promise.resolve(responses);
- });
- return;
- }
- queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
- if (result.hasException()) {
- promise.reject(result.releaseException());
- return;
- }
- auto records = result.releaseReturnValue();
- Vector<Ref<FetchResponse>> responses;
- responses.reserveInitialCapacity(records.size());
- for (auto& record : records)
- responses.uncheckedAppend(record.response->cloneForJS());
- promise.resolve(responses);
- });
-}
-
-void Cache::add(RequestInfo&& info, DOMPromiseDeferred<void>&& promise)
-{
- addAll(Vector<RequestInfo> { WTFMove(info) }, WTFMove(promise));
-}
-
-static inline bool hasResponseVaryStarHeaderValue(const FetchResponse& response)
-{
- auto varyValue = response.headers().internalHeaders().get(WebCore::HTTPHeaderName::Vary);
- bool hasStar = false;
- varyValue.split(',', false, [&](StringView view) {
- if (!hasStar && stripLeadingAndTrailingHTTPSpaces(view) == "*")
- hasStar = true;
- });
- return hasStar;
-}
-
-class FetchTasksHandler : public RefCounted<FetchTasksHandler> {
-public:
- explicit FetchTasksHandler(Function<void(ExceptionOr<Vector<Record>>&&)>&& callback)
- : m_callback(WTFMove(callback))
- {
- }
-
- ~FetchTasksHandler()
- {
- if (m_callback)
- m_callback(WTFMove(m_records));
- }
-
- const Vector<Record>& records() const { return m_records; }
-
- size_t addRecord(Record&& record)
- {
- ASSERT(!isDone());
- m_records.append(WTFMove(record));
- return m_records.size() - 1;
- }
-
- void addResponseBody(size_t position, Ref<SharedBuffer>&& data)
- {
- ASSERT(!isDone());
- m_records[position].responseBody = WTFMove(data);
- }
-
- bool isDone() const { return !m_callback; }
-
- void error(Exception&& exception)
- {
- if (auto callback = WTFMove(m_callback))
- callback(WTFMove(exception));
- }
-
-private:
- Vector<Record> m_records;
- Function<void(ExceptionOr<Vector<Record>>&&)> m_callback;
-};
-
-ExceptionOr<Ref<FetchRequest>> Cache::requestFromInfo(RequestInfo&& info, bool ignoreMethod)
-{
- RefPtr<FetchRequest> request;
- if (WTF::holds_alternative<RefPtr<FetchRequest>>(info)) {
- request = WTF::get<RefPtr<FetchRequest>>(info).releaseNonNull();
- if (request->method() != "GET" && !ignoreMethod)
- return Exception { TypeError, ASCIILiteral("Request method is not GET") };
- } else
- request = FetchRequest::create(*scriptExecutionContext(), WTFMove(info), { }).releaseReturnValue();
-
- if (!protocolIsInHTTPFamily(request->url()))
- return Exception { TypeError, ASCIILiteral("Request url is not HTTP/HTTPS") };
-
- return request.releaseNonNull();
-}
-
-void Cache::addAll(Vector<RequestInfo>&& infos, DOMPromiseDeferred<void>&& promise)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- Vector<Ref<FetchRequest>> requests;
- requests.reserveInitialCapacity(infos.size());
- for (auto& info : infos) {
- bool ignoreMethod = false;
- auto requestOrException = requestFromInfo(WTFMove(info), ignoreMethod);
- if (requestOrException.hasException()) {
- promise.reject(requestOrException.releaseException());
- return;
- }
- requests.uncheckedAppend(requestOrException.releaseReturnValue());
- }
-
- auto taskHandler = adoptRef(*new FetchTasksHandler([protectedThis = makeRef(*this), this, promise = WTFMove(promise)](ExceptionOr<Vector<Record>>&& result) mutable {
- if (result.hasException()) {
- promise.reject(result.releaseException());
- return;
- }
- batchPutOperation(result.releaseReturnValue(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
- promise.settle(WTFMove(result));
- });
- }));
-
- for (auto& request : requests) {
- auto& requestReference = request.get();
- FetchResponse::fetch(*scriptExecutionContext(), requestReference, [this, request = WTFMove(request), taskHandler = taskHandler.copyRef()](ExceptionOr<FetchResponse&>&& result) mutable {
-
- if (taskHandler->isDone())
- return;
-
- if (result.hasException()) {
- taskHandler->error(result.releaseException());
- return;
- }
-
- auto& response = result.releaseReturnValue();
-
- if (!response.ok()) {
- taskHandler->error(Exception { TypeError, ASCIILiteral("Response is not OK") });
- return;
- }
-
- if (hasResponseVaryStarHeaderValue(response)) {
- taskHandler->error(Exception { TypeError, ASCIILiteral("Response has a '*' Vary header value") });
- return;
- }
-
- if (response.status() == 206) {
- taskHandler->error(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
- return;
- }
-
- CacheQueryOptions options;
- for (const auto& record : taskHandler->records()) {
- if (DOMCacheEngine::queryCacheMatch(request->resourceRequest(), record.request, record.response, options)) {
- taskHandler->error(Exception { InvalidStateError, ASCIILiteral("addAll cannot store several matching requests")});
- return;
- }
- }
- size_t recordPosition = taskHandler->addRecord(toConnectionRecord(request.get(), response, nullptr));
-
- response.consumeBodyWhenLoaded([taskHandler = WTFMove(taskHandler), recordPosition](ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
- if (taskHandler->isDone())
- return;
-
- if (result.hasException()) {
- taskHandler->error(result.releaseException());
- return;
- }
- if (auto value = result.releaseReturnValue())
- taskHandler->addResponseBody(recordPosition, value.releaseNonNull());
- });
- });
- }
-}
-
-void Cache::put(RequestInfo&& info, Ref<FetchResponse>&& response, DOMPromiseDeferred<void>&& promise)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- bool ignoreMethod = false;
- auto requestOrException = requestFromInfo(WTFMove(info), ignoreMethod);
- if (requestOrException.hasException()) {
- promise.reject(requestOrException.releaseException());
- return;
- }
- auto request = requestOrException.releaseReturnValue();
-
- if (hasResponseVaryStarHeaderValue(response.get())) {
- promise.reject(Exception { TypeError, ASCIILiteral("Response has a '*' Vary header value") });
- return;
- }
-
- if (response->status() == 206) {
- promise.reject(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
- return;
- }
-
- // FIXME: Add support for ReadableStream.
- if (response->hasReadableStreamBody()) {
- promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
- return;
- }
-
- if (response->isDisturbed()) {
- promise.reject(Exception { TypeError, ASCIILiteral("Response is disturbed or locked") });
- return;
- }
-
- if (response->isLoading()) {
- setPendingActivity(this);
- response->consumeBodyWhenLoaded([promise = WTFMove(promise), request = WTFMove(request), response = WTFMove(response), this](ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
- if (result.hasException())
- promise.reject(result.releaseException());
- else {
- DOMCacheEngine::ResponseBody body;
- if (auto buffer = result.releaseReturnValue())
- body = buffer.releaseNonNull();
- batchPutOperation(request.get(), response.get(), WTFMove(body), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
- promise.settle(WTFMove(result));
- });
- }
- unsetPendingActivity(this);
- });
- return;
- }
-
- batchPutOperation(request.get(), response.get(), response->consumeBody(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
- promise.settle(WTFMove(result));
- });
-}
-
-void Cache::remove(RequestInfo&& info, CacheQueryOptions&& options, DOMPromiseDeferred<IDLBoolean>&& promise)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- auto requestOrException = requestFromInfo(WTFMove(info), options.ignoreMethod);
- if (requestOrException.hasException()) {
- promise.resolve(false);
- return;
- }
-
- batchDeleteOperation(requestOrException.releaseReturnValue(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<bool>&& result) mutable {
- promise.settle(WTFMove(result));
- });
-}
-
-void Cache::keys(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, KeysPromise&& promise)
-{
- if (UNLIKELY(!scriptExecutionContext()))
- return;
-
- RefPtr<FetchRequest> request;
- if (info) {
- auto requestOrException = requestFromInfo(WTFMove(info.value()), options.ignoreMethod);
- if (requestOrException.hasException()) {
- promise.resolve(Vector<Ref<FetchRequest>> { });
- return;
- }
- request = requestOrException.releaseReturnValue();
- }
-
- if (!request) {
- retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
- if (exception) {
- promise.reject(WTFMove(exception.value()));
- return;
- }
- Vector<Ref<FetchRequest>> requests;
- requests.reserveInitialCapacity(m_records.size());
- for (auto& record : m_records)
- requests.uncheckedAppend(record.request.copyRef());
- promise.resolve(requests);
- });
- return;
- }
-
- queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
- if (result.hasException()) {
- promise.reject(result.releaseException());
- return;
- }
-
- auto records = result.releaseReturnValue();
- Vector<Ref<FetchRequest>> requests;
- requests.reserveInitialCapacity(records.size());
- for (auto& record : records)
- requests.uncheckedAppend(record.request.copyRef());
- promise.resolve(requests);
- });
-}
-
-void Cache::retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&& callback)
-{
- setPendingActivity(this);
- m_connection->retrieveRecords(m_identifier, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
- if (!m_isStopped) {
- if (!result.hasValue()) {
- callback(DOMCacheEngine::errorToException(result.error()));
- return;
- }
-
- if (result.hasValue())
- updateRecords(WTFMove(result.value()));
- callback(std::nullopt);
- }
- unsetPendingActivity(this);
- });
-}
-
-void Cache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&& callback)
-{
- retrieveRecords([this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](std::optional<Exception>&& exception) mutable {
- if (exception) {
- callback(WTFMove(exception.value()));
- return;
- }
- callback(queryCacheWithTargetStorage(request.get(), options, m_records));
- });
-}
-
-static inline bool queryCacheMatch(const FetchRequest& request, const FetchRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options)
-{
- // We need to pass the resource request with all correct headers hence why we call resourceRequest().
- return DOMCacheEngine::queryCacheMatch(request.resourceRequest(), cachedRequest.resourceRequest(), cachedResponse, options);
-}
-
-Vector<CacheStorageRecord> Cache::queryCacheWithTargetStorage(const FetchRequest& request, const CacheQueryOptions& options, const Vector<CacheStorageRecord>& targetStorage)
-{
- if (!options.ignoreMethod && request.method() != "GET")
- return { };
-
- Vector<CacheStorageRecord> records;
- for (auto& record : targetStorage) {
- if (queryCacheMatch(request, record.request.get(), record.response->resourceResponse(), options))
- records.append({ record.identifier, record.updateResponseCounter, record.request.copyRef(), record.response.copyRef() });
- }
- return records;
-}
-
-void Cache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<bool>&&)>&& callback)
-{
- setPendingActivity(this);
- m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
- if (!m_isStopped) {
- if (!result.hasValue())
- callback(DOMCacheEngine::errorToException(result.error()));
- else
- callback(!result.value().isEmpty());
- }
- unsetPendingActivity(this);
- });
-}
-
-Record toConnectionRecord(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody)
-{
- // FIXME: Add a setHTTPHeaderFields on ResourceResponseBase.
- ResourceResponse cachedResponse = response.resourceResponse();
- for (auto& header : response.headers().internalHeaders())
- cachedResponse.setHTTPHeaderField(header.key, header.value);
-
- ResourceRequest cachedRequest = request.internalRequest();
- cachedRequest.setHTTPHeaderFields(request.headers().internalHeaders());
-
- ASSERT(!cachedRequest.isNull());
- ASSERT(!cachedResponse.isNull());
-
- return { 0, 0,
- request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
- response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
- };
-}
-
-void Cache::batchPutOperation(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
-{
- Vector<Record> records;
- records.append(toConnectionRecord(request, response, WTFMove(responseBody)));
-
- batchPutOperation(WTFMove(records), WTFMove(callback));
-}
-
-void Cache::batchPutOperation(Vector<Record>&& records, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
-{
- setPendingActivity(this);
- m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
- if (!m_isStopped) {
- if (!result.hasValue())
- callback(DOMCacheEngine::errorToException(result.error()));
- else
- callback({ });
- }
- unsetPendingActivity(this);
- });
-}
-
-void Cache::updateRecords(Vector<Record>&& records)
-{
- ASSERT(scriptExecutionContext());
- Vector<CacheStorageRecord> newRecords;
-
- for (auto& record : records) {
- size_t index = m_records.findMatching([&](const auto& item) { return item.identifier == record.identifier; });
- if (index != notFound) {
- auto& current = m_records[index];
- if (current.updateResponseCounter != record.updateResponseCounter) {
- auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
- auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
- response->setBodyData(WTFMove(record.responseBody));
-
- current.response = WTFMove(response);
- current.updateResponseCounter = record.updateResponseCounter;
- }
- newRecords.append(WTFMove(current));
- } else {
- auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() });
- auto request = FetchRequest::create(*scriptExecutionContext(), std::nullopt, WTFMove(requestHeaders), WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer));
-
- auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
- auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
- response->setBodyData(WTFMove(record.responseBody));
-
- newRecords.append(CacheStorageRecord { record.identifier, record.updateResponseCounter, WTFMove(request), WTFMove(response) });
- }
- }
- m_records = WTFMove(newRecords);
-}
-
-void Cache::stop()
-{
- m_isStopped = true;
-}
-
-const char* Cache::activeDOMObjectName() const
-{
- return "Cache";
-}
-
-bool Cache::canSuspendForDocumentSuspension() const
-{
- return m_records.isEmpty() && !hasPendingActivity();
-}
-
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/Modules/cache/Cache.h (221497 => 221498)
--- trunk/Source/WebCore/Modules/cache/Cache.h 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/Modules/cache/Cache.h 2017-09-01 21:47:57 UTC (rev 221498)
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "ActiveDOMObject.h"
-#include "CacheStorageConnection.h"
-#include "CacheStorageRecord.h"
-
-namespace WebCore {
-
-class ScriptExecutionContext;
-
-class Cache final : public RefCounted<Cache>, public ActiveDOMObject {
-public:
- static Ref<Cache> create(ScriptExecutionContext& context, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&& connection) { return adoptRef(*new Cache(context, WTFMove(name), identifier, WTFMove(connection))); }
- ~Cache();
-
- using RequestInfo = FetchRequest::Info;
-
- using KeysPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchRequest>>>;
-
- void match(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>&&);
- void put(RequestInfo&&, Ref<FetchResponse>&&, DOMPromiseDeferred<void>&&);
- void remove(RequestInfo&&, CacheQueryOptions&&, DOMPromiseDeferred<IDLBoolean>&&);
- void keys(std::optional<RequestInfo>&&, CacheQueryOptions&&, KeysPromise&&);
-
- const String& name() const { return m_name; }
- uint64_t identifier() const { return m_identifier; }
-
- using MatchCallback = WTF::Function<void(ExceptionOr<FetchResponse*>)>;
- void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&);
-
-private:
- Cache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
-
- ExceptionOr<Ref<FetchRequest>> requestFromInfo(RequestInfo&&, bool ignoreMethod);
-
- // ActiveDOMObject
- void stop() final;
- const char* activeDOMObjectName() const final;
- bool canSuspendForDocumentSuspension() const final;
-
- void retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&&);
- Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
- void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&&);
- void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
- void batchPutOperation(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
- void batchPutOperation(Vector<DOMCacheEngine::Record>&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
-
- void updateRecords(Vector<DOMCacheEngine::Record>&&);
-
- String m_name;
- uint64_t m_identifier;
- Ref<CacheStorageConnection> m_connection;
-
- Vector<CacheStorageRecord> m_records;
- bool m_isStopped { false };
-};
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/Modules/cache/Cache.idl (221497 => 221498)
--- trunk/Source/WebCore/Modules/cache/Cache.idl 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/Modules/cache/Cache.idl 2017-09-01 21:47:57 UTC (rev 221498)
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-typedef (FetchRequest or USVString) RequestInfo;
-
-[
- SecureContext,
- Exposed=(Window,Worker),
- EnabledAtRuntime=CacheAPI,
-] interface Cache {
- [NewObject] Promise<any> match(RequestInfo request, optional CacheQueryOptions options);
- [NewObject] Promise<sequence<FetchResponse>> matchAll(optional RequestInfo request, optional CacheQueryOptions options);
- [NewObject] Promise<void> add(RequestInfo request);
- [NewObject] Promise<void> addAll(sequence<RequestInfo> requests);
- [NewObject] Promise<void> put(RequestInfo request, FetchResponse response);
- [NewObject, ImplementedAs=remove] Promise<boolean> delete(RequestInfo request, optional CacheQueryOptions options);
- [NewObject] Promise<sequence<Request>> keys(optional RequestInfo request, optional CacheQueryOptions options);
-};
Modified: trunk/Source/WebCore/Modules/cache/CacheStorage.cpp (221497 => 221498)
--- trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/Modules/cache/CacheStorage.cpp 2017-09-01 21:47:57 UTC (rev 221498)
@@ -27,7 +27,7 @@
#include "CacheStorage.h"
#include "CacheQueryOptions.h"
-#include "JSCache.h"
+#include "JSDOMCache.h"
#include "JSFetchResponse.h"
#include "ScriptExecutionContext.h"
@@ -49,7 +49,7 @@
return origin ? origin->toString() : String();
}
-static void doSequentialMatch(size_t index, Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
+static void doSequentialMatch(size_t index, Vector<Ref<DOMCache>>&& caches, DOMCache::RequestInfo&& info, CacheQueryOptions&& options, DOMCache::MatchCallback&& completionHandler)
{
if (index >= caches.size()) {
completionHandler(nullptr);
@@ -69,14 +69,14 @@
});
}
-static inline void startSequentialMatch(Vector<Ref<Cache>>&& caches, Cache::RequestInfo&& info, CacheQueryOptions&& options, Cache::MatchCallback&& completionHandler)
+static inline void startSequentialMatch(Vector<Ref<DOMCache>>&& caches, DOMCache::RequestInfo&& info, CacheQueryOptions&& options, DOMCache::MatchCallback&& completionHandler)
{
doSequentialMatch(0, WTFMove(caches), WTFMove(info), WTFMove(options), WTFMove(completionHandler));
}
-static inline Vector<Ref<Cache>> copyCaches(const Vector<Ref<Cache>>& caches)
+static inline Vector<Ref<DOMCache>> copyCaches(const Vector<Ref<DOMCache>>& caches)
{
- Vector<Ref<Cache>> copy;
+ Vector<Ref<DOMCache>> copy;
copy.reserveInitialCapacity(caches.size());
for (auto& cache : caches)
copy.uncheckedAppend(cache.copyRef());
@@ -83,7 +83,7 @@
return copy;
}
-void CacheStorage::match(Cache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
+void CacheStorage::match(DOMCache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
{
retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
if (exception) {
@@ -150,11 +150,11 @@
ASSERT(scriptExecutionContext());
- Vector<Ref<Cache>> caches;
+ Vector<Ref<DOMCache>> caches;
caches.reserveInitialCapacity(cachesInfo.infos.size());
for (auto& info : cachesInfo.infos) {
auto position = m_caches.findMatching([&](const auto& cache) { return info.identifier == cache->identifier(); });
- caches.uncheckedAppend(position != notFound ? m_caches[position].copyRef() : Cache::create(*scriptExecutionContext(), WTFMove(info.name), info.identifier, m_connection.copyRef()));
+ caches.uncheckedAppend(position != notFound ? m_caches[position].copyRef() : DOMCache::create(*scriptExecutionContext(), WTFMove(info.name), info.identifier, m_connection.copyRef()));
}
m_caches = WTFMove(caches);
@@ -165,7 +165,7 @@
});
}
-void CacheStorage::open(const String& name, DOMPromiseDeferred<IDLInterface<Cache>>&& promise)
+void CacheStorage::open(const String& name, DOMPromiseDeferred<IDLInterface<DOMCache>>&& promise)
{
retrieveCaches([this, name, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
if (exception) {
@@ -176,7 +176,7 @@
auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; });
if (position != notFound) {
auto& cache = m_caches[position];
- promise.resolve(Cache::create(*scriptExecutionContext(), String { cache->name() }, cache->identifier(), m_connection.copyRef()));
+ promise.resolve(DOMCache::create(*scriptExecutionContext(), String { cache->name() }, cache->identifier(), m_connection.copyRef()));
return;
}
@@ -189,7 +189,7 @@
if (!result.hasValue())
promise.reject(DOMCacheEngine::errorToException(result.error()));
else {
- auto cache = Cache::create(*scriptExecutionContext(), String { name }, result.value(), m_connection.copyRef());
+ auto cache = DOMCache::create(*scriptExecutionContext(), String { name }, result.value(), m_connection.copyRef());
promise.resolve(cache);
m_caches.append(WTFMove(cache));
}
Modified: trunk/Source/WebCore/Modules/cache/CacheStorage.h (221497 => 221498)
--- trunk/Source/WebCore/Modules/cache/CacheStorage.h 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/Modules/cache/CacheStorage.h 2017-09-01 21:47:57 UTC (rev 221498)
@@ -25,8 +25,8 @@
#pragma once
-#include "Cache.h"
#include "CacheStorageConnection.h"
+#include "DOMCache.h"
#include "FetchRequest.h"
#include <wtf/Forward.h>
@@ -38,9 +38,9 @@
using KeysPromise = DOMPromiseDeferred<IDLSequence<IDLDOMString>>;
- void match(Cache::RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
+ void match(DOMCache::RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
void has(const String&, DOMPromiseDeferred<IDLBoolean>&&);
- void open(const String&, DOMPromiseDeferred<IDLInterface<Cache>>&&);
+ void open(const String&, DOMPromiseDeferred<IDLInterface<DOMCache>>&&);
void remove(const String&, DOMPromiseDeferred<IDLBoolean>&&);
void keys(KeysPromise&&);
@@ -55,7 +55,7 @@
void retrieveCaches(WTF::Function<void(std::optional<Exception>&&)>&&);
String origin() const;
- Vector<Ref<Cache>> m_caches;
+ Vector<Ref<DOMCache>> m_caches;
uint64_t m_updateCounter { 0 };
Ref<CacheStorageConnection> m_connection;
bool m_isStopped { false };
Copied: trunk/Source/WebCore/Modules/cache/DOMCache.cpp (from rev 221497, trunk/Source/WebCore/Modules/cache/Cache.cpp) (0 => 221498)
--- trunk/Source/WebCore/Modules/cache/DOMCache.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.cpp 2017-09-01 21:47:57 UTC (rev 221498)
@@ -0,0 +1,561 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMCache.h"
+
+#include "CacheQueryOptions.h"
+#include "FetchResponse.h"
+#include "HTTPParsers.h"
+#include "JSFetchRequest.h"
+#include "JSFetchResponse.h"
+#include "ScriptExecutionContext.h"
+#include "URL.h"
+
+using namespace WebCore::DOMCacheEngine;
+
+namespace WebCore {
+
+static Record toConnectionRecord(const FetchRequest&, FetchResponse&, ResponseBody&&);
+
+DOMCache::DOMCache(ScriptExecutionContext& context, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&& connection)
+ : ActiveDOMObject(&context)
+ , m_name(WTFMove(name))
+ , m_identifier(identifier)
+ , m_connection(WTFMove(connection))
+{
+ suspendIfNeeded();
+}
+
+DOMCache::~DOMCache()
+{
+}
+
+void DOMCache::match(RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
+{
+ doMatch(WTFMove(info), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
+ if (result.hasException()) {
+ promise->reject(result.releaseException());
+ return;
+ }
+ if (!result.returnValue()) {
+ promise->resolve();
+ return;
+ }
+ promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
+ });
+}
+
+void DOMCache::doMatch(RequestInfo&& info, CacheQueryOptions&& options, MatchCallback&& callback)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ auto requestOrException = requestFromInfo(WTFMove(info), options.ignoreMethod);
+ if (requestOrException.hasException()) {
+ callback(nullptr);
+ return;
+ }
+ auto request = requestOrException.releaseReturnValue();
+
+ queryCache(request.get(), WTFMove(options), [callback = WTFMove(callback)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ callback(result.releaseException());
+ return;
+ }
+ if (result.returnValue().isEmpty()) {
+ callback(nullptr);
+ return;
+ }
+ callback(result.returnValue()[0].response->cloneForJS().ptr());
+ });
+}
+
+void DOMCache::matchAll(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, MatchAllPromise&& promise)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ RefPtr<FetchRequest> request;
+ if (info) {
+ auto requestOrException = requestFromInfo(WTFMove(info.value()), options.ignoreMethod);
+ if (requestOrException.hasException()) {
+ promise.resolve({ });
+ return;
+ }
+ request = requestOrException.releaseReturnValue();
+ }
+
+ if (!request) {
+ retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
+ Vector<Ref<FetchResponse>> responses;
+ responses.reserveInitialCapacity(m_records.size());
+ for (auto& record : m_records)
+ responses.uncheckedAppend(record.response->cloneForJS());
+ promise.resolve(responses);
+ });
+ return;
+ }
+ queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ promise.reject(result.releaseException());
+ return;
+ }
+ auto records = result.releaseReturnValue();
+ Vector<Ref<FetchResponse>> responses;
+ responses.reserveInitialCapacity(records.size());
+ for (auto& record : records)
+ responses.uncheckedAppend(record.response->cloneForJS());
+ promise.resolve(responses);
+ });
+}
+
+void DOMCache::add(RequestInfo&& info, DOMPromiseDeferred<void>&& promise)
+{
+ addAll(Vector<RequestInfo> { WTFMove(info) }, WTFMove(promise));
+}
+
+static inline bool hasResponseVaryStarHeaderValue(const FetchResponse& response)
+{
+ auto varyValue = response.headers().internalHeaders().get(WebCore::HTTPHeaderName::Vary);
+ bool hasStar = false;
+ varyValue.split(',', false, [&](StringView view) {
+ if (!hasStar && stripLeadingAndTrailingHTTPSpaces(view) == "*")
+ hasStar = true;
+ });
+ return hasStar;
+}
+
+class FetchTasksHandler : public RefCounted<FetchTasksHandler> {
+public:
+ explicit FetchTasksHandler(Function<void(ExceptionOr<Vector<Record>>&&)>&& callback)
+ : m_callback(WTFMove(callback))
+ {
+ }
+
+ ~FetchTasksHandler()
+ {
+ if (m_callback)
+ m_callback(WTFMove(m_records));
+ }
+
+ const Vector<Record>& records() const { return m_records; }
+
+ size_t addRecord(Record&& record)
+ {
+ ASSERT(!isDone());
+ m_records.append(WTFMove(record));
+ return m_records.size() - 1;
+ }
+
+ void addResponseBody(size_t position, Ref<SharedBuffer>&& data)
+ {
+ ASSERT(!isDone());
+ m_records[position].responseBody = WTFMove(data);
+ }
+
+ bool isDone() const { return !m_callback; }
+
+ void error(Exception&& exception)
+ {
+ if (auto callback = WTFMove(m_callback))
+ callback(WTFMove(exception));
+ }
+
+private:
+ Vector<Record> m_records;
+ Function<void(ExceptionOr<Vector<Record>>&&)> m_callback;
+};
+
+ExceptionOr<Ref<FetchRequest>> DOMCache::requestFromInfo(RequestInfo&& info, bool ignoreMethod)
+{
+ RefPtr<FetchRequest> request;
+ if (WTF::holds_alternative<RefPtr<FetchRequest>>(info)) {
+ request = WTF::get<RefPtr<FetchRequest>>(info).releaseNonNull();
+ if (request->method() != "GET" && !ignoreMethod)
+ return Exception { TypeError, ASCIILiteral("Request method is not GET") };
+ } else
+ request = FetchRequest::create(*scriptExecutionContext(), WTFMove(info), { }).releaseReturnValue();
+
+ if (!protocolIsInHTTPFamily(request->url()))
+ return Exception { TypeError, ASCIILiteral("Request url is not HTTP/HTTPS") };
+
+ return request.releaseNonNull();
+}
+
+void DOMCache::addAll(Vector<RequestInfo>&& infos, DOMPromiseDeferred<void>&& promise)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ Vector<Ref<FetchRequest>> requests;
+ requests.reserveInitialCapacity(infos.size());
+ for (auto& info : infos) {
+ bool ignoreMethod = false;
+ auto requestOrException = requestFromInfo(WTFMove(info), ignoreMethod);
+ if (requestOrException.hasException()) {
+ promise.reject(requestOrException.releaseException());
+ return;
+ }
+ requests.uncheckedAppend(requestOrException.releaseReturnValue());
+ }
+
+ auto taskHandler = adoptRef(*new FetchTasksHandler([protectedThis = makeRef(*this), this, promise = WTFMove(promise)](ExceptionOr<Vector<Record>>&& result) mutable {
+ if (result.hasException()) {
+ promise.reject(result.releaseException());
+ return;
+ }
+ batchPutOperation(result.releaseReturnValue(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ promise.settle(WTFMove(result));
+ });
+ }));
+
+ for (auto& request : requests) {
+ auto& requestReference = request.get();
+ FetchResponse::fetch(*scriptExecutionContext(), requestReference, [this, request = WTFMove(request), taskHandler = taskHandler.copyRef()](ExceptionOr<FetchResponse&>&& result) mutable {
+
+ if (taskHandler->isDone())
+ return;
+
+ if (result.hasException()) {
+ taskHandler->error(result.releaseException());
+ return;
+ }
+
+ auto& response = result.releaseReturnValue();
+
+ if (!response.ok()) {
+ taskHandler->error(Exception { TypeError, ASCIILiteral("Response is not OK") });
+ return;
+ }
+
+ if (hasResponseVaryStarHeaderValue(response)) {
+ taskHandler->error(Exception { TypeError, ASCIILiteral("Response has a '*' Vary header value") });
+ return;
+ }
+
+ if (response.status() == 206) {
+ taskHandler->error(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
+ return;
+ }
+
+ CacheQueryOptions options;
+ for (const auto& record : taskHandler->records()) {
+ if (DOMCacheEngine::queryCacheMatch(request->resourceRequest(), record.request, record.response, options)) {
+ taskHandler->error(Exception { InvalidStateError, ASCIILiteral("addAll cannot store several matching requests")});
+ return;
+ }
+ }
+ size_t recordPosition = taskHandler->addRecord(toConnectionRecord(request.get(), response, nullptr));
+
+ response.consumeBodyWhenLoaded([taskHandler = WTFMove(taskHandler), recordPosition](ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
+ if (taskHandler->isDone())
+ return;
+
+ if (result.hasException()) {
+ taskHandler->error(result.releaseException());
+ return;
+ }
+ if (auto value = result.releaseReturnValue())
+ taskHandler->addResponseBody(recordPosition, value.releaseNonNull());
+ });
+ });
+ }
+}
+
+void DOMCache::put(RequestInfo&& info, Ref<FetchResponse>&& response, DOMPromiseDeferred<void>&& promise)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ bool ignoreMethod = false;
+ auto requestOrException = requestFromInfo(WTFMove(info), ignoreMethod);
+ if (requestOrException.hasException()) {
+ promise.reject(requestOrException.releaseException());
+ return;
+ }
+ auto request = requestOrException.releaseReturnValue();
+
+ if (hasResponseVaryStarHeaderValue(response.get())) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Response has a '*' Vary header value") });
+ return;
+ }
+
+ if (response->status() == 206) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
+ return;
+ }
+
+ // FIXME: Add support for ReadableStream.
+ if (response->hasReadableStreamBody()) {
+ promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
+ return;
+ }
+
+ if (response->isDisturbed()) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Response is disturbed or locked") });
+ return;
+ }
+
+ if (response->isLoading()) {
+ setPendingActivity(this);
+ response->consumeBodyWhenLoaded([promise = WTFMove(promise), request = WTFMove(request), response = WTFMove(response), this](ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
+ if (result.hasException())
+ promise.reject(result.releaseException());
+ else {
+ DOMCacheEngine::ResponseBody body;
+ if (auto buffer = result.releaseReturnValue())
+ body = buffer.releaseNonNull();
+ batchPutOperation(request.get(), response.get(), WTFMove(body), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ promise.settle(WTFMove(result));
+ });
+ }
+ unsetPendingActivity(this);
+ });
+ return;
+ }
+
+ batchPutOperation(request.get(), response.get(), response->consumeBody(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ promise.settle(WTFMove(result));
+ });
+}
+
+void DOMCache::remove(RequestInfo&& info, CacheQueryOptions&& options, DOMPromiseDeferred<IDLBoolean>&& promise)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ auto requestOrException = requestFromInfo(WTFMove(info), options.ignoreMethod);
+ if (requestOrException.hasException()) {
+ promise.resolve(false);
+ return;
+ }
+
+ batchDeleteOperation(requestOrException.releaseReturnValue(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<bool>&& result) mutable {
+ promise.settle(WTFMove(result));
+ });
+}
+
+void DOMCache::keys(std::optional<RequestInfo>&& info, CacheQueryOptions&& options, KeysPromise&& promise)
+{
+ if (UNLIKELY(!scriptExecutionContext()))
+ return;
+
+ RefPtr<FetchRequest> request;
+ if (info) {
+ auto requestOrException = requestFromInfo(WTFMove(info.value()), options.ignoreMethod);
+ if (requestOrException.hasException()) {
+ promise.resolve(Vector<Ref<FetchRequest>> { });
+ return;
+ }
+ request = requestOrException.releaseReturnValue();
+ }
+
+ if (!request) {
+ retrieveRecords([this, promise = WTFMove(promise)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ promise.reject(WTFMove(exception.value()));
+ return;
+ }
+ Vector<Ref<FetchRequest>> requests;
+ requests.reserveInitialCapacity(m_records.size());
+ for (auto& record : m_records)
+ requests.uncheckedAppend(record.request.copyRef());
+ promise.resolve(requests);
+ });
+ return;
+ }
+
+ queryCache(request.releaseNonNull(), WTFMove(options), [promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable {
+ if (result.hasException()) {
+ promise.reject(result.releaseException());
+ return;
+ }
+
+ auto records = result.releaseReturnValue();
+ Vector<Ref<FetchRequest>> requests;
+ requests.reserveInitialCapacity(records.size());
+ for (auto& record : records)
+ requests.uncheckedAppend(record.request.copyRef());
+ promise.resolve(requests);
+ });
+}
+
+void DOMCache::retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&& callback)
+{
+ setPendingActivity(this);
+ m_connection->retrieveRecords(m_identifier, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
+ if (!m_isStopped) {
+ if (!result.hasValue()) {
+ callback(DOMCacheEngine::errorToException(result.error()));
+ return;
+ }
+
+ if (result.hasValue())
+ updateRecords(WTFMove(result.value()));
+ callback(std::nullopt);
+ }
+ unsetPendingActivity(this);
+ });
+}
+
+void DOMCache::queryCache(Ref<FetchRequest>&& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&& callback)
+{
+ retrieveRecords([this, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](std::optional<Exception>&& exception) mutable {
+ if (exception) {
+ callback(WTFMove(exception.value()));
+ return;
+ }
+ callback(queryCacheWithTargetStorage(request.get(), options, m_records));
+ });
+}
+
+static inline bool queryCacheMatch(const FetchRequest& request, const FetchRequest& cachedRequest, const ResourceResponse& cachedResponse, const CacheQueryOptions& options)
+{
+ // We need to pass the resource request with all correct headers hence why we call resourceRequest().
+ return DOMCacheEngine::queryCacheMatch(request.resourceRequest(), cachedRequest.resourceRequest(), cachedResponse, options);
+}
+
+Vector<CacheStorageRecord> DOMCache::queryCacheWithTargetStorage(const FetchRequest& request, const CacheQueryOptions& options, const Vector<CacheStorageRecord>& targetStorage)
+{
+ if (!options.ignoreMethod && request.method() != "GET")
+ return { };
+
+ Vector<CacheStorageRecord> records;
+ for (auto& record : targetStorage) {
+ if (queryCacheMatch(request, record.request.get(), record.response->resourceResponse(), options))
+ records.append({ record.identifier, record.updateResponseCounter, record.request.copyRef(), record.response.copyRef() });
+ }
+ return records;
+}
+
+void DOMCache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<bool>&&)>&& callback)
+{
+ setPendingActivity(this);
+ m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
+ if (!m_isStopped) {
+ if (!result.hasValue())
+ callback(DOMCacheEngine::errorToException(result.error()));
+ else
+ callback(!result.value().isEmpty());
+ }
+ unsetPendingActivity(this);
+ });
+}
+
+Record toConnectionRecord(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody)
+{
+ // FIXME: Add a setHTTPHeaderFields on ResourceResponseBase.
+ ResourceResponse cachedResponse = response.resourceResponse();
+ for (auto& header : response.headers().internalHeaders())
+ cachedResponse.setHTTPHeaderField(header.key, header.value);
+
+ ResourceRequest cachedRequest = request.internalRequest();
+ cachedRequest.setHTTPHeaderFields(request.headers().internalHeaders());
+
+ ASSERT(!cachedRequest.isNull());
+ ASSERT(!cachedResponse.isNull());
+
+ return { 0, 0,
+ request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
+ response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
+ };
+}
+
+void DOMCache::batchPutOperation(const FetchRequest& request, FetchResponse& response, DOMCacheEngine::ResponseBody&& responseBody, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
+{
+ Vector<Record> records;
+ records.append(toConnectionRecord(request, response, WTFMove(responseBody)));
+
+ batchPutOperation(WTFMove(records), WTFMove(callback));
+}
+
+void DOMCache::batchPutOperation(Vector<Record>&& records, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
+{
+ setPendingActivity(this);
+ m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
+ if (!m_isStopped) {
+ if (!result.hasValue())
+ callback(DOMCacheEngine::errorToException(result.error()));
+ else
+ callback({ });
+ }
+ unsetPendingActivity(this);
+ });
+}
+
+void DOMCache::updateRecords(Vector<Record>&& records)
+{
+ ASSERT(scriptExecutionContext());
+ Vector<CacheStorageRecord> newRecords;
+
+ for (auto& record : records) {
+ size_t index = m_records.findMatching([&](const auto& item) { return item.identifier == record.identifier; });
+ if (index != notFound) {
+ auto& current = m_records[index];
+ if (current.updateResponseCounter != record.updateResponseCounter) {
+ auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
+ auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
+ response->setBodyData(WTFMove(record.responseBody));
+
+ current.response = WTFMove(response);
+ current.updateResponseCounter = record.updateResponseCounter;
+ }
+ newRecords.append(WTFMove(current));
+ } else {
+ auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() });
+ auto request = FetchRequest::create(*scriptExecutionContext(), std::nullopt, WTFMove(requestHeaders), WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer));
+
+ auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
+ auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
+ response->setBodyData(WTFMove(record.responseBody));
+
+ newRecords.append(CacheStorageRecord { record.identifier, record.updateResponseCounter, WTFMove(request), WTFMove(response) });
+ }
+ }
+ m_records = WTFMove(newRecords);
+}
+
+void DOMCache::stop()
+{
+ m_isStopped = true;
+}
+
+const char* DOMCache::activeDOMObjectName() const
+{
+ return "Cache";
+}
+
+bool DOMCache::canSuspendForDocumentSuspension() const
+{
+ return m_records.isEmpty() && !hasPendingActivity();
+}
+
+
+} // namespace WebCore
Copied: trunk/Source/WebCore/Modules/cache/DOMCache.h (from rev 221497, trunk/Source/WebCore/Modules/cache/Cache.h) (0 => 221498)
--- trunk/Source/WebCore/Modules/cache/DOMCache.h (rev 0)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.h 2017-09-01 21:47:57 UTC (rev 221498)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ActiveDOMObject.h"
+#include "CacheStorageConnection.h"
+#include "CacheStorageRecord.h"
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+class DOMCache final : public RefCounted<DOMCache>, public ActiveDOMObject {
+public:
+ static Ref<DOMCache> create(ScriptExecutionContext& context, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&& connection) { return adoptRef(*new DOMCache(context, WTFMove(name), identifier, WTFMove(connection))); }
+ ~DOMCache();
+
+ using RequestInfo = FetchRequest::Info;
+
+ using KeysPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchRequest>>>;
+
+ void match(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>&&);
+ void put(RequestInfo&&, Ref<FetchResponse>&&, DOMPromiseDeferred<void>&&);
+ void remove(RequestInfo&&, CacheQueryOptions&&, DOMPromiseDeferred<IDLBoolean>&&);
+ void keys(std::optional<RequestInfo>&&, CacheQueryOptions&&, KeysPromise&&);
+
+ const String& name() const { return m_name; }
+ uint64_t identifier() const { return m_identifier; }
+
+ using MatchCallback = WTF::Function<void(ExceptionOr<FetchResponse*>)>;
+ void doMatch(RequestInfo&&, CacheQueryOptions&&, MatchCallback&&);
+
+private:
+ DOMCache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
+
+ ExceptionOr<Ref<FetchRequest>> requestFromInfo(RequestInfo&&, bool ignoreMethod);
+
+ // ActiveDOMObject
+ void stop() final;
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
+
+ void retrieveRecords(WTF::Function<void(std::optional<Exception>&&)>&&);
+ Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
+ void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<Vector<CacheStorageRecord>>&&)>&&);
+ void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
+ void batchPutOperation(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
+ void batchPutOperation(Vector<DOMCacheEngine::Record>&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
+
+ void updateRecords(Vector<DOMCacheEngine::Record>&&);
+
+ String m_name;
+ uint64_t m_identifier;
+ Ref<CacheStorageConnection> m_connection;
+
+ Vector<CacheStorageRecord> m_records;
+ bool m_isStopped { false };
+};
+
+} // namespace WebCore
Copied: trunk/Source/WebCore/Modules/cache/DOMCache.idl (from rev 221497, trunk/Source/WebCore/Modules/cache/Cache.idl) (0 => 221498)
--- trunk/Source/WebCore/Modules/cache/DOMCache.idl (rev 0)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.idl 2017-09-01 21:47:57 UTC (rev 221498)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+typedef (FetchRequest or USVString) RequestInfo;
+
+[
+ SecureContext,
+ Exposed=(Window,Worker),
+ EnabledAtRuntime=CacheAPI,
+ InterfaceName=Cache,
+] interface DOMCache {
+ [NewObject] Promise<any> match(RequestInfo request, optional CacheQueryOptions options);
+ [NewObject] Promise<sequence<FetchResponse>> matchAll(optional RequestInfo request, optional CacheQueryOptions options);
+ [NewObject] Promise<void> add(RequestInfo request);
+ [NewObject] Promise<void> addAll(sequence<RequestInfo> requests);
+ [NewObject] Promise<void> put(RequestInfo request, FetchResponse response);
+ [NewObject, ImplementedAs=remove] Promise<boolean> delete(RequestInfo request, optional CacheQueryOptions options);
+ [NewObject] Promise<sequence<Request>> keys(optional RequestInfo request, optional CacheQueryOptions options);
+};
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (221497 => 221498)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-09-01 21:45:30 UTC (rev 221497)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-09-01 21:47:57 UTC (rev 221498)
@@ -1677,8 +1677,8 @@
4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */; settings = {ATTRIBUTES = (Private, ); }; };
413015D91C7B571400091C6E /* FetchResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413015D51C7B570400091C6E /* FetchResponse.cpp */; };
413015D91C7B571400091C6F /* FetchBodySource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413015D51C7B570400091C6F /* FetchBodySource.cpp */; };
- 41380C261F3436A600155FDA /* Cache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41380C201F34368A00155FDA /* Cache.cpp */; };
- 41380C271F3436AC00155FDA /* Cache.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C251F34369A00155FDA /* Cache.h */; };
+ 41380C261F3436A600155FDA /* DOMCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41380C201F34368A00155FDA /* DOMCache.cpp */; };
+ 41380C271F3436AC00155FDA /* DOMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C251F34369A00155FDA /* DOMCache.h */; };
41380C281F3436AC00155FDA /* CacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41380C211F34368D00155FDA /* CacheStorage.cpp */; };
41380C291F3436AC00155FDA /* CacheStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 41380C221F34369000155FDA /* CacheStorage.h */; };
4138D3351244054800323D33 /* EventContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4138D3331244054800323D33 /* EventContext.h */; };
@@ -3319,11 +3319,11 @@
7CE191701F2ABE7100272F78 /* JSFetchReferrerPolicy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE191671F2AB70100272F78 /* JSFetchReferrerPolicy.cpp */; };
7CE191711F2ABE7100272F78 /* JSFetchReferrerPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191681F2AB70300272F78 /* JSFetchReferrerPolicy.h */; };
7CE191721F2ABE7100272F78 /* JSFetchRequestCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916E1F2AB70D00272F78 /* JSFetchRequestCache.cpp */; };
- 7CE191721F2ABE7100272F79 /* JSCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916E1F2AB70D00272F79 /* JSCache.cpp */; };
+ 7CE191721F2ABE7100272F79 /* JSDOMCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916E1F2AB70D00272F79 /* JSDOMCache.cpp */; };
7CE191721F2ABE7100272F7A /* JSCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916E1F2AB70D00272F7A /* JSCacheStorage.cpp */; };
7CE191721F2ABE7100272F7B /* JSCacheQueryOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916E1F2AB70D00272F7B /* JSCacheQueryOptions.cpp */; };
7CE191731F2ABE7100272F78 /* JSFetchRequestCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191641F2AB6FB00272F78 /* JSFetchRequestCache.h */; };
- 7CE191731F2ABE7100272F79 /* JSCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191641F2AB6FB00272F79 /* JSCache.h */; };
+ 7CE191731F2ABE7100272F79 /* JSDOMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191641F2AB6FB00272F79 /* JSDOMCache.h */; };
7CE191731F2ABE7100272F7A /* JSCacheStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191641F2AB6FB00272F7A /* JSCacheStorage.h */; };
7CE191741F2ABE7100272F78 /* JSFetchRequestCredentials.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE1916B1F2AB70800272F78 /* JSFetchRequestCredentials.cpp */; };
7CE191751F2ABE7100272F78 /* JSFetchRequestCredentials.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE191661F2AB6FF00272F78 /* JSFetchRequestCredentials.h */; };
@@ -9394,12 +9394,12 @@
413015D61C7B570400091C6F /* FetchBodySource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchBodySource.h; sourceTree = "<group>"; };
413015D71C7B570400091C6E /* FetchResponse.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchResponse.idl; sourceTree = "<group>"; };
413015D81C7B570400091C6E /* FetchResponse.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = FetchResponse.js; sourceTree = "<group>"; };
- 41380C201F34368A00155FDA /* Cache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Cache.cpp; path = Modules/cache/Cache.cpp; sourceTree = SOURCE_ROOT; };
+ 41380C201F34368A00155FDA /* DOMCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DOMCache.cpp; path = Modules/cache/DOMCache.cpp; sourceTree = SOURCE_ROOT; };
41380C211F34368D00155FDA /* CacheStorage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = CacheStorage.cpp; path = Modules/cache/CacheStorage.cpp; sourceTree = SOURCE_ROOT; };
41380C221F34369000155FDA /* CacheStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CacheStorage.h; path = Modules/cache/CacheStorage.h; sourceTree = SOURCE_ROOT; };
- 41380C231F34369400155FDA /* Cache.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = Cache.idl; path = Modules/cache/Cache.idl; sourceTree = SOURCE_ROOT; };
+ 41380C231F34369400155FDA /* DOMCache.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = DOMCache.idl; path = Modules/cache/DOMCache.idl; sourceTree = SOURCE_ROOT; };
41380C241F34369700155FDA /* CacheStorage.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = CacheStorage.idl; path = Modules/cache/CacheStorage.idl; sourceTree = SOURCE_ROOT; };
- 41380C251F34369A00155FDA /* Cache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Cache.h; path = Modules/cache/Cache.h; sourceTree = SOURCE_ROOT; };
+ 41380C251F34369A00155FDA /* DOMCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DOMCache.h; path = Modules/cache/DOMCache.h; sourceTree = SOURCE_ROOT; };
41380C2A1F343E2F00155FDA /* WorkerGlobalScopeCaches.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = WorkerGlobalScopeCaches.idl; path = Modules/cache/WorkerGlobalScopeCaches.idl; sourceTree = SOURCE_ROOT; };
41380C2B1F343E2F00155FDA /* DOMWindowCaches.idl */ = {isa = PBXFileReference; lastKnownFileType = text; name = DOMWindowCaches.idl; path = Modules/cache/DOMWindowCaches.idl; sourceTree = SOURCE_ROOT; };
4138D3331244054800323D33 /* EventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventContext.h; sourceTree = "<group>"; };
@@ -11479,7 +11479,7 @@
7CE1915D1F2A9B4F00272F78 /* FetchRequestRedirect.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FetchRequestRedirect.h; sourceTree = "<group>"; };
7CE1915F1F2A9B4F00272F78 /* FetchRequestRedirect.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = FetchRequestRedirect.idl; sourceTree = "<group>"; };
7CE191641F2AB6FB00272F78 /* JSFetchRequestCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSFetchRequestCache.h; sourceTree = "<group>"; };
- 7CE191641F2AB6FB00272F79 /* JSCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSCache.h; sourceTree = "<group>"; };
+ 7CE191641F2AB6FB00272F79 /* JSDOMCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSDOMCache.h; sourceTree = "<group>"; };
7CE191641F2AB6FB00272F7A /* JSCacheStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSCacheStorage.h; sourceTree = "<group>"; };
7CE191651F2AB6FD00272F78 /* JSFetchRequestMode.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequestMode.cpp; sourceTree = "<group>"; };
7CE191661F2AB6FF00272F78 /* JSFetchRequestCredentials.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSFetchRequestCredentials.h; sourceTree = "<group>"; };
@@ -11491,7 +11491,7 @@
7CE1916C1F2AB70A00272F78 /* JSFetchRequestMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSFetchRequestMode.h; sourceTree = "<group>"; };
7CE1916D1F2AB70C00272F78 /* JSFetchRequestInit.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequestInit.cpp; sourceTree = "<group>"; };
7CE1916E1F2AB70D00272F78 /* JSFetchRequestCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequestCache.cpp; sourceTree = "<group>"; };
- 7CE1916E1F2AB70D00272F79 /* JSCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSCache.cpp; sourceTree = "<group>"; };
+ 7CE1916E1F2AB70D00272F79 /* JSDOMCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMCache.cpp; sourceTree = "<group>"; };
7CE1916E1F2AB70D00272F7A /* JSCacheStorage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSCacheStorage.cpp; sourceTree = "<group>"; };
7CE1916E1F2AB70D00272F7B /* JSCacheQueryOptions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSCacheQueryOptions.cpp; sourceTree = "<group>"; };
7CE1916F1F2AB70F00272F78 /* JSFetchRequestRedirect.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSFetchRequestRedirect.cpp; sourceTree = "<group>"; };
@@ -17807,9 +17807,6 @@
41380C1E1F34366000155FDA /* cache */ = {
isa = PBXGroup;
children = (
- 41380C201F34368A00155FDA /* Cache.cpp */,
- 41380C251F34369A00155FDA /* Cache.h */,
- 41380C231F34369400155FDA /* Cache.idl */,
41FB279B1F34CEF000795487 /* CacheQueryOptions.h */,
41FB27991F34CE9C00795487 /* CacheQueryOptions.idl */,
41380C211F34368D00155FDA /* CacheStorage.cpp */,
@@ -17818,6 +17815,9 @@
41D129C91F3D0EE300D15E47 /* CacheStorageConnection.cpp */,
41D129CC1F3D0EE300D15E47 /* CacheStorageConnection.h */,
41D129CA1F3D0EE300D15E47 /* CacheStorageRecord.h */,
+ 41380C201F34368A00155FDA /* DOMCache.cpp */,
+ 41380C251F34369A00155FDA /* DOMCache.h */,
+ 41380C231F34369400155FDA /* DOMCache.idl */,
41FABD2E1F4E0251006A6C97 /* DOMCacheEngine.cpp */,
41FABD2B1F4DFE42006A6C97 /* DOMCacheEngine.h */,
41FB278E1F34C28200795487 /* DOMWindowCaches.cpp */,
@@ -18081,11 +18081,11 @@
41FB27881F34461B00795488 /* CacheAPI */ = {
isa = PBXGroup;
children = (
- 7CE1916E1F2AB70D00272F79 /* JSCache.cpp */,
- 7CE191641F2AB6FB00272F79 /* JSCache.h */,
7CE1916E1F2AB70D00272F7B /* JSCacheQueryOptions.cpp */,
7CE1916E1F2AB70D00272F7A /* JSCacheStorage.cpp */,
7CE191641F2AB6FB00272F7A /* JSCacheStorage.h */,
+ 7CE1916E1F2AB70D00272F79 /* JSDOMCache.cpp */,
+ 7CE191641F2AB6FB00272F79 /* JSDOMCache.h */,
);
name = CacheAPI;
sourceTree = "<group>";
@@ -26987,7 +26987,6 @@
1A569CFC0D7E2B82007C3983 /* c_runtime.h in Headers */,
1A569CFE0D7E2B82007C3983 /* c_utility.h in Headers */,
07C046C41E42508B007201E7 /* CAAudioStreamDescription.h in Headers */,
- 41380C271F3436AC00155FDA /* Cache.h in Headers */,
BCB16C1A0979C3BD00467741 /* CachedCSSStyleSheet.h in Headers */,
BC64B4CC0CB4295D005F2B62 /* CachedFont.h in Headers */,
1AEF4E67170E160300AB2799 /* CachedFontClient.h in Headers */,
@@ -27442,6 +27441,7 @@
A8185F3909765766005826D9 /* DocumentType.h in Headers */,
973889A1116EA9DC00ADF313 /* DocumentWriter.h in Headers */,
1A8F6BC30DB55CDC001DB794 /* DOMApplicationCache.h in Headers */,
+ 41380C271F3436AC00155FDA /* DOMCache.h in Headers */,
41FABD2D1F4DFE4A006A6C97 /* DOMCacheEngine.h in Headers */,
FC9A0F75164094CF003D6B8D /* DOMCSSNamespace.h in Headers */,
9B3A8872145632F9003AE8F5 /* DOMDOMSettableTokenList.h in Headers */,
@@ -28117,7 +28117,6 @@
7C77C3DC1DEF86D700A50BFA /* JSBlobLineEndings.h in Headers */,
7C77C3D51DEF178E00A50BFA /* JSBlobPropertyBag.h in Headers */,
14DCF3B31B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h in Headers */,
- 7CE191731F2ABE7100272F79 /* JSCache.h in Headers */,
7CE191731F2ABE7100272F7A /* JSCacheStorage.h in Headers */,
1449E24C107D4A8400B5793F /* JSCallbackData.h in Headers */,
07277E4D17D018CC0015534E /* JSCanvasCaptureMediaStreamTrack.h in Headers */,
@@ -28198,6 +28197,7 @@
93B70D6409EB0C7C009D8468 /* JSDOMBinding.h in Headers */,
416E6FE81BBD12DF000A3F65 /* JSDOMBindingInternalsBuiltins.h in Headers */,
7C45C9D41E3FCBDF00AAB558 /* JSDOMBindingSecurity.h in Headers */,
+ 7CE191731F2ABE7100272F79 /* JSDOMCache.h in Headers */,
7C8139AA1ED6604B00CE26E8 /* JSDOMCastedThisErrorBehavior.h in Headers */,
413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */,
930841341CDDB15500B0958C /* JSDOMConvert.h in Headers */,
@@ -31125,7 +31125,6 @@
1A569CFB0D7E2B82007C3983 /* c_runtime.cpp in Sources */,
1A569CFD0D7E2B82007C3983 /* c_utility.cpp in Sources */,
07C046C31E42508B007201E7 /* CAAudioStreamDescription.cpp in Sources */,
- 41380C261F3436A600155FDA /* Cache.cpp in Sources */,
BCB16C190979C3BD00467741 /* CachedCSSStyleSheet.cpp in Sources */,
BC64B4CB0CB4295D005F2B62 /* CachedFont.cpp in Sources */,
51C0AA410F2AA15E001648C2 /* CachedFrame.cpp in Sources */,
@@ -31503,6 +31502,7 @@
A8185F3A09765766005826D9 /* DocumentType.cpp in Sources */,
973889A0116EA9DC00ADF313 /* DocumentWriter.cpp in Sources */,
1A8F6BC20DB55CDC001DB794 /* DOMApplicationCache.cpp in Sources */,
+ 41380C261F3436A600155FDA /* DOMCache.cpp in Sources */,
41FABD2F1F4E02CB006A6C97 /* DOMCacheEngine.cpp in Sources */,
FD677738195CAF3D0072E0D3 /* DOMCSSNamespace.cpp in Sources */,
7AABA25914BC613300AA9A11 /* DOMEditor.cpp in Sources */,
@@ -32133,7 +32133,6 @@
7C77C3DB1DEF86D700A50BFA /* JSBlobLineEndings.cpp in Sources */,
7C77C3D41DEF178E00A50BFA /* JSBlobPropertyBag.cpp in Sources */,
14DCF3B21B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp in Sources */,
- 7CE191721F2ABE7100272F79 /* JSCache.cpp in Sources */,
7CE191721F2ABE7100272F7B /* JSCacheQueryOptions.cpp in Sources */,
7CE191721F2ABE7100272F7A /* JSCacheStorage.cpp in Sources */,
1449E287107D4DB400B5793F /* JSCallbackData.cpp in Sources */,
@@ -32221,6 +32220,7 @@
1AC2260C0DB69F190089B669 /* JSDOMApplicationCache.cpp in Sources */,
7C45C9CF1E3EFDF700AAB558 /* JSDOMBindingSecurity.cpp in Sources */,
7CC01D0A1E4A7B0400E529CC /* JSDOMBuiltinConstructorBase.cpp in Sources */,
+ 7CE191721F2ABE7100272F79 /* JSDOMCache.cpp in Sources */,
7CC01D0B1E4A7B0400E529CC /* JSDOMConstructorBase.cpp in Sources */,
7CC01D0C1E4A7B0400E529CC /* JSDOMConstructorWithDocument.cpp in Sources */,
7C8E34B21E4A33B00054CE23 /* JSDOMConvertDate.cpp in Sources */,