2024-11-30 18:35:45 +13:00
|
|
|
|
/*
|
2025-04-25 17:41:40 +12:00
|
|
|
|
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
|
2024-11-30 18:35:45 +13:00
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-08-04 22:17:20 +03:00
|
|
|
|
#include <LibWeb/CookieStore/CookieStore.h>
|
2025-04-25 17:41:40 +12:00
|
|
|
|
#include <LibWeb/ServiceWorker/EventNames.h>
|
2024-11-30 18:35:45 +13:00
|
|
|
|
#include <LibWeb/ServiceWorker/ServiceWorkerGlobalScope.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Web::ServiceWorker {
|
|
|
|
|
|
|
|
|
|
|
|
GC_DEFINE_ALLOCATOR(ServiceWorkerGlobalScope);
|
|
|
|
|
|
|
|
|
|
|
|
ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() = default;
|
|
|
|
|
|
|
|
|
|
|
|
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(JS::Realm& realm, GC::Ref<Web::Page> page)
|
|
|
|
|
|
: HTML::WorkerGlobalScope(realm, page)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-04 22:17:20 +03:00
|
|
|
|
void ServiceWorkerGlobalScope::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
|
|
|
|
|
|
|
visitor.visit(m_cookie_store);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-25 17:41:40 +12:00
|
|
|
|
// 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-04 22:17:20 +03:00
|
|
|
|
// https://cookiestore.spec.whatwg.org/#ServiceWorkerGlobalScope
|
|
|
|
|
|
GC::Ref<CookieStore::CookieStore> ServiceWorkerGlobalScope::cookie_store()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto& realm = this->realm();
|
|
|
|
|
|
|
|
|
|
|
|
// The cookieStore getter steps are to return this’s associated CookieStore.
|
|
|
|
|
|
if (!m_cookie_store)
|
|
|
|
|
|
m_cookie_store = realm.create<CookieStore::CookieStore>(realm);
|
|
|
|
|
|
return *m_cookie_store;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-30 18:35:45 +13:00
|
|
|
|
}
|