ruffle/desktop/src/navigator.rs

64 lines
1.9 KiB
Rust
Raw Normal View History

//! Navigator backend for web
use log;
2019-09-17 03:37:11 +00:00
use ruffle_core::backend::navigator::{NavigationMethod, NavigatorBackend};
use std::collections::HashMap;
use url::Url;
2019-09-17 03:37:11 +00:00
use webbrowser;
/// Implementation of `NavigatorBackend` for non-web environments that can call
/// out to a web browser.
2019-09-17 03:37:11 +00:00
pub struct ExternalNavigatorBackend {}
impl ExternalNavigatorBackend {
pub fn new() -> Self {
2019-09-17 03:37:11 +00:00
ExternalNavigatorBackend {}
}
}
impl NavigatorBackend for ExternalNavigatorBackend {
2019-09-17 03:37:11 +00:00
fn navigate_to_url(
&self,
url: String,
_window_spec: Option<String>,
vars_method: Option<(NavigationMethod, HashMap<String, String>)>,
) {
//TODO: Should we return a result for failed opens? Does Flash care?
2019-09-17 03:37:11 +00:00
//NOTE: Flash desktop players / projectors ignore the window parameter,
// unless it's a `_layer`, and we shouldn't handle that anyway.
let mut parsed_url = match Url::parse(&url) {
Ok(parsed_url) => parsed_url,
Err(e) => {
2019-09-17 03:37:11 +00:00
log::error!(
"Could not parse URL because of {}, the corrupt URL was: {}",
e,
url
);
return;
}
};
let modified_url = match vars_method {
Some((_, query_pairs)) => {
2019-09-17 03:37:11 +00:00
{
//lifetime limiter because we don't have NLL yet
let mut modifier = parsed_url.query_pairs_mut();
for (k, v) in query_pairs.iter() {
modifier.append_pair(k, v);
}
}
parsed_url.into_string()
2019-09-17 03:37:11 +00:00
}
None => url,
};
2019-09-17 03:37:11 +00:00
match webbrowser::open(&modified_url) {
2019-09-17 03:37:11 +00:00
Ok(_output) => {}
Err(e) => log::error!("Could not open URL {}: {}", modified_url, e),
};
}
2019-09-17 03:37:11 +00:00
}