2 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "ActiveDOMObject.h"
29 #include "CacheStorageConnection.h"
30 #include "CacheStorageRecord.h"
34 class ScriptExecutionContext;
36 class Cache final : public RefCounted<Cache>, public ActiveDOMObject {
38 static Ref<Cache> create(ScriptExecutionContext& context, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&& connection) { return adoptRef(*new Cache(context, WTFMove(name), identifier, WTFMove(connection))); }
41 using RequestInfo = FetchRequest::Info;
43 using KeysPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FetchRequest>>>;
45 void match(RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
46 void matchAll(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
47 void add(RequestInfo&&, DOMPromiseDeferred<void>&&);
49 void addAll(Vector<RequestInfo>&&, DOMPromiseDeferred<void>&&);
50 void put(RequestInfo&&, Ref<FetchResponse>&&, DOMPromiseDeferred<void>&&);
51 void remove(RequestInfo&&, CacheQueryOptions&&, DOMPromiseDeferred<IDLBoolean>&&);
52 void keys(std::optional<RequestInfo>&&, CacheQueryOptions&&, KeysPromise&&);
54 const String& name() const { return m_name; }
55 uint64_t identifier() const { return m_identifier; }
58 Cache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
60 enum class MatchType { All, OnlyFirst };
61 void doMatch(std::optional<RequestInfo>&&, CacheQueryOptions&&, Ref<DeferredPromise>&&, MatchType);
65 const char* activeDOMObjectName() const final;
66 bool canSuspendForDocumentSuspension() const final;
68 void retrieveRecords(WTF::Function<void()>&&);
69 Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
70 void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(const Vector<CacheStorageRecord>&)>&&);
71 void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
72 void batchPutOperation(const FetchRequest&, FetchResponse&, WTF::Function<void(ExceptionOr<void>&&)>&&);
74 void updateRecords(Vector<CacheStorageConnection::Record>&&);
77 uint64_t m_identifier;
78 Ref<CacheStorageConnection> m_connection;
80 Vector<CacheStorageRecord> m_records;
81 bool m_isStopped { false };
84 } // namespace WebCore