diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index ced2b8a97a9..69c0dedeb27 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, + "ServiceWorkerContainer"sv, "ServiceWorkerRegistration"sv, "SVGTransform"sv, "ShadowRoot"sv, diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index e105504dc11..5a7600be3bd 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 +ServiceWorkerContainer ServiceWorkerRegistration Set ShadowRealm diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 201e430a368..42a67b025b3 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/ServiceWorkerContainer.cpp HTML/ServiceWorkerRegistration.cpp HTML/SessionHistoryEntry.cpp HTML/SessionHistoryTraversalQueue.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 043ec030d55..1728abd62d4 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 ServiceWorkerContainer; class ServiceWorkerRegistration; class SharedResourceRequest; class Storage; diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.cpp b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.cpp new file mode 100644 index 00000000000..e675d4f4f92 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, Tim Ledbetter + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::HTML { + +JS_DEFINE_ALLOCATOR(ServiceWorkerContainer); + +ServiceWorkerContainer::ServiceWorkerContainer(JS::Realm& realm) + : DOM::EventTarget(realm) +{ +} + +void ServiceWorkerContainer::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(ServiceWorkerContainer); +} + +JS::NonnullGCPtr ServiceWorkerContainer::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.h b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.h new file mode 100644 index 00000000000..27a3a602441 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024, Tim Ledbetter + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::HTML { + +class ServiceWorkerContainer : public DOM::EventTarget { + WEB_PLATFORM_OBJECT(ServiceWorkerContainer, DOM::EventTarget); + JS_DECLARE_ALLOCATOR(ServiceWorkerContainer); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm); + + explicit ServiceWorkerContainer(JS::Realm&); + virtual ~ServiceWorkerContainer() override = default; + + virtual void initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.idl b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.idl new file mode 100644 index 00000000000..f3271cd2462 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ServiceWorkerContainer.idl @@ -0,0 +1,29 @@ +#import +#import +#import +#import + +// https://w3c.github.io/ServiceWorker/#serviceworkercontainer-interface +[SecureContext, Exposed=(Window,Worker)] +interface ServiceWorkerContainer : EventTarget { + [FIXME] readonly attribute ServiceWorker? controller; + [FIXME] readonly attribute Promise ready; + + [FIXME, NewObject] Promise register((TrustedScriptURL or USVString) scriptURL, optional RegistrationOptions options = {}); + + [FIXME, NewObject] Promise<(ServiceWorkerRegistration or undefined)> getRegistration(optional USVString clientURL = ""); + [FIXME, NewObject] Promise> getRegistrations(); + + [FIXME] undefined startMessages(); + + // events + [FIXME] attribute EventHandler oncontrollerchange; + [FIXME] attribute EventHandler onmessage; // event.source of message events is ServiceWorker object + [FIXME] attribute EventHandler onmessageerror; +}; + +dictionary RegistrationOptions { + USVString scope; + WorkerType type = "classic"; + ServiceWorkerUpdateViaCache updateViaCache = "imports"; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 04a62c08424..7b0f6c96ffe 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/ServiceWorkerContainer) libweb_js_bindings(HTML/ServiceWorkerRegistration) libweb_js_bindings(HTML/Storage) libweb_js_bindings(HTML/SubmitEvent)