-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
script: initial CookieStore implementation #37968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
DeleteCookies(ServoUrl), | ||
DeleteCookie(ServoUrl, String), | ||
DeleteCookieAsync(CookieStoreId, CookieRequestId, ServoUrl, String), | ||
NewCookieListener(CookieStoreId, IpcSender<CookieAsyncResponse>, ServoUrl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For lifecycle management I believe I will also need a RemoveCookieListener
message for when a global navigates to a new page. The spec makes clear that CookieStore's relevant URL is the global's creation_url
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that sounds like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you currently sending that message? I think it could be done on drop of the global.
EDIT: drop of the cookiestore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I noticed that I forgot to wire this up yesterday. I'll look at adding this to the drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far, thank you.
How do you want to scope this PR?
components/script/dom/cookiestore.rs
Outdated
// 1. Perform the steps defined in Cookies § Retrieval Model to compute the "cookie-string from a given cookie | ||
// store" with url as request-uri. The cookie-string itself is ignored, but the intermediate cookie-list is | ||
// used in subsequent steps. | ||
// For the purposes of the steps, the cookie-string is being generated for a "non-HTTP" API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also belongs in resource threads, and instead I would just document the method with a note on sending a message to run the "in-parallel" steps.
components/script/dom/window.rs
Outdated
.or_init(|| Storage::new(self, StorageType::Local, CanGc::note())) | ||
} | ||
|
||
// https://wicg.github.io/cookie-store/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct link is https://wicg.github.io/cookie-store/#dom-window-cookiestore(and format is wrong also).
DeleteCookies(ServoUrl), | ||
DeleteCookie(ServoUrl, String), | ||
DeleteCookieAsync(CookieStoreId, CookieRequestId, ServoUrl, String), | ||
NewCookieListener(CookieStoreId, IpcSender<CookieAsyncResponse>, ServoUrl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that sounds like a good idea.
I think the goal for this PR is going to be setting up the infrastructure needed to be able to do the most minimal Set-Get-Delete implementation. The change event listener is definitely going to be in a follow up |
Sounds good. |
3da8cfe
to
5bb0b8b
Compare
5bb0b8b
to
29d7c76
Compare
29d7c76
to
803abad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial commend; I'll take another look later today.
components/script/dom/window.rs
Outdated
} | ||
|
||
// https://cookiestore.spec.whatwg.org/#Window | ||
fn CookieStore(&self) -> DomRoot<CookieStore> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can pass a can_gc argument using Bindings.conf
.
self.store_id, | ||
global.creation_url().clone(), | ||
options.name.to_string(), | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and elsewhere you could log an error if the send fails. In theory it never should.
creation_url.clone(), | ||
Serde(cookie.build()), | ||
NonHTTP, | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it fails you probably want to. remove the inflight promise as well, and reject it with an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah probably just going to make a small helper for this then. I wish there was a nice way to make this a type/lifetime error somehow.
p.reject_error(Error::Security, can_gc); | ||
return p; | ||
} | ||
// 4. Let url be settings’s creation URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I always add a line between the last line of code and the next comment.
fn cookie_to_list_item(cookie: Cookie) -> CookieListItem { | ||
CookieListItem { | ||
// Let domain be the result of running UTF-8 decode without BOM on cookie’s domain. | ||
domain: cookie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a TODO to actually call into UTF-8 decode without BOM
components/net/resource_thread.rs
Outdated
); | ||
return; | ||
} | ||
let _ = sender.unwrap().send(CookieAsyncResponse { data }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nicer to do a Let Some() = else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, thank you. I might spend some time looking at the spec again and into some things mentioned below, in the meantime let's address the current comments.
components/script/dom/cookiestore.rs
Outdated
.collect_vec(), | ||
CanGc::note()); | ||
}, | ||
_ => {promise.resolve_native(&(), CanGc::note());} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better yo be explicit here.
} | ||
|
||
struct CookieListener { | ||
task_source: SendableTaskSource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document which task source this is, and add a link to the spec is such an appropriate link exists
DeleteCookies(ServoUrl), | ||
DeleteCookie(ServoUrl, String), | ||
DeleteCookieAsync(CookieStoreId, CookieRequestId, ServoUrl, String), | ||
NewCookieListener(CookieStoreId, IpcSender<CookieAsyncResponse>, ServoUrl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you currently sending that message? I think it could be done on drop of the global.
EDIT: drop of the cookiestore.
.send(CoreResourceMsg::GetCookieDataForUrlAsync( | ||
self.store_id, | ||
creation_url.clone(), | ||
Some(name.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I'm not quite sure how to make this work with the decoding that happens later in parallel. Should we do the decoding before turning it into a string, which means decoding it here, or can we do it later on the string in parallel. But rust strings are already utf8 I believe. Needs some looking into. Any relevant tests failing at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the only encoding/decoding tests that exist are checking if we strip the BOM from the name and we currently pass the test. (We don't strip it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some UTF8 encoding checks in the tests for the cookie change events, which we haven't implemented at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I guess we can then leave it as it, and revisit when the others parts are implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one nit; thank you.
components/script/dom/cookiestore.rs
Outdated
Some(name.to_string()), | ||
)); | ||
if res.is_err() { | ||
self.in_flight.borrow_mut().pop_back(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would it's simpler to only push it back if the send is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I do like that a bit more, since now the pattern is consistent about pushing back if we send a message. Now anytime we send a message we always have a pattern to check to make sure we also stored a promise.
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
Signed-off-by: Sebastian C <sebsebmc@gmail.com>
8808ff4
to
b28d6a5
Compare
Not sure what happened there, is that just a flake on the MacOS runner? |
Wild. Never seen that before! Let's try again. |
This is a first draft at implementing the required infrastructure for CookieStore, which requires setting up IPC between script and the resource thread to allow for async/"in parallel" handling of cookie changes that have a promise API.
Cookie Store also will need to receive change events when cookies for a url are changed so the architecture needs to support that.
Expect this PR to be reworked once the architecture becomes more settled, cookie change events will be implemented in follow up PRs
Testing: WPT tests exist for this API
Part of #37674