mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
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:
parent
b72932bc88
commit
f51a5661f8
11 changed files with 211 additions and 207 deletions
|
@ -18,8 +18,8 @@ use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
|||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::{
|
||||
AllowOrDenyRequest, CompositorEventVariant, FilterPattern, GamepadHapticEffectType, LoadStatus,
|
||||
PermissionPrompt, PermissionRequest, PromptCredentialsInput, PromptDefinition, PromptOrigin,
|
||||
PromptResult, Servo, ServoDelegate, ServoError, TouchEventType, WebView, WebViewDelegate,
|
||||
PermissionRequest, PromptCredentialsInput, PromptDefinition, PromptOrigin, PromptResult, Servo,
|
||||
ServoDelegate, ServoError, TouchEventType, WebView, WebViewDelegate,
|
||||
};
|
||||
use tinyfiledialogs::{self, MessageBoxIcon, OkCancel};
|
||||
use url::Url;
|
||||
|
@ -509,16 +509,10 @@ impl WebViewDelegate for RunningAppState {
|
|||
inner_mut.need_present = true;
|
||||
}
|
||||
|
||||
fn request_permission(
|
||||
&self,
|
||||
_webview: servo::WebView,
|
||||
prompt: PermissionPrompt,
|
||||
result_sender: IpcSender<PermissionRequest>,
|
||||
) {
|
||||
let _ = result_sender.send(match self.inner().headless {
|
||||
true => PermissionRequest::Denied,
|
||||
false => prompt_user(prompt),
|
||||
});
|
||||
fn request_permission(&self, _webview: servo::WebView, request: PermissionRequest) {
|
||||
if !self.inner().headless {
|
||||
prompt_user(request);
|
||||
}
|
||||
}
|
||||
|
||||
fn notify_new_frame_ready(&self, _webview: servo::WebView) {
|
||||
|
@ -564,37 +558,27 @@ impl WebViewDelegate for RunningAppState {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn prompt_user(prompt: PermissionPrompt) -> PermissionRequest {
|
||||
fn prompt_user(request: PermissionRequest) {
|
||||
use tinyfiledialogs::YesNo;
|
||||
|
||||
let message = match prompt {
|
||||
PermissionPrompt::Request(permission_name) => {
|
||||
format!("Do you want to grant permission for {:?}?", permission_name)
|
||||
},
|
||||
PermissionPrompt::Insecure(permission_name) => {
|
||||
format!(
|
||||
"The {:?} feature is only safe to use in secure context, but servo can't guarantee\n\
|
||||
that the current context is secure. Do you want to proceed and grant permission?",
|
||||
permission_name
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
let message = format!(
|
||||
"Do you want to grant permission for {:?}?",
|
||||
request.feature()
|
||||
);
|
||||
match tinyfiledialogs::message_box_yes_no(
|
||||
"Permission request dialog",
|
||||
&message,
|
||||
MessageBoxIcon::Question,
|
||||
YesNo::No,
|
||||
) {
|
||||
YesNo::Yes => PermissionRequest::Granted,
|
||||
YesNo::No => PermissionRequest::Denied,
|
||||
YesNo::Yes => request.allow(),
|
||||
YesNo::No => request.deny(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn prompt_user(_prompt: PermissionPrompt) -> PermissionRequest {
|
||||
// TODO popup only supported on linux
|
||||
PermissionRequest::Denied
|
||||
fn prompt_user(_request: PermissionRequest) {
|
||||
// Requests are denied by default.
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
|
@ -21,9 +21,8 @@ use servo::webrender_traits::SurfmanRenderingContext;
|
|||
use servo::{
|
||||
AllowOrDenyRequest, ContextMenuResult, EmbedderProxy, EventLoopWaker, InputMethodType, Key,
|
||||
KeyState, KeyboardEvent, LoadStatus, MediaSessionActionType, MediaSessionEvent, MouseButton,
|
||||
NavigationRequest, PermissionPrompt, PermissionRequest, PromptDefinition, PromptOrigin,
|
||||
PromptResult, Servo, ServoDelegate, ServoError, TouchEventType, TouchId, WebView,
|
||||
WebViewDelegate,
|
||||
NavigationRequest, PermissionRequest, PromptDefinition, PromptOrigin, PromptResult, Servo,
|
||||
ServoDelegate, ServoError, TouchEventType, TouchId, WebView, WebViewDelegate,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
|
@ -209,31 +208,15 @@ impl WebViewDelegate for RunningAppState {
|
|||
Some(new_webview)
|
||||
}
|
||||
|
||||
fn request_permission(
|
||||
&self,
|
||||
_webview: WebView,
|
||||
prompt: PermissionPrompt,
|
||||
result_sender: IpcSender<PermissionRequest>,
|
||||
) {
|
||||
let message = match prompt {
|
||||
PermissionPrompt::Request(permission_name) => {
|
||||
format!("Do you want to grant permission for {:?}?", permission_name)
|
||||
},
|
||||
PermissionPrompt::Insecure(permission_name) => {
|
||||
format!(
|
||||
"The {:?} feature is only safe to use in secure context, but servo can't guarantee\n\
|
||||
that the current context is secure. Do you want to proceed and grant permission?",
|
||||
permission_name
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
fn request_permission(&self, _webview: WebView, request: PermissionRequest) {
|
||||
let message = format!(
|
||||
"Do you want to grant permission for {:?}?",
|
||||
request.feature()
|
||||
);
|
||||
let result = match self.callbacks.host_callbacks.prompt_yes_no(message, true) {
|
||||
PromptResult::Primary => PermissionRequest::Granted,
|
||||
PromptResult::Secondary | PromptResult::Dismissed => PermissionRequest::Denied,
|
||||
PromptResult::Primary => request.allow(),
|
||||
PromptResult::Secondary | PromptResult::Dismissed => request.deny(),
|
||||
};
|
||||
|
||||
let _ = result_sender.send(result);
|
||||
}
|
||||
|
||||
fn request_resize_to(&self, _webview: WebView, size: DeviceIntSize) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue