ladybird/Libraries/LibWeb/HTML/WorkerNavigator.cpp
Niccolo Antonelli-Dziri 9f4a712e57 LibWeb: Add basics for the Permissions API
This adds the basic infrastructure for the Permissions API, including
the `Permissions` and `PermissionStatus` interfaces. The API is exposed
via `navigator.permissions` on both `Window` and `WorkerGlobalScope`.

- `is_permission_supported` is hardcoded to return false.
- The `query()` method checks for a secure context but rejects all
queries since no powerful features are supported yet.

The permission store and permission key related methods and algorithms.
Ability for the user agent to store the permissions entries.

Passes a few more subtests in `permissions/`.

https://wpt.live/permissions/idlharness.any.html

https://wpt.live/permissions/idlharness.any.worker.html

https://wpt.live/permissions/edge-cases.https.html

This one behaves differently because now the `query` property is
defined. And the last subtest passes for the wrong reason.
"Querying "fullscreen" permission with "allowWithoutGesture" false
is unsupported"
but in fact everything is currently unsupported.

https://wpt.live/fullscreen/api/permission.tentative.https.html

permission is marked as experimental in Navigator and WorkerNavigator,
so tests that now pass actually don't because the tests don't have
access to the interfaces.
2026-05-11 21:01:01 +02:00

74 lines
2 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGC/Heap.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/WorkerNavigator.h>
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/HTML/WorkerNavigator.h>
#include <LibWeb/PermissionsAPI/Permissions.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(WorkerNavigator);
GC::Ref<WorkerNavigator> WorkerNavigator::create(WorkerGlobalScope& global_scope)
{
return global_scope.realm().create<WorkerNavigator>(global_scope);
}
WorkerNavigator::WorkerNavigator(WorkerGlobalScope& global_scope)
: PlatformObject(global_scope.realm())
{
}
WorkerNavigator::~WorkerNavigator() = default;
void WorkerNavigator::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(WorkerNavigator);
Base::initialize(realm);
}
void WorkerNavigator::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_media_capabilities);
visitor.visit(m_serial);
visitor.visit(m_service_worker_container);
visitor.visit(m_permissions);
}
GC::Ref<MediaCapabilitiesAPI::MediaCapabilities> WorkerNavigator::media_capabilities()
{
if (!m_media_capabilities)
m_media_capabilities = realm().create<MediaCapabilitiesAPI::MediaCapabilities>(realm());
return *m_media_capabilities;
}
GC::Ref<Serial::Serial> WorkerNavigator::serial()
{
if (!m_serial)
m_serial = realm().create<Serial::Serial>(realm());
return *m_serial;
}
GC::Ref<ServiceWorker::ServiceWorkerContainer> WorkerNavigator::service_worker()
{
if (!m_service_worker_container)
m_service_worker_container = realm().create<ServiceWorker::ServiceWorkerContainer>(realm());
return *m_service_worker_container;
}
GC::Ref<PermissionsAPI::Permissions> WorkerNavigator::permissions()
{
if (!m_permissions)
m_permissions = realm().create<PermissionsAPI::Permissions>(realm());
return *m_permissions;
}
}