16

Portals API

 3 years ago
source link: https://wicg.github.io/portals/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
This spec is behind the explainer

This specification document has not yet been updated to reflect the 2020-04 updates to the explainer . We’ll fix that as soon as we can, but please be aware that there are probably contradictions, and the explainer should be taken as more authoritative for the time being.

1. Introduction

This section is non-normative.

This specification extendsto define a new kind of top-level browsing context , which can be embedded in another document, and a mechanism for replacing the contents of another top-level browsing context with the previously embedded context.

It is structured as a series of patches to HTML and other specifications, with each major section indicating where each it would be placed in the event of eventual graduation from incubation.

2. Portal browsing contexts

The following section would be added as a new sub-section of's Browsing contexts section.

Every browsing context has a portal state , which may be " none " (the default), " portal " or " orphaned ". A nested browsing context always has the" none ".

Briefly, these correspond to:

  • " portal ": top-level browsing contexts embedded in a portal element

  • " orphaned ": top-level browsing contexts which have run activate but have not (yet) been

  • " none ": all other browsing contexts

fUbQBje.png!web

A top-level " none " context can become " orphaned " byanother context. An " orphaned " context can beto become a " portal " context. A " portal " context can become a " none " context by beingby itshost browsing context.

A browsing context can be closed while in any of these states.

A portal browsing context is a browsing context whoseis " portal ".

The host element of aportal browsing contextis a portal element which embeds its rendered output and receives messages sent from the portal browsing context.

A portal element may only be awhile it is browsing-context connected or during the dispatch of the portalactivate event from which it was obtained using adoptPredecessor() .

The host browsing context of aportal browsing contextis its's node document 's browsing context .

The portal task source is a task source used for tasks related to the portal lifecycle and communication between aportal browsing contextand itshost browsing context.

To activate a portal browsing context successorBrowsingContext in place of predecessorBrowsingContext with origin sourceOrigin , data serializeWithTransferResult , and promise promise , run the following steps in parallel :
  1. Assert : Theof predecessorBrowsingContext is " none ".

  2. Set theof successorBrowsingContext to null.

    User agents should , however, attempt to preserve the rendering of the guest browsing context until predecessorBrowsingContext has been replaced with successorBrowsingContext in the rendering.

    Note: This is intended to avoid a visual glitch, such as a "white flash", where the guest browsing context briefly disappears.

  3. Set theof predecessorBrowsingContext to " orphaned ".

  4. Update the user interface to replace predecessorBrowsingContext with successorBrowsingContext (e.g., by updating the tab/window contents and browser chrome).

  5. Let successorWindow be successorBrowsingContext ’s associated WindowProxy 's [[Window]] internal slot value.

  6. Queue a global task on thegiven successorWindow to run the following steps:

    1. Assert : Theof successorBrowsingContext is " portal ".

    2. Set theof successorBrowsingContext to " none ".

    3. Let targetRealm be successorWindow ’s realm .

    4. Let dataClone be null.

    5. If successorBrowsingContext ’s active document 's origin is same origin with sourceOrigin , then:

      1. Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ), and set dataClone to deserializeRecord .[[Deserialized]].

        If this throws an exception, catch it and do nothing.

    6. Let event be the result of creating an event using PortalActivateEvent and targetRealm .

    7. Initialize event ’s type attribute to portalactivate .

    8. Initialize event ’s data attribute to dataClone .

    9. Set event ’spredecessor browsing contextto predecessorBrowsingContext .

    10. Set event ’sto successorWindow .

    11. Set event ’sto promise .

    12. Dispatch event to successorWindow .

    13. Let adoptedPredecessorElement be event ’sadopted predecessor element.

    14. If adoptedPredecessorElement is not null, then:

      1. Set adoptedPredecessorElement ’sto false.

      2. If adoptedPredecessorElement may not have a guest browsing contextand itsguest browsing contextis not null, then discard it.

        This unceremoniously discards the browsing context, as if the element had been removed from the document after previously being attached. This is distinct from the case where the predecessor was never adopted, below, which closes the browsing context, which dispatches the unload event, somewhat similarly to if it had performed an ordinary navigation.

        Typically authors would not call adoptPredecessor() unless they intend to insert it into the document before thebecomes false.

    15. Otherwise:

      1. Queue a global task on thegiven predecessorBrowsingContext ’s active window to resolve promise with undefined.

      2. Close predecessorBrowsingContext .

        The user agent should not ask the user for confirmation during the prompt to unload step (and so the browsing context should be discarded ).

