From e7012cb0782af2103e8eadae70d40a2b22eaab54 Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Thu, 6 Sep 2018 14:03:40 -0400 Subject: [PATCH] Add user activation interface. Describe the interface and augment PostMessage options to contain the required fields. Fixes #4008 --- source | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/source b/source index f839d5d391c..488c1d4d724 100644 --- a/source +++ b/source @@ -73335,7 +73335,7 @@ END:VCARD seconds, so that the user can possibly perceive the link between an interaction with the page and the page calling the activation-gated API.

-

These two values imply two boolean user activation states for W:

+

These two values imply two boolean user activation states for W:

Sticky activation
@@ -73481,6 +73481,74 @@ END:VCARD
+

The UserActivation interface

+ +

The user activation states are exposed via the UserActivation + interface. UserActivation objects can be created either as a live or snapshot object, + it depends on how the object was referenced. Objects accessed via navigator's userActivation attribute are live, in that changes + will in the user activation states will be reflected in the attributes of the object. + UserActivation objects retrieved via MessageEvent's userActivation attribute will be snapshot objects, + that is a snapshot of the source's state.

+ +
[Exposed=(Window,Worker,AudioWorklet)]
+interface UserActivation {
+  readonly attribute boolean hasBeenActive;
+  readonly attribute boolean isActive;
+};
+
+partial interface Navigator {
+  [SameObject] readyonly attribute UserActivation userActivation;
+};
+ +
+ +
navigator . userActivation
+ +
+ +

Returns the a live object representing the current user activation states.

+ +
+ +
userActivation . hasBeenActive
+ +
+ +

Returns the state of the sticky activation.

+ +
+ +
userActivation . isActive
+ +
+ +

Returns the state of the transient activation.

+ +
+ +
+ +
+ +

The hasBeenActive attribute + must return the state of the sticky activation. If the object is live it must + always reflect the current state. If the object is a snapshot it must reflect the state at which + the time the object was created.

+ +

The isActive attribute must return + the state of the transient activation. If the object is live it must always + reflect the current state. If the object is a snapshot it must reflect the state at which the time + the object was created.

+ +

The userActivation attribute must + return a live representation of the user activation states.

+ +

Activation behavior of elements

@@ -96717,6 +96785,7 @@ interface MessageEvent : Event { readonly attribute DOMString lastEventId; readonly attribute MessageEventSource? source; readonly attribute FrozenArray<MessagePort> ports; + readonly attribute UserActivation? userActivation; void initMessageEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional any data = null, optional USVString origin = "", optional DOMString lastEventId = "", optional MessageEventSource? source = null, optional sequence<MessagePort> ports = []); }; @@ -96727,6 +96796,7 @@ dictionary MessageEventInit : EventInit { DOMString lastEventId = ""; MessageEventSource? source = null; sequence<MessagePort> ports = []; + UserActivation? userActivation = null; }; typedef (WindowProxy or MessagePort or ServiceWorker) MessageEventSource; @@ -96779,6 +96849,15 @@ typedef (WindowProxy or MessagePort or ServiceWo +
event . userActivation
+ +
+ +

Returns a snapshot of the UserActivation state in the + source at the time of postMessage().

+ +
+ @@ -96811,6 +96890,10 @@ typedef (WindowProxy or MessagePort or ServiceWo value it was initialized to. It represents, in cross-document messaging and channel messaging, the MessagePort array being sent.

+

The userActivation attribute + must return the value it was initialized to. It represents the UserActivation state + at the source.

+

The initMessageEvent() method must initialize the event in a manner analogous to the similarly-named +

  • Let userActivationSnapshot be null

  • + +
  • If options's includeUserActivation member is true, set + userActivationSnapshot to be incumbent settings's global object's (if + available) user activation states.

  • +
  • Let targetOrigin be options["targetOrigin"].

  • @@ -98824,8 +98913,10 @@ function receiver(e) { attribute initialized to origin, the source attribute initialized to source, the data attribute initialized to - messageClone, and the ports attribute - initialized to newPorts.

    + messageClone, the ports attribute + initialized to newPorts, and the userActivation attribute initialized to + userActivationSnapshot.

    @@ -99140,6 +99231,7 @@ interface MessagePort : EventTarget { dictionary PostMessageOptions { sequence<object> transfer = []; + boolean includeUserActivation = false; };
    @@ -99304,6 +99396,14 @@ dictionary PostMessageOptions { MessagePort, then throw a "DataCloneError" DOMException.

    +
  • Let userActivationSnapshot be null.

  • + +
  • Let incumbent settings be the incumbent settings object.

  • + +
  • If options's includeUserActivation member is true, set + userActivationSnapshot to be incumbent settings's global object's (if + available) user activation states.

  • +
  • Let doomed be false.

  • If targetPort is not null and transfer Fire an event named message at finalTargetPort, using MessageEvent, with the data attribute - initialized to messageClone and the ports attribute initialized to - newPorts.

  • + initialized to messageClone, the ports + attribute initialized to newPorts, and the userActivation attribute initialized to + userActivationSnapshot.

    @@ -99430,6 +99531,11 @@ dictionary PostMessageOptions { message queue must be enabled, as if the start() method had been called.

    +

    If a MessagePort object's onmessage IDL attribute is set, the port's port + message queue must be enabled, as if the start() + method had been called.

    +