A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.

To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).

Component Model Strawman: Isolation: Difference between revisions

From WHATWG Wiki
Jump to navigation Jump to search
No edit summary
(Replaced content with 'Stub.')
Line 1: Line 1:
= Overview =
Stub.
 
The isolated components definition is a <tt>provide</tt> attributed HTML file which is loaded in separate namespace.
It is basically a document loaded by an iframe. But it has different way for communicating with the host document.
 
See also the "Isolation" section on [[Component_Model_Strawman:_Declarative_Syntax]].
 
== Terms ==
 
* '''Confined''': disallow a component from accessing the containing page. Useful when a page does not trust the component or its source.
* '''Encapsulated''': disallow the containing page from accessing the internals of the component. Useful when a component wants to prevent a page from meddling with it.
* '''Isolated''': a component that is both confined and encapsulated.
 
== Considerations ==
 
To facilitate component isolation:
 
=== Autonomy ===
 
Components should be autonomous entities that can be loaded and applied as a single building block. Avoid requiring extensive manipulations on both side of the page <=> component divide.
 
This will also help in implementing decorators.
 
=== Interface ===
 
The interface of a component should be minimal and well defined. Embedding pages should not be required (nor able to in the case of encapsulation) to access, or even know about, the internals of a component. Conversely, the function of a component should not depend on being able to access the DOM or any other information of the hosting page that is not provided through an interface.
 
The component should be able to apply and filter data and styles passed in as it sees fit.
 
= Approaches =
 
== Element Registration ==
 
* XXX: define the element name resolution order.
 
Isolated providing document can register new elements for the host document.
But in slightly different way: the lifecycle callbacks including <tt>open</tt> and <tt>close</tt> use
<tt>HTMLElementProxy</tt> instead of <tt>HTMLElement</tt>, that means <tt>open</tt> should return
an instance of <tt>HTMLElementProxy</tt> and <tt>close</tt> callback receives it as a parameter.
 
<pre>
 
<head>
  <element for="x-comment">
    <script>
      HTMLElementElement.current.open = function() {
        var element = return new HTMLElementProxy();
        element.addEventListener("message", ...);
        return element;
      }});
    </script>
  </element>
</head>
 
</pre>
 
== HTMLElementProxy ==
 
An element on the host document is represented as a <tt>HTMLElementProxy</tt> object in the isolated document.
If an isolated-registered element is built on the host document, a set of lifecycle callback is invoked on the isolated document.
The <tt>open</tt> callback should return an <tt>HTMLElementProxy</tt> object, which is then connected to
associated element on the host document.
Scripts in both document can communicate through the proxy using MessageEvent.
 
<pre>
 
interface [
  Constructor()
] HTMLElementProxy : EventTarget {
  void postMessage(any message, optional sequence<Transferable> transfer);
}
 
// Should be implemented by HTMLElement family.
interface [
  Constructor(),
  NoInterfaceObject
] HTMLElementHost {
  void postMessage(any message, optional sequence<Transferable> transfer);
}
 
</pre>
 
== Isolated ShadowRoot ==
 
Shadow Trees for the host document can live in the isolated document.
The <tt>ShadowRoot</tt> constructor can accept <tt>HTMLElementProxy</tt> instead of <tt>HTMLElement</tt>.
 
<pre>
 
<head>
  <element for="x-comment">
    <script>
      HTMLElementElement.current.open = function() {
        var element = return new HTMLElementProxy();
        var shadow = new ShadowRoot(element);
        // Build the shadow tree here...
        return element;
      }});
    </script>
  </element>
</head>
 
</pre>
 
Isolated <tt>ShadowRoot</tt> objects don't propagate events across two documents.

Revision as of 23:43, 26 October 2011

Stub.