In the case that structured deserialization throws, it may be useful to do something else to indicate it, rather than simply providing null data.

We need to specify how the session history of each browsing context is affected by activation, and supply non-normative text that explains how these histories are expected to be presented to the user.

To adopt the predecessor browsing context predecessorBrowsingContext in successorWindow , run the following steps:
  1. Let document be the document of successorWindow .

  2. Let portalElement be the result of creating an element given document , portal , and the HTML namespace .

  3. Set portalElement ’sto true.

  4. Assert : portalElement is an HTMLPortalElement .

  5. Queue a global task on thegiven predecessorBrowsingContext ’s active window to run the following steps:

    1. Assert : Theof predecessorBrowsingContext is " orphaned ".

    2. Set theof predecessorBrowsingContext to " portal ", and set theof predecessorBrowsingContext to portalElement .

  6. Return portalElement .

Since the task to set the, and thus expose the PortalHost object, is queued first, and from the same task source , it is exposed at the time thereturned from activate(options) is resolved.
<c- c1="">
 // In the successor document.
</c->
onportalactivate 
<c- o="">
 =
</c-> event 
<c- p="">
 =>
</c-> 
<c- p="">
 {
</c->
  
<c- c1="">
 // The predecessor document is adopted into a <portal> element...
</c->
  document
<c- p="">
 .
</c->body
<c- p="">
 .
</c->appendChild
<c- p="">
 (
</c->event
<c- p="">
 .
</c->adoptPredecessor
<c- p="">
 ());
</c->

<c- p="">
 });
</c->


<c- c1="">
 // In the predecessor document.
</c->
portalElement
<c- p="">
 .
</c->activate
<c- p="">
 ().
</c->then
<c- p="">
 (()
</c-> 
<c- p="">
 =>
</c-> 
<c- p="">
 {
</c->
  
<c- c1="">
 // ...and it is guaranteed to observe that change by the time the
</c->
  
<c- c1="">
 // activation promise resolves.
</c->
  console
<c- p="">
 .
</c->assert
<c- p="">
 (
</c->window
<c- p="">
 .
</c->portalHost 
<c- k="">
 instanceof
</c-> PortalHost
<c- p="">
 );
</c->

<c- p="">
 });
</c->

3. The portal element

The following section would be added as a new subsection of's Embedded content section.

A portal element allows for aportal browsing contextto be embedded in an HTML document.

A portal element portalElement has a guest browsing context , which is theportal browsing contextwhoseis portalElement , or null if no such browsing context exists.

A portal element has a just-adopted flag , which is a boolean and is initially false. It is set during dispatch of the portalactivate event.

The src attribute gives the URL of a page that theguest browsing contextis to contain. The attribute, if present, must be a valid non-empty URL potentially surrounded by spaces .

The referrerpolicy attribute is a referrer policy attribute . Its purpose is to set thereferrer policy used whensetting the source URL of a portal element.

A portal is similar to an iframe , in that it allows another browsing context to be embedded. However, theportal browsing contexthosted by a portal is part of a separate browsing context group , and thus a separateagent. The user agent is therefore free to use a separate event loop for the browsing contexts, even if they are same origin-domain .

[<a data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed" id="ref-for-Exposed">
 <c- g="">
  Exposed
 </c-></a>=
<c- n="">
 Window
</c->, <a data-link-type="extended-attribute" href="https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor" id="ref-for-htmlconstructor">
 <c- g="">
  HTMLConstructor
 </c-></a>]

<c- b="">
 interface
