diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index f9620ac3253..806a0c567cd 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3764,6 +3764,7 @@ static void generate_using_namespace_definitions(SourceGenerator& generator) using namespace Web::Geometry; using namespace Web::HighResolutionTime; using namespace Web::HTML; + using namespace Web::IndexedDB; using namespace Web::Internals; using namespace Web::IntersectionObserver; using namespace Web::RequestIdleCallback; diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index e1c5c285a52..786f5b75f6c 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -447,6 +447,7 @@ set(SOURCES Infra/ByteSequences.cpp Infra/JSON.cpp Infra/Strings.cpp + IndexedDB/IDBFactory.cpp Internals/Inspector.cpp Internals/InternalAnimationTimeline.cpp Internals/Internals.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 2968a65138b..f07a2cd2858 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -498,6 +498,10 @@ namespace Web::HighResolutionTime { class Performance; } +namespace Web::IndexedDB { +class IDBFactory; +} + namespace Web::Internals { class Inspector; class Internals; diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp index 417366c6832..afad8ed1b4c 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +67,7 @@ void WindowOrWorkerGlobalScopeMixin::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(m_supported_entry_types_array); visitor.visit(m_timers); visitor.visit(m_registered_performance_observer_objects); + visitor.visit(m_indexed_db); for (auto& entry : m_performance_entry_buffer_map) entry.value.visit_edges(visitor); } @@ -689,6 +690,16 @@ JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin return JS::NonnullGCPtr { *m_performance }; } +JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::indexed_db() +{ + auto& vm = this_impl().vm(); + auto& realm = this_impl().realm(); + + if (!m_indexed_db) + m_indexed_db = vm.heap().allocate(realm, realm); + return *m_indexed_db; +} + // https://w3c.github.io/performance-timeline/#dfn-frozen-array-of-supported-entry-types JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::supported_entry_types() const { diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h index e525abe2a72..7b05710cb41 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h @@ -70,6 +70,8 @@ public: JS::NonnullGCPtr supported_entry_types() const; + JS::NonnullGCPtr indexed_db(); + protected: void initialize(JS::Realm&); void visit_edges(JS::Cell::Visitor&); @@ -103,6 +105,8 @@ private: JS::GCPtr m_performance; + JS::GCPtr m_indexed_db; + mutable JS::GCPtr m_supported_entry_types_array; }; diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl index 8f1e018a101..06861329147 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl @@ -3,6 +3,7 @@ #import #import #import +#import // FIXME: Support VoidFunction in the IDL parser callback VoidFunction = undefined (); @@ -43,4 +44,7 @@ interface mixin WindowOrWorkerGlobalScope { // https://w3c.github.io/hr-time/#the-performance-attribute [Replaceable] readonly attribute Performance performance; + + // https://w3c.github.io/IndexedDB/#factory-interface + [SameObject] readonly attribute IDBFactory indexedDB; }; diff --git a/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.cpp b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.cpp new file mode 100644 index 00000000000..72ed33ec6cc --- /dev/null +++ b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::IndexedDB { + +JS_DEFINE_ALLOCATOR(IDBFactory); + +IDBFactory::IDBFactory(JS::Realm& realm) + : Bindings::PlatformObject(realm) +{ +} + +IDBFactory::~IDBFactory() = default; + +void IDBFactory::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBFactory); +} + +} diff --git a/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.h b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.h new file mode 100644 index 00000000000..b2d87a3eb78 --- /dev/null +++ b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::IndexedDB { + +// https://w3c.github.io/IndexedDB/#idbfactory +class IDBFactory : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(IDBFactory, Bindings::PlatformObject); + JS_DECLARE_ALLOCATOR(IDBFactory); + +public: + virtual ~IDBFactory() override; + +protected: + explicit IDBFactory(JS::Realm&); + + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.idl b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.idl new file mode 100644 index 00000000000..5c006e14e58 --- /dev/null +++ b/Userland/Libraries/LibWeb/IndexedDB/IDBFactory.idl @@ -0,0 +1,16 @@ +// https://w3c.github.io/IndexedDB/#idbfactory +[Exposed=(Window,Worker)] +interface IDBFactory { + // FIXME: [NewObject] IDBOpenDBRequest open(DOMString name, + // optional [EnforceRange] unsigned long long version); + // FIXME: [NewObject] IDBOpenDBRequest deleteDatabase(DOMString name); + + // FIXME: Promise> databases(); + + // FIXME: short cmp(any first, any second); +}; + +dictionary IDBDatabaseInfo { + DOMString name; + unsigned long long version; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 88db52aae37..920b815d0ac 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -216,6 +216,7 @@ libweb_js_bindings(HTML/WorkerGlobalScope) libweb_js_bindings(HTML/WorkerLocation) libweb_js_bindings(HTML/WorkerNavigator) libweb_js_bindings(HighResolutionTime/Performance) +libweb_js_bindings(IndexedDB/IDBFactory) libweb_js_bindings(Internals/Inspector) libweb_js_bindings(Internals/InternalAnimationTimeline) libweb_js_bindings(Internals/Internals)