Skip to content

Commit 41e373c

Browse files
kjaroshDinnerbone
authored andcommitted
core: Move OpenURLMode from core to web
After changes in desktop, this is the only place where it is used. This additionally renames it to OpenUrlMode.
1 parent f15b14a commit 41e373c

File tree

4 files changed

+28
-41
lines changed

4 files changed

+28
-41
lines changed

core/src/backend/navigator.rs

-18
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,6 @@ pub enum SocketMode {
5656
Ask,
5757
}
5858

59-
/// The handling mode of links opening a new website.
60-
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
61-
#[derive(Clone, Copy, Debug, PartialEq)]
62-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63-
pub enum OpenURLMode {
64-
/// Allow all links to open a new website.
65-
#[cfg_attr(feature = "serde", serde(rename = "allow"))]
66-
Allow,
67-
68-
/// A confirmation dialog opens with every link trying to open a new website.
69-
#[cfg_attr(feature = "serde", serde(rename = "confirm"))]
70-
Confirm,
71-
72-
/// Deny all links to open a new website.
73-
#[cfg_attr(feature = "serde", serde(rename = "deny"))]
74-
Deny,
75-
}
76-
7759
impl NavigationMethod {
7860
/// Convert an SWF method enum into a NavigationMethod.
7961
pub fn from_send_vars_method(s: SendVarsMethod) -> Option<Self> {

desktop/src/cli.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::preferences::storage::StorageBackend;
22
use crate::RUFFLE_VERSION;
33
use anyhow::{anyhow, Error};
44
use clap::{Parser, ValueEnum};
5-
use ruffle_core::backend::navigator::{OpenURLMode, SocketMode};
5+
use ruffle_core::backend::navigator::SocketMode;
66
use ruffle_core::config::Letterbox;
77
use ruffle_core::events::{GamepadButton, KeyCode};
88
use ruffle_core::{LoadBehavior, PlayerRuntime, StageAlign, StageScaleMode};
@@ -372,16 +372,6 @@ impl FromStr for OpenUrlMode {
372372
}
373373
}
374374

375-
impl From<OpenUrlMode> for OpenURLMode {
376-
fn from(value: OpenUrlMode) -> Self {
377-
match value {
378-
OpenUrlMode::Confirm => OpenURLMode::Confirm,
379-
OpenUrlMode::Allow => OpenURLMode::Allow,
380-
OpenUrlMode::Deny => OpenURLMode::Deny,
381-
}
382-
}
383-
}
384-
385375
// TODO The following enum exists in order to preserve
386376
// the behavior of mapping gamepad buttons,
387377
// We should probably do something smarter here.

web/src/builder.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::external_interface::JavascriptInterface;
2-
use crate::navigator::WebNavigatorBackend;
2+
use crate::navigator::{OpenUrlMode, WebNavigatorBackend};
33
use crate::{
44
audio, log_adapter, storage, ui, JavascriptPlayer, RuffleHandle, SocketProxy,
55
RUFFLE_GLOBAL_PANIC,
66
};
77
use js_sys::Promise;
88
use ruffle_core::backend::audio::{AudioBackend, NullAudioBackend};
9-
use ruffle_core::backend::navigator::OpenURLMode;
109
use ruffle_core::backend::storage::{MemoryStorageBackend, StorageBackend};
1110
use ruffle_core::backend::ui::FontDefinition;
1211
use ruffle_core::compatibility_rules::CompatibilityRules;
@@ -54,7 +53,7 @@ pub struct RuffleInstanceBuilder {
5453
pub(crate) max_execution_duration: Duration,
5554
pub(crate) player_version: Option<u8>,
5655
pub(crate) preferred_renderer: Option<String>, // TODO: Enumify?
57-
pub(crate) open_url_mode: OpenURLMode,
56+
pub(crate) open_url_mode: OpenUrlMode,
5857
pub(crate) allow_networking: NetworkingAccessMode,
5958
pub(crate) socket_proxy: Vec<SocketProxy>,
6059
pub(crate) credential_allow_list: Vec<String>,
@@ -90,7 +89,7 @@ impl Default for RuffleInstanceBuilder {
9089
max_execution_duration: Duration::from_secs_f64(15.0),
9190
player_version: None,
9291
preferred_renderer: None,
93-
open_url_mode: OpenURLMode::Allow,
92+
open_url_mode: OpenUrlMode::Allow,
9493
allow_networking: NetworkingAccessMode::All,
9594
socket_proxy: vec![],
9695
credential_allow_list: vec![],
@@ -248,9 +247,9 @@ impl RuffleInstanceBuilder {
248247
#[wasm_bindgen(js_name = "setOpenUrlMode")]
249248
pub fn set_open_url_mode(&mut self, value: &str) {
250249
self.open_url_mode = match value {
251-
"allow" => OpenURLMode::Allow,
252-
"confirm" => OpenURLMode::Confirm,
253-
"deny" => OpenURLMode::Deny,
250+
"allow" => OpenUrlMode::Allow,
251+
"confirm" => OpenUrlMode::Confirm,
252+
"deny" => OpenUrlMode::Deny,
254253
_ => return,
255254
};
256255
}

web/src/navigator.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use gloo_net::websocket::{futures::WebSocket, Message};
77
use js_sys::{Array, Promise, Uint8Array};
88
use ruffle_core::backend::navigator::{
99
async_return, create_fetch_error, create_specific_fetch_error, get_encoding, ErrorResponse,
10-
NavigationMethod, NavigatorBackend, OpenURLMode, OwnedFuture, Request, SuccessResponse,
10+
NavigationMethod, NavigatorBackend, OwnedFuture, Request, SuccessResponse,
1111
};
1212
use ruffle_core::config::NetworkingAccessMode;
1313
use ruffle_core::indexmap::IndexMap;
@@ -32,13 +32,29 @@ use web_sys::{
3232
RequestCredentials, RequestInit, Response as WebResponse,
3333
};
3434

35+
/// The handling mode of links opening a new website.
36+
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
37+
pub enum OpenUrlMode {
38+
/// Allow all links to open a new website.
39+
#[serde(rename = "allow")]
40+
Allow,
41+
42+
/// A confirmation dialog opens with every link trying to open a new website.
43+
#[serde(rename = "confirm")]
44+
Confirm,
45+
46+
/// Deny all links to open a new website.
47+
#[serde(rename = "deny")]
48+
Deny,
49+
}
50+
3551
pub struct WebNavigatorBackend {
3652
log_subscriber: Arc<Layered<WASMLayer, Registry>>,
3753
allow_script_access: bool,
3854
allow_networking: NetworkingAccessMode,
3955
upgrade_to_https: bool,
4056
base_url: Option<Url>,
41-
open_url_mode: OpenURLMode,
57+
open_url_mode: OpenUrlMode,
4258
socket_proxies: Vec<SocketProxy>,
4359
credential_allow_list: Vec<String>,
4460
player: Weak<Mutex<Player>>,
@@ -52,7 +68,7 @@ impl WebNavigatorBackend {
5268
upgrade_to_https: bool,
5369
base_url: Option<String>,
5470
log_subscriber: Arc<Layered<WASMLayer, Registry>>,
55-
open_url_mode: OpenURLMode,
71+
open_url_mode: OpenUrlMode,
5672
socket_proxies: Vec<SocketProxy>,
5773
credential_allow_list: Vec<String>,
5874
) -> Self {
@@ -168,7 +184,7 @@ impl NavigatorBackend for WebNavigatorBackend {
168184
let window = window().expect("window()");
169185

170186
if url.scheme() != "javascript" {
171-
if self.open_url_mode == OpenURLMode::Confirm {
187+
if self.open_url_mode == OpenUrlMode::Confirm {
172188
let message = format!("The SWF file wants to open the website {}", &url);
173189
// TODO: Add a checkbox with a GUI toolkit
174190
let confirm = window
@@ -180,7 +196,7 @@ impl NavigatorBackend for WebNavigatorBackend {
180196
);
181197
return;
182198
}
183-
} else if self.open_url_mode == OpenURLMode::Deny {
199+
} else if self.open_url_mode == OpenUrlMode::Deny {
184200
tracing::warn!("SWF tried to open a website, but opening a website is not allowed");
185201
return;
186202
}

0 commit comments

Comments
 (0)