</c-> <dfn data-dfn-type="interface" data-export="" id="htmlportalelement"><code>
  <c- g="">
   HTMLPortalElement
  </c-></code></dfn> : <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement" id="ref-for-htmlelement">
 <c- n="">
  HTMLElement
 </c-></a> {
    [<a data-link-type="extended-attribute" href="https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions" id="ref-for-cereactions">
 <c- g="">
  CEReactions
 </c-></a>] 
<c- b="">
 attribute
</c-> <a data-link-type="interface" href="https://heycam.github.io/webidl/#idl-USVString" id="ref-for-idl-USVString">
 <c- b="">
  USVString
 </c-></a> <a data-link-type="attribute" data-type="USVString" href="#dom-htmlportalelement-src" id="ref-for-dom-htmlportalelement-src">
 <c- g="">
  src
 </c-></a>;
    [<a data-link-type="extended-attribute" href="https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions" id="ref-for-cereactions①">
 <c- g="">
  CEReactions
 </c-></a>] 
<c- b="">
 attribute
</c-> <a data-link-type="interface" href="https://heycam.github.io/webidl/#idl-DOMString" id="ref-for-idl-DOMString">
 <c- b="">
  DOMString
 </c-></a> <a data-link-type="attribute" data-type="DOMString" href="#dom-htmlportalelement-referrerpolicy" id="ref-for-dom-htmlportalelement-referrerpolicy">
 <c- g="">
  referrerPolicy
 </c-></a>;

    [<a data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#NewObject" id="ref-for-NewObject">
 <c- g="">
  NewObject
 </c-></a>] 
<c- b="">
 Promise
</c-><
<c- b="">
 void
</c->> <a data-link-type="method" href="#dom-htmlportalelement-activate" id="ref-for-dom-htmlportalelement-activate②">
 <c- g="">
  activate
 </c-></a>(
<c- b="">
 optional
</c-> <a data-link-type="idl-name" href="#dictdef-portalactivateoptions" id="ref-for-dictdef-portalactivateoptions">
 <c- n="">
  PortalActivateOptions
 </c-></a> <dfn data-dfn-for="HTMLPortalElement/activate(options), HTMLPortalElement/activate()" data-dfn-type="argument" data-export="" id="dom-htmlportalelement-activate-options-options"><code>
  <c- g="">
   options
  </c-></code><a href="#dom-htmlportalelement-activate-options-options"></a></dfn>);
    
<c- b="">
 void
</c-> <a data-link-type="method" href="#dom-htmlportalelement-postmessage" id="ref-for-dom-htmlportalelement-postmessage">
 <c- g="">
  postMessage
 </c-></a>(
<c- b="">
 any
</c-> <dfn data-dfn-for="HTMLPortalElement/postMessage(message, options), HTMLPortalElement/postMessage(message)" data-dfn-type="argument" data-export="" id="dom-htmlportalelement-postmessage-message-options-message"><code>
  <c- g="">
   message
  </c-></code><a href="#dom-htmlportalelement-postmessage-message-options-message"></a></dfn>, 
<c- b="">
 optional
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/web-messaging.html#postmessageoptions" id="ref-for-postmessageoptions">
 <c- n="">
  PostMessageOptions
 </c-></a> <dfn data-dfn-for="HTMLPortalElement/postMessage(message, options), HTMLPortalElement/postMessage(message)" data-dfn-type="argument" data-export="" id="dom-htmlportalelement-postmessage-message-options-options"><code>
  <c- g="">
   options
  </c-></code><a href="#dom-htmlportalelement-postmessage-message-options-options"></a></dfn> = {});

    
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler">
 <c- n="">
  EventHandler
 </c-></a> <dfn data-dfn-for="HTMLPortalElement" data-dfn-type="attribute" data-export="" data-type="EventHandler" id="dom-htmlportalelement-onmessage"><code>
  <c- g="">
   onmessage
  </c-></code></dfn>;
    
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler①">
 <c- n="">
  EventHandler
 </c-></a> <dfn data-dfn-for="HTMLPortalElement" data-dfn-type="attribute" data-export="" data-type="EventHandler" id="dom-htmlportalelement-onmessageerror"><code>
  <c- g="">
   onmessageerror
  </c-></code></dfn>;
};


<c- b="">
 dictionary
</c-> <dfn data-dfn-type="dictionary" data-export="" id="dictdef-portalactivateoptions"><code>
  <c- g="">
   PortalActivateOptions
  </c-></code></dfn> : <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/web-messaging.html#postmessageoptions" id="ref-for-postmessageoptions①">
 <c- n="">
  PostMessageOptions
 </c-></a> {
    
<c- b="">
 any
</c-> <dfn data-dfn-for="PortalActivateOptions" data-dfn-type="dict-member" data-export="" data-type="any " id="dom-portalactivateoptions-data"><code>
  <c- g="">
   data
  </c-></code></dfn>;
};

The src IDL attribute must reflect the src content attribute.

The referrerPolicy IDL attribute must reflect the referrerpolicy content attribute, limited to only known values .

