diff options
author | Tom Schuster <evilpies@gmail.com> | 2015-07-30 00:36:29 +0200 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-11-23 15:45:02 -0500 |
commit | 0e0e051f3f88c8c5238ffee0412dd880d980fe0d (patch) | |
tree | 16acf228c101aa4769e0003e3b7c7ee53959cba7 /components/script/dom/document.rs | |
parent | e3eee5a41b2bc6e3517cdcdc745d74c59a82e76e (diff) | |
download | servo-0e0e051f3f88c8c5238ffee0412dd880d980fe0d.tar.gz servo-0e0e051f3f88c8c5238ffee0412dd880d980fe0d.zip |
Implement document.domain getter
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1fda0761c66..be57cf45ae4 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -105,7 +105,7 @@ use string_cache::{Atom, QualName}; use style::restyle_hints::ElementSnapshot; use style::stylesheets::Stylesheet; use time; -use url::Url; +use url::{Host, Url}; use util::str::{DOMString, split_html_space_chars, str_join}; #[derive(JSTraceable, PartialEq, HeapSizeOf)] @@ -1647,6 +1647,19 @@ impl DocumentMethods for Document { } } + // https://html.spec.whatwg.org/multipage/#relaxing-the-same-origin-restriction + fn Domain(&self) -> DOMString { + // TODO: This should use the effective script origin when it exists + let origin = self.window.get_url(); + + if let Some(&Host::Ipv6(ipv6)) = origin.host() { + // Omit square brackets for IPv6 addresses. + return DOMString::from(ipv6.serialize()); + } + + DOMString::from(origin.serialize_host().unwrap_or_else(|| "".to_owned())) + } + // https://dom.spec.whatwg.org/#dom-document-documenturi fn DocumentURI(&self) -> DOMString { self.URL() |