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() diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index 5ccd72d087d..328c54b1c2e 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -81,7 +81,7 @@ partial /*sealed*/ interface Document { // resource metadata management // [PutForwards=href, Unforgeable] readonly attribute Location/*?*/ location; - // attribute DOMString domain; + readonly attribute DOMString domain; // readonly attribute DOMString referrer; [Throws] attribute DOMString cookie; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 40ae2ccd47e..f9e15ea99fb 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -29953,6 +29953,12 @@ "deleted": [], "items": { "testharness": { + "html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html": [ + { + "path": "html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html", + "url": "/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html" + } + ], "html/semantics/forms/form-submission-0/url-encoded.html": [ { "path": "html/semantics/forms/form-submission-0/url-encoded.html", diff --git a/tests/wpt/metadata/XMLHttpRequest/send-after-setting-document-domain.htm.ini b/tests/wpt/metadata/XMLHttpRequest/send-after-setting-document-domain.htm.ini deleted file mode 100644 index 4114af649a9..00000000000 --- a/tests/wpt/metadata/XMLHttpRequest/send-after-setting-document-domain.htm.ini +++ /dev/null @@ -1,5 +0,0 @@ -[send-after-setting-document-domain.htm] - type: testharness - [loading documents from original origin after setting document.domain] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html.ini b/tests/wpt/metadata/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html.ini new file mode 100644 index 00000000000..81f58d2ecba --- /dev/null +++ b/tests/wpt/metadata/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html.ini @@ -0,0 +1,4 @@ +[document_domain.html] + type: testharness + [new document] + expected: FAIL diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index eedba2f8c04..8f863d110c5 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -9003,9 +9003,6 @@ [Document interface: document.implementation.createDocument(null, "", null) must inherit property "enableStyleSheetsForSet" with the proper type (33)] expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "domain" with the proper type (35)] - expected: FAIL - [Document interface: document.implementation.createDocument(null, "", null) must inherit property "referrer" with the proper type (36)] expected: FAIL diff --git a/tests/wpt/web-platform-tests/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html b/tests/wpt/web-platform-tests/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html new file mode 100644 index 00000000000..af933217336 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html @@ -0,0 +1,25 @@ + + + + + + + + + + +