The activate(options) method must run these steps:
  1. Let portalBrowsingContext be theguest browsing contextofthis.

  2. If portalBrowsingContext is null, throw an " InvalidStateError " DOMException .

  3. Let predecessorBrowsingContext be the browsing context ofthis's node document .

  4. If predecessorBrowsingContext is null, throw an " InvalidStateError " DOMException .

  5. If theof predecessorBrowsingContext is not " none ", throw an " InvalidStateError " DOMException .

    Note: This means that a portal element inside aportal browsing contextcannot be activated.

  6. Let serializeWithTransferResult be StructuredSerializeWithTransfer ( options [" data "], options [" transfer "]). Rethrow any exceptions.

  7. Let promise be a newpromise.

  8. Let sourceOrigin bethis's relevant settings object 's origin .

  9. Run the steps to portalBrowsingContext in place of predecessorBrowsingContext with sourceOrigin , serializeWithTransferResult , and promise .

  10. Return promise .

The postMessage(message, options) method must run these steps:
  1. Let portalBrowsingContext be theguest browsing contextofthis.

  2. If portalBrowsingContext is null, throw an " InvalidStateError " DOMException .

  3. Let sourceOrigin bethis's relevant settings object 's origin .

  4. Let transfer be options [" transfer "].

  5. Let serializeWithTransferResult be StructuredSerializeWithTransfer ( message , transfer ). Rethrow any exceptions.

  6. Queue a global task on thegiven portalBrowsingContext ’s active window to run the following steps:

    1. If portalBrowsingContext ’s active document 's origin is not same origin with sourceOrigin , then abort these steps.

    2. Let origin be the serialization of sourceOrigin .

    3. Let targetWindow be portalBrowsingContext ’s associated WindowProxy 's [[Window]] internal slot value.

    4. Let portalHost be the targetWindow ’s.

    5. Let targetRealm be the targetWindow ’s realm .

    6. Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ).

      If this throws an exception, catch it, fire an event named messageerror at portalHost using MessageEvent with the origin attribute initialized to origin and the source attribute initialized to portalHost , then abort these steps.

    7. Let messageClone be deserializeRecord .[[Deserialized]].

    8. Let newPorts be a newfrozen array consisting of all MessagePort objects in deserializeRecord .[[TransferredValues]], if any, maintaining their relative order.

    9. Fire an event named message at portalHost using MessageEvent , with the origin attribute initialized to origin , the source attribute initialized to portalHost , the data attribute initialized to messageClone , and the ports attribute initialized to newPorts .

To determine whether a portal element may have a guest browsing context , run the following steps:
  1. If element ’s node document 's browsing context is not a top-level browsing context , then return false.

    The user agent may choose to emit a warning if the author attempts to use a portal element in a nested browsing context , as this is not supported.

  2. If element ’s node document 's URL 's scheme is not an HTTP(S) scheme , then return false.

    This is to prevent problems later, if the portaled content attempts toadopt its predecessor. Since portaled content can only have a HTTP(S) scheme , adoption would fail, and so its simpler to restrict things at this stage.

  3. If element ’s node document 's active sandboxing flag set is not empty, then return false.

    Since portals cannot be created in child browsing contexts anyway, this step is about preventing portal uses in auxiliary browsing contexts spawned by sandboxed iframe s, or pages using CSP’ssandbox directive.

    This restriction is largely added for simplicity. If there are use cases for portals inside sandboxed documents, we can enable them in the future, with appropriate opt-in. See issue #207 for discussion.

  4. If element is browsing-context connected , then return true.

  5. If element ’sis true, then return true.

  6. Return false.

To close a portal element element , run the following steps:
  1. If element ’sguest browsing contextis not null, then close it.

    The user agent should not ask the user for confirmation during the prompt to unload step (and so the browsing context should be discarded ).

To set the source URL of a portal element element , run the following steps:
  1. Assert : element may have a guest browsing context.

  2. Let hostBrowsingContext be element ’s node document 's browsing context .

  3. Assert : hostBrowsingContext is a top-level browsing context .

  4. If element has no src attribute specified, or its value is the empty string, then element and return.

  5. Parse the value of the src attribute. If that is not successful, then element and return.

    Otherwise, let url be the resulting URL record .

  6. If the scheme of url is not an HTTP(S) scheme , then element and return.

  7. If element ’sguest browsing contextis null, then run the following steps:

    1. Let newBrowsingContext be the result of creating a new top-level browsing context .

    2. Set theof newBrowsingContext to " portal ", and set theof newBrowsingContext to element .

  8. Let guestBrowsingContext be element ’sguest browsing context.

  9. Assert : guestBrowsingContext is not null.

  10. Let resource be a new request whose URL is url and whose referrer policy is the current state of element ’s referrerpolicy content attribute.

  11. Navigate guestBrowsingContext to resource .

