Repository navigation
Add postMessage override that provides WindowPostMessageOptions. - #3800
Conversation
|
@domenic WDYT? Tentative WPT tests are here for review: https://chromium-review.googlesource.com/c/chromium/src/+/1118850 |
domenic
left a comment
There was a problem hiding this comment.
Some issues, but the basic idea is clear. I'll follow up with a more general comment in #3799.
I wonder whether we should update all of the spec examples to use this overload. If we believe it to be the right pattern in general, that might be a good idea. You can Ctrl+F for postMessage( in the rendered output to find a lot.
On the other hand, maybe spec examples should be a bit more conservative, not using newer, less-supported features.
| callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span> time); | ||
|
|
||
| dictionary <dfn>WindowPostMessageOptions</dfn> | ||
| { |
| { | ||
| USVString targetOrigin = "/"; | ||
| }; | ||
| </pre> |
| they are no longer usable on the sending side.</p> | ||
|
|
||
| <p>Target origin is specified as a member of <var>options</var>. If options is not provided | ||
| targetOrigin of the dictionary is initialized to "<code data-x="">/</code>".</p> |
There was a problem hiding this comment.
I would phrase this as:
A target origin may be specified using the <code data-x="">targetOrigin</code> member of <var>options</var>. If not provided, it defaults to "<code data-x="">/</code>". This restricts the message to same-origin targets only.| <p>Target origin is specified as a member of <var>options</var>. If options is not provided | ||
| targetOrigin of the dictionary is initialized to "<code data-x="">/</code>".</p> | ||
|
|
||
| <p>If the origin of the target window doesn't match the given origin, the message is discarded, |
There was a problem hiding this comment.
We should change "given" to "target" here.
|
|
||
| <p>If the origin of the target window doesn't match the given origin, the message is discarded, | ||
| to avoid information leakage. To send the message to the target regardless of origin, set the | ||
| target origin to "<code data-x="">*</code>". To restrict the message to same-origin targets only, |
There was a problem hiding this comment.
We can remove the "To restrict the message..." sentence now.
|
|
||
| <p>This is an alternate version of postMessage where the target origin is specified as a parameter. | ||
| Calling <code data-x="">window.postMessage(message, target, transfer);</code> is equivalent | ||
| to <code data-x="">window.postMessage(message, transfer, {targetOrigin: target});</code> |
There was a problem hiding this comment.
Nits:
- Wrapping not quite right. Use https://output.jsbin.com/maferi.
- Missing
</p> - Remove semicolons
- Add period at the end
| @@ -95417,7 +95435,7 @@ function receiver(e) { | |||
| <div w-nodev> | |||
|
|
|||
| <p>The <dfn><code data-x="dom-window-postMessage">postMessage(<var>message</var>, | |||
There was a problem hiding this comment.
You lost the definition for postMessage(message, targetOrigin, transfer). It will need a second data-x, since it's a second method.
See https://html.spec.whatwg.org/#dom-document-open for the general pattern here. You'll need to define something like "window message-posting steps" which takes message, transfer, targetOrigin, then define the two methods each of which call the window message-posting steps.
| window, in same-origin cases. See discussion at | ||
| https://github.com/whatwg/html/issues/1542#issuecomment-233502636 --> | ||
|
|
||
| <li><p>Let <var>targetOrigin</var> be <var>options</var>'s targetOrigin.</p></li> |
There was a problem hiding this comment.
You can use either "the value of options's targetOrigin member" or (newer, rarer style) options["targetOrigin"].
a2fdfb3 to
c9bf3a9
Compare
|
Ok; transfer moved to the dictionary. It digresses from the consistency we were after but I think the argument to put it in the dictionary is reasonable. |
|
If we're updating all versions of https://w3c.github.io/ServiceWorker/#service-worker-postmessage |
|
Yes that is the intent. We have to agree on it first though.. See #3799 where the main discussion is happening. |
domenic
left a comment
There was a problem hiding this comment.
Lots of editorial work to do, but normative aspects all look good, thanks!
| <var>options</var>. If not provided, it defaults to "<code data-x="">/</code>". This restricts | ||
| the message to same-origin targets only.</p> | ||
|
|
||
| <p>This is an alternate version of postMessage where the target origin is specified as a |
| <dl class="domintro"> | ||
|
|
||
| <dt><var>window</var> . <code subdfn data-x="dom-window-postMessage">postMessage</code>(<var>message</var>, <var>targetOrigin</var> [, <var>transfer</var> ] )</dt> | ||
| <dt><var>window</var> . <code subdfn data-x="dom-window-postMessage">postMessage</code>(<var>message</var>[, <var>options</var> ])</dt> |
There was a problem hiding this comment.
Nit: space between ] and ), I guess? Spec is inconsistent, but we should be consistent within this block, at least. I'm also OK with deleting the space from the below.
|
|
||
| <dd> | ||
|
|
||
| <p>This is an alternate version of postMessage where the target origin is specified as a |
There was a problem hiding this comment.
postMessage -> <code data-x="dom-window-postMessage-options">postMessage()</code>
| <p>This is an alternate version of postMessage where the target origin is specified as a | ||
| parameter. Calling <code data-x="">window.postMessage(message, target, transfer)</code> is | ||
| equivalent to <code data-x="">window.postMessage(message, transfer, {targetOrigin: | ||
| target})</code>.</p> |
There was a problem hiding this comment.
This needs updating since transfer moved into the options dictionary.
| <p>The <dfn><code data-x="dom-window-postMessage">postMessage(<var>message</var>, | ||
| <var>targetOrigin</var>, <var>transfer</var>)</code></dfn> method, when invoked on a | ||
| <code>Window</code> object must run the following steps:</p> | ||
| <p>The <dfn>window post message steps</dfn>, given a <var>targetWindow</var>, <var>message</var> |
There was a problem hiding this comment.
Comma after message and after options
| <li><p>Let <var>targetPort</var> be the port with which this <code>MessagePort</code> is | ||
| entangled, if any; otherwise let it be null.</p></li> | ||
|
|
||
| <li><p>Let <var>options</var> be a new instance of <code>PostMessageOptions</code> |
| <var>dedicatedWorkerGlobal</var>. <var>transfer</var> can be passed as a list of objects that are | ||
| to be transferred rather than cloned.</dd> | ||
|
|
||
| <dt><var>dedicatedWorkerGlobal</var> . <code subdfn |
There was a problem hiding this comment.
Same dt/dt/dd structure as before.
| and <dfn><code data-x="dom-DedicatedWorkerGlobalScope-postMessage-options">postMessage()</code></dfn> | ||
| methods on <code>DedicatedWorkerGlobalScope</code> objects act as if, when invoked, it | ||
| immediately invoked the respective <span data-x="dom-MessagePort-postMessage">postMessage</span> | ||
| and <span data-x="dom-MessagePort-postMessage-options">postMessage (with options)</span> on the port, |
There was a problem hiding this comment.
Use code, not span.
Insert parameter lists for all four methods.
| <var>transfer</var> can be passed as a list of objects that are to be transferred rather than | ||
| cloned.</dd> | ||
|
|
||
| <dt><var>worker</var> . <code subdfn data-x="dom-Worker-postMessage-options">postMessage</code>(<var>message</var> [, <var>options</var> ]) |
There was a problem hiding this comment.
Same dt/dt/dd structure as before.
| <p>All messages received by that port must immediately be retargeted at the <code>Worker</code> | ||
| object.</p> | ||
|
|
||
| <p>The <dfn><code data-x="dom-Worker-postMessage">postMessage()</code></dfn> method on |
There was a problem hiding this comment.
Use span, not code; add parameter lists to all four.
This is similar to the HTML changes in whatwg/html#3800
|
Even though it shows up in the thread, I had a hard time spotting the corresponding changes for Service Workers. Here they are: w3c/ServiceWorker#1344 |
| callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span> time); | ||
|
|
||
| dictionary <dfn>WindowPostMessageOptions</dfn> : <span>PostMessageOptions</span> { | ||
| USVString targetOrigin = "/"; |
There was a problem hiding this comment.
Should we name this simply "origin" for convenience?
There was a problem hiding this comment.
Hmm, I think the explicitness is good. This isn't "the origin of a posted message", as origin would indicate, it's "the target origin to which you are posting the message".
There was a problem hiding this comment.
Mkay, I don't like that it gets so long.
| "<var>transfer</var>" → <var>transfer</var> ]».</p></li> | ||
|
|
||
| <li><p>Run the <span>window post message steps</span> providing | ||
| <var>targetWindow</var>, <var>message</var> and <var>options</var>.</p></li> |
| <li><p>Let <var>targetWindow</var> be this <code>Window</code> object.</p></li> | ||
|
|
||
| <li><p>Run the <span>window post message steps</span> providing <var>targetWindow</var>, | ||
| <var>message</var> and <var>options</var>.</p></li> |
|
Removing "needs implementer interest" per #3799 (comment). Also please rebase on master, I guess there have been conflicts. |
|
Commas addressed PTAL. |
annevk
left a comment
There was a problem hiding this comment.
I wonder if for the non-Window postMessage() methods we should mark the transfer argument as non-optional and non-defaulting. It probably doesn't matter, but it seems slightly cleaner to make overloading pick the dictionary-based version as much as possible.
I also pushed some formatting nits.
Are the tests updated as well? The link in the comment following OP is rather outdated.
|
Tests ended up in https://github.com/web-platform-tests/wpt/tree/5a792b6bf4e0d39f2b65301b592dffffa8bd9b15/webmessaging/with-options. I'll merge this, and file an issue to make them un-.tentative. |
|
@dtapuska did you, or can you, file issues on the other implementers? |
This is similar to the HTML changes in whatwg/html#3800
This is similar to the HTML changes in whatwg/html#3800
This is similar to the HTML changes in whatwg/html#3800
Fixes issue #3799
/web-messaging.html ( diff )
/window-object.html ( diff )
/workers.html ( diff )