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 ServiceWorkerRegistration.id and supporting algorithm changes. (Fixes #1512) #1526

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

wanderview
Copy link
Member

@wanderview wanderview commented Jul 31, 2020

This commit adds support for a registration id value. This will be used to uniquely identify registrations
instead of scope. This will make it easier for a developer to migrate a registration from one scope to
another.

The commit consists of the following changes:

  • Add a DOMString id and associated getter to the registration.
  • Add an origin to the internal registration type.
  • Move the scope internal representation to ServiceWorker and add a new getter.
  • Make the ServiceWorkerRegistration.scope return the oldest associated worker's scope.
  • Migrate the registration map to be keyed by the tuple (origin,id).
  • Migrate the job queue map to be keyed by the tuple (origin,id).
  • Adjust job equality checks to treat register jobs to account for new id and scope semantics.
  • Support changing the scope during register operations.
  • Reject register operations that change the scope to a value that is already in use by another registration.
  • Properly un-control clients whose URL no longer matches a new active worker's scope.

Preview | Diff


Preview | Diff

@sideshowbarker
Copy link
Contributor

Hi Ben. There’s some W3C tooling that doesn’t yet recognize you on GitHub, but you can fix it by going to to https://www.w3.org/users/myprofile to log into your W3C account — and from there, follow the Connected Accounts link in the sidebar to connect your W3C account with your GitHub account.

@ylafon
Copy link
Member

ylafon commented Aug 2, 2020

Marked as non substantive for IPR from ash-nazg.

@wanderview
Copy link
Member Author

Thanks, I've connected my account.

@wanderview wanderview changed the title DO NOT MERGE - Add id to ServiceWorkerRegistration. (Fixes #1512) Add ServiceWorkerRegistration.id and supporting algorithm changes. (Fixes #1512) Aug 14, 2020
@wanderview wanderview marked this pull request as ready for review August 14, 2020 21:24
Copy link
Contributor

@jakearchibald jakearchibald left a comment

Choose a reason for hiding this comment

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

Mostly prose nits. The only real concern is the backwards compatibility break with reg.scope.

docs/index.bs Outdated Show resolved Hide resolved
@@ -208,9 +210,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
<section dfn-for="service worker registration">
<h3 id="service-worker-registration-concept">Service Worker Registration</h3>

A <dfn export id="dfn-service-worker-registration" for="">service worker registration</dfn> is a tuple of a [=service worker registration/scope url=] and a set of [=/service workers=], an <a>installing worker</a>, a <a>waiting worker</a>, and an <a>active worker</a>. A user agent *may* enable many [=/service worker registrations=] at a single origin so long as the [=service worker registration/scope url=] of the [=/service worker registration=] differs. A [=/service worker registration=] of an identical [=service worker registration/scope url=] when one already exists in the user agent causes the existing [=/service worker registration=] to be replaced.
A <dfn export id="dfn-service-worker-registration" for="">service worker registration</dfn> is a tuple of an [=environment settings object/origin=], an [=service worker registration/id=], and a set of [=/service workers=]; an <a>installing worker</a>, a <a>waiting worker</a>, and an <a>active worker</a>. A user agent *may* enable many [=/service worker registrations=] at a single origin so long as the [=service worker registration/id=] of the [=/service worker registration=] differs.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about just removing this paragraph? It doesn't seem to be saying anything that isn't already said elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I can just remove it as it include a <dfn> tag for "service worker registration".

:: A [=/service worker registration=]
:: A [=/service worker registration=] or null.

1. Run the following steps atomically.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we have this a few places in the spec, but I don't actually know what it means.

docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
@@ -2797,6 +2862,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. If |registration|'s [=active worker=] is not null, then:
1. [=Terminate Service Worker|Terminate=] |registration|'s [=active worker=].
1. Run the [=Update Worker State=] algorithm passing |registration|'s [=active worker=] and "`redundant`" as the arguments.
1. Let |oldUsingClients| be a [=list=] of [=/service worker clients=] who are <a>using</a> |registration|.

Note: We must get the list of clients prior to clearing the old <a>active worker</a> from |registration|. Otherwise the [=/service worker client=] will not be considered to be <a>using</a> |registration| any more since |registration| will no longer be the <a>containing service worker registration</a>.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
docs/index.bs Outdated Show resolved Hide resolved
@wanderview
Copy link
Member Author

Thanks for the review @jakearchibald! I will work on addressing this next week after I clear some other things off my TODO list.

@@ -683,6 +702,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
</pre>
<pre class="idl" id="registration-option-list-dictionary">
dictionary RegistrationOptions {
DOMString id;
Copy link
Member

Choose a reason for hiding this comment

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

Please write a test with isolated surrogates to ensure implementations do not use UTF-8 to store these strings. (If you decide to change this to USVString to allow implementations to do that it's probably still worth writing a test.)

Base automatically changed from master to main February 4, 2021 19:56
…ixes w3c#1512)

This commit adds support for a registration `id` value.  This will be used to uniquely identify registrations
instead of `scope`.  This will make it easier for a developer to migrate a registration from one `scope` to
another.

The commit consists of the following changes:

* Add a DOMString `id` and associated getter to the registration.
* Add an `origin` to the internal registration type.
* Move the `scope` internal representation to `ServiceWorker` and add a new getter.
* Make the `ServiceWorkerRegistration.scope` return the oldest associated worker's `scope`.
* Migrate the registration map to be keyed by the tuple `(origin,id)`.
* Migrate the job queue map to be keyed by the tuple `(origin,id)`.
* Adjust job equality checks to treat register jobs to account for new id and scope semantics.
* Support changing the scope during register operations.
* Reject register operations that change the scope to a value that is already in use by another registration.
* Properly un-control clients whose URL no longer matches a new active worker's scope.
@wanderview
Copy link
Member Author

I think I've updated everything here finally. No need to rush to re-review, though. I'll be working on implementation for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants