mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
servoshell: Port Permission dialog code to use egui instead of tinyfiledialogs (#35577)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
parent
a433b20259
commit
f6e2e3d418
2 changed files with 49 additions and 30 deletions
|
@ -22,8 +22,6 @@ use servo::{
|
||||||
PermissionRequest, PromptDefinition, PromptOrigin, PromptResult, Servo, ServoDelegate,
|
PermissionRequest, PromptDefinition, PromptOrigin, PromptResult, Servo, ServoDelegate,
|
||||||
ServoError, TouchEventType, WebView, WebViewDelegate,
|
ServoError, TouchEventType, WebView, WebViewDelegate,
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
use tinyfiledialogs::MessageBoxIcon;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::app::PumpResult;
|
use super::app::PumpResult;
|
||||||
|
@ -537,10 +535,14 @@ impl WebViewDelegate for RunningAppState {
|
||||||
self.add_dialog(webview, file_dialog);
|
self.add_dialog(webview, file_dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_permission(&self, _webview: servo::WebView, request: PermissionRequest) {
|
fn request_permission(&self, webview: servo::WebView, permission_request: PermissionRequest) {
|
||||||
if !self.servoshell_preferences.headless {
|
if self.servoshell_preferences.headless {
|
||||||
prompt_user(request);
|
permission_request.deny();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let permission_dialog = Dialog::new_permission_request_dialog(permission_request);
|
||||||
|
self.add_dialog(webview, permission_dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn notify_new_frame_ready(&self, _webview: servo::WebView) {
|
fn notify_new_frame_ready(&self, _webview: servo::WebView) {
|
||||||
|
@ -594,30 +596,6 @@ impl WebViewDelegate for RunningAppState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
fn prompt_user(request: PermissionRequest) {
|
|
||||||
use tinyfiledialogs::YesNo;
|
|
||||||
|
|
||||||
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 => request.allow(),
|
|
||||||
YesNo::No => request.deny(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
fn prompt_user(_request: PermissionRequest) {
|
|
||||||
// Requests are denied by default.
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn platform_get_selected_devices(devices: Vec<String>) -> Option<String> {
|
fn platform_get_selected_devices(devices: Vec<String>) -> Option<String> {
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
|
|
|
@ -9,7 +9,7 @@ use egui::Modal;
|
||||||
use egui_file_dialog::{DialogState, FileDialog as EguiFileDialog};
|
use egui_file_dialog::{DialogState, FileDialog as EguiFileDialog};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use servo::ipc_channel::ipc::IpcSender;
|
use servo::ipc_channel::ipc::IpcSender;
|
||||||
use servo::{AuthenticationRequest, FilterPattern, PromptResult};
|
use servo::{AuthenticationRequest, FilterPattern, PermissionRequest, PromptResult};
|
||||||
|
|
||||||
pub enum Dialog {
|
pub enum Dialog {
|
||||||
File {
|
File {
|
||||||
|
@ -35,6 +35,10 @@ pub enum Dialog {
|
||||||
password: String,
|
password: String,
|
||||||
request: Option<AuthenticationRequest>,
|
request: Option<AuthenticationRequest>,
|
||||||
},
|
},
|
||||||
|
Permission {
|
||||||
|
message: String,
|
||||||
|
request: Option<PermissionRequest>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dialog {
|
impl Dialog {
|
||||||
|
@ -95,6 +99,17 @@ impl Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_permission_request_dialog(permission_request: PermissionRequest) -> Self {
|
||||||
|
let message = format!(
|
||||||
|
"Do you want to grant permission for {:?}?",
|
||||||
|
permission_request.feature()
|
||||||
|
);
|
||||||
|
Dialog::Permission {
|
||||||
|
message,
|
||||||
|
request: Some(permission_request),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, ctx: &egui::Context) -> bool {
|
pub fn update(&mut self, ctx: &egui::Context) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Dialog::File {
|
Dialog::File {
|
||||||
|
@ -261,6 +276,32 @@ impl Dialog {
|
||||||
});
|
});
|
||||||
is_open
|
is_open
|
||||||
},
|
},
|
||||||
|
Dialog::Permission { message, request } => {
|
||||||
|
let mut is_open = true;
|
||||||
|
let modal = Modal::new("permission".into());
|
||||||
|
modal.show(ctx, |ui| {
|
||||||
|
make_dialog_label(message, ui, None);
|
||||||
|
egui::Sides::new().show(
|
||||||
|
ui,
|
||||||
|
|_ui| {},
|
||||||
|
|ui| {
|
||||||
|
if ui.button("Allow").clicked() {
|
||||||
|
let request =
|
||||||
|
request.take().expect("non-None until dialog is closed");
|
||||||
|
request.allow();
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
if ui.button("Deny").clicked() {
|
||||||
|
let request =
|
||||||
|
request.take().expect("non-None until dialog is closed");
|
||||||
|
request.deny();
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
is_open
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue