Repository navigation
script: initial CookieStore implementation - #37968
Conversation
| DeleteCookies(ServoUrl), | ||
| DeleteCookie(ServoUrl, String), | ||
| DeleteCookieAsync(CookieStoreId, CookieRequestId, ServoUrl, String), | ||
| NewCookieListener(CookieStoreId, IpcSender<CookieAsyncResponse>, ServoUrl), |
There was a problem hiding this comment.
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.
yes that sounds like a good idea.
There was a problem hiding this comment.
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.
Yeah, I noticed that I forgot to wire this up yesterday. I'll look at adding this to the drop
gterzian
left a comment
There was a problem hiding this comment.
Looks great so far, thank you.
How do you want to scope this PR?
| // 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.
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.
| .or_init(|| Storage::new(self, StorageType::Local, CanGc::note())) | ||
| } | ||
|
|
||
| // https://wicg.github.io/cookie-store/ |
There was a problem hiding this comment.
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.
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
gterzian
left a comment
There was a problem hiding this comment.
Some initial commend; I'll take another look later today.
| } | ||
|
|
||
| // https://cookiestore.spec.whatwg.org/#Window | ||
| fn CookieStore(&self) -> DomRoot<CookieStore> { |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
We should add a TODO to actually call into UTF-8 decode without BOM
| ); | ||
| return; | ||
| } | ||
| let _ = sender.unwrap().send(CookieAsyncResponse { data }); |
There was a problem hiding this comment.
It's nicer to do a Let Some() = else
gterzian
left a comment
There was a problem hiding this comment.
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.
| .collect_vec(), | ||
| CanGc::note()); | ||
| }, | ||
| _ => {promise.resolve_native(&(), CanGc::note());} |
There was a problem hiding this comment.
I think it's better yo be explicit here.
| } | ||
|
|
||
| struct CookieListener { | ||
| task_source: SendableTaskSource, |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Ok, I guess we can then leave it as it, and revisit when the others parts are implemented.
| Some(name.to_string()), | ||
| )); | ||
| if res.is_err() { | ||
| self.in_flight.borrow_mut().pop_back(); |
There was a problem hiding this comment.
I would it's simpler to only push it back if the send is ok.
There was a problem hiding this comment.
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