/* * Copyright (c) 2026, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::ServiceWorker { struct CacheQueryOptions { bool ignore_search { false }; bool ignore_method { false }; bool ignore_vary { false }; }; // https://w3c.github.io/ServiceWorker/#dfn-cache-batch-operation struct CacheBatchOperation : public GC::Cell { GC_CELL(CacheBatchOperation, GC::Cell); GC_DECLARE_ALLOCATOR(CacheBatchOperation); enum class Type : u8 { Delete, Put, }; CacheBatchOperation(Type type, GC::Ref request, GC::Ptr response = {}, CacheQueryOptions options = {}) : type(type) , request(request) , response(response) , options(options) { } virtual void visit_edges(Visitor&) override; Type type; GC::Ref request; GC::Ptr response; CacheQueryOptions options; }; // https://w3c.github.io/ServiceWorker/#cache-interface class Cache : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Cache, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(Cache); public: GC::Ref match(Fetch::RequestInfo, CacheQueryOptions); GC::Ref match_all(Optional, CacheQueryOptions); GC::Ref add(Fetch::RequestInfo); GC::Ref add_all(ReadonlySpan); GC::Ref put(Fetch::RequestInfo, GC::Ref); GC::Ref delete_(Fetch::RequestInfo, CacheQueryOptions); GC::Ref keys(Optional, CacheQueryOptions); private: Cache(JS::Realm&, GC::Ref); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; enum class CloneCache { No, Yes, }; GC::Ref query_cache(GC::Ref request_query, CacheQueryOptions options = {}, GC::Ptr = {}, CloneCache = Cache::CloneCache::Yes); WebIDL::ExceptionOr batch_cache_operations(GC::Ref>>); GC::Ref m_request_response_list; }; }