Closed Bug 1345943 Opened 5 years ago Closed 5 years ago

Client.postMessage() should set the correct MessageEvent.source

Categories

(Core :: DOM: Service Workers, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: bkelly, Assigned: bkelly)

References

Details

Attachments

(2 files)

While working on bug 1293277 I noticed that we always set the MessageEvent.source to the service worker controlling the Client.

https://dxr.mozilla.org/mozilla-central/source/dom/workers/ServiceWorkerClient.cpp#206

This was probably correct back when Clients.matchAll() only ever returned controlled Client objects.  We can now, however, use `includeUncontrolled:true` to access a Client from a ServiceWorker that does not control the Client.

I'm going to fix this separately so I can write and land a test.
This makes us try to set the MessageEvent.source to the same service worker that called Clients.postMessage().  Right now we have to look it back up via SWM, but I expect to change this soon in bug 1293277.
Attachment #8845702 - Flags: review?(bugmail)
This patch adds a WPT test that verifies we get the correct MessageEvent.source for different ServiceWorkers.  We fail this on current mozilla-central because we only return the controller and therefore MessageEvent.source is null.  After the P1 patch we pass this test.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=e0d5466ba0945743848ce731ae6b73b333def1f7
Attachment #8845704 - Flags: review?(bugmail)
Attachment #8845702 - Flags: review?(bugmail) → review+
Comment on attachment 8845704 [details] [diff] [review]
P2 Add WPT verifying MessageEvent.source is set correctly when sent from waiting ServiceWorker. r=asuth

Review of attachment 8845704 [details] [diff] [review]:
-----------------------------------------------------------------

A most excellent test.

Restating, the test:
- Lines up `script` and `script+?update'` in the registration's active and waiting slots, respectively.  An iframe holds `script` active.
- Messages the waiting and active scripts which echo the received data back, with the test asserting the source is correct.  The string payloads of 'waiting' and 'active' are for debugging support.
Attachment #8845704 - Flags: review?(bugmail) → review+
Pushed by bkelly@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/673d75fec08e
P1 Set the MessageEvent.source to ServiceWorker that called Client.postMessage(). r=asuth
https://hg.mozilla.org/integration/mozilla-inbound/rev/92e2cc20107e
P2 Add WPT verifying MessageEvent.source is set correctly when sent from waiting ServiceWorker. r=asuth
https://hg.mozilla.org/mozilla-central/rev/673d75fec08e
https://hg.mozilla.org/mozilla-central/rev/92e2cc20107e
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.