libservo: Flesh out permissions API (#35396)

- Update the script crate to better reflect the modern Permission
  specifcation -- removing the necessity for an `Insecure` variant of
  the permissions prompt.
- Have all allow/deny type requests in the internal API use an
  `AllowOrDeny` enum for clarity.
- Expose `PermissionsRequest` and `PermissionFeature` data types to the
  API and use them in the delegate method.
- Update both servoshell implementations to use the API.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-10 16:50:33 +01:00 committed by GitHub
parent b72932bc88
commit f51a5661f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 211 additions and 207 deletions

View file

@ -24,8 +24,8 @@ use cssparser::match_ignore_ascii_case;
use devtools_traits::ScriptToDevtoolsControlMsg;
use dom_struct::dom_struct;
use embedder_traits::{
ClipboardEventType, EmbedderMsg, LoadStatus, MouseButton, MouseEventType, TouchEventType,
TouchId, WheelDelta,
AllowOrDeny, ClipboardEventType, EmbedderMsg, LoadStatus, MouseButton, MouseEventType,
TouchEventType, TouchId, WheelDelta,
};
use encoding_rs::{Encoding, UTF_8};
use euclid::default::{Point2D, Rect, Size2D};
@ -94,6 +94,7 @@ use crate::dom::bindings::codegen::Bindings::NavigatorBinding::Navigator_Binding
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionName;
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRootMethods;
use crate::dom::bindings::codegen::Bindings::TouchBinding::TouchMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{
@ -2492,7 +2493,7 @@ impl Document {
let (chan, port) = ipc::channel().expect("Failed to create IPC channel!");
let msg = EmbedderMsg::AllowUnload(self.webview_id(), chan);
self.send_to_embedder(msg);
can_unload = port.recv().unwrap();
can_unload = port.recv().unwrap() == AllowOrDeny::Allow;
}
// Step 9
if !recursive_flag {
@ -3309,6 +3310,26 @@ impl Document {
.parse(url)
.map(ServoUrl::from)
}
/// <https://html.spec.whatwg.org/multipage/#allowed-to-use>
pub(crate) fn allowed_to_use_feature(&self, _feature: PermissionName) -> bool {
// Step 1. If document's browsing context is null, then return false.
if !self.has_browsing_context {
return false;
}
// Step 2. If document is not fully active, then return false.
if !self.is_fully_active() {
return false;
}
// Step 3. If the result of running is feature enabled in document for origin on
// feature, document, and document's origin is "Enabled", then return true.
// Step 4. Return false.
// TODO: All features are currently enabled for `Document`s because we do not
// implement the Permissions Policy specification.
true
}
}
fn is_character_value_key(key: &Key) -> bool {