Skip to content
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

Merged
merged 6 commits into from
Oct 24, 2016

Conversation

jungkees
Copy link
Contributor

@jungkees jungkees commented Sep 13, 2016

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

jungkees added a commit to w3c/ServiceWorker that referenced this pull request Sep 13, 2016
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.
@jungkees
Copy link
Contributor Author

@annevk, please take a look in line with the related changes to HTML and SW.

@annevk
Copy link
Member

annevk commented Sep 13, 2016

So how can this be an environment settings object? Isn't this information what's used for the eventual creation of one?

@annevk
Copy link
Member

annevk commented Sep 13, 2016

Also, if a reserved client knows the target browsing context, should we still provide that as a slot?

@jungkees
Copy link
Contributor Author

So how can this be an environment settings object? Isn't this information what's used for the eventual creation of one?

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 id will be used to set the actual environment settings object's id when it's created later. Also, I wanted it to be a type of an environment settings object as we should be able to enumerate these client objects in the service worker steps: get(id), matchAll(), etc.

Also, if a reserved client knows the target browsing context, should we still provide that as a slot?

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 clients.get(id) or clients.matchAll(), it won't have any reference to the original request. (We plan to use the state of the active document of the target browsing context for WinodwClient's properties associated with the reserved client.)

@annevk
Copy link
Member

annevk commented Sep 13, 2016

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?

@jungkees
Copy link
Contributor Author

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.

@annevk
Copy link
Member

annevk commented Sep 14, 2016

I think what I'm saying is that if this object lives on a request, a request should not be used to create it.

@jungkees
Copy link
Contributor Author

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?

@annevk
Copy link
Member

annevk commented Sep 14, 2016

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.

@jungkees
Copy link
Contributor Author

It seems a little weird to duplicate the URL field.

request' url and request's reserved client's creation URL?

I wonder if we're not better off if we keep some of these concepts distinct and not try to group them all together.

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?

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.

Which environment settings object do you mean? One for reserved client? Or one with the resulting fetched resource?

@annevk
Copy link
Member

annevk commented Sep 14, 2016

request' url and request's reserved client's creation URL?

Right. Also, what happens if we hit a redirect?

I'm curious if you don't want to use an environment settings object to represent a reserved client in the first place?

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.

jungkees added a commit to jungkees/html that referenced this pull request Sep 28, 2016
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
jungkees added a commit to w3c/ServiceWorker that referenced this pull request Oct 6, 2016
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.
jungkees added a commit to jungkees/html that referenced this pull request Oct 13, 2016
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
@jungkees
Copy link
Contributor Author

@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.

jungkees added a commit to w3c/ServiceWorker that referenced this pull request Oct 13, 2016
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.
Copy link
Member

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)

Copy link
Contributor Author

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.
Copy link
Member

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.

Copy link
Member

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.)

Copy link
Contributor Author

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.

@annevk
Copy link
Member

annevk commented Oct 13, 2016

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.

@jungkees
Copy link
Contributor Author

We should wait with this until HTML lands right? Otherwise the cross-references will lead nowhere.

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.

The only thing worth doing might be adding a note to each field

Will do!

jungkees added a commit to w3c/ServiceWorker that referenced this pull request Oct 13, 2016
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.
jungkees added a commit to w3c/ServiceWorker that referenced this pull request Oct 14, 2016
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.
jungkees added a commit to w3c/ServiceWorker that referenced this pull request Oct 14, 2016
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 annevk mentioned this pull request Oct 24, 2016
<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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@jungkees jungkees Oct 24, 2016

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.

Copy link
Member

@annevk annevk Oct 24, 2016

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.)

Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great. Thanks!

@jungkees jungkees changed the title Add request's reserved client Add request's reserved client and target client id Oct 24, 2016
@jungkees
Copy link
Contributor Author

@annevk, I updated the commit message of this PR in the OP, too.

annevk pushed a commit to whatwg/html that referenced this pull request Oct 24, 2016
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
jungkees and others added 6 commits October 24, 2016 13:56
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.
@annevk annevk merged commit fb87b70 into whatwg:master Oct 24, 2016
@annevk
Copy link
Member

annevk commented Oct 24, 2016

Thanks @jungkees, all good now.

@jungkees
Copy link
Contributor Author

Looks good. Thanks!

@jungkees jungkees deleted the add-reserved-client branch October 24, 2016 12:03
alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants