LibWeb: Implement Navigator.serviceWorker

This currently returns a stubbed `ServiceWorkerContainer` object.
This commit is contained in:
Tim Ledbetter 2024-08-22 18:09:35 +01:00 committed by Andreas Kling
parent 53ab6fa403
commit f3405b6eb2
Notes: github-actions[bot] 2024-08-25 10:54:02 +00:00
3 changed files with 18 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/Clipboard/Clipboard.h>
#include <LibWeb/HTML/Navigator.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/ServiceWorkerContainer.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h>
@ -64,6 +65,7 @@ void Navigator::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_plugin_array);
visitor.visit(m_clipboard);
visitor.visit(m_user_activation);
visitor.visit(m_service_worker_container);
}
JS::NonnullGCPtr<MimeTypeArray> Navigator::mime_types()
@ -113,4 +115,11 @@ Optional<FlyString> Navigator::do_not_track() const
return {};
}
JS::NonnullGCPtr<ServiceWorkerContainer> Navigator::service_worker()
{
if (!m_service_worker_container)
m_service_worker_container = heap().allocate<ServiceWorkerContainer>(realm(), realm());
return *m_service_worker_container;
}
}

View file

@ -54,6 +54,8 @@ public:
Optional<FlyString> do_not_track() const;
JS::NonnullGCPtr<ServiceWorkerContainer> service_worker();
static WebIDL::Long max_touch_points();
virtual ~Navigator() override;
@ -77,6 +79,9 @@ private:
// https://html.spec.whatwg.org/multipage/interaction.html#dom-navigator-useractivation
JS::GCPtr<UserActivation> m_user_activation;
// https://w3c.github.io/ServiceWorker/#navigator-serviceworker
JS::GCPtr<ServiceWorkerContainer> m_service_worker_container;
};
}

View file

@ -6,6 +6,7 @@
#import <HTML/NavigatorOnLine.idl>
#import <HTML/NavigatorConcurrentHardware.idl>
#import <HTML/PluginArray.idl>
#import <HTML/ServiceWorkerContainer.idl>
#import <HTML/UserActivation.idl>
#import <StorageAPI/NavigatorStorage.idl>
@ -25,6 +26,9 @@ interface Navigator {
// https://www.w3.org/TR/tracking-dnt/#dom-navigator-donottrack
readonly attribute DOMString? doNotTrack;
// https://w3c.github.io/ServiceWorker/#navigator-serviceworker
[SecureContext, SameObject] readonly attribute ServiceWorkerContainer serviceWorker;
};
// NOTE: As NavigatorContentUtils, NavigatorCookies, NavigatorPlugins, and NavigatorAutomationInformation