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.
53 lines
1.7 KiB
C++
53 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2026, Niccolo Antonelli-Dziri <niccolo.antonelli-dziri@protonmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/Bindings/Permissions.h>
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/DOM/EventTarget.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/PermissionsAPI/Permissions.h>
|
|
|
|
namespace Web::PermissionsAPI {
|
|
|
|
class WEB_API PermissionStatus : public DOM::EventTarget {
|
|
WEB_PLATFORM_OBJECT(PermissionStatus, DOM::EventTarget);
|
|
GC_DECLARE_ALLOCATOR(PermissionStatus);
|
|
|
|
public:
|
|
static GC::Ref<PermissionStatus> create(JS::Realm&, Bindings::PermissionDescriptor);
|
|
|
|
// https://w3c.github.io/permissions/#dom-permissionstatus-state
|
|
Bindings::PermissionState state() const { return m_state; }
|
|
void set_state(Bindings::PermissionState state) { m_state = state; }
|
|
|
|
// https://w3c.github.io/permissions/#dom-permissionstatus-name
|
|
String const& name() const { return m_name; }
|
|
|
|
Bindings::PermissionDescriptor const& query() const { return m_query; }
|
|
|
|
// https://w3c.github.io/permissions/#dfn-permissionstatus-update-steps
|
|
void update_steps();
|
|
|
|
// https://w3c.github.io/permissions/#dom-permissionstatus-onchange
|
|
void set_onchange(GC::Ptr<WebIDL::CallbackType> event_handler);
|
|
GC::Ptr<WebIDL::CallbackType> onchange();
|
|
|
|
private:
|
|
PermissionStatus(JS::Realm&, String const&, Bindings::PermissionDescriptor const&);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
String m_name;
|
|
Bindings::PermissionState m_state { Bindings::PermissionState::Prompt };
|
|
|
|
// https://w3c.github.io/permissions/#dfn-query
|
|
Bindings::PermissionDescriptor m_query;
|
|
};
|
|
|
|
}
|