Skip to content

Commit

Permalink
[e] (0) Merge the two postMessage algorithsm back into one.
Browse files Browse the repository at this point in the history
Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=9395

git-svn-id: http://svn.whatwg.org/webapps@5002 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Apr 12, 2010
1 parent b3cd1ed commit 147a8f9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 441 deletions.
172 changes: 32 additions & 140 deletions complete.html
Expand Up @@ -1046,8 +1046,7 @@ <h2 class="no-num no-toc" id=contents>Table of contents</h2>
<ol>
<li><a href=#authors><span class=secno>10.4.2.1 </span>Authors</a></li>
<li><a href=#user-agents><span class=secno>10.4.2.2 </span>User agents</a></ol></li>
<li><a href=#posting-messages><span class=secno>10.4.3 </span>Posting messages</a></li>
<li><a href=#posting-messages-with-message-ports><span class=secno>10.4.4 </span>Posting messages with message ports</a></ol></li>
<li><a href=#posting-messages><span class=secno>10.4.3 </span>Posting messages</a></ol></li>
<li><a href=#channel-messaging><span class=secno>10.5 </span>Channel messaging</a>
<ol>
<li><a href=#introduction-9><span class=secno>10.5.1 </span>Introduction</a></li>
Expand Down Expand Up @@ -53915,8 +53914,7 @@ <h3 id=the-window-object><span class=secno>6.2 </span>The <code><a href=#window>
any <a href=#dom-showmodaldialog title=dom-showModalDialog>showModalDialog</a>(in DOMString url, in optional any argument<!--, in optional DOMString features-->);

// <a href=#crossDocumentMessages>cross-document messaging</a>
void <a href=#dom-window-postmessage-2 title=dom-window-postMessage-2>postMessage</a>(in any message, in DOMString targetOrigin);
void <a href=#dom-window-postmessage-3 title=dom-window-postMessage-3>postMessage</a>(in any message, in DOMString targetOrigin, in <a href=#messageportarray>MessagePortArray</a> ports);
void <a href=#dom-window-postmessage title=dom-window-postMessage>postMessage</a>(in any message, in DOMString targetOrigin, in optional <a href=#messageportarray>MessagePortArray</a> ports);

// <a href=#event-handler-idl-attributes>event handler IDL attributes</a>
attribute <a href=#function>Function</a> <a href=#handler-onabort title=handler-onabort>onabort</a>;
Expand Down Expand Up @@ -54058,11 +54056,7 @@ <h4 id=security-window><span class=secno>6.2.1 </span>Security</h4>

<ul><li>The <code title=dom-location><a href=#dom-location>location</a></code> object

<li>The <code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage()</a></code>
method with two arguments

<li>The <code title=dom-window-postMessage-3><a href=#dom-window-postmessage-3>postMessage()</a></code>
method with three arguments
<li>The <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code> method

<li>The <code title=dom-frames><a href=#dom-frames>frames</a></code> attribute

Expand All @@ -54089,7 +54083,7 @@ <h4 id=security-window><span class=secno>6.2.1 </span>Security</h4>

<p>For instance, if two frames containing <code><a href=#document>Document</a></code>s
from different <a href=#origin title=origin>origins</a> access the same
<code><a href=#window>Window</a></code> object's <code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage()</a></code> method, they
<code><a href=#window>Window</a></code> object's <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code> method, they
will get distinct objects that are not equal.</p>

</div>
Expand Down Expand Up @@ -71553,7 +71547,7 @@ <h4 id=introduction-8><span class=secno>10.4.1 </span>Introduction</h4>

<p>For example, if document A contains an <code><a href=#the-iframe-element>iframe</a></code>
element that contains document B, and script in document A calls
<code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage()</a></code> on the
<code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code> on the
<code><a href=#window>Window</a></code> object of document B, then a message event will
be fired on that object, marked as originating from the
<code><a href=#window>Window</a></code> of document A. The script in document A might
Expand Down Expand Up @@ -71607,7 +71601,7 @@ <h5 id=authors><span class=secno>10.4.2.1 </span>Authors</h5>
should also check that the data in question is of the expected
format. Otherwise, if the source of the event has been attacked
using a cross-site scripting flaw, further unchecked processing of
information sent using the <code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage()</a></code> method could
information sent using the <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code> method could
result in the attack being propagated into the receiver.</p>

<p>Authors should not use the wildcard keyword (*) in the <var title="">targetOrigin</var> argument in messages that contain any
Expand Down Expand Up @@ -71636,7 +71630,7 @@ <h5 id=user-agents><span class=secno>10.4.2.2 </span>User agents</h5>

<h4 id=posting-messages><span class=secno>10.4.3 </span>Posting messages</h4>

<dl class=domintro><dt><var title="">window</var> . <code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage</a></code>(<var title="">message</var>, <var title="">targetOrigin</var> [, <var title="">ports</var> ])</dt>
<dl class=domintro><dt><var title="">window</var> . <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage</a></code>(<var title="">message</var>, <var title="">targetOrigin</var> [, <var title="">ports</var> ])</dt>

<dd>

