Skip to content

Commit

Permalink
core: Fixing Errors and Attempting to Understand my Own Code (Address r…
Browse files Browse the repository at this point in the history
  • Loading branch information
William-McGonagle committed Dec 17, 2024
1 parent 1ebe6bc commit 66dac93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
12 changes: 6 additions & 6 deletions web/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::external_interface::JavascriptInterface;
use crate::navigator::{OpenUrlMode, WebNavigatorBackend};
use crate::navigator::{OpenUrlMode, OpenUrlModeHandler, WebNavigatorBackend};
use crate::{
audio, log_adapter, storage, ui, JavascriptPlayer, RuffleHandle, SocketProxy,
RUFFLE_GLOBAL_PANIC,
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct RuffleInstanceBuilder {
pub(crate) max_execution_duration: Duration,
pub(crate) player_version: Option<u8>,
pub(crate) preferred_renderer: Option<String>, // TODO: Enumify?
pub(crate) open_url_mode: OpenUrlMode,
pub(crate) open_url_mode: OpenUrlModeHandler,
pub(crate) allow_networking: NetworkingAccessMode,
pub(crate) socket_proxy: Vec<SocketProxy>,
pub(crate) credential_allow_list: Vec<String>,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Default for RuffleInstanceBuilder {
max_execution_duration: Duration::from_secs_f64(15.0),
player_version: None,
preferred_renderer: None,
open_url_mode: OpenUrlMode::Allow,
open_url_mode: OpenUrlModeHandler::Static(OpenUrlMode::Allow),
allow_networking: NetworkingAccessMode::All,
socket_proxy: vec![],
credential_allow_list: vec![],
Expand Down Expand Up @@ -247,9 +247,9 @@ impl RuffleInstanceBuilder {
#[wasm_bindgen(js_name = "setOpenUrlMode")]
pub fn set_open_url_mode(&mut self, value: &str) {
self.open_url_mode = match value {
"allow" => OpenUrlMode::Allow,
"confirm" => OpenUrlMode::Confirm,
"deny" => OpenUrlMode::Deny,
"allow" => OpenUrlModeHandler::Static(OpenUrlMode::Allow),
"confirm" => OpenUrlModeHandler::Static(OpenUrlMode::Confirm),
"deny" => OpenUrlModeHandler::Static(OpenUrlMode::Deny),
_ => return,
};
}
Expand Down
20 changes: 9 additions & 11 deletions web/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,38 +208,36 @@ impl NavigatorBackend for WebNavigatorBackend {

let window = window().expect("window()");



let final_url = if url.scheme() != "javascript" {
match self.open_url_mode.handle(resolved_url.as_str()) {
match self.open_url_mode.handle(url.as_str()) {
OpenUrlOutcome::Mode(OpenUrlMode::Deny) => {
tracing::warn!("Opening a website is denied: {}", resolved_url);
tracing::warn!("Opening a website is denied: {}", url);
return; // Blocked outright
}
OpenUrlOutcome::Mode(OpenUrlMode::Confirm) => {
let message = format!("The SWF file wants to open the website {}", resolved_url);
let message = format!("The SWF file wants to open the website {}", url);
let confirm = window
.confirm_with_message(&message)
.expect("Failed to show confirmation dialog");

if confirm {
tracing::info!("User confirmed opening URL: {}", resolved_url);
resolved_url.to_string()
tracing::info!("User confirmed opening URL: {}", url);
url.to_string()
} else {
tracing::info!("User declined opening URL: {}", resolved_url);
tracing::info!("User declined opening URL: {}", url);
return;
}
}
OpenUrlOutcome::Mode(OpenUrlMode::Allow) => {
tracing::info!("Opening URL: {}", resolved_url);
resolved_url.to_string()
tracing::info!("Opening URL: {}", url);
url.to_string()
}
OpenUrlOutcome::Redirect(new_url) => {
tracing::info!("Redirecting to: {}", new_url);
new_url
}
}
} else { resolved_url.to_string() };
} else { url.to_string() };

// TODO: Should we return a result for failed opens? Does Flash care?
match vars_method {
Expand Down

0 comments on commit 66dac93

Please sign in to comment.