diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-01 22:51:51 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-01 22:51:51 +0530 |
commit | 7d79df4a05948e0ce6e3abc6bef0f833d8bf541e (patch) | |
tree | da2adbe296aba690add7a8d3cd0402447a2a5d1f /components/script/dom/document.rs | |
parent | 0397e2a24d3e5c988b089ef100002397f4cabdfa (diff) | |
parent | 3c6cc642ee43375fecb191004b49bedf1b6c4146 (diff) | |
download | servo-7d79df4a05948e0ce6e3abc6bef0f833d8bf541e.tar.gz servo-7d79df4a05948e0ce6e3abc6bef0f833d8bf541e.zip |
Auto merge of #10304 - Ms2ger:cookie-averse, r=nox
Implement Document::cookie correctly for cookie-averse documents.
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10304)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a24580d0f95..12b47cf4d96 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1467,6 +1467,19 @@ impl Document { let target = node.upcast(); event.fire(target); } + + /// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object + fn is_cookie_averse(&self) -> bool { + /// https://url.spec.whatwg.org/#network-scheme + fn url_has_network_scheme(url: &Url) -> bool { + match &*url.scheme { + "ftp" | "http" | "https" => true, + _ => false, + } + } + + self.browsing_context.is_none() || !url_has_network_scheme(&self.url) + } } #[derive(PartialEq, HeapSizeOf)] @@ -2397,7 +2410,10 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-cookie fn GetCookie(&self) -> Fallible<DOMString> { - // TODO: return empty string for cookie-averse Document + if self.is_cookie_averse() { + return Ok(DOMString::new()); + } + let url = self.url(); if !is_scheme_host_port_tuple(&url) { return Err(Error::Security); @@ -2410,7 +2426,10 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-cookie fn SetCookie(&self, cookie: DOMString) -> ErrorResult { - // TODO: ignore for cookie-averse Document + if self.is_cookie_averse() { + return Ok(()); + } + let url = self.url(); if !is_scheme_host_port_tuple(url) { return Err(Error::Security); |