diff --git a/ports/servoshell/desktop/app_state.rs b/ports/servoshell/desktop/app_state.rs index 2f4a7d8adee..b9df312ae71 100644 --- a/ports/servoshell/desktop/app_state.rs +++ b/ports/servoshell/desktop/app_state.rs @@ -357,7 +357,7 @@ impl WebViewDelegate for RunningAppState { &self, webview: servo::WebView, definition: PromptDefinition, - origin: PromptOrigin, + _origin: PromptOrigin, ) { if self.inner().headless { let _ = match definition { @@ -378,24 +378,9 @@ impl WebViewDelegate for RunningAppState { let okcancel_dialog = Dialog::new_okcancel_dialog(message, sender); self.add_dialog(webview, okcancel_dialog); }, - _ => { - let _ = thread::Builder::new() - .name("AlertDialog".to_owned()) - .spawn(move || match definition { - PromptDefinition::Input(mut message, mut default, sender) => { - if origin == PromptOrigin::Untrusted { - message = tiny_dialog_escape(&message); - default = tiny_dialog_escape(&default); - } - let result = tinyfiledialogs::input_box("", &message, &default); - sender.send(result) - }, - - _ => Ok(()), - }) - .unwrap() - .join() - .expect("Thread spawning failed"); + PromptDefinition::Input(message, default, sender) => { + let input_dialog = Dialog::new_input_dialog(message, default, sender); + self.add_dialog(webview, input_dialog); }, } } @@ -598,28 +583,3 @@ fn platform_get_selected_devices(devices: Vec) -> Option { } None } - -// This is a mitigation for #25498, not a verified solution. -// There may be codepaths in tinyfiledialog.c that this is -// inadquate against, as it passes the string via shell to -// different programs depending on what the user has installed. -#[cfg(target_os = "linux")] -fn tiny_dialog_escape(raw: &str) -> String { - let s: String = raw - .chars() - .filter_map(|c| match c { - '\n' => Some('\n'), - '\0'..='\x1f' => None, - '<' => Some('\u{FF1C}'), - '>' => Some('\u{FF1E}'), - '&' => Some('\u{FF06}'), - _ => Some(c), - }) - .collect(); - shellwords::escape(&s) -} - -#[cfg(not(target_os = "linux"))] -fn tiny_dialog_escape(raw: &str) -> String { - raw.to_string() -} diff --git a/ports/servoshell/desktop/dialog.rs b/ports/servoshell/desktop/dialog.rs index d184dee7648..cd3b6a4abd6 100644 --- a/ports/servoshell/desktop/dialog.rs +++ b/ports/servoshell/desktop/dialog.rs @@ -25,6 +25,11 @@ pub enum Dialog { message: String, sender: IpcSender, }, + Input { + message: String, + input_text: String, + sender: IpcSender>, + }, } impl Dialog { @@ -65,6 +70,18 @@ impl Dialog { Dialog::OkCancel { message, sender } } + pub fn new_input_dialog( + message: String, + default: String, + sender: IpcSender>, + ) -> Self { + Dialog::Input { + message, + input_text: default, + sender, + } + } + pub fn update(&mut self, ctx: &egui::Context) -> bool { match self { Dialog::File { @@ -108,7 +125,7 @@ impl Dialog { let mut is_open = true; let modal = Modal::new("alert".into()); modal.show(ctx, |ui| { - make_dialog_label(message, ui); + make_dialog_label(message, ui, None); egui::Sides::new().show( ui, |_ui| {}, @@ -128,7 +145,7 @@ impl Dialog { let mut is_open = true; let modal = Modal::new("OkCancel".into()); modal.show(ctx, |ui| { - make_dialog_label(message, ui); + make_dialog_label(message, ui, None); egui::Sides::new().show( ui, |_ui| {}, @@ -150,13 +167,45 @@ impl Dialog { }); is_open }, + Dialog::Input { + message, + input_text, + sender, + } => { + let mut is_open = true; + Modal::new("input".into()).show(ctx, |ui| { + make_dialog_label(message, ui, Some(input_text)); + egui::Sides::new().show( + ui, + |_ui| {}, + |ui| { + if ui.button("Ok").clicked() { + is_open = false; + if let Err(e) = sender.send(Some(input_text.clone())) { + warn!("Failed to send input dialog response: {}", e); + } + } + if ui.button("Cancel").clicked() { + is_open = false; + if let Err(e) = sender.send(None) { + warn!("Failed to send input dialog response: {}", e); + } + } + }, + ); + }); + is_open + }, } } } -fn make_dialog_label(message: &str, ui: &mut egui::Ui) { +fn make_dialog_label(message: &str, ui: &mut egui::Ui, input_text: Option<&mut String>) { let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui); frame.content_ui.set_min_width(150.0); frame.content_ui.label(message); + if let Some(input_text) = input_text { + frame.content_ui.text_edit_singleline(input_text); + } frame.end(ui); }