Unlike an iframe element, a portal element supports a state where it has no associated browsing context. This is the initial state of a portal element (i.e., it has no initial about:blank document; instead it navigates directly to the first parsable URL assigned to it).

Similarly, a portal element responds to an unparsable src URL by closing its browsing context, rather than by navigating to about:blank .

Whenever a portal element element has its src attribute set, changed, or removed, run the following steps:

  1. If element may have a guest browsing context, thenof element .

Whenever a portal element element becomes browsing-context connected , run the following steps:

  1. If element may not have a guest browsing context, then abort these steps.

  2. If element ’sguest browsing contextis not null, then abort these steps.

    This ensures that a newly portal element can be inserted into the document without navigating it.
  3. of element .

Whenever a portal element element becomes browsing-context disconnected , run the following steps:

  1. If element may not have a guest browsing contextand itsguest browsing contextis not null, then discard it.

It might be convenient to not immediately detach the portal element, but instead to do so in a microtask. This would allow developers to reinsert the portal element without losing its browsing context.

Whenever a portal element element is adopted , run the following steps:

  1. Let guestBrowsingContext be element ’sguest browsing context.

  2. If guestBrowsingContext is null, then abort these steps.

  3. Discard guestBrowsingContext .

In particular, this means a portal element loses itsguest browsing contextif it is moved to the active document of a nested browsing context .

Similarly, the steps when a portal element’sprevent elements from creating a newguest browsing contextwhile inside such documents.

It is therefore impossible to embed aportal browsing contextin a nested browsing context .

Whenever a Document object document whose browsing context is aportal browsing contextis marked as completely loaded , run the following steps as part of the queued task:

  1. Let element be document ’s browsing context 's.

  2. Fire an event named load at element .

The following events are dispatched on HTMLPortalElement objects:

Event name Interface Dispatched when message MessageEvent A message is received by the object, and deserialization does not throw an exception. messageerror MessageEvent A message is received by the object, but deserialization throws an exception.

The portal element exposes onmessage and onmessageerror as event handler content attributes .

3.1. Portal hosts

Every Window has a portal host object , which is a PortalHost . It is exposed through the portalHost attribute getter at times when the window may be in aportal browsing context.

Thecan be used to communicate with thehost browsing context. Its operations throw if used while its context is not aportal browsing context(i.e. there is no host), in the event that JavaScript code has saved a reference to it. At such times, the window.portalHost getter will return null.

<c- b="">
 partial
</c-> 
<c- b="">
 interface
</c-> <a data-link-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window" id="ref-for-window①">
 <c- g="">
  Window
 </c-></a> {
    
<c- b="">
 readonly
</c-> 
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="#portalhost" id="ref-for-portalhost②">
 <c- n="">
  PortalHost
 </c-></a>? <a data-link-type="attribute" data-readonly="" data-type="PortalHost?" href="#dom-window-portalhost" id="ref-for-dom-window-portalhost②">
 <c- g="">
  portalHost
 </c-></a>;
};
The portalHost attribute’s getter must run the following steps:
  1. Let context bethis's browsing context .

  2. If context is null or theof context is not " portal ", then return null.

  3. Returnthis's.

The PortalHost interface definition is as follows:

[<a data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed" id="ref-for-Exposed①">
 <c- g="">
  Exposed
 </c-></a>=
<c- n="">
 Window
</c->]

<c- b="">
 interface
</c-> <dfn data-dfn-type="interface" data-export="" id="portalhost"><code>
  <c- g="">
   PortalHost
  </c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget">
 <c- n="">
  EventTarget
 </c-></a> {
    
<c- b="">
 void
</c-> <a data-link-type="method" href="#dom-portalhost-postmessage" id="ref-for-dom-portalhost-postmessage">
 <c- g="">
  postMessage
 </c-></a>(
<c- b="">
 any
</c-> <dfn data-dfn-for="PortalHost/postMessage(message, options), PortalHost/postMessage(message)" data-dfn-type="argument" data-export="" id="dom-portalhost-postmessage-message-options-message"><code>
  <c- g="">
   message
  </c-></code><a href="#dom-portalhost-postmessage-message-options-message"></a></dfn>, 
<c- b="">
 optional
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/web-messaging.html#postmessageoptions" id="ref-for-postmessageoptions②">
 <c- n="">
  PostMessageOptions
 </c-></a> <dfn data-dfn-for="PortalHost/postMessage(message, options), PortalHost/postMessage(message)" data-dfn-type="argument" data-export="" id="dom-portalhost-postmessage-message-options-options"><code>
  <c- g="">
   options
  </c-></code><a href="#dom-portalhost-postmessage-message-options-options"></a></dfn>);

    
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler②">
 <c- n="">
  EventHandler
 </c-></a> <dfn data-dfn-for="PortalHost" data-dfn-type="attribute" data-export="" data-type="EventHandler" id="dom-portalhost-onmessage"><code>
  <c- g="">
   onmessage
  </c-></code><a href="#dom-portalhost-onmessage"></a></dfn>;
    
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler③">
 <c- n="">
  EventHandler
 </c-></a> <dfn data-dfn-for="PortalHost" data-dfn-type="attribute" data-export="" data-type="EventHandler" id="dom-portalhost-onmessageerror"><code>
  <c- g="">
   onmessageerror
  </c-></code><a href="#dom-portalhost-onmessageerror"></a></dfn>;
};
The postMessage(message, options) method must run these steps:
  1. Let browsingContext bethis's relevant global object 's browsing context .

  2. If browsingContext has aother than " portal ", throw an " InvalidStateError " DOMException .

    Note: This roughly means that it has not yet been activated, as far as this event loop has been told. It is possible that this browsing context will bein parallel to this message being sent; in such cases, messages may not be delivered.

  3. Let sourceOrigin bethis's relevant settings object 's origin .

  4. Let transfer be options [" transfer "].

  5. Let serializeWithTransferResult be StructuredSerializeWithTransfer ( message , transfer ). Rethrow any exceptions.

  6. Let hostElement be theof browsingContext .

  7. Queue an element task on thegiven hostElement to run the following steps:

    1. If browsingContext is not theguest browsing contextof hostElement , then abort these steps.

      Note: This might happen if this event loop had a queued task to deliver a message, but it was not executed before the portal was. In such cases, the message is not delivered.

    2. Let targetSettings be the relevant settings object of hostElement .

    3. If targetSettings ’s origin is not same origin with sourceOrigin , then abort these steps.

    4. Let origin be the serialization of sourceOrigin .

    5. Let targetRealm be targetSettings ’s realm .

    6. Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ).

      If this throws an exception, catch it, fire an event named messageerror at element using MessageEvent with the origin attribute initialized to origin and the source attribute initialized to element .

    7. Let messageClone be deserializeRecord .[[Deserialized]].

    8. Let newPorts be a newfrozen array consisting of all MessagePort objects in deserializeRecord .[[TransferredValues]], if any, maintaining their relative order.

    9. Fire an event named message at the element using MessageEvent , with the origin attribute initialized to origin , the source attribute initialized to element , the data attribute initialized to messageClone , and the ports attribute initialized to newPorts .

The following events are dispatched on PortalHost objects:

Event name Interface Dispatched when message MessageEvent A message is received by the object, and deserialization does not throw an exception. messageerror MessageEvent A message is received by the object, but deserialization throws an exception.

3.2. The PortalActivateEvent interface

[<a data-link-type="extended-attribute" href="https://heycam.github.io/webidl/#Exposed" id="ref-for-Exposed②">
 <c- g="">
  Exposed
 </c-></a>=
<c- n="">
 Window
</c->]

<c- b="">
 interface
</c-> <dfn data-dfn-type="interface" data-export="" id="portalactivateevent"><code>
  <c- g="">
   PortalActivateEvent
  </c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#event" id="ref-for-event">
 <c- n="">
  Event
 </c-></a> {
    <dfn data-dfn-for="PortalActivateEvent" data-dfn-type="constructor" data-export="" data-lt="PortalActivateEvent(type, eventInitDict)|constructor(type, eventInitDict)|PortalActivateEvent(type)|constructor(type)" id="dom-portalactivateevent-portalactivateevent"><code>
  <c- g="">
   constructor
  </c-></code><a href="#dom-portalactivateevent-portalactivateevent"></a></dfn>(<a data-link-type="interface" href="https://heycam.github.io/webidl/#idl-DOMString" id="ref-for-idl-DOMString①">
 <c- b="">
  DOMString
 </c-></a> <dfn data-dfn-for="PortalActivateEvent/PortalActivateEvent(type, eventInitDict), PortalActivateEvent/constructor(type, eventInitDict), PortalActivateEvent/PortalActivateEvent(type), PortalActivateEvent/constructor(type)" data-dfn-type="argument" data-export="" id="dom-portalactivateevent-portalactivateevent-type-eventinitdict-type"><code>
  <c- g="">
   type
  </c-></code><a href="#dom-portalactivateevent-portalactivateevent-type-eventinitdict-type"></a></dfn>, 
<c- b="">
 optional
</c-> <a data-link-type="idl-name" href="#dictdef-portalactivateeventinit" id="ref-for-dictdef-portalactivateeventinit">
 <c- n="">
  PortalActivateEventInit
 </c-></a> <dfn data-dfn-for="PortalActivateEvent/PortalActivateEvent(type, eventInitDict), PortalActivateEvent/constructor(type, eventInitDict), PortalActivateEvent/PortalActivateEvent(type), PortalActivateEvent/constructor(type)" data-dfn-type="argument" data-export="" id="dom-portalactivateevent-portalactivateevent-type-eventinitdict-eventinitdict"><code>
  <c- g="">
   eventInitDict
  </c-></code><a href="#dom-portalactivateevent-portalactivateevent-type-eventinitdict-eventinitdict"></a></dfn> = {});

    
<c- b="">
 readonly
</c-> 
<c- b="">
 attribute
</c-> 
<c- b="">
 any
</c-> <dfn data-dfn-for="PortalActivateEvent" data-dfn-type="attribute" data-export="" data-readonly="" data-type="any" id="dom-portalactivateevent-data"><code>
  <c- g="">
   data
  </c-></code></dfn>;
    <a data-link-type="idl-name" href="#htmlportalelement" id="ref-for-htmlportalelement②">
 <c- n="">
  HTMLPortalElement
 </c-></a> <a data-link-type="method" href="#dom-portalactivateevent-adoptpredecessor" id="ref-for-dom-portalactivateevent-adoptpredecessor②">
 <c- g="">
  adoptPredecessor
 </c-></a>();
};


<c- b="">
 dictionary
</c-> <dfn data-dfn-type="dictionary" data-export="" id="dictdef-portalactivateeventinit"><code>
  <c- g="">
   PortalActivateEventInit
  </c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit" id="ref-for-dictdef-eventinit">
 <c- n="">
  EventInit
 </c-></a> {
    
<c- b="">
 any
</c-> <dfn data-default="null" data-dfn-for="PortalActivateEventInit" data-dfn-type="dict-member" data-export="" data-type="any " id="dom-portalactivateeventinit-data"><code>
  <c- g="">
   data
  </c-></code><a href="#dom-portalactivateeventinit-data"></a></dfn> = 
<c- b="">
 null
</c->;
};