Expand All @@ -71657,7 +71651,7 @@ <h4 id=posting-messages><span class=secno>10.4.3 </span>Posting messages</h4>

</dl><div class=impl>

<p>When a script invokes the <dfn id=dom-window-postmessage-2 title=dom-window-postMessage-2><code>postMessage(<var title="">message</var>, <var title="">targetOrigin</var>)</code></dfn> method (with only two
<p>When a script invokes the <dfn id=dom-window-postmessage title=dom-window-postMessage><code>postMessage(<var title="">message</var>, <var title="">targetOrigin</var>, <var title="">ports</var>)</code></dfn> method (with two or three
arguments) on a <code><a href=#window>Window</a></code> object, the user agent must
follow these steps:

Expand All @@ -71683,123 +71677,35 @@ <h4 id=posting-messages><span class=secno>10.4.3 </span>Posting messages</h4>

<li>

<p>Return from the <code title=dom-window-postMessage-2><a href=#dom-window-postmessage-2>postMessage()</a></code> method, but
asynchronously continue running these steps.</p>

</li>

<li>

<p>If the <var title="">targetOrigin</var> argument is a single
literal U+002F SOLIDUS character (/), and the
<code><a href=#document>Document</a></code> of the <code><a href=#window>Window</a></code> object on which
the method was invoked does not have the <a href=#same-origin>same origin</a>
as the <a href=#entry-script>entry script</a>'s <a href="#script's-document" title="script's
document">document</a>, then abort these steps silently.</p>

<p>Otherwise, if the <var title="">targetOrigin</var> argument is
an <a href=#absolute-url>absolute URL</a>, and the <code><a href=#document>Document</a></code> of the
<code><a href=#window>Window</a></code> object on which the method was invoked does
not have the <a href=#same-origin>same origin</a> as <var title="">targetOrigin</var>, then abort these steps silently.</p>

<p>Otherwise, the <var title="">targetOrigin</var> argument is a
single literal U+002A ASTERISK character (*), and no origin check
is made.</p>

</li>

<li>

<p>Create an event that uses the <code><a href=#messageevent>MessageEvent</a></code>
interface, with the event name <code title=event-message><a href=#event-message>message</a></code>, which does not bubble, is
not cancelable, and has no default action. The <code title=dom-MessageEvent-data><a href=#dom-messageevent-data>data</a></code> attribute must be set to
the value of <var title="">message clone</var>, the <code title=dom-MessageEvent-origin><a href=#dom-messageevent-origin>origin</a></code> attribute must be
set to the <a href=#unicode-serialization-of-an-origin title="Unicode serialization of an
origin">Unicode serialization</a> of the <a href=#origin>origin</a> of
the script that invoked the method, and the <code title=dom-MessageEvent-source><a href=#dom-messageevent-source>source</a></code> attribute must be
set to the <a href="#script's-global-object">script's global object</a>'s
<code><a href=#windowproxy>WindowProxy</a></code> object.</p> <!-- invariant: the global
object is always a Window if the script can see this method -->

</li>

<li>

<p><a href=#queue-a-task>Queue a task</a> to dispatch the event created in the
previous step at the <code><a href=#window>Window</a></code> object on which the
method was invoked. The <a href=#task-source>task source</a> for this <a href=#concept-task title=concept-task>task</a> is the <a href=#posted-message-task-source>posted message task
source</a>.</p>

</li>

</ol></div>


<div class=impl>

<h4 id=posting-messages-with-message-ports><span class=secno>10.4.4 </span>Posting messages with message ports</h4>

<p>When a script invokes the <dfn id=dom-window-postmessage-3 title=dom-window-postMessage-3><code>postMessage(<var title="">message</var>, <var title="">targetOrigin</var>, <var title="">ports</var>)</code></dfn> method (with three arguments) on
a <code><a href=#window>Window</a></code> object, the user agent must follow these
steps:

<ol><!-- EXCEPT WHERE NOTED, THESE STEPS ARE IDENTICAL TO THE PREVIOUS SECTION --><!-- one exception is the use of -3 instead of -2 in the xrefs --><li>

<p>If the value of the <var title="">targetOrigin</var> argument
is neither a single U+002A ASTERISK character (*), a single U+002F
SOLIDUS character (/), nor an <a href=#absolute-url>absolute URL</a> with a
<code title=url-host-specific><a href=#url-host-specific>&lt;host-specific&gt;</a></code>
component that is either empty or a single U+002F SOLIDUS
character (/), then throw a <code><a href=#syntax_err>SYNTAX_ERR</a></code> exception and
abort the overall set of steps.</p>
<p>If the <var title="">ports</var> argument is present but either
any of the entries in <var title="">ports</var> are null, or any
<code><a href=#messageport>MessagePort</a></code> object is listed in <var title="">ports</var> more than once, or any of the
<code><a href=#messageport>MessagePort</a></code> objects listed in <var title="">ports</var> have already been cloned once before, then
throw an <code><a href=#invalid_state_err>INVALID_STATE_ERR</a></code> exception and abort these
steps.</p>

</li>

<li>

<p>Let <var title="">message clone</var> be the result of
obtaining a <a href=#structured-clone>structured clone</a> of the <var title="">message</var> argument. If this throws an exception, then
throw that exception and abort these steps.</p>

</li>

<li> <!-- NEW STEP -->

<p>If the <var title="">ports</var> argument is empty<!-- or null
(if we make it nullable)-->, then act as if the method had just
been <a href=#dom-window-postmessage-2 title=dom-window-postMessage-2>called with two
arguments</a>, <var title="">message</var> and <var title="">targetOrigin</var>.</p>

</li>

<li> <!-- NEW STEP -->

<p>If any of the entries in <var title="">ports</var> are null, if
any <code><a href=#messageport>MessagePort</a></code> object is listed in <var title="">ports</var> more than once, or if any of the
<code><a href=#messageport>MessagePort</a></code> objects listed in <var title="">ports</var> have already been cloned once before, then
throw an <code><a href=#invalid_state_err>INVALID_STATE_ERR</a></code> exception.</p>

</li>
<p>Let <var title="">new ports</var> be an empty array.</p>

<li> <!-- NEW STEP -->
<p>If the <var title="">ports</var> argument is present, then for
each port in <var title="">ports</var> in turn, obtain a new port
by <a href=#clone-a-port title="clone a port">cloning</a> the port with the
<code><a href=#window>Window</a></code> object on which the method was invoked as the
owner of the clone, and append the clone to the <var title="">new
ports</var> array.</p>

<p>Let <var title="">new ports</var> be an empty array.</p>
<p class=note>If the original <var title="">ports</var> argument
was omitted or empty, then the <var title="">new ports</var> array
will be empty.</p>

<p>For each port in <var title="">ports</var> in turn,
obtain a new port by <a href=#clone-a-port title="clone a port">cloning</a> the
port with the <code><a href=#window>Window</a></code> object on which the method was
invoked as the owner of the clone, and append the clone to the
<var title="">new ports</var> array.</p>
<!--
<p class="note">If the original <var title="">ports</var>
array was empty, then the <var title="">new ports</var> array will
also be empty.</p>
-->
</li>

<li>

<p>Return from the <code title=dom-window-postMessage-3><a href=#dom-window-postmessage-3>postMessage()</a></code> method, but
<p>Return from the <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code> method, but
asynchronously continue running these steps.</p>

</li>
Expand Down Expand Up @@ -71832,17 +71738,12 @@ <h4 id=posting-messages-with-message-ports><span class=secno>10.4.4 </span>Posti
the value of <var title="">message clone</var>, the <code title=dom-MessageEvent-origin><a href=#dom-messageevent-origin>origin</a></code> attribute must be
set to the <a href=#unicode-serialization-of-an-origin title="Unicode serialization of an
origin">Unicode serialization</a> of the <a href=#origin>origin</a> of
the script that invoked the method, and the <code title=dom-MessageEvent-source><a href=#dom-messageevent-source>source</a></code> attribute must be
the script that invoked the method, the <code title=dom-MessageEvent-source><a href=#dom-messageevent-source>source</a></code> attribute must be
set to the <a href="#script's-global-object">script's global object</a>'s
<code><a href=#windowproxy>WindowProxy</a></code> object.</p> <!-- invariant: the global
object is always a Window if the script can see this method -->

</li>

<li> <!-- NEW STEP -->

<p>Let the <code title=dom-MessageEvent-ports><a href=#dom-messageevent-ports>ports</a></code> attribute
of the event be the <var title="">new ports</var> array.</p>
<code><a href=#windowproxy>WindowProxy</a></code> object, and the <code title=dom-MessageEvent-ports><a href=#dom-messageevent-ports>ports</a></code> attribute must be set
to the <var title="">new ports</var> array.</p> <!-- invariant:
the global object is always a Window if the script can see this
method -->

</li>

Expand All @@ -71855,16 +71756,7 @@ <h4 id=posting-messages-with-message-ports><span class=secno>10.4.4 </span>Posti

</li>

</ol><p class=note>These steps, with the exception of the third,
fourth, and fifth steps and the penultimate step, are identical to
those in the previous section.</p>

<!-- v2: we can merge this section and the previous section when
implementations have shipped postMessage(). Anne asked that these
sections be kept separate so that implementors can avoid getting
confused with the 'port' step. -->

</div>
</ol></div>



Expand All @@ -71889,7 +71781,7 @@ <h4 id=introduction-9><span class=secno>10.5.1 </span>Introduction</h4>
<pre>var channel = new MessageChannel();</pre>

<p>One of the ports is kept as the local port, and the other port is
sent to the remote code, e.g. using <code title=dom-window-postMessage-3><a href=#dom-window-postmessage-3>postMessage()</a></code>:</p>
sent to the remote code, e.g. using <code title=dom-window-postMessage><a href=#dom-window-postmessage>postMessage()</a></code>:</p>

<pre>otherWindow.postMessage('hello', 'http://example.com', [channel.port2]);</pre>

Expand Down

0 comments on commit 147a8f9

Please sign in to comment.