2019-09-01 19:24:04 +00:00
|
|
|
//! Browser-related platform functions
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2019-09-03 01:49:36 +00:00
|
|
|
use swf::avm1::types::SendVarsMethod;
|
2019-09-01 19:24:04 +00:00
|
|
|
|
|
|
|
/// Enumerates all possible navigation methods.
|
|
|
|
pub enum NavigationMethod {
|
|
|
|
/// Indicates that navigation should generate a GET request.
|
|
|
|
GET,
|
|
|
|
|
|
|
|
/// Indicates that navigation should generate a POST request.
|
2019-09-17 03:37:11 +00:00
|
|
|
POST,
|
2019-09-01 19:24:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 01:49:36 +00:00
|
|
|
impl NavigationMethod {
|
|
|
|
/// Convert an SWF method enum into a NavigationMethod.
|
|
|
|
pub fn from_send_vars_method(s: SendVarsMethod) -> Option<Self> {
|
|
|
|
match s {
|
|
|
|
SendVarsMethod::None => None,
|
|
|
|
SendVarsMethod::Get => Some(Self::GET),
|
|
|
|
SendVarsMethod::Post => Some(Self::POST),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 19:24:04 +00:00
|
|
|
/// A backend interacting with a browser environment.
|
|
|
|
pub trait NavigatorBackend {
|
|
|
|
/// Cause a browser navigation to a given URL.
|
2019-09-17 03:37:11 +00:00
|
|
|
///
|
2019-09-01 19:24:04 +00:00
|
|
|
/// The URL given may be any URL scheme a browser can support. This may not
|
|
|
|
/// be meaningful for all environments: for example, `javascript:` URLs may
|
|
|
|
/// not be executable in a desktop context.
|
2019-09-17 03:37:11 +00:00
|
|
|
///
|
2019-09-01 19:24:04 +00:00
|
|
|
/// The `window` parameter, if provided, should be treated identically to
|
|
|
|
/// the `window` parameter on an HTML `<a>nchor` tag.
|
2019-09-17 03:37:11 +00:00
|
|
|
///
|
2019-09-01 19:24:04 +00:00
|
|
|
/// This function may be used to send variables to an eligible target. If
|
|
|
|
/// desired, the `vars_method` will be specified with a suitable
|
|
|
|
/// `NavigationMethod` and a key-value representation of the variables to
|
|
|
|
/// be sent. What the backend needs to do depends on the `NavigationMethod`:
|
2019-09-17 03:37:11 +00:00
|
|
|
///
|
2019-09-01 19:24:04 +00:00
|
|
|
/// * `GET` - Variables are appended onto the query parameters of the given
|
|
|
|
/// URL.
|
|
|
|
/// * `POST` - Variables are sent as form data in a POST request, as if the
|
|
|
|
/// user had filled out and submitted an HTML form.
|
2019-09-17 03:37:11 +00:00
|
|
|
///
|
2019-09-01 19:24:04 +00:00
|
|
|
/// Flash Player implemented sandboxing to prevent certain kinds of XSS
|
|
|
|
/// attacks. The `NavigatorBackend` is not responsible for enforcing this
|
|
|
|
/// sandbox.
|
2019-09-17 03:37:11 +00:00
|
|
|
fn navigate_to_url(
|
|
|
|
&self,
|
|
|
|
url: String,
|
|
|
|
window: Option<String>,
|
|
|
|
vars_method: Option<(NavigationMethod, HashMap<String, String>)>,
|
|
|
|
);
|
2019-09-01 19:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A null implementation for platforms that do not live in a web browser.
|
2019-09-17 03:37:11 +00:00
|
|
|
pub struct NullNavigatorBackend {}
|
2019-09-01 19:24:04 +00:00
|
|
|
|
|
|
|
impl NullNavigatorBackend {
|
|
|
|
pub fn new() -> Self {
|
2019-09-17 03:37:11 +00:00
|
|
|
NullNavigatorBackend {}
|
2019-09-01 19:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for NullNavigatorBackend {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NavigatorBackend for NullNavigatorBackend {
|
2019-09-17 03:37:11 +00:00
|
|
|
fn navigate_to_url(
|
|
|
|
&self,
|
|
|
|
_url: String,
|
|
|
|
_window: Option<String>,
|
|
|
|
_vars_method: Option<(NavigationMethod, HashMap<String, String>)>,
|
|
|
|
) {
|
2019-09-01 19:24:04 +00:00
|
|
|
}
|
2019-09-17 03:37:11 +00:00
|
|
|
}
|