Bug 179822 - [Service Workers] Implement "Notify Controller Change" algorithm
Summary: [Service Workers] Implement "Notify Controller Change" algorithm
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
Keywords: InRadar
Depends on:
Reported: 2017-11-17 09:03 PST by Chris Dumez
Modified: 2017-11-27 12:41 PST (History)
6 users (show)

See Also:

WIP Patch (11.46 KB, patch)
2017-11-17 10:18 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (17.74 KB, patch)
2017-11-17 10:47 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (19.58 KB, patch)
2017-11-17 18:25 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (19.53 KB, patch)
2017-11-17 18:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2017-11-17 09:03:00 PST
Implement "Notify Controller Change" algorithm:
- https://w3c.github.io/ServiceWorker/#notify-controller-change
Comment 1 Chris Dumez 2017-11-17 10:18:47 PST
Created attachment 327193 [details]
WIP Patch
Comment 2 Chris Dumez 2017-11-17 10:47:00 PST
Created attachment 327194 [details]
Comment 3 youenn fablet 2017-11-17 16:22:21 PST
Comment on attachment 327194 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=327194&action=review

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:419
> +    scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this)](ScriptExecutionContext&) mutable {

I know the spec is written this way but It seems a bit weird to post a task here for dispatching an event.
It does not seem observable to dispatch the event directly without the post task, at least in the current context it is used.
Might be safer to stick to the spec though, not sure...

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:424
> +        dispatchEvent(controllerChangeEvent);

do we need controllerChangeEvent variable?

> Source/WebCore/workers/service/server/SWClientConnection.cpp:168
> +void SWClientConnection::notifyClientsOfControllerChange(const HashSet<uint64_t>& scriptExecutionContexts, const ServiceWorkerData& newController)

newController can probably be an r value.

> Source/WebCore/workers/service/server/SWClientConnection.cpp:177
> +        client->setActiveServiceWorker(ServiceWorker::getOrCreate(*client, ServiceWorkerData { newController }));

Maybe we should assert that client has an active service worker.
Not sure whether we could also assert that we are actually changing from worker.

> Source/WebCore/workers/service/server/SWServerJobQueue.cpp:235
> +    // - Set clientâs active worker to registrationâs active worker.

I see client^as here.

> LayoutTests/http/tests/workers/service/controller-change.html:38
> +    let frame = await withFrame(scopeURL);

In sw-test-pre.js, there is an interceptedFrame function that could be reused to replace register and withFrame.
Comment 4 Chris Dumez 2017-11-17 18:25:26 PST
Created attachment 327293 [details]
Comment 5 Chris Dumez 2017-11-17 18:28:57 PST
Created attachment 327294 [details]
Comment 6 Chris Dumez 2017-11-17 19:42:23 PST
Comment on attachment 327294 [details]

Clearing flags on attachment: 327294

Committed r225011: <https://trac.webkit.org/changeset/225011>
Comment 7 Chris Dumez 2017-11-17 19:42:25 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2017-11-17 19:43:26 PST
Comment 9 Matt Lewis 2017-11-27 12:41:16 PST
This change has cause the test:
to start crashing


See bug: