diff --git a/Cargo.lock b/Cargo.lock index 75e20ecc4..717dda434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4343,7 +4343,6 @@ dependencies = [ "tracing", "url", "urlencoding", - "webbrowser", "zip", ] diff --git a/desktop/src/backends/navigator.rs b/desktop/src/backends/navigator.rs index 9c30cbc5a..cedfede4a 100644 --- a/desktop/src/backends/navigator.rs +++ b/desktop/src/backends/navigator.rs @@ -10,16 +10,22 @@ use url::Url; pub struct DesktopNavigatorInterface; impl NavigatorInterface for DesktopNavigatorInterface { - fn confirm_website_navigation(&self, url: &Url) -> bool { - let message = format!("The SWF file wants to open the website {}", url); - // TODO: Add a checkbox with a GUI toolkit - MessageDialog::new() - .set_title("Open website?") - .set_level(MessageLevel::Info) - .set_description(message) - .set_buttons(MessageButtons::OkCancel) - .show() - == MessageDialogResult::Ok + fn navigate_to_website(&self, url: Url, ask: bool) { + if ask { + let message = format!("The SWF file wants to open the website {}", url); + // TODO: Add a checkbox with a GUI toolkit + let result = MessageDialog::new() + .set_title("Open website?") + .set_level(MessageLevel::Info) + .set_description(message) + .set_buttons(MessageButtons::OkCancel) + .show(); + if result != MessageDialogResult::Ok { + return; + } + } + + crate::util::open_url(&url); } fn open_file(&self, path: &Path) -> io::Result { diff --git a/desktop/src/util.rs b/desktop/src/util.rs index dc6e771bb..64838bcb7 100644 --- a/desktop/src/util.rs +++ b/desktop/src/util.rs @@ -283,3 +283,14 @@ pub fn plot_stats_in_tracy(instance: &wgpu::Instance) { tracy.frame_mark(); } + +pub fn open_url(url: &Url) { + // TODO: This opens local files in the browser while flash opens them + // in the default program for the respective filetype. + // This especially includes mailto links. Ruffle opens the browser which opens + // the preferred program while flash opens the preferred program directly. + match webbrowser::open(url.as_str()) { + Ok(_output) => {} + Err(e) => tracing::error!("Could not open URL {}: {}", url.as_str(), e), + }; +} diff --git a/frontend-utils/Cargo.toml b/frontend-utils/Cargo.toml index b4c8d9ddb..10c2668ed 100644 --- a/frontend-utils/Cargo.toml +++ b/frontend-utils/Cargo.toml @@ -23,7 +23,6 @@ async-channel = { workspace = true } slotmap = { workspace = true } async-io = "2.3.4" futures-lite = "2.3.0" -webbrowser = "1.0.1" reqwest = { version = "0.12.7", default-features = false, features = ["rustls-tls", "cookies", "charset", "http2", "macos-system-configuration"] } tokio = { workspace = true, features = ["net"] } diff --git a/frontend-utils/src/backends/navigator.rs b/frontend-utils/src/backends/navigator.rs index 4796dd623..771b01508 100644 --- a/frontend-utils/src/backends/navigator.rs +++ b/frontend-utils/src/backends/navigator.rs @@ -28,7 +28,7 @@ use tracing::warn; use url::{ParseError, Url}; pub trait NavigatorInterface: Clone + Send + 'static { - fn confirm_website_navigation(&self, url: &Url) -> bool; + fn navigate_to_website(&self, url: Url, ask: bool); fn open_file(&self, path: &Path) -> io::Result; @@ -182,26 +182,13 @@ impl NavigatorBackend return; } - if self.open_url_mode == OpenURLMode::Confirm { - if !self.interface.confirm_website_navigation(&modified_url) { - tracing::info!("SWF tried to open a website, but the user declined the request"); - return; - } - } else if self.open_url_mode == OpenURLMode::Deny { + if self.open_url_mode == OpenURLMode::Deny { tracing::warn!("SWF tried to open a website, but opening a website is not allowed"); return; } - // If the user confirmed or if in Allow mode, open the website - - // TODO: This opens local files in the browser while flash opens them - // in the default program for the respective filetype. - // This especially includes mailto links. Ruffle opens the browser which opens - // the preferred program while flash opens the preferred program directly. - match webbrowser::open(modified_url.as_ref()) { - Ok(_output) => {} - Err(e) => tracing::error!("Could not open URL {}: {}", modified_url.as_str(), e), - }; + let ask = self.open_url_mode == OpenURLMode::Confirm; + self.interface.navigate_to_website(modified_url, ask); } fn fetch(&self, request: Request) -> OwnedFuture, ErrorResponse> { @@ -499,9 +486,7 @@ mod tests { use super::*; impl NavigatorInterface for () { - fn confirm_website_navigation(&self, _url: &Url) -> bool { - true - } + fn navigate_to_website(&self, _url: Url, _ask: bool) {} fn open_file(&self, path: &Path) -> io::Result { File::open(path)