diff options
Diffstat (limited to 'components/script/dom/urlhelper.rs')
-rw-r--r-- | components/script/dom/urlhelper.rs | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/components/script/dom/urlhelper.rs b/components/script/dom/urlhelper.rs index 4376a85e390..684d6666e0c 100644 --- a/components/script/dom/urlhelper.rs +++ b/components/script/dom/urlhelper.rs @@ -4,7 +4,9 @@ use dom::bindings::str::USVString; -use url::{Url, SchemeData}; +use url::{Url, UrlParser, SchemeData}; + +use url::urlutils::{UrlUtils, UrlUtilsWrapper}; use std::borrow::ToOwned; use std::fmt::Write; @@ -22,6 +24,12 @@ impl UrlHelper { }) } + // https://url.spec.whatwg.org/#dom-urlutils-hash + pub fn SetHash(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_fragment(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-host pub fn Host(url: &Url) -> USVString { USVString(match url.scheme_data { @@ -36,11 +44,23 @@ impl UrlHelper { }) } + // https://url.spec.whatwg.org/#dom-urlutils-host + pub fn SetHost(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_host(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-hostname pub fn Hostname(url: &Url) -> USVString { USVString(url.serialize_host().unwrap_or_else(|| "".to_owned())) } + // https://url.spec.whatwg.org/#dom-urlutils-hostname + pub fn SetHostname(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_host_and_port(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-href pub fn Href(url: &Url) -> USVString { USVString(url.serialize()) @@ -51,15 +71,26 @@ impl UrlHelper { USVString(url.password().unwrap_or("").to_owned()) } + // https://url.spec.whatwg.org/#dom-urlutils-password + pub fn SetPassword(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_password(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-pathname pub fn Pathname(url: &Url) -> USVString { - // FIXME: Url null check is skipped for now USVString(match url.scheme_data { SchemeData::NonRelative(ref scheme_data) => scheme_data.clone(), SchemeData::Relative(..) => url.serialize_path().unwrap() }) } + // https://url.spec.whatwg.org/#dom-urlutils-pathname + pub fn SetPathname(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_path(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-port pub fn Port(url: &Url) -> USVString { USVString(match url.port() { @@ -68,11 +99,23 @@ impl UrlHelper { }) } + // https://url.spec.whatwg.org/#dom-urlutils-port + pub fn SetPort(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_port(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-protocol pub fn Protocol(url: &Url) -> USVString { USVString(format!("{}:", url.scheme.clone())) } + // https://url.spec.whatwg.org/#dom-urlutils-protocol + pub fn SetProtocol(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_scheme(&value.0); + } + // https://html.spec.whatwg.org/multipage/#same-origin pub fn SameOrigin(urlA: &Url, urlB: &Url) -> bool { if urlA.host() != urlB.host() { @@ -96,8 +139,20 @@ impl UrlHelper { }) } + // https://url.spec.whatwg.org/#dom-urlutils-search + pub fn SetSearch(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_query(&value.0); + } + // https://url.spec.whatwg.org/#dom-urlutils-username pub fn Username(url: &Url) -> USVString { USVString(url.username().unwrap_or("").to_owned()) } + + // https://url.spec.whatwg.org/#dom-urlutils-username + pub fn SetUsername(url: &mut Url, value: USVString) { + let mut wrapper = UrlUtilsWrapper { url: url, parser: &UrlParser::new() }; + let _ = wrapper.set_username(&value.0); + } } |