Skip to content

Commit 748b068

Browse files
authored
Teach MessageEvent to work with origins
Currently, MessageEvent's origin holds a serialized origin. In order for Origin.from(...) to function as intended for sources with opaque origins, we need to hold an origin on MessageEvent instead. This patch adds an "origin" concept to `MessageEvent`, and shifts call sites to initialize that value with an origin whenever possible. It also adjusts the "extract an origin" steps to return the stored origin when present, and to return null in cases where the object was initialized with an untrusted origin representation (e.g., when its constructor is called with a MessageEventInit dictionary). Closes #11993.
1 parent 9c00904 commit 748b068

1 file changed

Lines changed: 45 additions & 23 deletions

File tree

source

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127963,6 +127963,10 @@ dictionary <dfn dictionary>MessageEventInit</dfn> : <span>EventInit</span> {
127963127963

127964127964
typedef (<span>WindowProxy</span> or <span>MessagePort</span> or <span>ServiceWorker</span>) <dfn typedef>MessageEventSource</dfn>;</code></pre>
127965127965

127966+
<p>Each <code>MessageEvent</code> has an <dfn data-x="concept-MessageEvent-origin"
127967+
for="MessageEvent" export>origin</dfn> (an <span>origin</span>, a string, or null), initially
127968+
null.</p>
127969+
127966127970
<dl class="domintro">
127967127971
<dt><code data-x=""><var>event</var>.<span subdfn data-x="dom-MessageEvent-data">data</span></code></dt>
127968127972

@@ -128010,17 +128014,37 @@ typedef (<span>WindowProxy</span> or <span>MessagePort</span> or <span>ServiceWo
128010128014

128011128015
<div algorithm>
128012128016
<p>The <dfn attribute for="MessageEvent"><code
128013-
data-x="dom-MessageEvent-origin">origin</code></dfn> attribute must return the value it was
128014-
initialized to. It represents, in <span>server-sent events</span> and <span>cross-document
128015-
messaging</span>, the <span data-x="concept-document-origin">origin</span> of the document that
128016-
sent the message (typically the scheme, hostname, and port of the document, but not its path or
128017-
<span data-x="concept-url-fragment">fragment</span>).</p>
128017+
data-x="dom-MessageEvent-origin">origin</code></dfn> attribute represents, in <span>server-sent
128018+
events</span> and <span>cross-document messaging</span>, the <span
128019+
data-x="concept-document-origin">origin</span> of the document that sent the message (typically
128020+
the scheme, hostname, and port of the document, but not its path or <span
128021+
data-x="concept-url-fragment">fragment</span>).</p>
128022+
128023+
<p>The <code data-x="dom-MessageEvent-origin">origin</code> getter steps are:</p>
128024+
128025+
<ol>
128026+
<li><p>If <span>this</span>'s <span data-x="concept-MessageEvent-origin">origin</span> is
128027+
an <span>origin</span>, then return the <span
128028+
data-x="serialization of an origin">serialization</span> of <span>this</span>'s <span
128029+
data-x="concept-MessageEvent-origin">origin</span>.</p></li>
128030+
128031+
<li><p>If <span>this</span>'s <span data-x="concept-MessageEvent-origin">origin</span> is
128032+
null, then return the empty string.</p></li>
128033+
128034+
<li><p>Return <span>this</span>'s <span
128035+
data-x="concept-MessageEvent-origin">origin</span>.</p></li>
128036+
</ol>
128037+
128038+
<p>When the <code data-x="dom-MessageEvent-origin">origin</code> attribute is "initialized"
128039+
(during <code>MessageEvent</code>'s <span data-x="dom-Event-constructor">constructor</span>, for
128040+
example), the initialization value is placed into the object's <span
128041+
data-x="concept-MessageEvent-origin">origin</span>.</p>
128018128042
</div>
128019128043

128020128044
<div algorithm>
128021128045
<p>Objects implementing the <code>MessageEvent</code> interface's <span>extract an origin</span>
128022-
steps are to return <span>this</span>'s <span>relevant settings object</span>'s
128023-
<span data-x="concept-settings-object-origin">origin</span>.</p>
128046+
steps are to return <span>this</span>'s <span data-x="concept-MessageEvent-origin">origin</span>
128047+
if it is an <span>origin</span>; otherwise null.</p>
128024128048
</div>
128025128049

128026128050
<div algorithm>
@@ -128687,10 +128711,10 @@ any-char = %x0000-0009 / %x000B-000C / %x000E-10FFFF
128687128711

128688128712
<li><p>Initialize <var>event</var>'s <code data-x="dom-Event-type">type</code> attribute to
128689128713
"<code data-x="event-message">message</code>", its <code
128690-
data-x="dom-MessageEvent-data">data</code> attribute to <var>data</var>, its <code
128691-
data-x="dom-MessageEvent-origin">origin</code> attribute to the <span data-x="serialization of
128692-
an origin">serialization</span> of the <span data-x="concept-url-origin">origin</span> of the
128693-
event stream's final URL (i.e., the URL after redirects), and its <code
128714+
data-x="dom-MessageEvent-data">data</code> attribute to <var>data</var>, its <span
128715+
data-x="concept-MessageEvent-origin">origin</span> to the <span
128716+
data-x="concept-url-origin">origin</span> of the event stream's final URL (i.e., the URL after
128717+
redirects), and its <code
128694128718
data-x="dom-MessageEvent-lastEventId">lastEventId</code> attribute to the <span
128695128719
data-x="concept-event-stream-last-event-id">last event ID string</span> of the event
128696128720
source.</p></li>
@@ -129158,8 +129182,7 @@ function receiver(e) {
129158129182
<code>Document</code></span>'s <span data-x="concept-document-origin">origin</span> is not
129159129183
<span>same origin</span> with <var>targetOrigin</var>, then return.</p></li>
129160129184

129161-
<li><p>Let <var>origin</var> be the <span data-x="serialization of an
129162-
origin">serialization</span> of <var>incumbentSettings</var>'s <span
129185+
<li><p>Let <var>origin</var> be <var>incumbentSettings</var>'s <span
129163129186
data-x="concept-settings-object-origin">origin</span>.</p></li>
129164129187

129165129188
<li><p>Let <var>source</var> be the <code>WindowProxy</code> object corresponding to
@@ -129173,8 +129196,8 @@ function receiver(e) {
129173129196

129174129197
<p>If this throws an exception, catch it, <span data-x="concept-event-fire">fire an
129175129198
event</span> named <code data-x="event-messageerror">messageerror</code> at
129176-
<var>targetWindow</var>, using <code>MessageEvent</code>, with the <code
129177-
data-x="dom-MessageEvent-origin">origin</code> attribute initialized to <var>origin</var> and
129199+
<var>targetWindow</var>, using <code>MessageEvent</code>, with its <span
129200+
data-x="concept-MessageEvent-origin">origin</span> initialized to <var>origin</var> and
129178129201
the <code data-x="dom-MessageEvent-source">source</code> attribute initialized to
129179129202
<var>source</var>, and then return.</p>
129180129203
</li>
@@ -129187,8 +129210,8 @@ function receiver(e) {
129187129210

129188129211
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
129189129212
data-x="event-message">message</code> at <var>targetWindow</var>, using
129190-
<code>MessageEvent</code>, with the <code data-x="dom-MessageEvent-origin">origin</code>
129191-
attribute initialized to <var>origin</var>, the <code
129213+
<code>MessageEvent</code>, with its <span
129214+
data-x="concept-MessageEvent-origin">origin</span> initialized to <var>origin</var>, the <code
129192129215
data-x="dom-MessageEvent-source">source</code> attribute initialized to <var>source</var>, the
129193129216
<code data-x="dom-MessageEvent-data">data</code> attribute initialized to
129194129217
<var>messageClone</var>, and the <code data-x="dom-MessageEvent-ports">ports</code> attribute
@@ -130057,17 +130080,16 @@ interface <dfn interface>BroadcastChannel</dfn> : <span>EventTarget</span> {
130057130080

130058130081
<p>If this throws an exception, catch it, <span data-x="concept-event-fire">fire an
130059130082
event</span> named <code data-x="event-messageerror">messageerror</code> at
130060-
<var>destination</var>, using <code>MessageEvent</code>, with the <code
130061-
data-x="dom-MessageEvent-origin">origin</code> attribute initialized to the <span
130062-
data-x="serialization of an origin">serialization</span> of <var>sourceOrigin</var>, and then
130063-
abort these steps.</p>
130083+
<var>destination</var>, using <code>MessageEvent</code>, with its <span
130084+
data-x="concept-MessageEvent-origin">origin</span> initialized to <var>sourceOrigin</var>, and
130085+
then abort these steps.</p>
130064130086
</li>
130065130087

130066130088
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
130067130089
data-x="event-message">message</code> at <var>destination</var>, using
130068130090
<code>MessageEvent</code>, with the <code data-x="dom-MessageEvent-data">data</code> attribute
130069-
initialized to <var>data</var> and the <code data-x="dom-MessageEvent-origin">origin</code>
130070-
attribute initialized to the <span data-x="serialization of an origin">serialization</span> of
130091+
initialized to <var>data</var> and its <span
130092+
data-x="concept-MessageEvent-origin">origin</span> initialized to
130071130093
<var>sourceOrigin</var>.</p></li>
130072130094
</ol>
130073130095
</li>

0 commit comments

Comments
 (0)