core: Require `SwfMovie::url`
This commit is contained in:
parent
e6f09d5adb
commit
b3fd1a47c6
|
@ -19,23 +19,18 @@ pub fn domain<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let movie = activation.base_clip().movie();
|
||||
|
||||
let domain = if let Some(url) = movie.url() {
|
||||
if let Ok(url) = url::Url::parse(url) {
|
||||
if url.scheme() == "file" {
|
||||
"localhost".into()
|
||||
} else if let Some(domain) = url.domain() {
|
||||
AvmString::new_utf8(activation.context.gc_context, domain)
|
||||
} else {
|
||||
// no domain?
|
||||
"localhost".into()
|
||||
}
|
||||
let domain = if let Ok(url) = url::Url::parse(movie.url()) {
|
||||
if url.scheme() == "file" {
|
||||
"localhost".into()
|
||||
} else if let Some(domain) = url.domain() {
|
||||
AvmString::new_utf8(activation.context.gc_context, domain)
|
||||
} else {
|
||||
tracing::error!("LocalConnection::domain: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
// no domain?
|
||||
"localhost".into()
|
||||
}
|
||||
} else {
|
||||
// No URL (loading local data).
|
||||
"localhost".into()
|
||||
tracing::error!("LocalConnection::domain: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
|
||||
Ok(Value::String(domain))
|
||||
|
|
|
@ -234,16 +234,11 @@ pub fn get_local<'gc>(
|
|||
|
||||
let movie = activation.base_clip().movie();
|
||||
|
||||
let mut movie_url = if let Some(url) = movie.url() {
|
||||
if let Ok(url) = url::Url::parse(url) {
|
||||
url
|
||||
} else {
|
||||
tracing::error!("SharedObject::get_local: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
let mut movie_url = if let Ok(url) = url::Url::parse(movie.url()) {
|
||||
url
|
||||
} else {
|
||||
// No URL (loading local data). Use a dummy URL to allow SharedObjects to work.
|
||||
url::Url::parse("file://localhost").unwrap()
|
||||
tracing::error!("SharedObject::get_local: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
movie_url.set_query(None);
|
||||
movie_url.set_fragment(None);
|
||||
|
|
|
@ -655,13 +655,10 @@ fn drop_target<'gc>(activation: &mut Activation<'_, 'gc>, this: DisplayObject<'g
|
|||
}
|
||||
|
||||
fn url<'gc>(activation: &mut Activation<'_, 'gc>, this: DisplayObject<'gc>) -> Value<'gc> {
|
||||
this.as_movie_clip()
|
||||
.map(|mc| mc.movie())
|
||||
.and_then(|mov| mov.url().map(|url| url.to_string()))
|
||||
.map_or_else(
|
||||
|| "".into(),
|
||||
|s| AvmString::new_utf8(activation.context.gc_context, s).into(),
|
||||
)
|
||||
this.as_movie_clip().map_or_else(
|
||||
|| "".into(),
|
||||
|mc| AvmString::new_utf8(activation.context.gc_context, mc.movie().url()).into(),
|
||||
)
|
||||
}
|
||||
|
||||
fn high_quality<'gc>(
|
||||
|
|
|
@ -571,8 +571,8 @@ fn load_playerglobal<'gc>(
|
|||
activation.avm2().native_instance_allocator_table = native::NATIVE_INSTANCE_ALLOCATOR_TABLE;
|
||||
activation.avm2().native_instance_init_table = native::NATIVE_INSTANCE_INIT_TABLE;
|
||||
|
||||
let movie =
|
||||
SwfMovie::from_data(PLAYERGLOBAL, None, None).expect("playerglobal.swf should be valid");
|
||||
let movie = SwfMovie::from_data(PLAYERGLOBAL, "file:///".into(), None)
|
||||
.expect("playerglobal.swf should be valid");
|
||||
|
||||
let slice = SwfSlice::from(Arc::new(movie));
|
||||
|
||||
|
|
|
@ -292,11 +292,7 @@ pub fn get_url<'gc>(
|
|||
LoaderStream::NotYetLoaded(_, _, false) => return Ok(Value::Null),
|
||||
LoaderStream::NotYetLoaded(root, _, true) | LoaderStream::Swf(root, _) => root,
|
||||
};
|
||||
|
||||
let url = root.url().map_or(Value::Null, |url| {
|
||||
AvmString::new_utf8(activation.context.gc_context, url).into()
|
||||
});
|
||||
return Ok(url);
|
||||
return Ok(AvmString::new_utf8(activation.context.gc_context, root.url()).into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,7 +410,7 @@ pub fn get_loader_url<'gc>(
|
|||
LoaderStream::Swf(root, _) => root,
|
||||
};
|
||||
|
||||
let loader_url = root.loader_url().or_else(|| root.url()).unwrap_or("");
|
||||
let loader_url = root.loader_url().unwrap_or_else(|| root.url());
|
||||
return Ok(AvmString::new_utf8(activation.context.gc_context, loader_url).into());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,16 +37,11 @@ pub fn get_local<'gc>(
|
|||
return Ok(Value::Null);
|
||||
};
|
||||
|
||||
let mut movie_url = if let Some(url) = movie.movie().url().map(|u| u.to_owned()) {
|
||||
if let Ok(url) = url::Url::parse(&url) {
|
||||
url
|
||||
} else {
|
||||
tracing::error!("SharedObject::get_local: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
let mut movie_url = if let Ok(url) = url::Url::parse(movie.movie().url()) {
|
||||
url
|
||||
} else {
|
||||
// No URL (loading local data). Use a dummy URL to allow SharedObjects to work.
|
||||
url::Url::parse("file://localhost").unwrap()
|
||||
tracing::error!("SharedObject::get_local: Unable to parse movie URL");
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
movie_url.set_query(None);
|
||||
movie_url.set_fragment(None);
|
||||
|
|
|
@ -693,7 +693,7 @@ impl<'gc> Loader<'gc> {
|
|||
.map(|u| u.to_string())
|
||||
.unwrap_or(response.url);
|
||||
|
||||
let mut movie = SwfMovie::from_data(&response.body, Some(url), None)?;
|
||||
let mut movie = SwfMovie::from_data(&response.body, url, None)?;
|
||||
on_metadata(movie.header());
|
||||
movie.append_parameters(parameters);
|
||||
player.lock().unwrap().set_root_movie(movie);
|
||||
|
@ -748,8 +748,7 @@ impl<'gc> Loader<'gc> {
|
|||
Ok(response) if replacing_root_movie => {
|
||||
ContentType::sniff(&response.body).expect(ContentType::Swf)?;
|
||||
|
||||
let movie =
|
||||
SwfMovie::from_data(&response.body, Some(response.url), loader_url)?;
|
||||
let movie = SwfMovie::from_data(&response.body, response.url, loader_url)?;
|
||||
player.lock().unwrap().set_root_movie(movie);
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -758,7 +757,7 @@ impl<'gc> Loader<'gc> {
|
|||
handle,
|
||||
player,
|
||||
&response.body,
|
||||
Some(response.url),
|
||||
response.url,
|
||||
loader_url,
|
||||
false,
|
||||
)?;
|
||||
|
@ -813,12 +812,12 @@ impl<'gc> Loader<'gc> {
|
|||
if replacing_root_movie {
|
||||
ContentType::sniff(&bytes).expect(ContentType::Swf)?;
|
||||
|
||||
let movie = SwfMovie::from_data(&bytes, Some("file:///".into()), None)?;
|
||||
let movie = SwfMovie::from_data(&bytes, "file:///".into(), None)?;
|
||||
player.lock().unwrap().set_root_movie(movie);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Loader::movie_loader_data(handle, player, &bytes, Some("file:///".into()), None, true)
|
||||
Loader::movie_loader_data(handle, player, &bytes, "file:///".into(), None, true)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1320,7 +1319,7 @@ impl<'gc> Loader<'gc> {
|
|||
handle: Handle,
|
||||
player: Arc<Mutex<Player>>,
|
||||
data: &[u8],
|
||||
url: Option<String>,
|
||||
url: String,
|
||||
loader_url: Option<String>,
|
||||
in_memory: bool,
|
||||
) -> Result<(), Error> {
|
||||
|
|
|
@ -2264,7 +2264,7 @@ impl PlayerBuilder {
|
|||
});
|
||||
if let Some(mut movie) = self.movie {
|
||||
if let Some(url) = self.spoofed_url.clone() {
|
||||
movie.set_url(Some(url));
|
||||
movie.set_url(url);
|
||||
}
|
||||
player_lock.set_root_movie(movie);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub struct SwfMovie {
|
|||
data: Vec<u8>,
|
||||
|
||||
/// The URL the SWF was downloaded from.
|
||||
url: Option<String>,
|
||||
url: String,
|
||||
|
||||
/// The URL that triggered the SWF load.
|
||||
loader_url: Option<String>,
|
||||
|
@ -70,7 +70,7 @@ impl SwfMovie {
|
|||
Self {
|
||||
header: HeaderExt::default_with_swf_version(swf_version),
|
||||
data: vec![],
|
||||
url: None,
|
||||
url: "file:///".into(),
|
||||
loader_url: None,
|
||||
parameters: Vec::new(),
|
||||
encoding: swf::UTF_8,
|
||||
|
@ -89,13 +89,13 @@ impl SwfMovie {
|
|||
let abs_path = path.as_ref().canonicalize()?;
|
||||
let url = url::Url::from_file_path(abs_path).map_err(|()| Error::InvalidSwfUrl)?;
|
||||
|
||||
Self::from_data(&data, Some(url.into()), loader_url)
|
||||
Self::from_data(&data, url.into(), loader_url)
|
||||
}
|
||||
|
||||
/// Construct a movie based on the contents of the SWF datastream.
|
||||
pub fn from_data(
|
||||
swf_data: &[u8],
|
||||
url: Option<String>,
|
||||
url: String,
|
||||
loader_url: Option<String>,
|
||||
) -> Result<Self, Error> {
|
||||
let compressed_len = swf_data.len();
|
||||
|
@ -144,11 +144,11 @@ impl SwfMovie {
|
|||
}
|
||||
|
||||
/// Get the URL this SWF was fetched from.
|
||||
pub fn url(&self) -> Option<&str> {
|
||||
self.url.as_deref()
|
||||
pub fn url(&self) -> &str {
|
||||
&self.url
|
||||
}
|
||||
|
||||
pub fn set_url(&mut self, url: Option<String>) {
|
||||
pub fn set_url(&mut self, url: String) {
|
||||
self.url = url;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ fn load_movie(url: &Url, opt: &Opt) -> Result<SwfMovie, Error> {
|
|||
.read_to_end(&mut buffer)
|
||||
.context("Couldn't read response from server")?;
|
||||
|
||||
SwfMovie::from_data(&buffer, Some(url.to_string()), None)
|
||||
SwfMovie::from_data(&buffer, url.to_string(), None)
|
||||
.map_err(|e| anyhow!(e.to_string()))
|
||||
.context("Couldn't load swf")?
|
||||
};
|
||||
|
|
|
@ -255,7 +255,7 @@ impl Ruffle {
|
|||
segments.push(&swf_name);
|
||||
}
|
||||
|
||||
let mut movie = SwfMovie::from_data(&swf_data.to_vec(), Some(url.to_string()), None)
|
||||
let mut movie = SwfMovie::from_data(&swf_data.to_vec(), url.to_string(), None)
|
||||
.map_err(|e| format!("Error loading movie: {e}"))?;
|
||||
movie.append_parameters(parse_movie_parameters(¶meters));
|
||||
|
||||
|
|
Loading…
Reference in New Issue