mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-07 21:17:07 +09:00
LibWeb: Stub CacheStorage interface
With this change we can again open login form https://discord.com/login instead of failing in js because `caches.open()` is not defined.
This commit is contained in:
parent
28bfe701b7
commit
7efdd1c1ec
Notes:
github-actions[bot]
2025-06-05 21:03:31 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 7efdd1c1ec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5012
10 changed files with 102 additions and 0 deletions
|
@ -738,6 +738,7 @@ set(SOURCES
|
|||
ResourceTiming/PerformanceResourceTiming.cpp
|
||||
SecureContexts/AbstractOperations.cpp
|
||||
Selection/Selection.cpp
|
||||
ServiceWorker/CacheStorage.cpp
|
||||
ServiceWorker/EventNames.cpp
|
||||
ServiceWorker/Job.cpp
|
||||
ServiceWorker/Registration.cpp
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
#include <LibWeb/Platform/ImageCodecPlugin.h>
|
||||
#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
|
||||
#include <LibWeb/ServiceWorker/CacheStorage.h>
|
||||
#include <LibWeb/UserTiming/PerformanceMark.h>
|
||||
#include <LibWeb/UserTiming/PerformanceMeasure.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
|
@ -77,6 +78,7 @@ void WindowOrWorkerGlobalScopeMixin::visit_edges(JS::Cell::Visitor& visitor)
|
|||
entry.value.visit_edges(visitor);
|
||||
visitor.visit(m_registered_event_sources);
|
||||
visitor.visit(m_crypto);
|
||||
visitor.visit(m_cache_storage);
|
||||
visitor.visit(m_resource_timing_secondary_buffer);
|
||||
}
|
||||
|
||||
|
@ -1020,4 +1022,15 @@ GC::Ref<Crypto::Crypto> WindowOrWorkerGlobalScopeMixin::crypto()
|
|||
return GC::Ref { *m_crypto };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#cache-storage-interface
|
||||
GC::Ref<ServiceWorker::CacheStorage> WindowOrWorkerGlobalScopeMixin::caches()
|
||||
{
|
||||
auto& platform_object = this_impl();
|
||||
auto& realm = platform_object.realm();
|
||||
|
||||
if (!m_cache_storage)
|
||||
m_cache_storage = realm.create<ServiceWorker::CacheStorage>(realm);
|
||||
return GC::Ref { *m_cache_storage };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <LibWeb/HTML/ImageBitmap.h>
|
||||
#include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
|
||||
#include <LibWeb/PerformanceTimeline/PerformanceEntryTuple.h>
|
||||
#include <LibWeb/ServiceWorker/CacheStorage.h>
|
||||
#include <LibWeb/WebSockets/WebSocket.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -100,6 +101,8 @@ public:
|
|||
|
||||
[[nodiscard]] GC::Ref<Crypto::Crypto> crypto();
|
||||
|
||||
[[nodiscard]] GC::Ref<ServiceWorker::CacheStorage> caches();
|
||||
|
||||
protected:
|
||||
void initialize(JS::Realm&);
|
||||
void visit_edges(JS::Cell::Visitor&);
|
||||
|
@ -146,6 +149,8 @@ private:
|
|||
|
||||
GC::Ptr<Crypto::Crypto> m_crypto;
|
||||
|
||||
GC::Ptr<ServiceWorker::CacheStorage> m_cache_storage;
|
||||
|
||||
bool m_error_reporting_mode { false };
|
||||
|
||||
WebSockets::WebSocket::List m_registered_web_sockets;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#import <HTML/ImageBitmap.idl>
|
||||
#import <HTML/MessagePort.idl>
|
||||
#import <IndexedDB/IDBFactory.idl>
|
||||
#import <ServiceWorker/CacheStorage.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#timerhandler
|
||||
typedef (DOMString or Function) TimerHandler;
|
||||
|
@ -39,4 +40,7 @@ interface mixin WindowOrWorkerGlobalScope {
|
|||
|
||||
// https://w3c.github.io/webcrypto/#crypto-interface
|
||||
[SameObject] readonly attribute Crypto crypto;
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#cache-storage-interface
|
||||
[SecureContext, SameObject] readonly attribute CacheStorage caches;
|
||||
};
|
||||
|
|
33
Libraries/LibWeb/ServiceWorker/CacheStorage.cpp
Normal file
33
Libraries/LibWeb/ServiceWorker/CacheStorage.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/CacheStoragePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/ServiceWorker/CacheStorage.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
|
||||
namespace Web::ServiceWorker {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(CacheStorage);
|
||||
|
||||
CacheStorage::CacheStorage(JS::Realm& realm)
|
||||
: Bindings::PlatformObject(realm)
|
||||
{
|
||||
}
|
||||
|
||||
void CacheStorage::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(CacheStorage);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#cache-storage-open
|
||||
GC::Ref<WebIDL::Promise> CacheStorage::open(String const&)
|
||||
{
|
||||
return WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "CacheStorage.open() is not yet implemented"_string));
|
||||
}
|
||||
|
||||
}
|
28
Libraries/LibWeb/ServiceWorker/CacheStorage.h
Normal file
28
Libraries/LibWeb/ServiceWorker/CacheStorage.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
|
||||
namespace Web::ServiceWorker {
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#cachestorage-interface
|
||||
class CacheStorage : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(CacheStorage, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(CacheStorage);
|
||||
|
||||
public:
|
||||
GC::Ref<WebIDL::Promise> open(String const& cache_name);
|
||||
|
||||
private:
|
||||
explicit CacheStorage(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
15
Libraries/LibWeb/ServiceWorker/CacheStorage.idl
Normal file
15
Libraries/LibWeb/ServiceWorker/CacheStorage.idl
Normal file
|
@ -0,0 +1,15 @@
|
|||
#import <Fetch/Request.idl>
|
||||
|
||||
// https://w3c.github.io/ServiceWorker/#cachestorage-interface
|
||||
[SecureContext, Exposed=(Window,Worker)]
|
||||
interface CacheStorage {
|
||||
//[NewObject] Promise<(Response or undefined)> match(RequestInfo request, optional MultiCacheQueryOptions options = {});
|
||||
//[NewObject] Promise<boolean> has(DOMString cacheName);
|
||||
[NewObject] Promise<Cache> open(DOMString cacheName);
|
||||
//[NewObject] Promise<boolean> delete(DOMString cacheName);
|
||||
//[NewObject] Promise<sequence<DOMString>> keys();
|
||||
};
|
||||
|
||||
//dictionary MultiCacheQueryOptions : CacheQueryOptions {
|
||||
// DOMString cacheName;
|
||||
//};
|
|
@ -297,6 +297,7 @@ libweb_js_bindings(ResizeObserver/ResizeObserver)
|
|||
libweb_js_bindings(ResizeObserver/ResizeObserverEntry)
|
||||
libweb_js_bindings(ResizeObserver/ResizeObserverSize)
|
||||
libweb_js_bindings(ResourceTiming/PerformanceResourceTiming)
|
||||
libweb_js_bindings(ServiceWorker/CacheStorage)
|
||||
libweb_js_bindings(ServiceWorker/ServiceWorker)
|
||||
libweb_js_bindings(ServiceWorker/ServiceWorkerContainer)
|
||||
libweb_js_bindings(ServiceWorker/ServiceWorkerGlobalScope GLOBAL)
|
||||
|
|
|
@ -44,6 +44,7 @@ static bool is_platform_object(Type const& type)
|
|||
"AudioTrack"sv,
|
||||
"BaseAudioContext"sv,
|
||||
"Blob"sv,
|
||||
"CacheStorage"sv,
|
||||
"CanvasGradient"sv,
|
||||
"CanvasPattern"sv,
|
||||
"CanvasRenderingContext2D"sv,
|
||||
|
|
|
@ -61,6 +61,7 @@ CSSStyleRule
|
|||
CSSStyleSheet
|
||||
CSSSupportsRule
|
||||
CSSTransition
|
||||
CacheStorage
|
||||
CanvasGradient
|
||||
CanvasPattern
|
||||
CanvasRenderingContext2D
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue