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 aportal
element -
"
orphaned
": top-level browsing contexts which have runactivate
but have not (yet) been -
"
none
": all other browsing contexts
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.
-
Assert : Theof predecessorBrowsingContext is "
none
". -
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.
-
Set theof predecessorBrowsingContext to "
orphaned
". -
Update the user interface to replace predecessorBrowsingContext with successorBrowsingContext (e.g., by updating the tab/window contents and browser chrome).
-
Let successorWindow be successorBrowsingContext ’s associated
WindowProxy
's [[Window]] internal slot value. -
Queue a global task on thegiven successorWindow to run the following steps:
-
Assert : Theof successorBrowsingContext is "
portal
". -
Set theof successorBrowsingContext to "
none
". -
Let targetRealm be successorWindow ’s realm .
-
Let dataClone be null.
-
If successorBrowsingContext ’s active document 's origin is same origin with sourceOrigin , then:
-
Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ), and set dataClone to deserializeRecord .[[Deserialized]].
If this throws an exception, catch it and do nothing.
-
-
Let event be the result of creating an event using
PortalActivateEvent
and targetRealm . -
Initialize event ’s
type
attribute toportalactivate
. -
Initialize event ’s
data
attribute to dataClone . -
Set event ’spredecessor browsing contextto predecessorBrowsingContext .
-
Set event ’sto successorWindow .
-
Set event ’sto promise .
-
Dispatch event to successorWindow .
-
Let adoptedPredecessorElement be event ’sadopted predecessor element.
-
If adoptedPredecessorElement is not null, then:
-
Set adoptedPredecessorElement ’sto false.
-
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 theunload
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.
-
-
Otherwise:
-
Queue a global task on thegiven predecessorBrowsingContext ’s active window to resolve promise with undefined.
-
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 ).
-
-
- portal-activate-event.html (live test) (source)
- portals-host-hidden-after-activation.html (live test) (source)
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.
-
Let document be the document of successorWindow .
-
Let portalElement be the result of creating an element given document ,
portal
, and the HTML namespace . -
Set portalElement ’sto true.
-
Assert : portalElement is an
HTMLPortalElement
. -
Queue a global task on thegiven predecessorBrowsingContext ’s active window to run the following steps:
-
Assert : Theof predecessorBrowsingContext is "
orphaned
". -
Set theof predecessorBrowsingContext to "
portal
", and set theof predecessorBrowsingContext to portalElement .
-
-
Return portalElement .
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 .
activate(options)
method
must run these steps:
-
Let portalBrowsingContext be theguest browsing contextofthis.
-
If portalBrowsingContext is null, throw an "
InvalidStateError
"DOMException
. -
Let predecessorBrowsingContext be the browsing context ofthis's node document .
-
If predecessorBrowsingContext is null, throw an "
InvalidStateError
"DOMException
. -
If theof predecessorBrowsingContext is not "
none
", throw an "InvalidStateError
"DOMException
.Note: This means that a
portal
element inside aportal browsing contextcannot be activated. -
Let serializeWithTransferResult be StructuredSerializeWithTransfer ( options ["
data
"], options ["transfer
"]). Rethrow any exceptions. -
Let promise be a newpromise.
-
Let sourceOrigin bethis's relevant settings object 's origin .
-
Run the steps to portalBrowsingContext in place of predecessorBrowsingContext with sourceOrigin , serializeWithTransferResult , and promise .
-
Return promise .
postMessage(message, options)
method
must run these steps:
-
Let portalBrowsingContext be theguest browsing contextofthis.
-
If portalBrowsingContext is null, throw an "
InvalidStateError
"DOMException
. -
Let sourceOrigin bethis's relevant settings object 's origin .
-
Let transfer be options ["
transfer
"]. -
Let serializeWithTransferResult be StructuredSerializeWithTransfer ( message , transfer ). Rethrow any exceptions.
-
Queue a global task on thegiven portalBrowsingContext ’s active window to run the following steps:
-
If portalBrowsingContext ’s active document 's origin is not same origin with sourceOrigin , then abort these steps.
-
Let origin be the serialization of sourceOrigin .
-
Let targetWindow be portalBrowsingContext ’s associated
WindowProxy
's [[Window]] internal slot value. -
Let portalHost be the targetWindow ’s.
-
Let targetRealm be the targetWindow ’s realm .
-
Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ).
If this throws an exception, catch it, fire an event named
messageerror
at portalHost usingMessageEvent
with theorigin
attribute initialized to origin and thesource
attribute initialized to portalHost , then abort these steps. -
Let messageClone be deserializeRecord .[[Deserialized]].
-
Let newPorts be a newfrozen array consisting of all
MessagePort
objects in deserializeRecord .[[TransferredValues]], if any, maintaining their relative order. -
Fire an event named
message
at portalHost usingMessageEvent
, with theorigin
attribute initialized to origin , thesource
attribute initialized to portalHost , thedata
attribute initialized to messageClone , and theports
attribute initialized to newPorts .
-
portal
element
may have a guest browsing context , run the following steps:
-
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. -
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.
-
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.
-
If element is browsing-context connected , then return true.
-
If element ’sis true, then return true.
-
Return false.
portal
element
element , run the following steps:
-
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 ).
portal
element
element , run the following steps:
-
Assert : element may have a guest browsing context.
-
Let hostBrowsingContext be element ’s node document 's browsing context .
-
Assert : hostBrowsingContext is a top-level browsing context .
-
If element has no
src
attribute specified, or its value is the empty string, then element and return. -
Parse the value of the
src
attribute. If that is not successful, then element and return.Otherwise, let url be the resulting URL record .
-
If the scheme of url is not an HTTP(S) scheme , then element and return.
-
If element ’sguest browsing contextis null, then run the following steps:
-
Let newBrowsingContext be the result of creating a new top-level browsing context .
-
Set theof newBrowsingContext to "
portal
", and set theof newBrowsingContext to element .
-
-
Let guestBrowsingContext be element ’sguest browsing context.
-
Assert : guestBrowsingContext is not null.
-
Let resource be a new request whose URL is url and whose referrer policy is the current state of element ’s
referrerpolicy
content attribute. -
Navigate guestBrowsingContext to resource .
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
.
- portal-non-http-navigation.html (live test) (source)
- portals-cross-origin-load.sub.html (live test) (source)
- portals-referrer.html (live test) (source)
- portals-referrer-inherit-header.html (live test) (source)
- portals-referrer-inherit-meta.html (live test) (source)
Whenever a portal
element element has its src
attribute set, changed, or removed, run the following steps:
-
If element may have a guest browsing context, thenof element .
Whenever a portal
element element becomes browsing-context connected , run the following steps:
-
If element may not have a guest browsing context, then abort these steps.
-
If element ’sguest browsing contextis not null, then abort these steps.
This ensures that a newlyportal
element can be inserted into the document without navigating it. -
of element .
Whenever a portal
element element becomes browsing-context disconnected , run the following steps:
-
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:
-
Let guestBrowsingContext be element ’sguest browsing context.
-
If guestBrowsingContext is null, then abort these steps.
-
Discard guestBrowsingContext .
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:
-
Let element be document ’s browsing context 's.
-
Fire an event named
load
at element .
- portal-onload-event.html (live test) (source)
- portals-cross-origin-load.sub.html (live test) (source)
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>; };
portalHost
attribute’s getter
must run the following steps:
-
Let context bethis's browsing context .
-
If context is null or theof context is not "
portal
", then return null. -
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>; };
postMessage(message, options)
method
must run these steps:
-
Let browsingContext bethis's relevant global object 's browsing context .
-
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.
-
Let sourceOrigin bethis's relevant settings object 's origin .
-
Let transfer be options ["
transfer
"]. -
Let serializeWithTransferResult be StructuredSerializeWithTransfer ( message , transfer ). Rethrow any exceptions.
-
Let hostElement be theof browsingContext .
-
Queue an element task on thegiven hostElement to run the following steps:
-
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.
-
Let targetSettings be the relevant settings object of hostElement .
-
If targetSettings ’s origin is not same origin with sourceOrigin , then abort these steps.
-
Let origin be the serialization of sourceOrigin .
-
Let targetRealm be targetSettings ’s realm .
-
Let deserializeRecord be StructuredDeserializeWithTransfer ( serializeWithTransferResult , targetRealm ).
If this throws an exception, catch it, fire an event named
messageerror
at element usingMessageEvent
with theorigin
attribute initialized to origin and thesource
attribute initialized to element . -
Let messageClone be deserializeRecord .[[Deserialized]].
-
Let newPorts be a newfrozen array consisting of all
MessagePort
objects in deserializeRecord .[[TransferredValues]], if any, maintaining their relative order. -
Fire an event named
message
at the element usingMessageEvent
, with theorigin
attribute initialized to origin , thesource
attribute initialized to element , thedata
attribute initialized to messageClone , and theports
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.
PortalActivateEvent
, given an
event , are as follows:
-
Set event ’spredecessor browsing contextto null.
-
Set event ’sto null.
-
Set event ’sadopted predecessor elementto null.
adoptPredecessor()
method
must run these steps:
-
Ifthis'sadopted predecessor elementis not null, throw an "
InvalidStateError
"DOMException
. -
Let predecessorBrowsingContext bethis'spredecessor browsing context.
-
Let successorWindow bethis's.
-
Run the steps toadopt the predecessor browsing context predecessorBrowsingContext in successorWindow , and let adoptedPredecessorElement be the result.
-
Setthis'sadopted predecessor elementto adoptedPredecessorElement .
-
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. -
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.
-
If request ’s initiator is "", its destination is "
document
", and its target browsing context is aportal browsing context, returnframe-src
.
-
Replace all references to " nested browsing context " with " nested browsing context orportal browsing context".
-
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:
-
While topLevelBrowsingContext is aportal browsing context:
-
Set topLevelBrowsingContext to itshost browsing context.
-
-
Return topLevelBrowsingContext .
5.3. Fetch Metadata Request Headers
This specification integrates withas follows.
-
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.
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 .
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
从规范出发的程序设计
[美] Carroll Morgan / 裘宗燕 / 机械工业出版社 / 2002-8 / 45.00元
本书详细论述了有关规范程序设计的内容,包括:程序和精化、谓词演算、选择、迭代、构造类型、模块和封装等,最后几章还包含了大量的实例研究和一些更高级的程序设计技术。本书提倡一种严格的程序开发方法,分析问题要用严格方式写出程序的规范,而后通过一系列具有严格理论基础的推导,最终得到可以运行的程序。 本书是被世界上许多重要大学采用的教材,适于计算机及相关专业的本科生和研究生使用。一起来看看 《从规范出发的程序设计》 这本书的介绍吧!