Skip to content

Truly independent web browser

LibWeb: Name permissions by PermissionName in the permission algorithms

Shannon Booth04d9f8d44c1d
diff --git a/Libraries/LibWeb/Geolocation/Geolocation.cpp b/Libraries/LibWeb/Geolocation/Geolocation.cpp
index dcd90b42231..cbe461664bf 100644
--- a/Libraries/LibWeb/Geolocation/Geolocation.cpp
+++ b/Libraries/LibWeb/Geolocation/Geolocation.cpp
@@ -218,7 +218,7 @@ void Geolocation::request_a_position(GC::Ref<WebIDL::CallbackType> success_callb
// AD-HOC: This is implemented by run_in_parallel_when_document_is_visible().
// 6. Let descriptor be a new PermissionDescriptor whose name is "geolocation".
- auto descriptor = PermissionsAPI::PermissionDescriptor { "geolocation"_utf16 };
+ auto descriptor = Web::Permissions::PermissionName::Geolocation;
// 7. In parallel:
// NB: The round trip to the UI process that asks the user for permission stands in for the parallel steps: the
@@ -304,7 +304,7 @@ void Geolocation::acquire_a_position(GC::Ref<WebIDL::CallbackType> success_callb
{
// 1. Let permission be get the current permission state of "geolocation".
// NB: This can run outside any script (when the user's answer arrives, e.g.), so the settings object is passed.
- auto permission = Web::PermissionsAPI::permission_state(Bindings::PermissionDescriptor { "geolocation"_utf16 }, window().associated_document().relevant_settings_object());
+ auto permission = Web::PermissionsAPI::permission_state(Web::Permissions::PermissionName::Geolocation, window().associated_document().relevant_settings_object());
// 2. If permission is "denied":
if (permission == Bindings::PermissionState::Denied) {
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 5e3c091680e..24f40f7c033 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2546,12 +2546,16 @@ void Internals::set_geolocation_emulated_position_unavailable()
page().set_emulated_position_data(Geolocation::GeolocationPositionError::ErrorCode::PositionUnavailable);
}
-GC::Ref<WebIDL::Promise> Internals::request_permission(Utf16String const& name)
+WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> Internals::request_permission(Utf16String const& name)
{
+ auto permission_name = PermissionsAPI::permission_name_from(name);
+ if (!permission_name.has_value())
+ return WebIDL::SimpleException { .type = WebIDL::SimpleExceptionType::TypeError, .message = Utf16String::formatted("Unknown permission: '{}'", name) };
+
auto& realm = window().principal_realm();
auto promise = WebIDL::create_promise_for(window());
auto& settings = window().associated_document().relevant_settings_object();
- PermissionsAPI::request_permission_with_user_prompt({ name }, settings, GC::create_function(realm.heap(), GC::captures(realm, promise), [](auto& realm, auto& promise, PermissionsAPI::PermissionState state) {
+ PermissionsAPI::request_permission_with_user_prompt(*permission_name, settings, GC::create_function(realm.heap(), GC::captures(realm, promise), [](auto& realm, auto& promise, PermissionsAPI::PermissionState state) {
HTML::TemporaryExecutionContext execution_context { realm };
WebIDL::resolve_promise(realm, promise, JS::PrimitiveString::create(realm.vm(), Bindings::idl_enum_to_string(state)));
}));
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 2136c034425..99ef59d757e 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -283,7 +283,7 @@ public:
void set_geolocation_emulated_position(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitude_accuracy, Optional<double> heading, Optional<double> speed);
void set_geolocation_emulated_position_unavailable();
- GC::Ref<WebIDL::Promise> request_permission(Utf16String const& name);
+ WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> request_permission(Utf16String const& name);
GC::Ref<WebIDL::Promise> set_permission(Utf16String const& name, Utf16String const& state);
void set_next_permission_prompt_outcome(Utf16String const& name, Utf16String const& outcome, bool held);
void set_system_microphone_authorization(Utf16String const& authorization, Utf16String const& answer, bool held);
diff --git a/Libraries/LibWeb/MediaCapture/MediaDevices.cpp b/Libraries/LibWeb/MediaCapture/MediaDevices.cpp
index 038d5b367fa..996ada21cb5 100644
--- a/Libraries/LibWeb/MediaCapture/MediaDevices.cpp
+++ b/Libraries/LibWeb/MediaCapture/MediaDevices.cpp
@@ -474,7 +474,7 @@ void MediaDevices::queue_get_user_media_task(GC::Ref<WebIDL::Promise> promise, O
}
}
- PermissionsAPI::PermissionDescriptor microphone_permission { "microphone"_utf16 };
+ auto microphone_permission = Web::Permissions::PermissionName::Microphone;
// 11.3.6 Read the current permission state for all candidate devices in candidateSet that are not attached to a live MediaStreamTrack in the current Document. Remove from candidateSet any candidate whose device's permission state is "denied".
if (PermissionsAPI::permission_state(microphone_permission) == PermissionsAPI::PermissionState::Denied) {
@@ -518,7 +518,7 @@ void MediaDevices::queue_get_user_media_task(GC::Ref<WebIDL::Promise> promise, O
// AD-HOC: The user may have taken the permission away while the device list was fetched, and no track
// is created for a document that may no longer capture.
auto& document = media_devices->m_window->associated_document();
- if (!document.is_fully_active() || PermissionsAPI::permission_state(PermissionsAPI::PermissionDescriptor { "microphone"_utf16 }, HTML::relevant_settings_object(*media_devices->m_window)) != PermissionsAPI::PermissionState::Granted) {
+ if (!document.is_fully_active() || PermissionsAPI::permission_state(Web::Permissions::PermissionName::Microphone, HTML::relevant_settings_object(*media_devices->m_window)) != PermissionsAPI::PermissionState::Granted) {
WebIDL::reject_promise(*promise, WebIDL::NotAllowedError::create("Permission denied"_utf16));
return;
}
@@ -602,7 +602,7 @@ void MediaDevices::queue_get_user_media_task(GC::Ref<WebIDL::Promise> promise, O
// AD-HOC: The user may have taken the permission away while the device opened, which ended no track of
// this request since none is tied to mediaDevices yet. Another page can keep the process
// allowed to capture, so the device opening says nothing of this document.
- if (PermissionsAPI::permission_state(PermissionsAPI::PermissionDescriptor { "microphone"_utf16 }, HTML::relevant_settings_object(*media_devices->m_window)) != PermissionsAPI::PermissionState::Granted) {
+ if (PermissionsAPI::permission_state(Web::Permissions::PermissionName::Microphone, HTML::relevant_settings_object(*media_devices->m_window)) != PermissionsAPI::PermissionState::Granted) {
track->stop();
WebIDL::reject_promise(*promise, WebIDL::NotAllowedError::create("Permission denied"_utf16));
return;
@@ -897,7 +897,7 @@ void MediaDevices::end_tracks_without_permission()
// NB: A track's source is the microphone, the one device Ladybird captures from, so every live track ends once the
// document may no longer use it.
auto& settings = HTML::relevant_settings_object(*m_window);
- if (PermissionsAPI::permission_state(PermissionsAPI::PermissionDescriptor { "microphone"_utf16 }, settings) == PermissionsAPI::PermissionState::Granted)
+ if (PermissionsAPI::permission_state(Web::Permissions::PermissionName::Microphone, settings) == PermissionsAPI::PermissionState::Granted)
return;
GC::RootVector<GC::Ref<MediaStreamTrack>> tracks_to_end;
@@ -916,7 +916,7 @@ void MediaDevices::end_tracks_without_permission()
void MediaDevices::track_was_cloned(Badge<MediaStreamTrack>, MediaStreamTrack& clone)
{
auto& settings = HTML::relevant_settings_object(*m_window);
- if (PermissionsAPI::permission_state(PermissionsAPI::PermissionDescriptor { "microphone"_utf16 }, settings) != PermissionsAPI::PermissionState::Granted) {
+ if (PermissionsAPI::permission_state(Web::Permissions::PermissionName::Microphone, settings) != PermissionsAPI::PermissionState::Granted) {
GC::RootVector<GC::Ref<MediaStreamTrack>> tracks_to_end;
tracks_to_end.append(clone);
end_tracks(move(tracks_to_end));
diff --git a/Libraries/LibWeb/NotificationsAPI/Notification.cpp b/Libraries/LibWeb/NotificationsAPI/Notification.cpp
index 9d3fc9f9a6f..a7d8f70b39b 100644
--- a/Libraries/LibWeb/NotificationsAPI/Notification.cpp
+++ b/Libraries/LibWeb/NotificationsAPI/Notification.cpp
@@ -719,7 +719,7 @@ GC::Ref<WebIDL::Promise> Notification::request_permission(GC::Ptr<WebIDL::Callba
return refuse("Notification permission can only be requested while handling a user gesture."sv);
window.consume_user_activation();
}
- PermissionsAPI::request_permission_with_user_prompt({ "notifications"_utf16 }, settings, settle);
+ PermissionsAPI::request_permission_with_user_prompt(Web::Permissions::PermissionName::Notifications, settings, settle);
// 4. Return promise.
return promise;
diff --git a/Libraries/LibWeb/NotificationsAPI/NotificationPermission.cpp b/Libraries/LibWeb/NotificationsAPI/NotificationPermission.cpp
index ebe5b7aa98a..cd40f2ed2c9 100644
--- a/Libraries/LibWeb/NotificationsAPI/NotificationPermission.cpp
+++ b/Libraries/LibWeb/NotificationsAPI/NotificationPermission.cpp
@@ -15,7 +15,7 @@ PermissionsAPI::PermissionState get_the_notifications_permission_state(HTML::Env
// To get the notifications permission state, run these steps:
// 1. Let permissionState be the result of getting the current permission state with "notifications".
- return PermissionsAPI::permission_state({ "notifications"_utf16 }, settings);
+ return PermissionsAPI::permission_state(Web::Permissions::PermissionName::Notifications, settings);
// NB: Steps 2 and 3, which turn "prompt" into "default", belong to the permission getter: Every other caller wants
// the raw state.
diff --git a/Libraries/LibWeb/PermissionsAPI/PermissionStatus.cpp b/Libraries/LibWeb/PermissionsAPI/PermissionStatus.cpp
index 8d14eaa7230..0974bf08bd2 100644
--- a/Libraries/LibWeb/PermissionsAPI/PermissionStatus.cpp
+++ b/Libraries/LibWeb/PermissionsAPI/PermissionStatus.cpp
@@ -24,9 +24,10 @@ namespace Web::PermissionsAPI {
GC_DEFINE_ALLOCATOR(PermissionStatus);
PermissionStatus::PermissionStatus(GC::Ref<DOM::EventTarget> relevant_global_object, Utf16String const& name,
- PermissionDescriptor query)
+ Web::Permissions::PermissionName permission_name, PermissionDescriptor query)
: DOM::EventTarget()
, m_name(name)
+ , m_permission_name(permission_name)
, m_query(move(query))
, m_global_object(relevant_global_object)
{
@@ -44,14 +45,15 @@ GC::Ref<PermissionStatus> PermissionStatus::create(GC::Ref<DOM::EventTarget> rel
auto name = permission_desc.name;
// 2. Assert: The feature identified by name is supported by the user agent.
- VERIFY(is_permission_supported(name));
+ auto permission_name = permission_name_from(name);
+ VERIFY(permission_name.has_value());
// 3. Let status be a new instance of the permission result type identified by name:
// FIXME: A permission result type is a PermissionStatus or one of its subtypes.
// If unspecified, this defaults to PermissionStatus. No subtypes exist yet in Ladybird.
// 1. Initialize status's [[query]] internal slot to permissionDesc.
// 2. Initialize status's name to name.
- auto status = GC::Heap::the().allocate<PermissionStatus>(relevant_global_object, name, move(permission_desc));
+ auto status = GC::Heap::the().allocate<PermissionStatus>(relevant_global_object, name, *permission_name, move(permission_desc));
// NB: The store tells every status when a permission changes, and the global keeps a status alive while it has a
// change listener.
@@ -76,14 +78,14 @@ void PermissionStatus::update_from_store()
if (auto* window = HTML::window_from_global_object(global); window && !window->associated_document().is_fully_active())
return;
- auto state = permission_state(m_query, HTML::relevant_settings_object(global));
+ auto state = permission_state(m_permission_name, HTML::relevant_settings_object(global));
if (state == m_state)
return;
// NB: The state is read again when the task runs, so a status that heard of several changes ends with the last.
HTML::queue_global_task(HTML::Task::Source::Permissions, global, GC::create_function(heap(), GC::captures(*this), [](auto& self) {
auto& global = self.relevant_global_object();
- auto state = permission_state(self.m_query, HTML::relevant_settings_object(global));
+ auto state = permission_state(self.m_permission_name, HTML::relevant_settings_object(global));
if (state == self.m_state)
return;
self.m_state = state;
diff --git a/Libraries/LibWeb/PermissionsAPI/PermissionStatus.h b/Libraries/LibWeb/PermissionsAPI/PermissionStatus.h
index 6f4553bc744..0e5b7854c75 100644
--- a/Libraries/LibWeb/PermissionsAPI/PermissionStatus.h
+++ b/Libraries/LibWeb/PermissionsAPI/PermissionStatus.h
@@ -37,11 +37,12 @@ public:
private:
PermissionStatus(GC::Ref<DOM::EventTarget> relevant_global_object, Utf16String const&,
- PermissionDescriptor);
+ Web::Permissions::PermissionName, PermissionDescriptor);
JS::Object& relevant_global_object() const;
virtual void visit_edges(Cell::Visitor&) override;
Utf16String m_name;
+ Web::Permissions::PermissionName m_permission_name;
PermissionState m_state { PermissionState::Prompt };
// https://w3c.github.io/permissions/#dfn-query
diff --git a/Libraries/LibWeb/PermissionsAPI/PermissionStore.cpp b/Libraries/LibWeb/PermissionsAPI/PermissionStore.cpp
index c76063e0983..f14b1a9a8ed 100644
--- a/Libraries/LibWeb/PermissionsAPI/PermissionStore.cpp
+++ b/Libraries/LibWeb/PermissionsAPI/PermissionStore.cpp
@@ -18,7 +18,7 @@
namespace Web::PermissionsAPI {
-bool permission_key_is_equal_to(PermissionDescriptor const&, URL::Origin const& key1, URL::Origin const& key2)
+bool permission_key_is_equal_to(Web::Permissions::PermissionName, URL::Origin const& key1, URL::Origin const& key2)
{
// FIXME: 1. If key1 is not of descriptor's permission key type or key2 is not of descriptor's permission key type, return false.
@@ -73,13 +73,13 @@ void PermissionStore::forget_statuses_of_this_agent()
agent_permission_statuses() = {};
}
-Optional<PermissionStoreEntry> PermissionStore::get_permission_store_entry(PermissionDescriptor const& descriptor, URL::Origin const& key)
+Optional<PermissionStoreEntry> PermissionStore::get_permission_store_entry(Web::Permissions::PermissionName name, URL::Origin const& key)
{
MutexLocker locker(m_mutex);
// 1. If the user agent's permission store contains an entry whose descriptor is descriptor, and whose key is equal to key given descriptor, return that entry.
for (auto const& entry : m_entries) {
- if (entry.descriptor.name == descriptor.name && permission_key_is_equal_to(descriptor, entry.permission_key, key))
+ if (entry.name == name && permission_key_is_equal_to(name, entry.permission_key, key))
return entry;
}
@@ -87,16 +87,16 @@ Optional<PermissionStoreEntry> PermissionStore::get_permission_store_entry(Permi
return {};
}
-void PermissionStore::set_permission_store_entry(PermissionDescriptor const& descriptor, URL::Origin const& key, PermissionState state)
+void PermissionStore::set_permission_store_entry(Web::Permissions::PermissionName name, URL::Origin const& key, PermissionState state)
{
MutexLocker locker(m_mutex);
// 1. Let newEntry be a new permission store entry whose descriptor is descriptor, and whose key is key, and whose state is state.
- PermissionStoreEntry new_entry { descriptor, key, state };
+ PermissionStoreEntry new_entry { name, key, state };
// 2. If the user agent's permission store contains an entry whose descriptor is descriptor, and whose key is equal to key given descriptor, replace that entry with newEntry and abort these steps.
for (auto& entry : m_entries) {
- if (entry.descriptor.name == descriptor.name && permission_key_is_equal_to(descriptor, entry.permission_key, key)) {
+ if (entry.name == name && permission_key_is_equal_to(name, entry.permission_key, key)) {
entry = new_entry;
return;
}
diff --git a/Libraries/LibWeb/PermissionsAPI/PermissionStore.h b/Libraries/LibWeb/PermissionsAPI/PermissionStore.h
index 6733ed6bf78..8212b118580 100644
--- a/Libraries/LibWeb/PermissionsAPI/PermissionStore.h
+++ b/Libraries/LibWeb/PermissionsAPI/PermissionStore.h
@@ -24,7 +24,7 @@ class PermissionStatus;
// https://w3c.github.io/permissions/#dfn-permission-store-entry
struct PermissionStoreEntry {
- PermissionDescriptor descriptor;
+ Web::Permissions::PermissionName name;
URL::Origin permission_key; // https://w3c.github.io/permissions/#dfn-permission-key
PermissionState state;
};
@@ -39,10 +39,10 @@ public:
static PermissionStore& the();
// https://w3c.github.io/permissions/#dfn-get-a-permission-store-entry
- Optional<PermissionStoreEntry> get_permission_store_entry(PermissionDescriptor const& descriptor, URL::Origin const& key);
+ Optional<PermissionStoreEntry> get_permission_store_entry(Web::Permissions::PermissionName, URL::Origin const& key);
// https://w3c.github.io/permissions/#dfn-set-a-permission-store-entry
- void set_permission_store_entry(PermissionDescriptor const& descriptor, URL::Origin const& key, PermissionState state);
+ void set_permission_store_entry(Web::Permissions::PermissionName, URL::Origin const& key, PermissionState state);
// The UI process owns the user agent's permission decisions. It tells this process the states of the sites it
// shows: the first time the process reads one, through the page reading it, and again whenever one changes. Of
@@ -84,7 +84,7 @@ private:
Web::Permissions::EffectiveState m_notifications_default { Web::Permissions::EffectiveState::Prompt };
};
-bool permission_key_is_equal_to(PermissionDescriptor const& descriptor, URL::Origin const& key1, URL::Origin const& key2);
+bool permission_key_is_equal_to(Web::Permissions::PermissionName, URL::Origin const& key1, URL::Origin const& key2);
bool permission_key_comparison_algorithm(URL::Origin const& key1, URL::Origin const& key2);
diff --git a/Libraries/LibWeb/PermissionsAPI/Permissions.cpp b/Libraries/LibWeb/PermissionsAPI/Permissions.cpp
index 6cc25db4970..f698e91e12d 100644
--- a/Libraries/LibWeb/PermissionsAPI/Permissions.cpp
+++ b/Libraries/LibWeb/PermissionsAPI/Permissions.cpp
@@ -24,7 +24,7 @@
namespace Web::PermissionsAPI {
-static Optional<Web::Permissions::PermissionName> permission_name_from(Utf16View name)
+Optional<Web::Permissions::PermissionName> permission_name_from(Utf16View name)
{
if (name == "geolocation"_utf16)
return Web::Permissions::PermissionName::Geolocation;
@@ -35,11 +35,6 @@ static Optional<Web::Permissions::PermissionName> permission_name_from(Utf16View
return {};
}
-bool is_permission_supported(Utf16View name)
-{
- return permission_name_from(name).has_value();
-}
-
static Optional<PermissionsPolicy::PolicyControlledFeature> policy_controlled_feature_for(Web::Permissions::PermissionName name)
{
switch (name) {
@@ -68,7 +63,7 @@ static PermissionState permission_state_from(Web::Permissions::EffectiveState st
}
// Steps 6 and 7 of https://w3c.github.io/permissions/#dfn-request-permission-to-use
-static void store_permission_decision(PermissionDescriptor const& descriptor, HTML::EnvironmentSettingsObject& settings, PermissionState current_state)
+static void store_permission_decision(Web::Permissions::PermissionName name, HTML::EnvironmentSettingsObject& settings, PermissionState current_state)
{
// 6. Let key be the result of generating a permission key for descriptor with settings's top-level origin and settings's origin.
VERIFY(settings.top_level_origin.has_value());
@@ -76,19 +71,19 @@ static void store_permission_decision(PermissionDescriptor const& descriptor, HT
// AD-HOC: Our permission state is backed by PermissionStore, so update it before returning to make the new current
// state observable to callers that continue synchronously.
- PermissionStore::the().set_permission_store_entry(descriptor, key, current_state);
+ PermissionStore::the().set_permission_store_entry(name, key, current_state);
// 7. Queue a task on the current settings object's responsible event loop to set a permission store entry with descriptor, key, and current state.
- HTML::queue_global_task(HTML::Task::Source::Permissions, settings.global_object(), GC::create_function(GC::Heap::the(), GC::captures(descriptor, key, current_state), [](auto& descriptor, auto& key, auto& current_state) {
- PermissionStore::the().set_permission_store_entry(descriptor, key, current_state);
+ HTML::queue_global_task(HTML::Task::Source::Permissions, settings.global_object(), GC::create_function(GC::Heap::the(), GC::captures(name, key, current_state), [](auto& name, auto& key, auto& current_state) {
+ PermissionStore::the().set_permission_store_entry(name, key, current_state);
}));
}
// https://w3c.github.io/permissions/#dfn-request-permission-to-use
-void request_permission_with_user_prompt(PermissionDescriptor const& descriptor, HTML::EnvironmentSettingsObject& settings, PermissionDecisionCallback on_decided)
+void request_permission_with_user_prompt(Web::Permissions::PermissionName name, HTML::EnvironmentSettingsObject& settings, PermissionDecisionCallback on_decided)
{
// 1. Let current state be the descriptor's permission state.
- auto current_state = permission_state(descriptor, settings);
+ auto current_state = permission_state(name, settings);
// 2. If current state is not "prompt", return current state and abort these steps.
if (current_state != PermissionState::Prompt) {
@@ -104,7 +99,7 @@ void request_permission_with_user_prompt(PermissionDescriptor const& descriptor,
return;
}
- auto settle = GC::create_function(GC::Heap::the(), GC::captures(descriptor, GC::Ref(settings), on_decided), [](auto& descriptor, auto& settings, auto& on_decided, Web::Permissions::EffectiveState answer) {
+ auto settle = GC::create_function(GC::Heap::the(), GC::captures(name, GC::Ref(settings), on_decided), [](auto& name, auto& settings, auto& on_decided, Web::Permissions::EffectiveState answer) {
// 4. If the user gives express permission to use the powerful feature, set current state to "granted"; otherwise to "denied".
// The user's interaction may provide new information about the user's intent for the origin.
// AD-HOC: A prompt the user dismisses or ignores leaves the permission at "prompt", rather than storing "denied";
@@ -119,17 +114,17 @@ void request_permission_with_user_prompt(PermissionDescriptor const& descriptor,
// It can't key an answer for an opaque top-level origin (a file: page's), so that answer is kept here, for
// as long as the origin lives.
if (settings->top_level_origin->is_opaque() && answer != Web::Permissions::EffectiveState::Prompt)
- store_permission_decision(descriptor, settings, current_state);
+ store_permission_decision(name, settings, current_state);
// 8. Return current state.
on_decided->function()(current_state);
});
- window->page().request_permission(window->associated_document().id(), descriptor.name, settle);
+ window->page().request_permission(window->associated_document().id(), Utf16String::from_utf8(Web::Permissions::to_string(name)), settle);
}
// https://w3c.github.io/permissions/#dfn-permission-state
-PermissionState permission_state(PermissionDescriptor const& descriptor, Optional<HTML::EnvironmentSettingsObject&> settings)
+PermissionState permission_state(Web::Permissions::PermissionName name, Optional<HTML::EnvironmentSettingsObject&> settings)
{
// 1. If settings wasn't passed, set it to the current settings object.
auto& settings_object = settings.has_value() ? settings.value() : HTML::current_settings_object();
@@ -139,10 +134,10 @@ PermissionState permission_state(PermissionDescriptor const& descriptor, Optiona
return PermissionState::Denied;
// 3. Let feature be descriptor's name.
- auto feature = permission_name_from(descriptor.name);
+ auto feature = name;
// 4. If there exists a policy-controlled feature for feature and settings' relevant global object has an associated Document run the following step:
- auto policy_controlled_feature = feature.has_value() ? policy_controlled_feature_for(*feature) : Optional<PermissionsPolicy::PolicyControlledFeature> {};
+ auto policy_controlled_feature = policy_controlled_feature_for(feature);
if (auto* window = HTML::window_from_global_object(settings_object.global_object()); policy_controlled_feature.has_value() && window) {
// 1. Let document be settings' relevant global object's associated Document.
auto& document = window->associated_document();
@@ -157,17 +152,15 @@ PermissionState permission_state(PermissionDescriptor const& descriptor, Optiona
auto key = permission_key_generation_algorithm(settings_object.top_level_origin.value(), settings_object.origin());
// 6. Let entry be the result of getting a permission store entry with descriptor and key.
- auto entry = PermissionStore::the().get_permission_store_entry(descriptor, key);
+ auto entry = PermissionStore::the().get_permission_store_entry(feature, key);
// 7. If entry is not null, return a PermissionState enum value from entry's state.
if (entry.has_value())
return entry.release_value().state;
// 8. Return the PermissionState enum value that represents the permission state of feature, taking into account any permission state constraints for descriptor's name.
- if (!feature.has_value())
- return PermissionState::Prompt;
auto& page = Bindings::principal_host_defined_page(settings_object.realm());
- return permission_state_from(PermissionStore::the().state_for(*feature, key, page));
+ return permission_state_from(PermissionStore::the().state_for(feature, key, page));
}
GC_DEFINE_ALLOCATOR(Permissions);
@@ -206,7 +199,7 @@ void Permissions::query(GC::Ref<JS::Object> permission_desc, GC::Ref<WebIDL::Pro
auto root_desc = root_desc_or_error.release_value();
// 4. If rootDesc["name"] is not supported, return a promise rejected with a TypeError.
- if (!PermissionsAPI::is_permission_supported(root_desc.name)) {
+ if (!permission_name_from(root_desc.name).has_value()) {
auto error = vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, root_desc.name, "PermissionName"sv);
WebIDL::reject_promise(promise, error.release_error().value());
return;
@@ -246,7 +239,7 @@ void Permissions::query(GC::Ref<JS::Object> permission_desc, GC::Ref<WebIDL::Pro
void permission_query_algorithm(PermissionDescriptor const& permission_desc, PermissionStatus& status, HTML::EnvironmentSettingsObject& settings)
{
// 1. Set status's state to permissionDesc's permission state.
- status.set_state(permission_state(permission_desc, settings));
+ status.set_state(permission_state(*permission_name_from(permission_desc.name), settings));
}
}
diff --git a/Libraries/LibWeb/PermissionsAPI/Permissions.h b/Libraries/LibWeb/PermissionsAPI/Permissions.h
index db69a892fd1..65755fec53b 100644
--- a/Libraries/LibWeb/PermissionsAPI/Permissions.h
+++ b/Libraries/LibWeb/PermissionsAPI/Permissions.h
@@ -16,19 +16,20 @@
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
+#include <LibWebCommon/Permissions/Permissions.h>
namespace Web::PermissionsAPI {
using PermissionDescriptor = Bindings::PermissionDescriptor;
using PermissionState = Bindings::PermissionState;
-bool is_permission_supported(Utf16View);
+Optional<Web::Permissions::PermissionName> permission_name_from(Utf16View);
-PermissionState permission_state(PermissionDescriptor const& descriptor, Optional<HTML::EnvironmentSettingsObject&> settings = {});
+PermissionState permission_state(Web::Permissions::PermissionName, Optional<HTML::EnvironmentSettingsObject&> settings = {});
// Asks the user when the state is "prompt"; the callback runs once a state other than "prompt" is known.
using PermissionDecisionCallback = GC::Ref<GC::Function<void(PermissionState)>>;
-void request_permission_with_user_prompt(PermissionDescriptor const&, HTML::EnvironmentSettingsObject&, PermissionDecisionCallback);
+void request_permission_with_user_prompt(Web::Permissions::PermissionName, HTML::EnvironmentSettingsObject&, PermissionDecisionCallback);
class WEB_API Permissions : public Bindings::GCAllocatedWrappable {
WEB_WRAPPABLE(Permissions, Bindings::GCAllocatedWrappable);
diff --git a/Libraries/LibWeb/WebRTC/RTCPeerConnection.cpp b/Libraries/LibWeb/WebRTC/RTCPeerConnection.cpp
index 93f76461e5f..129af4b3908 100644
--- a/Libraries/LibWeb/WebRTC/RTCPeerConnection.cpp
+++ b/Libraries/LibWeb/WebRTC/RTCPeerConnection.cpp
@@ -79,8 +79,7 @@ WebIDL::ExceptionOr<GC::Ref<RTCPeerConnection>> RTCPeerConnection::create_for_co
// Like other browsers, only reveal local addresses to pages that may capture audio, which could tell where the
// user is anyway. Everyone else gets mDNS names in their place.
// https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-mdns-ice-candidates#section-3.1
- PermissionsAPI::PermissionDescriptor microphone_permission { "microphone"_utf16 };
- auto may_capture = PermissionsAPI::permission_state(microphone_permission) == PermissionsAPI::PermissionState::Granted;
+ auto may_capture = PermissionsAPI::permission_state(Web::Permissions::PermissionName::Microphone) == PermissionsAPI::PermissionState::Granted;
config.set("host_candidates"sv, may_capture ? "exposed"sv : "obfuscated"sv);
if (!configuration.certificates.is_empty())
return WebIDL::NotSupportedError::create("Custom RTC certificates are not supported"_utf16);