Skip to content

Commit c9b4790

Browse files
authored
Teach ExtendableMessageEvent to work with origins. (#1821)
Currently, ExtendableMessageEvent'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 ExtendableMessageEvent instead. This patch adds an "origin" concept to `ExtendableMessageEvent`, and shifts call sites to initialize that value with an origin whenever possible. It also adds "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 ExtendableMessageEventInit dictionary). This replicates whatwg/html#11993's work on `MessageEvent`, and should fix #1820.
1 parent 4a9e044 commit c9b4790

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

index.bs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
515515
<dt>Otherwise</dt>
516516
<dd>a new {{Client}} object that represents |incumbentGlobal|'s associated worker</dd>
517517
</dl>
518-
1. Let |origin| be the [=serialization of an origin|serialization=] of |incumbentSettings|'s [=environment settings object/origin=].
518+
1. Let |origin| be |incumbentSettings|'s [=environment settings object/origin=].
519519
1. Let |destination| be the {{ServiceWorkerGlobalScope}} object associated with |serviceWorker|.
520520
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=global object/Realm=]).
521521

522-
If this throws an exception, let |e| be the result of [=creating an event=] named {{ServiceWorkerGlobalScope/messageerror!!event}}, using {{ExtendableMessageEvent}}, with the {{ExtendableMessageEvent/origin}} attribute initialized to |origin| and the {{ExtendableMessageEvent/source}} attribute initialized to |source|.
522+
If this throws an exception, let |e| be the result of [=creating an event=] named {{ServiceWorkerGlobalScope/messageerror!!event}}, using {{ExtendableMessageEvent}}, with its [=ExtendableMessageEvent/origin=] initialized to |origin| and the {{ExtendableMessageEvent/source}} attribute initialized to |source|.
523523
1. Else:
524524
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
525525
1. Let |newPorts| be a new [=frozen array type|frozen array=] consisting of all {{MessagePort}} objects in |deserializeRecord|.\[[TransferredValues]], if any, maintaining their relative order.
526-
1. Let |e| be the result of [=creating an event=] named {{ServiceWorkerGlobalScope/message!!event}}, using {{ExtendableMessageEvent}}, with the {{ExtendableMessageEvent/origin}} attribute initialized to |origin|, the {{ExtendableMessageEvent/source}} attribute initialized to |source|, the {{ExtendableMessageEvent/data}} attribute initialized to |messageClone|, and the {{ExtendableMessageEvent/ports}} attribute initialized to |newPorts|.
526+
1. Let |e| be the result of [=creating an event=] named {{ServiceWorkerGlobalScope/message!!event}}, using {{ExtendableMessageEvent}}, with its [=ExtendableMessageEvent/origin=] initialized to |origin|, the {{ExtendableMessageEvent/source}} attribute initialized to |source|, the {{ExtendableMessageEvent/data}} attribute initialized to |messageClone|, and the {{ExtendableMessageEvent/ports}} attribute initialized to |newPorts|.
527527
1. [=Dispatch=] |e| at |destination|.
528528
1. Invoke [=Update Service Worker Extended Events Set=] with |serviceWorker| and |e|.
529529
</section>
@@ -1276,14 +1276,14 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
12761276
1. If |targetClient| is null, return.
12771277
1. Let |destination| be the {{ServiceWorkerContainer}} object whose associated [=ServiceWorkerContainer/service worker client=] is |targetClient|.
12781278
1. Add a [=task=] that runs the following steps to |destination|'s [=ServiceWorkerContainer/client message queue=]:
1279-
1. Let |origin| be the [=serialization of an origin|serialization=] of |sourceSettings|'s [=environment settings object/origin=].
1279+
1. Let |origin| be |sourceSettings|'s [=environment settings object/origin=].
12801280
1. Let |source| be the result of [=getting the service worker object=] that represents |contextObject|'s [=relevant global object=]'s [=ServiceWorkerGlobalScope/service worker=] in |targetClient|.
12811281
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=relevant Realm=]).
12821282

1283-
If this throws an exception, catch it, [=fire an event=] named {{ServiceWorkerContainer/messageerror!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin| and the {{MessageEvent/source}} attribute initialized to |source|, and then abort these steps.
1283+
If this throws an exception, catch it, [=fire an event=] named {{ServiceWorkerContainer/messageerror!!event}} at |destination|, using {{MessageEvent}}, with its [=MessageEvent/origin=] initialized to |origin| and the {{MessageEvent/source}} attribute initialized to |source|, and then abort these steps.
12841284
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
12851285
1. Let |newPorts| be a new [=frozen array type|frozen array=] consisting of all {{MessagePort}} objects in |deserializeRecord|.\[[TransferredValues]], if any.
1286-
1. [=Dispatch|Dispatch an event=] named {{Window/message!!event}} at |destination|, using {{MessageEvent}}, with the {{MessageEvent/origin}} attribute initialized to |origin|, the {{MessageEvent/source}} attribute initialized to |source|, the {{MessageEvent/data}} attribute initialized to |messageClone|, and the {{MessageEvent/ports}} attribute initialized to |newPorts|.
1286+
1. [=Dispatch|Dispatch an event=] named {{Window/message!!event}} at |destination|, using {{MessageEvent}}, with its [=MessageEvent/origin=] initialized to |origin|, the {{MessageEvent/source}} attribute initialized to |source|, the {{MessageEvent/data}} attribute initialized to |messageClone|, and the {{MessageEvent/ports}} attribute initialized to |newPorts|.
12871287
</section>
12881288

12891289
<section>
@@ -1819,6 +1819,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
18191819
};
18201820
</pre>
18211821

1822+
Each {{ExtendableMessageEvent}} has an <dfn for="ExtendableMessageEvent">origin</dfn> (an [=/origin=], a string, or null), initially null.
1823+
18221824
[=/Service workers=] define the <a method lt="waitUntil()" for="ExtendableEvent">extendable</a> {{ServiceWorkerGlobalScope/message!!event}} event to allow extending the lifetime of the event. For the {{ServiceWorkerGlobalScope/message!!event}} event, [=/service workers=] use the {{ExtendableMessageEvent}} interface which extends the {{ExtendableEvent}} interface.
18231825

18241826
<section>
@@ -1830,13 +1832,23 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
18301832
<section>
18311833
<h4 id="extendablemessage-event-origin">{{ExtendableMessageEvent/origin|event.origin}}</h4>
18321834

1833-
The <dfn attribute for="ExtendableMessageEvent">origin</dfn> attribute *must* return the value it was initialized to. When the object is created, this attribute *must* be initialized to the empty string. It represents the [=environment settings object/origin=] of the [=/service worker client=] that sent the message.
1835+
The <dfn attribute for="ExtendableMessageEvent">origin</dfn> attribute represents the [=environment settings object/origin=] of the [=/service worker client=] that sent the message.
1836+
1837+
The {{ExtendableMessageEvent/origin}} getter steps are:
1838+
1839+
1. If [=this=]'s [=ExtendableMessageEvent/origin=] is an [=/origin=], then return the [=serialization of an origin|serialization=] of [=this=]'s [=ExtendableMessageEvent/origin=].
1840+
1. If [=this=]'s [=ExtendableMessageEvent/origin=] is null, then return the empty string.
1841+
1. Return [=this=]'s [=ExtendableMessageEvent/origin=].
1842+
1843+
When the {{ExtendableMessageEvent/origin}} attribute is "initialized" (during {{ExtendableMessageEvent}}'s constructor, for example), the initialization value is placed into the object's [=ExtendableMessageEvent/origin=].
18341844
</section>
18351845

18361846
<section>
18371847
<h4 id="extendablemessage-event-lasteventid">{{ExtendableMessageEvent/lastEventId|event.lastEventId}}</h4>
18381848

18391849
The <dfn attribute for="ExtendableMessageEvent">lastEventId</dfn> attribute *must* return the value it was initialized to. When the object is created, this attribute *must* be initialized to the empty string.
1850+
1851+
Objects implementing the {{ExtendableMessageEvent}} interface's [=extract an origin=] steps are to return [=this=]'s [=ExtendableMessageEvent/origin=] if it is an [=/origin=]; otherwise null.
18401852
</section>
18411853

18421854
<section>

0 commit comments

Comments
 (0)