-
Notifications
You must be signed in to change notification settings - Fork 331
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
Add request's reserved client and target client id #383
Conversation
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
@annevk, please take a look in line with the related changes to HTML and SW. |
So how can this be an environment settings object? Isn't this information what's used for the eventual creation of one? |
Also, if a reserved client knows the target browsing context, should we still provide that as a slot? |
I defined an algorithm setting up and returning an environment settings object that has different algorithms than those of browsing context/worker's environment settings object: whatwg/html@df5262b#diff-36cd38f49b9afa08222c0dc9ebfe35ebR77922
The reserved client's target browsing context just returns request's target browsing context which was set in https://html.spec.whatwg.org/#process-a-navigate-fetch step 2. The reason why reserved client should hold this information is that when a service worker gets this client later from |
This setup sounds a little weird. This object is passed along with a request but it echoes data from a request? Why wouldn't we just store that data on the object and create it together with the request? |
Do you mean we may use the target browsing context passed to "process a navigate fetch" directly to set up the object and delete the target browsing context internal slot from request? If so, I think that will work. FYI, this is the added step to set up the reserved object: whatwg/html@df5262b#diff-36cd38f49b9afa08222c0dc9ebfe35ebR82116 If I understood correctly, we may pass the target browsing context to this algorithm. |
I think what I'm saying is that if this object lives on a request, a request should not be used to create it. |
I understood. So, rather than passing a request to create an object, I'll change the object creation algorithm to take a request's url and target browsing context. Does that make sense? |
I guess. It seems a little weird to duplicate the URL field. I wonder if we're not better off if we keep some of these concepts distinct and not try to group them all together. An alternative would be that we just add some properties to request (perhaps grouped together) and at a different stage use those to create an environment settings object. |
request' url and request's reserved client's creation URL?
Could you be more specific with the idea? I'm curious if you don't want to use an environment settings object to represent a reserved client in the first place?
Which environment settings object do you mean? One for reserved client? Or one with the resulting fetched resource? |
Right. Also, what happens if we hit a redirect?
Yeah, it doesn't seem like it's entirely the right fit. Maybe it's better if we had a client concept that's either an environment settings object or a "reserved client", or some such. |
Before this patch, we didn't have a concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has its id, creation URL and target browsing context such that service workers' FetchEvent hanlder can reference this client information before the corresponding environmet setings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation - Set request's reserved client id such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it - Add Window object's active worker internal slot - Add WorkerGlobalObject's active worker internal slot - Add "match service worker registration" logic to attach controller Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - SW (WIP): w3c/ServiceWorker@df39d89 - Fetch: whatwg/fetch#383
22f9e68
to
4511e2e
Compare
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
Before this patch, we didn't have a concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has its id, creation URL and target browsing context such that service workers' FetchEvent hanlder can reference this client information before the corresponding environmet setings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation - Set request's reserved client id such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it - Add Window object's active worker internal slot - Add WorkerGlobalObject's active worker internal slot - Add "match service worker registration" logic to attach controller Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - SW (WIP): w3c/ServiceWorker@df39d89 - Fetch: whatwg/fetch#383
@annevk, I updated it back to use a reserved client (an environment) instead of just a reserved client id. Please check out whatwg/html#1776 (comment) Also, the last patch suggests we remove the target browsing context internal slot of the request. I presumed there's no usage of accessing this state yet and reserved client's target browsing context may be used for that purposed if necessary onwards. |
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
@@ -662,6 +662,15 @@ <h4 id=terminology-headers>Headers</h4> | |||
<span data-anolis-spec=html>environment settings object</span>). | |||
|
|||
<p>A <span title=concept-request>request</span> has an associated | |||
<dfn title=concept-request-reserved-client data-export data-dfn-for=request>reserved client</dfn> | |||
(null or an <span data-anolis-spec=html>environment</span> or an | |||
<span data-anolis-spec=html>environment settings object</span>). Unless stated otherwise it is null. |
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.
Preferred way is: (null, an x, or an xx)
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.
Done.
|
||
<p>A <span title=concept-request>request</span> has an associated | ||
<dfn title=concept-request-target-client-id data-export data-dfn-for=request>target client id</dfn> | ||
(null or a string). Unless stated otherwise it is null. |
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.
Can't we just use the empty string here? It's usually better to not change data types if not necessary.
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.
(That is, any JavaScript API for this should probably just return the empty string, and not return either a string or null.)
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.
Right. Missed that point. Addressed.
We should wait with this until HTML lands right? Otherwise the cross-references will lead nowhere. But it looks good. The only thing worth doing might be adding a note to each field mentioning that they are only useful for navigation (and worker?) requests and can be left alone otherwise. |
Right. HTML also cross-references to fetch (request's reserved client and target clientid). So, ideally they should land at the same time when both of them are good-to-go.
Will do! |
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
a39ace9
to
36a3288
Compare
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
<span data-anolis-spec=html>id</span> of the <span data-anolis-spec=html>target browsing | ||
context</span>'s <span data-anolis-spec=html>active document</span>'s | ||
<span data-anolis-spec=html>environment settings object</span> captured before entering the | ||
<span title=concept-fetch>fetch</span> algorithm. |
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 was about to merge, but I don't understand this. The target client ID isn't that a reserved ID of sorts?
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 discussed this during the f2f last month. This is used to expose the target client's id to fetch event's handler without the handle fetch having to cross the process border to get the target browsing context's document's environment's id from its own steps. The reserved client's target browsing context is used within SW's clients' method (like clients.get(reservedClientId)
) to get the target's active document's related window properties later.
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.
So to speak, it's used to initialize fetchEvent.targetClientId
without crossing the process border during running the handle fetch steps.
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.
But this ID goes away, right? This is the ID of the global that disappears somewhere during the navigation. (Disappears into history, that is.)
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.
Right. But having discussed with @jakearchibald, this is also a value we'd want to expose to devs to help maintaining their Caches (i.e. for the per-client cache control).
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.
Okay, thanks for confirming. Once the HTML PR has a commit message and is landed I'll merge this with a couple of minor tweaks.
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.
Sounds great. Thanks!
@annevk, I updated the commit message of this PR in the OP, too. |
Before this patch, there has been no concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has an id, a creation URL, a target browsing context, and an active service worker such that service workers' FetchEvent handlers can reference this client information before the corresponding environment settings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation; for worker creation requests, create an environment settings object and set the fields correspondingly - Set request's reserved client to the created environment or environment settings object such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it Note: The reserved client's active service worker is set, if available, during the fetch (in service worker's Handle Fetch algorithm). Related issue: w3c/ServiceWorker#870 Related change: whatwg/fetch#383
This patch defines request's reserved client id and target client id that are set to a reserved environment's id and the target browsing context's active document's settings object's id respectively during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - HTML: whatwg/html#1776 - SW (WIP): w3c/ServiceWorker@df39d89
The changes in HTML navigation algorithm creates an environment, store a matched active service worker in the environment, and passes the environment to fetch (in request's reserved client.) The access to this environment is needed to dispatch a FetchEvent to the matched service worker.
By adding the reserved client internal slot, the target browsing context in a request becomes redundant. * If request's target browsing context has other planned usages, ignore this patch.
c66b0f7
to
3e175d4
Compare
Thanks @jungkees, all good now. |
Looks good. Thanks! |
Before this patch, there has been no concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has an id, a creation URL, a target browsing context, and an active service worker such that service workers' FetchEvent handlers can reference this client information before the corresponding environment settings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation; for worker creation requests, create an environment settings object and set the fields correspondingly - Set request's reserved client to the created environment or environment settings object such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it Note: The reserved client's active service worker is set, if available, during the fetch (in service worker's Handle Fetch algorithm). Related issue: w3c/ServiceWorker#870 Related change: whatwg/fetch#383
Add request's reserved client and target client id
This patch defines the request's reserved client and the target client
id. The reserved client of a request is set to an environment or an
environment settings object during a navigation or a worker creation
request, respectively. The target client id of a request is set to the
target browsing context's active document's environment settings
object's id during a navigation. The given values are primarily used
to provide the reserved client's id and target client's id to service
workers' fetch event handlers.
This removes the request's target browsing context as the reserved
client provides the same information.
Related issue: w3c/ServiceWorker#870
Related change: whatwg/html#1776