LibWeb/ServiceWorker: Implement ServiceWorkerGlobalScope event handlers

This commit is contained in:
Shannon Booth 2025-04-25 17:41:40 +12:00 committed by Andreas Kling
commit 3bb36d9379
Notes: github-actions[bot] 2025-04-25 09:03:54 +00:00
3 changed files with 83 additions and 7 deletions

View file

@ -1,9 +1,10 @@
/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/ServiceWorker/EventNames.h>
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
namespace Web::ServiceWorker {
@ -17,4 +18,64 @@ ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(JS::Realm& realm, GC::Ref<Web
{
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-oninstall
void ServiceWorkerGlobalScope::set_oninstall(GC::Ptr<WebIDL::CallbackType> value)
{
set_event_handler_attribute(EventNames::install, value);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-oninstall
GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::oninstall()
{
return event_handler_attribute(EventNames::install);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onactivate
void ServiceWorkerGlobalScope::set_onactivate(GC::Ptr<WebIDL::CallbackType> value)
{
set_event_handler_attribute(EventNames::activate, value);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onactivate
GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::onactivate()
{
return event_handler_attribute(EventNames::activate);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onfetch
void ServiceWorkerGlobalScope::set_onfetch(GC::Ptr<WebIDL::CallbackType> value)
{
set_event_handler_attribute(EventNames::fetch, value);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onfetch
GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::onfetch()
{
return event_handler_attribute(EventNames::fetch);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onmessage
void ServiceWorkerGlobalScope::set_onmessage(GC::Ptr<WebIDL::CallbackType> value)
{
set_event_handler_attribute(EventNames::message, value);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onmessage
GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::onmessage()
{
return event_handler_attribute(EventNames::message);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onmessageerror
void ServiceWorkerGlobalScope::set_onmessageerror(GC::Ptr<WebIDL::CallbackType> value)
{
set_event_handler_attribute(EventNames::messageerror, value);
}
// https://w3c.github.io/ServiceWorker/#dom-serviceworkerglobalscope-onmessageerror
GC::Ptr<WebIDL::CallbackType> ServiceWorkerGlobalScope::onmessageerror()
{
return event_handler_attribute(EventNames::messageerror);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -18,6 +18,21 @@ class ServiceWorkerGlobalScope : public HTML::WorkerGlobalScope {
public:
virtual ~ServiceWorkerGlobalScope() override;
void set_oninstall(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> oninstall();
void set_onactivate(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onactivate();
void set_onfetch(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onfetch();
void set_onmessage(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onmessage();
void set_onmessageerror(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onmessageerror();
protected:
explicit ServiceWorkerGlobalScope(JS::Realm&, GC::Ref<Web::Page>);
};

View file

@ -9,10 +9,10 @@ interface ServiceWorkerGlobalScope : WorkerGlobalScope {
[FIXME, NewObject] Promise<undefined> skipWaiting();
[FIXME] attribute EventHandler oninstall;
[FIXME] attribute EventHandler onactivate;
[FIXME] attribute EventHandler onfetch;
attribute EventHandler oninstall;
attribute EventHandler onactivate;
attribute EventHandler onfetch;
[FIXME] attribute EventHandler onmessage;
[FIXME] attribute EventHandler onmessageerror;
attribute EventHandler onmessage;
attribute EventHandler onmessageerror;
};