mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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 -->
This commit is contained in:
commit
7d79df4a05
2 changed files with 21 additions and 7 deletions
|
@ -1467,6 +1467,19 @@ impl Document {
|
||||||
let target = node.upcast();
|
let target = node.upcast();
|
||||||
event.fire(target);
|
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)]
|
#[derive(PartialEq, HeapSizeOf)]
|
||||||
|
@ -2397,7 +2410,10 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
||||||
fn GetCookie(&self) -> Fallible<DOMString> {
|
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();
|
let url = self.url();
|
||||||
if !is_scheme_host_port_tuple(&url) {
|
if !is_scheme_host_port_tuple(&url) {
|
||||||
return Err(Error::Security);
|
return Err(Error::Security);
|
||||||
|
@ -2410,7 +2426,10 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
||||||
fn SetCookie(&self, cookie: DOMString) -> ErrorResult {
|
fn SetCookie(&self, cookie: DOMString) -> ErrorResult {
|
||||||
// TODO: ignore for cookie-averse Document
|
if self.is_cookie_averse() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let url = self.url();
|
let url = self.url();
|
||||||
if !is_scheme_host_port_tuple(url) {
|
if !is_scheme_host_port_tuple(url) {
|
||||||
return Err(Error::Security);
|
return Err(Error::Security);
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[document-cookie.html]
|
|
||||||
type: testharness
|
|
||||||
[getting cookie for a cookie-averse document returns empty string, setting does nothing]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue