You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
<dd>a new {{Client}} object that represents |incumbentGlobal|'s associated worker</dd>
517
517
</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=].
519
519
1. Let |destination| be the {{ServiceWorkerGlobalScope}} object associated with |serviceWorker|.
520
520
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=global object/Realm=]).
521
521
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|.
523
523
1. Else:
524
524
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
525
525
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|.
527
527
1. [=Dispatch=] |e| at |destination|.
528
528
1. Invoke [=Update Service Worker Extended Events Set=] with |serviceWorker| and |e|.
1. Let |destination| be the {{ServiceWorkerContainer}} object whose associated [=ServiceWorkerContainer/service worker client=] is |targetClient|.
1278
1278
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=].
1280
1280
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|.
1281
1281
1. Let |deserializeRecord| be <a abstract-op>StructuredDeserializeWithTransfer</a>(|serializeWithTransferResult|, |destination|'s [=relevant Realm=]).
1282
1282
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.
1284
1284
1. Let |messageClone| be |deserializeRecord|.\[[Deserialized]].
1285
1285
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|.
Each {{ExtendableMessageEvent}} has an <dfn for="ExtendableMessageEvent">origin</dfn> (an [=/origin=], a string, or null), initially null.
1823
+
1822
1824
[=/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.
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.
When the {{ExtendableMessageEvent/origin}} attribute is "initialized" (during {{ExtendableMessageEvent}}'s constructor, for example), the initialization value is placed into the object's [=ExtendableMessageEvent/origin=].
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.
0 commit comments