For now, there is no ports attribute on PortalActivateEvent , despite it being used for data transfer in a similar way to MessageEvent . This omission is for simplicity, and could be reconsidered if a use case is found. (See also whatwg/html#4521 for a potential expansion.)

A PortalActivateEvent has an associated predecessor browsing context , which is a top-level browsing context or null, a successor window , which is a Window , an activation promise , which is apromise, and a adopted predecessor element , which is a portal element or null.

The event constructing steps for PortalActivateEvent , given an event , are as follows:
  1. Set event ’spredecessor browsing contextto null.

  2. Set event ’sto null.

  3. Set event ’sadopted predecessor elementto null.

The adoptPredecessor() method must run these steps:
  1. Ifthis'sadopted predecessor elementis not null, throw an " InvalidStateError " DOMException .

  2. Let predecessorBrowsingContext bethis'spredecessor browsing context.

  3. Let successorWindow bethis's.

  4. Run the steps toadopt the predecessor browsing context predecessorBrowsingContext in successorWindow , and let adoptedPredecessorElement be the result.

  5. Setthis'sadopted predecessor elementto adoptedPredecessorElement .

  6. Queue a global task on thegiven predecessorBrowsingContext ’s active window to resolvethis'swith undefined.

    Note: Queuing this immediately makes it possible to send messages to the adopted portal during dispatch of the portalactivate event without ordering issues between the task to resolve the activation promise and the task to deliver the message.

  7. Return adoptedPredecessorElement .

4. Miscellaneous HTML updates

This section contains various small patches to miscellaneous areas of the HTML Standard.

4.1. The MessageEvent interface

The MessageEventSource union is extended to include the new interfaces which can produce MessageEvent events.

<c- b="">
 typedef
</c-> (<a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/window-object.html#windowproxy" id="ref-for-windowproxy②">
 <c- n="">
  WindowProxy
 </c-></a> 
<c- b="">
 or
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/web-messaging.html#messageport" id="ref-for-messageport②">
 <c- n="">
  MessagePort
 </c-></a> 
<c- b="">
 or
</c-> <a data-link-type="idl-name" href="https://w3c.github.io/ServiceWorker/#serviceworker" id="ref-for-serviceworker">
 <c- n="">
  ServiceWorker
 </c-></a> 
<c- b="">
 or
</c-> <a data-link-type="idl-name" href="#htmlportalelement" id="ref-for-htmlportalelement③">
 <c- n="">
  HTMLPortalElement
 </c-></a> 
<c- b="">
 or
</c-> <a data-link-type="idl-name" href="#portalhost" id="ref-for-portalhost⑤">
 <c- n="">
  PortalHost
 </c-></a>) <dfn data-dfn-type="typedef" data-export="" id="typedefdef-messageeventsource"><code>
  <c- g="">
   MessageEventSource
  </c-></code></dfn>;

4.2. Event handlers

The table of event handlers which must be supported by Window objects, as event handler IDL attributes on the Window objects themselves (i.e. the table containing onafterprint ), gets extended with the following row:

Event handler Event handler event type onportalactivate portalactivate

The corresponding WindowEventHandlers mixin gets extended as follows:

<c- b="">
 partial
</c-> 
<c- b="">
 interface
</c-> 
<c- b="">
 mixin
</c-> <a data-link-type="interface" href="https://html.spec.whatwg.org/multipage/webappapis.html#windoweventhandlers" id="ref-for-windoweventhandlers①">
 <c- g="">
  WindowEventHandlers
 </c-></a> {
    
<c- b="">
 attribute
</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler④">
 <c- n="">
  EventHandler
 </c-></a> <dfn data-dfn-for="WindowEventHandlers" data-dfn-type="attribute" data-export="" data-type="EventHandler" id="dom-windoweventhandlers-onportalactivate"><code>
  <c- g="">
   onportalactivate
  </c-></code><a href="#dom-windoweventhandlers-onportalactivate"></a></dfn>;
};

The Events index is also updated with the following additional row:

Event Interface Interesting targets Description portalactivate PortalActivateEvent Window Fired at the Window of aportal browsing contextwhen thatportal browsing contextis activated.

5. Updates to other specifications

5.1. Content Security Policy

This specification integrates withas follows.

The algorithm for determining the effective directive for a request request is modified by prepending the following:
  1. If request ’s initiator is "", its destination is " document ", and its target browsing context is aportal browsing context, return frame-src .

The frame-ancestors Navigation Response Check is modified as follows:
  1. Replace all references to " nested browsing context " with " nested browsing context orportal browsing context".

  2. Replace all references to " parent browsing context " with " parent browsing context orhost browsing context".

activate(options) should also respect the CSPnavigate-to directive.

5.2. RFC 7034

This specification integrates with, which defines the X-Frame-Options HTTP header, as follows. Note thatalso has an open issue, whatwg/html#1230 , to define X-Frame-Options processing, and perhaps these updates would be done as part of resolving that issue.

If a browser receives content with this header field in response to a navigation request whose target browsing context is aportal browsing context, then the browser must apply the rules inas though it were to be displayed in a frame in thehost browsing contextinstead and as though the origin of the top-level browsing context topLevelBrowsingContext were the origin of the result of the following algorithm:

  1. While topLevelBrowsingContext is aportal browsing context:

    1. Set topLevelBrowsingContext to itshost browsing context.

  2. Return topLevelBrowsingContext .

5.3. Fetch Metadata Request Headers

This specification integrates withas follows.

The algorithm to set the Sec-Fetch-Mode header for a request r is modified as follows:
  1. Where the algorithm checks whether r ’s reserved client 's target browsing context is a nested browsing context , check instead whether it is a nested browsing context or aportal browsing context.

The effect of this is that the request for a document in aportal browsing contextwill contain the following HTTP header, as though it were in a nested browsing context .
Sec-Fetch-Mode: nested-navigate

Per the existing processing model, the other fetch metadata headers will automatically have the same values as they would would if the load were occurring in an iframe element, with no spec updates needed.

6. Security Considerations

We should expand this section further. Much of what was formerly there is in§ 5 Updates to other specificationsnow. Once we have a more comprehensive view of all the security-related spec updates, we should summarize them in a non-normative fashion here.

6.1. Overview

This section is non-normative.

In general, aportal browsing contextshould respect policies that would apply to a nested browsing context , e.g. that would restrict whether a document can be embedded in a document from another origin .


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK