Remove some useless Option<T> wrappers from ServoUrl methods

This commit is contained in:
Anthony Ramine 2017-03-25 14:43:28 +01:00
parent bc5c4fa892
commit 54d37d920c
6 changed files with 34 additions and 56 deletions

View file

@ -192,7 +192,7 @@ pub fn main_fetch(request: Rc<Request>,
.read() .read()
.unwrap() .unwrap()
.is_host_secure(request.current_url().domain().unwrap()) { .is_host_secure(request.current_url().domain().unwrap()) {
request.url_list.borrow_mut().last_mut().unwrap().as_mut_url().unwrap().set_scheme("https").unwrap(); request.url_list.borrow_mut().last_mut().unwrap().as_mut_url().set_scheme("https").unwrap();
} }
} }

View file

@ -129,7 +129,7 @@ impl NetworkHttpRequestFactory {
fn create(&self, url: ServoUrl, method: Method, headers: Headers) fn create(&self, url: ServoUrl, method: Method, headers: Headers)
-> Result<HyperRequest<Fresh>, NetworkError> { -> Result<HyperRequest<Fresh>, NetworkError> {
let connection = HyperRequest::with_connector(method, let connection = HyperRequest::with_connector(method,
url.clone().into_url().unwrap(), url.clone().into_url(),
&*self.connector); &*self.connector);
if let Err(HttpError::Ssl(ref error)) = connection { if let Err(HttpError::Ssl(ref error)) = connection {
@ -222,7 +222,7 @@ fn strict_origin_when_cross_origin(referrer_url: ServoUrl, url: ServoUrl) -> Opt
fn strip_url(mut referrer_url: ServoUrl, origin_only: bool) -> Option<ServoUrl> { fn strip_url(mut referrer_url: ServoUrl, origin_only: bool) -> Option<ServoUrl> {
if referrer_url.scheme() == "https" || referrer_url.scheme() == "http" { if referrer_url.scheme() == "https" || referrer_url.scheme() == "http" {
{ {
let referrer = referrer_url.as_mut_url().unwrap(); let referrer = referrer_url.as_mut_url();
referrer.set_username("").unwrap(); referrer.set_username("").unwrap();
referrer.set_password(None).unwrap(); referrer.set_password(None).unwrap();
referrer.set_fragment(None); referrer.set_fragment(None);

View file

@ -384,12 +384,12 @@ impl HTMLFormElement {
fn mutate_action_url(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData, encoding: EncodingRef) { fn mutate_action_url(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData, encoding: EncodingRef) {
let charset = &*encoding.whatwg_name().unwrap(); let charset = &*encoding.whatwg_name().unwrap();
if let Some(ref mut url) = load_data.url.as_mut_url() { load_data.url
url.query_pairs_mut().clear() .as_mut_url()
.query_pairs_mut().clear()
.encoding_override(Some(self.pick_encoding())) .encoding_override(Some(self.pick_encoding()))
.extend_pairs(form_data.into_iter() .extend_pairs(form_data.into_iter()
.map(|field| (field.name.clone(), field.replace_value(charset)))); .map(|field| (field.name.clone(), field.replace_value(charset))));
}
self.plan_to_navigate(load_data); self.plan_to_navigate(load_data);
} }
@ -403,13 +403,12 @@ impl HTMLFormElement {
let charset = &*encoding.whatwg_name().unwrap(); let charset = &*encoding.whatwg_name().unwrap();
load_data.headers.set(ContentType::form_url_encoded()); load_data.headers.set(ContentType::form_url_encoded());
load_data.url
if let Some(ref mut url) = load_data.url.as_mut_url() { .as_mut_url()
url.query_pairs_mut().clear() .query_pairs_mut().clear()
.encoding_override(Some(self.pick_encoding())) .encoding_override(Some(self.pick_encoding()))
.extend_pairs(form_data.into_iter() .extend_pairs(form_data.into_iter()
.map(|field| (field.name.clone(), field.replace_value(charset)))); .map(|field| (field.name.clone(), field.replace_value(charset))));
}
load_data.url.query().unwrap_or("").to_string().into_bytes() load_data.url.query().unwrap_or("").to_string().into_bytes()
} }

View file

@ -52,9 +52,8 @@ impl URL {
} }
pub fn set_query_pairs(&self, pairs: &[(String, String)]) { pub fn set_query_pairs(&self, pairs: &[(String, String)]) {
if let Some(ref mut url) = self.url.borrow_mut().as_mut_url() { let mut url = self.url.borrow_mut();
url.query_pairs_mut().clear().extend_pairs(pairs); url.as_mut_url().query_pairs_mut().clear().extend_pairs(pairs);
}
} }
} }

View file

@ -45,49 +45,31 @@ impl UrlHelper {
USVString(quirks::username(url.as_url()).to_owned()) USVString(quirks::username(url.as_url()).to_owned())
} }
pub fn SetHash(url: &mut ServoUrl, value: USVString) { pub fn SetHash(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { quirks::set_hash(url.as_mut_url(), &value.0)
quirks::set_hash(url, &value.0)
}
} }
pub fn SetHost(url: &mut ServoUrl, value: USVString) { pub fn SetHost(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_host(url.as_mut_url(), &value.0);
let _ = quirks::set_host(url, &value.0);
}
} }
pub fn SetPort(url: &mut ServoUrl, value: USVString) { pub fn SetPort(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_port(url.as_mut_url(), &value.0);
let _ = quirks::set_port(url, &value.0);
}
} }
pub fn SetSearch(url: &mut ServoUrl, value: USVString) { pub fn SetSearch(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { quirks::set_search(url.as_mut_url(), &value.0)
quirks::set_search(url, &value.0)
}
} }
pub fn SetPathname(url: &mut ServoUrl, value: USVString) { pub fn SetPathname(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { quirks::set_pathname(url.as_mut_url(), &value.0)
quirks::set_pathname(url, &value.0)
}
} }
pub fn SetHostname(url: &mut ServoUrl, value: USVString) { pub fn SetHostname(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_hostname(url.as_mut_url(), &value.0);
let _ = quirks::set_hostname(url, &value.0);
}
} }
pub fn SetPassword(url: &mut ServoUrl, value: USVString) { pub fn SetPassword(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_password(url.as_mut_url(), &value.0);
let _ = quirks::set_password(url, &value.0);
}
} }
pub fn SetProtocol(url: &mut ServoUrl, value: USVString) { pub fn SetProtocol(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_protocol(url.as_mut_url(), &value.0);
let _ = quirks::set_protocol(url, &value.0);
}
} }
pub fn SetUsername(url: &mut ServoUrl, value: USVString) { pub fn SetUsername(url: &mut ServoUrl, value: USVString) {
if let Some(ref mut url) = url.as_mut_url() { let _ = quirks::set_username(url.as_mut_url(), &value.0);
let _ = quirks::set_username(url, &value.0);
}
} }
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy // https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
pub fn is_origin_trustworthy(url: &ServoUrl) -> bool { pub fn is_origin_trustworthy(url: &ServoUrl) -> bool {

View file

@ -47,10 +47,8 @@ impl ServoUrl {
Arc::try_unwrap(self.0).unwrap_or_else(|s| (*s).clone()).into_string() Arc::try_unwrap(self.0).unwrap_or_else(|s| (*s).clone()).into_string()
} }
// NOTE: These methods return options that are always true temporarily until pub fn into_url(self) -> Url {
// we special-case some urls to avoid going through rust-url. Arc::try_unwrap(self.0).unwrap_or_else(|s| (*s).clone())
pub fn into_url(self) -> Option<Url> {
Some(Arc::try_unwrap(self.0).unwrap_or_else(|s| (*s).clone()))
} }
pub fn as_url(&self) -> &Url { pub fn as_url(&self) -> &Url {
@ -94,24 +92,24 @@ impl ServoUrl {
self.0.as_str() self.0.as_str()
} }
pub fn as_mut_url(&mut self) -> Option<&mut Url> { pub fn as_mut_url(&mut self) -> &mut Url {
Some(Arc::make_mut(&mut self.0)) Arc::make_mut(&mut self.0)
} }
pub fn set_username(&mut self, user: &str) -> Result<(), ()> { pub fn set_username(&mut self, user: &str) -> Result<(), ()> {
Arc::make_mut(&mut self.0).set_username(user) self.as_mut_url().set_username(user)
} }
pub fn set_ip_host(&mut self, addr: IpAddr) -> Result<(), ()> { pub fn set_ip_host(&mut self, addr: IpAddr) -> Result<(), ()> {
Arc::make_mut(&mut self.0).set_ip_host(addr) self.as_mut_url().set_ip_host(addr)
} }
pub fn set_password(&mut self, pass: Option<&str>) -> Result<(), ()> { pub fn set_password(&mut self, pass: Option<&str>) -> Result<(), ()> {
Arc::make_mut(&mut self.0).set_password(pass) self.as_mut_url().set_password(pass)
} }
pub fn set_fragment(&mut self, fragment: Option<&str>) { pub fn set_fragment(&mut self, fragment: Option<&str>) {
Arc::make_mut(&mut self.0).set_fragment(fragment) self.as_mut_url().set_fragment(fragment)
} }
pub fn username(&self) -> &str { pub fn username(&self) -> &str {