mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 06:09:08 +00:00
LibWeb/ServiceWorker: Implement ServiceWorkerGlobalScope event handlers
This commit is contained in:
parent
50b7e0807d
commit
3bb36d9379
Notes:
github-actions[bot]
2025-04-25 09:03:54 +00:00
Author: https://github.com/shannonbooth
Commit: 3bb36d9379
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4463
3 changed files with 83 additions and 7 deletions
|
@ -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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/ServiceWorker/EventNames.h>
|
||||||
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
|
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
|
||||||
|
|
||||||
namespace Web::ServiceWorker {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,21 @@ class ServiceWorkerGlobalScope : public HTML::WorkerGlobalScope {
|
||||||
public:
|
public:
|
||||||
virtual ~ServiceWorkerGlobalScope() override;
|
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:
|
protected:
|
||||||
explicit ServiceWorkerGlobalScope(JS::Realm&, GC::Ref<Web::Page>);
|
explicit ServiceWorkerGlobalScope(JS::Realm&, GC::Ref<Web::Page>);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,10 +9,10 @@ interface ServiceWorkerGlobalScope : WorkerGlobalScope {
|
||||||
|
|
||||||
[FIXME, NewObject] Promise<undefined> skipWaiting();
|
[FIXME, NewObject] Promise<undefined> skipWaiting();
|
||||||
|
|
||||||
[FIXME] attribute EventHandler oninstall;
|
attribute EventHandler oninstall;
|
||||||
[FIXME] attribute EventHandler onactivate;
|
attribute EventHandler onactivate;
|
||||||
[FIXME] attribute EventHandler onfetch;
|
attribute EventHandler onfetch;
|
||||||
|
|
||||||
[FIXME] attribute EventHandler onmessage;
|
attribute EventHandler onmessage;
|
||||||
[FIXME] attribute EventHandler onmessageerror;
|
attribute EventHandler onmessageerror;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue