core: Remove `NavigatorBackend::resolve_relative_url`
The resolved URL only used by `NavigatorBackend::fetch`. So simply inline `NavigatorBackend::resolve_relative_url` into `NavigatorBackend::fetch`, per implementation.
This commit is contained in:
parent
ea665d91f2
commit
87ce0f56b7
|
@ -3,7 +3,6 @@
|
|||
use crate::loader::Error;
|
||||
use crate::string::WStr;
|
||||
use indexmap::IndexMap;
|
||||
use std::borrow::Cow;
|
||||
use std::future::Future;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
|
@ -191,16 +190,6 @@ pub trait NavigatorBackend {
|
|||
/// This seems highly limiting.
|
||||
fn spawn_future(&mut self, future: OwnedFuture<(), Error>);
|
||||
|
||||
/// Resolve a relative URL.
|
||||
///
|
||||
/// This function must not change URLs which are already protocol, domain,
|
||||
/// and path absolute. For URLs that are relative, the implementer of
|
||||
/// this function may opt to convert them to absolute using an implementor
|
||||
/// defined base. For a web browser, the most obvious base would be the
|
||||
/// current document's base URL, while the most obvious base for a desktop
|
||||
/// client would be the file-URL form of the current path.
|
||||
fn resolve_relative_url<'a>(&self, url: &'a str) -> Cow<'a, str>;
|
||||
|
||||
/// Handle any context specific pre-processing
|
||||
///
|
||||
/// Changing http -> https for example. This function may alter any part of the
|
||||
|
@ -349,15 +338,6 @@ impl NavigatorBackend for NullNavigatorBackend {
|
|||
self.spawner.spawn_local(future);
|
||||
}
|
||||
|
||||
fn resolve_relative_url<'a>(&self, url: &'a str) -> Cow<'a, str> {
|
||||
let relative = url_from_relative_path(&self.relative_base_path, url);
|
||||
if let Ok(relative) = relative {
|
||||
String::from(relative).into()
|
||||
} else {
|
||||
url.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_process_url(&self, url: Url) -> Url {
|
||||
url
|
||||
}
|
||||
|
|
|
@ -352,14 +352,7 @@ impl<'gc> Loader<'gc> {
|
|||
.expect("Could not upgrade weak reference to player");
|
||||
|
||||
Box::pin(async move {
|
||||
// clippy reports a false positive for explicitly dropped guards:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/6446
|
||||
// A workaround for this is to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
|
||||
let fetch = {
|
||||
let player_lock = player.lock().unwrap();
|
||||
let url = player_lock.navigator().resolve_relative_url(&url);
|
||||
player_lock.navigator().fetch(&url, options)
|
||||
};
|
||||
let fetch = player.lock().unwrap().navigator().fetch(&url, options);
|
||||
|
||||
let response = fetch.await.map_err(|error| {
|
||||
player
|
||||
|
@ -402,14 +395,7 @@ impl<'gc> Loader<'gc> {
|
|||
.expect("Could not upgrade weak reference to player");
|
||||
|
||||
Box::pin(async move {
|
||||
// clippy reports a false positive for explicitly dropped guards:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/6446
|
||||
// A workaround for this is to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
|
||||
let fetch = {
|
||||
let player_lock = player.lock().unwrap();
|
||||
let url = player_lock.navigator().resolve_relative_url(&url);
|
||||
player_lock.navigator().fetch(&url, options)
|
||||
};
|
||||
let fetch = player.lock().unwrap().navigator().fetch(&url, options);
|
||||
|
||||
let mut replacing_root_movie = false;
|
||||
player.lock().unwrap().update(|uc| -> Result<(), Error> {
|
||||
|
@ -517,14 +503,7 @@ impl<'gc> Loader<'gc> {
|
|||
.expect("Could not upgrade weak reference to player");
|
||||
|
||||
Box::pin(async move {
|
||||
// clippy reports a false positive for explicitly dropped guards:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/6446
|
||||
// A workaround for this is to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
|
||||
let fetch = {
|
||||
let player_lock = player.lock().unwrap();
|
||||
let url = player_lock.navigator().resolve_relative_url(&url);
|
||||
player_lock.navigator().fetch(&url, options)
|
||||
};
|
||||
let fetch = player.lock().unwrap().navigator().fetch(&url, options);
|
||||
|
||||
let response = fetch.await?;
|
||||
|
||||
|
@ -572,14 +551,7 @@ impl<'gc> Loader<'gc> {
|
|||
.expect("Could not upgrade weak reference to player");
|
||||
|
||||
Box::pin(async move {
|
||||
// clippy reports a false positive for explicitly dropped guards:
|
||||
// https://github.com/rust-lang/rust-clippy/issues/6446
|
||||
// A workaround for this is to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
|
||||
let fetch = {
|
||||
let player_lock = player.lock().unwrap();
|
||||
let url = player_lock.navigator().resolve_relative_url(&url);
|
||||
player_lock.navigator().fetch(&url, options)
|
||||
};
|
||||
let fetch = player.lock().unwrap().navigator().fetch(&url, options);
|
||||
|
||||
let data = fetch.await;
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use ruffle_core::backend::navigator::{
|
|||
};
|
||||
use ruffle_core::indexmap::IndexMap;
|
||||
use ruffle_core::loader::Error;
|
||||
use std::borrow::Cow;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use url::Url;
|
||||
|
@ -106,7 +105,7 @@ impl NavigatorBackend for ExternalNavigatorBackend {
|
|||
|
||||
fn fetch(&self, url: &str, options: RequestOptions) -> OwnedFuture<Response, Error> {
|
||||
// TODO: honor sandbox type (local-with-filesystem, local-with-network, remote, ...)
|
||||
let full_url = match self.movie_url.clone().join(url) {
|
||||
let full_url = match self.movie_url.join(url) {
|
||||
Ok(url) => url,
|
||||
Err(e) => {
|
||||
let msg = format!("Invalid URL {}: {}", url, e);
|
||||
|
@ -202,15 +201,6 @@ impl NavigatorBackend for ExternalNavigatorBackend {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_relative_url<'a>(&self, url: &'a str) -> Cow<'a, str> {
|
||||
let relative = self.movie_url.join(url);
|
||||
if let Ok(relative) = relative {
|
||||
String::from(relative).into()
|
||||
} else {
|
||||
url.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_process_url(&self, mut url: Url) -> Url {
|
||||
if self.upgrade_to_https && url.scheme() == "http" && url.set_scheme("https").is_err() {
|
||||
log::error!("Url::set_scheme failed on: {}", url);
|
||||
|
|
|
@ -73,6 +73,19 @@ impl WebNavigatorBackend {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_relative_url<'a>(&self, url: &'a str) -> Cow<'a, str> {
|
||||
let window = web_sys::window().expect("window()");
|
||||
let document = window.document().expect("document()");
|
||||
|
||||
if let Some(base_uri) = self.base_uri(&document) {
|
||||
if let Ok(new_url) = url_from_relative_url(&base_uri, url) {
|
||||
return String::from(new_url).into();
|
||||
}
|
||||
}
|
||||
|
||||
url.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl NavigatorBackend for WebNavigatorBackend {
|
||||
|
@ -237,19 +250,6 @@ impl NavigatorBackend for WebNavigatorBackend {
|
|||
})
|
||||
}
|
||||
|
||||
fn resolve_relative_url<'a>(&self, url: &'a str) -> Cow<'a, str> {
|
||||
let window = web_sys::window().expect("window()");
|
||||
let document = window.document().expect("document()");
|
||||
|
||||
if let Some(base_uri) = self.base_uri(&document) {
|
||||
if let Ok(new_url) = url_from_relative_url(&base_uri, url) {
|
||||
return String::from(new_url).into();
|
||||
}
|
||||
}
|
||||
|
||||
url.into()
|
||||
}
|
||||
|
||||
fn pre_process_url(&self, mut url: Url) -> Url {
|
||||
if self.upgrade_to_https && url.scheme() == "http" && url.set_scheme("https").is_err() {
|
||||
log::error!("Url::set_scheme failed on: {}", url);
|
||||
|
|
Loading…
Reference in New Issue