diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2016-04-21 00:18:37 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2016-04-23 20:27:58 +0200 |
commit | 7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3 (patch) | |
tree | d486c090f3287be1036f2aea0f544b65ec95d43e /components/script/origin.rs | |
parent | 305c283602882850be9d39c43b980d0fc0f93a3c (diff) | |
download | servo-7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3.tar.gz servo-7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3.zip |
Upgrade to rust-url 1.0 and hyper 0.9
Diffstat (limited to 'components/script/origin.rs')
-rw-r--r-- | components/script/origin.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/components/script/origin.rs b/components/script/origin.rs index 096ffbbd6fb..97e03162679 100644 --- a/components/script/origin.rs +++ b/components/script/origin.rs @@ -2,9 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::cell::RefCell; +use ref_filter_map::ref_filter_map; +use std::cell::{RefCell, Ref}; use std::rc::Rc; -use url::{OpaqueOrigin, Origin as UrlOrigin}; +use url::Origin as UrlOrigin; use url::{Url, Host}; /// A representation of an [origin](https://html.spec.whatwg.org/multipage/#origin-2). @@ -21,9 +22,8 @@ no_jsmanaged_fields!(Origin); impl Origin { /// Create a new origin comprising a unique, opaque identifier. pub fn opaque_identifier() -> Origin { - let opaque = UrlOrigin::UID(OpaqueOrigin::new()); Origin { - inner: Rc::new(RefCell::new(opaque)), + inner: Rc::new(RefCell::new(UrlOrigin::new_opaque())), } } @@ -40,18 +40,15 @@ impl Origin { /// Does this origin represent a host/scheme/port tuple? pub fn is_scheme_host_port_tuple(&self) -> bool { - match *self.inner.borrow() { - UrlOrigin::Tuple(..) => true, - UrlOrigin::UID(..) => false, - } + self.inner.borrow().is_tuple() } /// Return the host associated with this origin. - pub fn host(&self) -> Option<Host> { - match *self.inner.borrow() { - UrlOrigin::Tuple(_, ref host, _) => Some(host.clone()), - UrlOrigin::UID(..) => None, - } + pub fn host(&self) -> Option<Ref<Host<String>>> { + ref_filter_map(self.inner.borrow(), |origin| match *origin { + UrlOrigin::Tuple(_, ref host, _) => Some(host), + UrlOrigin::Opaque(..) => None, + }) } /// https://html.spec.whatwg.org/multipage/#same-origin |