Skip to content

Commit

Permalink
Add postMessage override that provides WindowPostMessageOptions.
Browse files Browse the repository at this point in the history
Fixes issue #3799
  • Loading branch information
dtapuska committed Jul 30, 2018
1 parent 39c948b commit 6cf8e04
Showing 1 changed file with 64 additions and 13 deletions.
77 changes: 64 additions & 13 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -78044,11 +78044,17 @@ interface <dfn data-export="" data-dfn-type="interface">Window</dfn> : <span>Eve
void <span data-x="dom-window-cancelAnimationFrame">cancelAnimationFrame</span>(unsigned long handle);

void <span data-x="dom-window-postMessage">postMessage</span>(any message, USVString targetOrigin, optional sequence&lt;<span data-x="idl-object">object</span>&gt; transfer = []);
void <span data-x="dom-window-postMessage-options">postMessage</span>(any message, optional <span>WindowPostMessageOptions</span> options);
};
<span>Window</span> includes <span>GlobalEventHandlers</span>;
<span>Window</span> includes <span>WindowEventHandlers</span>;

callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span> time);</code></pre>
callback <dfn>FrameRequestCallback</dfn> = void (<span>DOMHighResTimeStamp</span> time);

dictionary <dfn>WindowPostMessageOptions</dfn> {
USVString targetOrigin = "/";
sequence&lt;<span data-x="idl-object">object</span>&gt; transfer = [];
};</code></pre>

<!-- for more features to add here, look here:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp
Expand Down Expand Up @@ -95356,10 +95362,9 @@ function receiver(e) {

<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>transfer</var> ] [, options ])</dt>

<dd>

<p>Posts a message to the given window. Messages can be structured objects, e.g. nested objects
and arrays, can contain JavaScript values (strings, numbers, <code>Date</code>
objects, etc), and can contain certain data objects such as <code>File</code> <code>Blob</code>,
Expand All @@ -95368,17 +95373,30 @@ function receiver(e) {
<p>Objects listed in <var>transfer</var> are transferred, not just cloned, meaning that
they are no longer usable on the sending side.</p>

<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,
without needing to explicitly state the origin, set the target origin to "<code
data-x="">/</code>".</p>
<p>A target origin can 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>

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

<p>Throws a <span>"<code>DataCloneError</code>"</span> <code>DOMException</code> if
<var>transfer</var> array contains duplicate objects or if <var>message</var> could not be
cloned.</p>

</dd>
<dt><var>window</var> . <code data-x="dom-window-postMessage">postMessage</code>(<var>message</var>, <var>targetOrigin</var> [, <var>transfer</var> ] )</dt>

<dd>

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

</dd>

</dl>

Expand All @@ -95393,14 +95411,11 @@ function receiver(e) {

<div w-nodev>

<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>
and <var>options</var> are as follows:</p>

<ol> <!-- a lot of this is similar or identical to port.postMessage -->

<li><p>Let <var>targetWindow</var> be this <code>Window</code> object.</p>

<li><p>Let <var>targetRealm</var> be <var>targetWindow</var>'s <span
data-x="concept-global-object-realm">Realm</span>.</p></li>

Expand All @@ -95410,6 +95425,9 @@ function receiver(e) {
window, in same-origin cases. See discussion at
https://github.com/whatwg/html/issues/1542#issuecomment-233502636 -->

<li><p>Let <var>targetOrigin</var> be the value of <var>options</var>'s <code
data-x="">targetOrigin</code> member.</p></li>

<li><p>If <var>targetOrigin</var> is a single U+002F SOLIDUS character (/), then set
<var>targetOrigin</var> to <var>incumbentSettings</var>'s <span
data-x="concept-settings-object-origin">origin</span>.</p>
Expand All @@ -95430,6 +95448,9 @@ function receiver(e) {
</ol>
</li>

<li><p>Let <var>transfer</var> be the value of <var>options</var>'s <code
data-x="">transfer</code> member.</p></li>

<li><p>Let <var>serializeWithTransferResult</var> be
<span>StructuredSerializeWithTransfer</span>(<var>message</var>, <var>transfer</var>). Rethrow
any exceptions.</p></li>
Expand Down Expand Up @@ -95483,6 +95504,36 @@ function receiver(e) {
</li>
</ol>

<p>The <dfn><code data-x="dom-window-postMessage-options">postMessage(<var>message</var>,
<var>options</var>)</code></dfn> method, when invoked on a
<code>Window</code> object must run the following steps:</p>
<ol>
<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>
</ol>

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

<ol>
<li><p>Let <var>targetWindow</var> be this <code>Window</code> object.</p></li>

<li><p>Let <var>options</var> be a new instance of <code>WindowPostMessageOptions</code>
object.</p></li>

<li><p>Set <var>options</var>'s <code data-x="">targetOrigin</code> member to be
<var>targetOrigin</var>.</p></li>

<li><p>Set <var>options</var>'s <code data-x="">transfer</code> member to be
<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>
</ol>

</div>


Expand Down

0 comments on commit 6cf8e04

Please sign in to comment.