From 0c0a4a6042f7d25186c65ca60aa04d066dc51e97 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 22 Aug 2024 22:59:01 +0100 Subject: [PATCH] LibWeb: Stub the `ServiceWorkerRegistration` interface --- .../BindingsGenerator/IDLGenerators.cpp | 1 + .../Text/expected/all-window-properties.txt | 1 + Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/Forward.h | 1 + .../LibWeb/HTML/ServiceWorkerRegistration.cpp | 31 +++++++++++++++++++ .../LibWeb/HTML/ServiceWorkerRegistration.h | 26 ++++++++++++++++ .../LibWeb/HTML/ServiceWorkerRegistration.idl | 26 ++++++++++++++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 8 files changed, 88 insertions(+) create mode 100644 Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.cpp create mode 100644 Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.h create mode 100644 Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.idl diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index a2e8e85f236..ced2b8a97a9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -85,6 +85,7 @@ static bool is_platform_object(Type const& type) "ReadableStream"sv, "Request"sv, "Selection"sv, + "ServiceWorkerRegistration"sv, "SVGTransform"sv, "ShadowRoot"sv, "Table"sv, diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 21c443a3b1d..e105504dc11 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -317,6 +317,7 @@ SVGUseElement Screen ScreenOrientation Selection +ServiceWorkerRegistration Set ShadowRealm ShadowRoot diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 86801ec5641..201e430a368 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -442,6 +442,7 @@ set(SOURCES HTML/Scripting/SerializedEnvironmentSettingsObject.cpp HTML/SelectedFile.cpp HTML/SelectItem.cpp + HTML/ServiceWorkerRegistration.cpp HTML/SessionHistoryEntry.cpp HTML/SessionHistoryTraversalQueue.cpp HTML/SharedResourceRequest.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index a17bf27fe86..043ec030d55 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -485,6 +485,7 @@ class Plugin; class PluginArray; class PromiseRejectionEvent; class SelectedFile; +class ServiceWorkerRegistration; class SharedResourceRequest; class Storage; class SubmitEvent; diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.cpp b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.cpp new file mode 100644 index 00000000000..d893db60612 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024, Tim Ledbetter + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::HTML { + +JS_DEFINE_ALLOCATOR(ServiceWorkerRegistration); + +ServiceWorkerRegistration::ServiceWorkerRegistration(JS::Realm& realm) + : DOM::EventTarget(realm) +{ +} + +void ServiceWorkerRegistration::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(ServiceWorkerRegistration); +} + +JS::NonnullGCPtr ServiceWorkerRegistration::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} +} diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.h b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.h new file mode 100644 index 00000000000..fb21d896529 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024, Tim Ledbetter + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::HTML { + +class ServiceWorkerRegistration : public DOM::EventTarget { + WEB_PLATFORM_OBJECT(ServiceWorkerRegistration, DOM::EventTarget); + JS_DECLARE_ALLOCATOR(ServiceWorkerRegistration); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm); + + explicit ServiceWorkerRegistration(JS::Realm&); + virtual ~ServiceWorkerRegistration() override = default; + + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.idl b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.idl new file mode 100644 index 00000000000..59c3e2e756e --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerRegistration.idl @@ -0,0 +1,26 @@ +#import +#import + +// https://w3c.github.io/ServiceWorker/#serviceworkerregistration-interface +[SecureContext, Exposed=(Window,Worker)] +interface ServiceWorkerRegistration : EventTarget { + [FIXME] readonly attribute ServiceWorker? installing; + [FIXME] readonly attribute ServiceWorker? waiting; + [FIXME] readonly attribute ServiceWorker? active; + [FIXME, SameObject] readonly attribute NavigationPreloadManager navigationPreload; + + [FIXME] readonly attribute USVString scope; + [FIXME] readonly attribute ServiceWorkerUpdateViaCache updateViaCache; + + [FIXME, NewObject] Promise update(); + [FIXME, NewObject] Promise unregister(); + + // event + [FIXME] attribute EventHandler onupdatefound; +}; + +enum ServiceWorkerUpdateViaCache { + "imports", + "all", + "none" +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 14a7d4ac587..04a62c08424 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -213,6 +213,7 @@ libweb_js_bindings(HTML/Plugin) libweb_js_bindings(HTML/PluginArray) libweb_js_bindings(HTML/PopStateEvent) libweb_js_bindings(HTML/PromiseRejectionEvent) +libweb_js_bindings(HTML/ServiceWorkerRegistration) libweb_js_bindings(HTML/Storage) libweb_js_bindings(HTML/SubmitEvent) libweb_js_bindings(HTML/TextMetrics)