Annotation of html5/postmsg/Overview.html, revision 1.16

1.10      ihickson    1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie"><title>HTML5 Web Messaging</title><style type="text/css">
1.1       ihickson    2:    pre { margin-left: 2em; white-space: pre-wrap; }
                      3:    h2 { margin: 3em 0 1em 0; }
                      4:    h3 { margin: 2.5em 0 1em 0; }
                      5:    h4 { margin: 2.5em 0 0.75em 0; }
                      6:    h5, h6 { margin: 2.5em 0 1em; }
                      7:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                      8:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                      9:    p { margin: 1em 0; }
                     10:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     11:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     12:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     13:    dt + dt { margin-top: 0; }
                     14:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     15:    dd p { margin-top: 0; }
                     16:    dd dl + p { margin-top: 1em; }
                     17:    dd table + p { margin-top: 1em; }
                     18:    p + * > li, dd li { margin: 1em 0; }
                     19:    dt, dfn { font-weight: bold; font-style: normal; }
                     20:    dt dfn { font-style: italic; }
                     21:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     22:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     23:    pre em { font-weight: bolder; font-style: normal; }
                     24:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     25:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     26:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     27:    table thead { border-bottom: solid; }
                     28:    table tbody th:first-child { border-left: solid; }
                     29:    table tbody th { text-align: left; }
                     30:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     31:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     32: 
                     33:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     34:    .matrix, .matrix td { border: none; text-align: right; }
                     35:    .matrix { margin-left: 2em; }
                     36:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     37:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     38:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                     39: 
                     40:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     41:    img.extra { float: right; }
                     42:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     43:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     44:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     45:    pre.css:first-line { color: #AAAA50; }
1.15      ihickson   46:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
1.1       ihickson   47:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     48:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     49:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     50:    dl.domintro dd p { margin: 0.5em 0; }
                     51:    dl.switch { padding-left: 2em; }
                     52:    dl.switch > dt { text-indent: -1.5em; }
                     53:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     54:    dl.triple { padding: 0 0 0 1em; }
                     55:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     56:    dl.triple dt:after { content: ':'; }
                     57:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     58:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     59:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     60:    a .diff-new { border-bottom: 1px blue solid; }
                     61: 
                     62:    h2 { page-break-before: always; }
                     63:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     64:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     65: 
                     66:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     67: 
                     68:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     69:    div.head p { margin: 0; }
                     70:    div.head h1 { margin: 0; }
                     71:    div.head .logo { float: right; margin: 0 1em; }
                     72:    div.head .logo img { border: none } /* remove border from top image */
                     73:    div.head dl { margin: 1em 0; }
                     74:    div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
                     75: 
                     76:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     77:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     78:    body > .toc > li > * { margin-bottom: 0.5em; }
                     79:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     80:    .toc, .toc li { list-style: none; }
                     81: 
                     82:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     83:    .brief li { margin: 0; padding: 0; }
                     84:    .brief li p { margin: 0; padding: 0; }
                     85: 
                     86:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     87:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     88:    .category-list li { display: inline; }
                     89:    .category-list li:not(:last-child)::after { content: ', '; }
                     90:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     91:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     92: 
                     93:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     94:    .XXX > :first-child { margin-top: 0; }
                     95:    p .XXX { line-height: 3em; }
                     96:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                     97:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                     98:    .annotation :link, .annotation :visited { color: inherit; }
                     99:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    100:    .annotation span { border: none ! important; }
                    101:    .note { color: green; background: transparent; font-family: sans-serif; }
                    102:    .warning { color: red; background: transparent; }
                    103:    .note, .warning { font-weight: bolder; font-style: italic; }
                    104:    p.note, div.note { padding: 0.5em 2em; }
                    105:    span.note { padding: 0 2em; }
                    106:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    107:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    108:    .warning:before { font-style: normal; }
                    109:    p.note:before { content: 'Note: '; }
                    110:    p.warning:before { content: '\26A0 Warning! '; }
                    111: 
                    112:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    113:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    114:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    115: 
                    116:    h4 { position: relative; z-index: 3; }
                    117:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    118:    .element {
                    119:      background: #EEEEFF;
                    120:      color: black;
                    121:      margin: 0 0 1em 0.15em;
                    122:      padding: 0 1em 0.25em 0.75em;
                    123:      border-left: solid #9999FF 0.25em;
                    124:      position: relative;
                    125:      z-index: 1;
                    126:    }
                    127:    .element:before {
                    128:      position: absolute;
                    129:      z-index: 2;
                    130:      top: 0;
                    131:      left: -1.15em;
                    132:      height: 2em;
                    133:      width: 0.9em;
                    134:      background: #EEEEFF;
                    135:      content: ' ';
                    136:      border-style: none none solid solid;
                    137:      border-color: #9999FF;
                    138:      border-width: 0.25em;
                    139:    }
                    140: 
                    141:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    142:    td > .example:only-child { margin: 0 0 0 0.1em; }
                    143: 
                    144:    .tall-and-narrow {
                    145:      font-size: 0.6em;
                    146:      column-width: 25em;
                    147:      column-gap: 1em;
                    148:      -moz-column-width: 25em;
                    149:      -moz-column-gap: 1em;
                    150:      -webkit-column-width: 25em;
                    151:      -webkit-column-gap: 1em;
                    152:    }
                    153: 
                    154:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    155:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    156:    ul.domTree li li { list-style: none; }
                    157:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    158:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    159:    ul.domTree span { font-style: italic; font-family: serif; }
                    160:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    161:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    162:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    163:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    164:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    165:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    166:    ul.domTree .t10 code { color: teal; }
                    167: 
1.7       ihickson  168:    body.dfnEnabled dfn { cursor: pointer; }
                    169:    .dfnPanel {
                    170:      display: inline;
                    171:      position: absolute;
                    172:      z-index: 10;
                    173:      height: auto;
                    174:      width: auto;
                    175:      padding: 0.5em 0.75em;
                    176:      font: small sans-serif, Droid Sans Fallback;
                    177:      background: #DDDDDD;
                    178:      color: black;
                    179:      border: outset 0.2em;
                    180:    }
                    181:    .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
                    182:    .dfnPanel :link, .dfnPanel :visited { color: black; }
                    183:    .dfnPanel p { font-weight: bolder; }
                    184:    .dfnPanel * + p { margin-top: 0.25em; }
                    185:    .dfnPanel li { list-style-position: inside; }
                    186: 
1.1       ihickson  187:    #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
                    188:    #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
                    189:    #configUI p label { display: block; }
                    190:    #configUI #updateUI, #configUI .loginUI { text-align: center; }
                    191:    #configUI input[type=button] { display: block; margin: auto; }
                    192:   </style><style type="text/css">
                    193: 
                    194:    .applies thead th > * { display: block; }
                    195:    .applies thead code { display: block; }
                    196:    .applies tbody th { whitespace: nowrap; }
                    197:    .applies td { text-align: center; }
                    198:    .applies .yes { background: yellow; }
                    199: 
                    200:    .matrix, .matrix td { border: none; text-align: right; }
                    201:    .matrix { margin-left: 2em; }
                    202: 
                    203:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    204:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    205:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    206: 
                    207:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    208:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    209:    #table-example-1 caption { padding-bottom: 0.5em; }
                    210:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    211:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    212:    #table-example-1 th { font-weight: normal; }
                    213:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    214:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    215:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    216:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    217:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    218:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    219:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    220:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    221:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    222:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    223: 
                    224:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    225:    .apple-table-examples * { font-family: "Times", serif; }
                    226:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    227:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    228:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    229:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    230:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    231:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    232:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    233:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    234:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    235:    .apple-table-examples sup { line-height: 0; }
                    236: 
                    237:    .details-example img { vertical-align: top; }
                    238: 
1.15      ihickson  239:   </style><style>
                    240:    .domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; }
                    241:   </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20{%20display:%20none;%20}%0Ahtml%20{%20border:%20solid%20yellow;%20}%20.domintro:before%20{%20display:%20none;%20}" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20{%20background:%20%23FFEEEE;%20}" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script type="text/javascript">
1.1       ihickson  242:    function getCookie(name) {
                    243:      var params = location.search.substr(1).split("&");
                    244:      for (var index = 0; index < params.length; index++) {
                    245:        if (params[index] == name)
                    246:          return "1";
                    247:        var data = params[index].split("=");
                    248:        if (data[0] == name)
                    249:          return unescape(data[1]);
                    250:      }
                    251:      var cookies = document.cookie.split("; ");
                    252:      for (var index = 0; index < cookies.length; index++) {
                    253:        var data = cookies[index].split("=");
                    254:        if (data[0] == name)
                    255:          return unescape(data[1]);
                    256:      }
                    257:      return null;
                    258:    }
                    259:    function load(script) {
                    260:      var e = document.createElement('script');
                    261:      e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
                    262:      document.body.appendChild(e);
                    263:    }
                    264:    function init() {
                    265:      if (location.search == '?slow-browser')
                    266:        return;
                    267:      var configUI = document.createElement('div');
                    268:      configUI.id = 'configUI';
                    269:      document.body.appendChild(configUI);
                    270:      // load('reviewer.js'); // would need cross-site XHR
                    271:      if (document.getElementById('head'))
                    272:        load('toc.js');
                    273:      load('styler.js');
                    274:      // load('updater.js'); // would need cross-site XHR
                    275:      load('dfn.js'); // doesn't support split-out specs, but, oh well.
                    276:      // load('status.js'); // would need cross-site XHR
                    277:      if (getCookie('profile') == '1')
                    278:        document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
                    279:      fixBrokenLink();
                    280:    }
                    281:   </script><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><body onload="init()"><div class="head" id="head">
                    282:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.10      ihickson  283:    <h1>HTML5 Web Messaging</h1>
1.1       ihickson  284:    <h2 class="no-num no-toc" id="generatedID"></h2>
                    285: 
1.16    ! ihickson  286:    <h2 class="no-num no-toc" id="editor-s-draft-23-february-2010">Editor's Draft 23 February 2010</h2>
1.1       ihickson  287:    <dl><dt>Latest Published Version:</dt>
                    288:     <dd><a href="http://www.w3.org/TR/postmsg/">http://www.w3.org/TR/postmsg/</a></dd>
                    289:     <dt>Latest Editor's Draft:</dt>
                    290:     <dd><a href="http://dev.w3.org/html5/postmsg/">http://dev.w3.org/html5/postmsg/</a></dd>
                    291: <!-- ZZZ: add the new version after it has shipped -->
                    292: <!--
                    293:     <dt>Previous Versions:</dt>
                    294: -->
                    295: <!-- :ZZZ -->
                    296:     <dt>Editors:</dt>
                    297:     <dd><a href="mailto:ian@hixie.ch">Ian Hickson</a>, Google, Inc.</dd>
1.3       ihickson  298:    </dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
1.1       ihickson  299:    &copy; 2009 <a href="http://www.w3.org/"><abbr title="World Wide
                    300:    Web Consortium">W3C</abbr></a><sup>&reg;</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts
                    301:    Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.org/"><abbr title="European Research
                    302:    Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
                    303:    <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
                    304:    <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
                    305:    and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document
                    306:    use</a> rules apply.</p>
1.6       ihickson  307: 
                    308:    <!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->
                    309:    <!-- temporarily removed after discussion with plh in October 2009 -->
                    310:    <!-- will be moved back to below W3C copyright in April 2009 -->
                    311:    <!--
                    312:    <p class="alt">The <a
                    313:    href="http://www.whatwg.org/specs/web-apps/current-work/multipage/">WHATWG
                    314:    version</a> of this specification is available under a license that
                    315:    permits reuse of the specification text.</p>
                    316:    -->
                    317:    <!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->
                    318: 
1.1       ihickson  319:   </div><hr class="top"><h2 class="no-num no-toc" id="abstract">Abstract</h2><p>This specification defines two mechanism for communicating
1.6       ihickson  320:   between browsing contexts in HTML documents.<h2 class="no-num no-toc" id="status-of-this-document">Status of This document</h2><!-- intro boilerplate (required) --><p><em>This section describes the status of this document at the
1.1       ihickson  321:   time of its publication. Other documents may supersede this
                    322:   document. A list of current W3C publications and the most recently
                    323:   formally published revision of this technical report can be found in
                    324:   the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
                    325:   at http://www.w3.org/TR/.</em></p><!-- where to send feedback (required) --><p>If you wish to make comments regarding this document, please send
                    326:   them to <a href="mailto:public-html-comments@w3.org">public-html-comments@w3.org</a>
                    327:   (<a href="mailto:public-html-comments-request@w3.org?subject=subscribe">subscribe</a>,
                    328:   <a href="http://lists.w3.org/Archives/Public/public-html-comments/">archives</a>)
                    329: 
                    330:   <!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING SENTENCE TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->  
                    331:   or <a href="mailto:whatwg@whatwg.org">whatwg@whatwg.org</a> (<a href="http://lists.whatwg.org/listinfo.cgi/whatwg-whatwg.org">subscribe</a>,
                    332:   <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/">archives</a>),
                    333:   <!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING SENTENCE TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->
                    334: 
                    335:   or submit them using <a href="http://www.w3.org/Bugs/Public/enter_bug.cgi?product=HTML%20WG">our
                    336:   public bug database</a>.
                    337: 
1.12      ihickson  338:   All feedback is welcome.</p><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><p>The working groups maintains <a href="http://www.w3.org/Bugs/Public/buglist.cgi?component=HTML5+Spec%20bugs&amp;component=HTML5+Spec%20proposals&amp;product=HTML%20WG&amp;resolution=NEEDSINFO&amp;resolution=LATER&amp;resolution=REMIND&amp;resolution=---&amp;order=bugs.resolution%2Cbugs.priority%2C%20bugs.bug_severity">a
1.1       ihickson  339:   list of all bug reports that the editor has not yet tried to
                    340:   address</a> and <a href="http://www.w3.org/html/wg/tracker/products/1">a list of issues
                    341:   for which the chairs have not yet declared a decision</a>. The
                    342:   editor also maintains <a href="http://www.whatwg.org/issues/">a list
                    343:   of all e-mails that he has not yet tried to address</a>. These bugs,
                    344:   issues, and e-mails apply to all HTML specifications, not just this
                    345:   one.</p><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- stability (required) --><p>Implementors should be aware that this specification is not
                    346:   stable. <strong>Implementors who are not taking part in the
                    347:   discussions are likely to find the specification changing out from
                    348:   under them in incompatible ways.</strong> Vendors interested in
                    349:   implementing this specification before it eventually reaches the
                    350:   Candidate Recommendation stage should join the aforementioned
1.6       ihickson  351:   mailing lists and take part in the discussions.</p><!-- not everyone agrees with this (requested before html5 fpwd) --><p>The publication of this document by the W3C as a W3C Working
1.1       ihickson  352:   Draft does not imply that all of the participants in the W3C HTML
                    353:   working group endorse the contents of the specification. Indeed, for
                    354:   any section of the specification, one can usually find many members
                    355:   of the working group or of the W3C as a whole who object strongly to
                    356:   the current text, the existence of the section at all, or the idea
                    357:   that the working group should even spend time discussing the concept
                    358:   of that section.</p><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- version history or list of changes (required) --><p>The latest stable version of the editor's draft of this
                    359:   specification is always available on <a href="http://dev.w3.org/html5/">the W3C CVS server</a> and in the <a href="http://svn.whatwg.org/webapps/">WHATWG Subversion
                    360:   repository</a>. The <a href="http://www.whatwg.org/specs/web-apps/current-work/complete.html">latest
                    361:   editor's working copy</a> (which may contain unfinished text in the
                    362:   process of being prepared) contains the latest draft text of this
                    363:   specification (amongst others). For more details, please see the <a href="http://wiki.whatwg.org/wiki/FAQ#What_are_the_various_versions_of_the_spec.3F">WHATWG
                    364:   FAQ</a>.</p><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING LIST TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><p>There are various ways to follow the change history for the
                    365:   HTML specifications:<dl><dt>E-mail notifications of changes</dt>
                    366:    <dd>HTML-Diffs mailing list (diff-marked HTML versions for each change): <a href="http://lists.w3.org/Archives/Public/public-html-diffs/latest">http://lists.w3.org/Archives/Public/public-html-diffs/latest</a></dd>
                    367:    <dd>Commit-Watchers mailing list (complete source diffs): <a href="http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org">http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</a></dd>
                    368:    <dt>Real-time notifications of changes:</dt>
                    369:    <dd>Generated diff-marked HTML versions for each change: <a href="http://twitter.com/HTML5">http://twitter.com/HTML5</a></dd>
                    370:    <dd>All (non-editorial) changes to the spec source: <a href="http://twitter.com/WHATWG">http://twitter.com/WHATWG</a></dd>
                    371:    <dt>Browsable version-control record of all changes:</dt>
                    372:    <dd>CVSWeb interface with side-by-side diffs: <a href="http://dev.w3.org/cvsweb/html5/">http://dev.w3.org/cvsweb/html5/</a></dd>
                    373:    <dd>Annotated summary with unified diffs: <a href="http://html5.org/tools/web-apps-tracker">http://html5.org/tools/web-apps-tracker</a></dd>
                    374:    <dd>Raw Subversion interface: <code>svn checkout http://svn.whatwg.org/webapps/</code></dd>
                    375:   </dl><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING LIST TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- status of document, group responsible (required) --><p>The W3C <a href="http://www.w3.org/html/wg/">HTML Working
                    376:   Group</a> is the W3C working group responsible for this
                    377:   specification's progress along the W3C Recommendation
                    378:   track.
                    379: 
1.16    ! ihickson  380:   This specification is the 23 February 2010 Editor's Draft.
1.1       ihickson  381:   </p><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- relationship to other work (required) --><p>This specification is part of <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/">a
1.6       ihickson  382:   larger specification</a> being produced by the <a href="http://www.whatwg.org/">WHATWG</a>, which is available under a
                    383:   license that permits reuse of the specification text.</p><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- context and rationale (required) --><!-- (this text is from the RDFa+HTML spec --><p>This specification is an extension to the HTML5 language. All
                    384:   normative content in the HTML5 specification, unless specifically
                    385:   overridden by this specification, is intended to be the basis for
                    386:   this specification.</p><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- required patent boilerplate --><p>This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
1.1       ihickson  387:   February 2004 W3C Patent Policy</a>. W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/40318/status" rel="disclosure">public list of
                    388:   any patent disclosures</a> made in connection with the deliverables
                    389:   of the group; that page also includes instructions for disclosing a
                    390:   patent. An individual who has actual knowledge of a patent which the
                    391:   individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
                    392:   Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
1.6       ihickson  393:   6 of the W3C Patent Policy</a>.<h2 class="no-num no-toc" id="contents">Table of Contents</h2>
1.1       ihickson  394: <!--begin-toc-->
                    395: <ol class="toc">
                    396:  <li><a href="#conformance-requirements"><span class="secno">1 </span>Conformance requirements</a></li>
1.10      ihickson  397:  <li><a href="#event-definitions"><span class="secno">2 </span>Event definitions</a></li>
                    398:  <li><a href="#crossDocumentMessages"><span class="secno">3 </span>Cross-document messaging</a>
1.1       ihickson  399:   <ol>
1.10      ihickson  400:    <li><a href="#introduction"><span class="secno">3.1 </span>Introduction</a></li>
                    401:    <li><a href="#security"><span class="secno">3.2 </span>Security</a>
1.1       ihickson  402:     <ol>
1.10      ihickson  403:      <li><a href="#authors"><span class="secno">3.2.1 </span>Authors</a></li>
                    404:      <li><a href="#user-agents"><span class="secno">3.2.2 </span>User agents</a></ol></li>
                    405:    <li><a href="#posting-messages"><span class="secno">3.3 </span>Posting messages</a></li>
                    406:    <li><a href="#posting-messages-with-message-ports"><span class="secno">3.4 </span>Posting messages with message ports</a></ol></li>
                    407:  <li><a href="#channel-messaging"><span class="secno">4 </span>Channel messaging</a>
1.1       ihickson  408:   <ol>
1.10      ihickson  409:    <li><a href="#introduction-0"><span class="secno">4.1 </span>Introduction</a></li>
                    410:    <li><a href="#message-channels"><span class="secno">4.2 </span>Message channels</a></li>
                    411:    <li><a href="#message-ports"><span class="secno">4.3 </span>Message ports</a>
1.1       ihickson  412:     <ol>
1.10      ihickson  413:      <li><a href="#ports-and-garbage-collection"><span class="secno">4.3.1 </span>Ports and garbage collection</a></ol></ol></li>
1.1       ihickson  414:  <li><a class="no-num" href="#references">References</a></li>
                    415:  <li><a class="no-num" href="#acknowledgements">Acknowledgements</a></ol>
                    416: <!--end-toc--><hr><h2 id="conformance-requirements"><span class="secno">1 </span>Conformance requirements</h2><p>This specification is an HTML specification. All the conformance
                    417:   requirements, conformance classes, definitions, dependencies,
1.4       ihickson  418:   terminology, and typographical conventions described in the core
1.10      ihickson  419:   HTML5 specification apply to this specification. <a href="#refsHTML5">[HTML5]</a><h2 id="event-definitions"><span class="secno">2 </span>Event definitions</h2><p>Messages in <span>server-sent events</span>, <span>Web
1.1       ihickson  420:   sockets</span>, <a href="#crossDocumentMessages">cross-document messaging</a>, and
                    421:   <a href="#channel-messaging">channel messaging</a> use the <dfn id="event-message" title="event-message"><code>message</code></dfn> event.
                    422:   
                    423:   <a href="#refsEVENTSOURCE">[EVENTSOURCE]</a>
                    424:   <a href="#refsWEBSOCKET">[WEBSOCKET]</a>
                    425:   
                    426:   <p>The following interface is defined for this event:<pre class="idl">interface <dfn id="messageevent">MessageEvent</dfn> : Event {
                    427:   readonly attribute any <a href="#dom-messageevent-data" title="dom-MessageEvent-data">data</a>;
                    428:   readonly attribute DOMString <a href="#dom-messageevent-origin" title="dom-MessageEvent-origin">origin</a>;
                    429:   readonly attribute DOMString <a href="#dom-messageevent-lasteventid" title="dom-MessageEvent-lastEventId">lastEventId</a>;
                    430:   readonly attribute <span>WindowProxy</span> <a href="#dom-messageevent-source" title="dom-MessageEvent-source">source</a>;
                    431:   readonly attribute <a href="#messageportarray">MessagePortArray</a> <a href="#dom-messageevent-ports" title="dom-MessageEvent-ports">ports</a>;
                    432:   void <a href="#dom-messageevent-initmessageevent" title="dom-MessageEvent-initMessageEvent">initMessageEvent</a>(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in any dataArg, in DOMString originArg, in DOMString lastEventIdArg, in <span>WindowProxy</span> sourceArg, in <a href="#messageportarray">MessagePortArray</a> portsArg);
                    433: };</pre><dl class="domintro"><dt><var title="">event</var> . <code title="dom-MessageEvent-data"><a href="#dom-messageevent-data">data</a></code></dt>
                    434: 
                    435:    <dd>
                    436: 
                    437:     <p>Returns the data of the message.</p>
                    438: 
                    439:    </dd>
                    440: 
                    441:    <dt><var title="">event</var> . <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code></dt>
                    442: 
                    443:    <dd>
                    444: 
                    445:     <p>Returns the origin of the message, for <span>server-sent
                    446:     events</span> and <a href="#crossDocumentMessages">cross-document messaging</a>.</p>
                    447: 
                    448:    </dd>
                    449: 
                    450:    <dt><var title="">event</var> . <code title="dom-MessageEvent-lastEventId"><a href="#dom-messageevent-lasteventid">lastEventId</a></code></dt>
                    451: 
                    452:    <dd>
                    453: 
                    454:     <p>Returns the last event ID, for <span>server-sent
                    455:     events</span>.</p>
                    456: 
                    457:    </dd>
                    458: 
                    459:    <dt><var title="">event</var> . <code title="dom-MessageEvent-source"><a href="#dom-messageevent-source">source</a></code></dt>
                    460: 
                    461:    <dd>
                    462: 
                    463:     <p>Returns the <code>WindowProxy</code> of the source window, for
                    464:     <a href="#crossDocumentMessages">cross-document messaging</a>.</p>
                    465: 
                    466:    </dd>
                    467: 
                    468:    <dt><var title="">event</var> . <code title="dom-MessageEvent-ports"><a href="#dom-messageevent-ports">ports</a></code></dt>
                    469: 
                    470:    <dd>
                    471: 
                    472:     <p>Returns the <code><a href="#messageportarray">MessagePortArray</a></code> sent with the
                    473:     message, for <a href="#crossDocumentMessages">cross-document messaging</a> and
                    474:     <a href="#channel-messaging">channel messaging</a>.</p>
                    475: 
                    476:    </dd>
                    477: 
                    478:   </dl><div class="impl">
                    479: 
                    480:   <p>The <dfn id="dom-messageevent-initmessageevent" title="dom-MessageEvent-initMessageEvent"><code>initMessageEvent()</code></dfn>
                    481:   method must initialize the event in a manner analogous to the
                    482:   similarly-named method in the DOM Events interfaces. <a href="#refsDOMEVENTS">[DOMEVENTS]</a></p>
                    483: 
                    484:   <p>The <dfn id="dom-messageevent-data" title="dom-MessageEvent-data"><code>data</code></dfn>
                    485:   attribute represents the message being sent.</p>
                    486: 
                    487:   <p>The <dfn id="dom-messageevent-origin" title="dom-MessageEvent-origin"><code>origin</code></dfn> attribute
                    488:   represents, in <span>server-sent events</span> and
                    489:   <a href="#crossDocumentMessages">cross-document messaging</a>, the <span>origin</span> of
                    490:   the document that sent the message (typically the scheme, hostname,
                    491:   and port of the document, but not its path or fragment
                    492:   identifier).</p>
                    493: 
                    494:   <p>The <dfn id="dom-messageevent-lasteventid" title="dom-MessageEvent-lastEventId"><code>lastEventId</code></dfn>
                    495:   attribute represents, in <span>server-sent events</span>, the <span title="concept-event-stream-last-event-id">last event ID
                    496:   string</span> of the event source.</p>
                    497: 
                    498:   <p>The <dfn id="dom-messageevent-source" title="dom-MessageEvent-source"><code>source</code></dfn> attribute
                    499:   represents, in <a href="#crossDocumentMessages">cross-document messaging</a>, the
                    500:   <code>WindowProxy</code> of the <span>browsing context</span> of the
                    501:   <code>Window</code> object from which the message came.</p>
                    502: 
                    503:   <p>The <dfn id="dom-messageevent-ports" title="dom-MessageEvent-ports"><code>ports</code></dfn>
                    504:   attribute represents, in <a href="#crossDocumentMessages">cross-document messaging</a> and
                    505:   <a href="#channel-messaging">channel messaging</a> the <code><a href="#messageportarray">MessagePortArray</a></code>
                    506:   being sent, if any.</p>
                    507: 
                    508:   <p>Except where otherwise specified, when the user agent creates and
                    509:   dispatches a <code title="event-message"><a href="#event-message">message</a></code> event in the
                    510:   algorithms described in the following sections, the <code title="dom-MessageEvent-lastEventId"><a href="#dom-messageevent-lasteventid">lastEventId</a></code> attribute
                    511:   must be the empty string, the <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code> attribute must be the
                    512:   empty string, the <code title="dom-MessageEvent-source"><a href="#dom-messageevent-source">source</a></code> attribute must be
                    513:   null, and the <code title="dom-MessageEvent-ports"><a href="#dom-messageevent-ports">ports</a></code>
                    514:   attribute must be null.</p>
                    515: 
1.10      ihickson  516:   </div><h2 id="crossDocumentMessages"><span class="secno">3 </span><dfn>Cross-document messaging</dfn></h2><p>Web browsers, for security and privacy reasons, prevent documents
1.1       ihickson  517:   in different domains from affecting each other; that is, cross-site
                    518:   scripting is disallowed.<p>While this is an important security feature, it prevents pages
                    519:   from different domains from communicating even when those pages are
                    520:   not hostile. This section introduces a messaging system that allows
                    521:   documents to communicate with each other regardless of their source
                    522:   domain, in a way designed to not enable cross-site scripting
                    523:   attacks.<div class="impl">
                    524: 
                    525:   <p>The <span>task source</span> for the <span title="concept-task">tasks</span> in <a href="#crossDocumentMessages">cross-document
                    526:   messaging</a> is the <dfn id="posted-message-task-source">posted message task source</dfn>.</p>
                    527: 
1.10      ihickson  528:   </div><h3 id="introduction"><span class="secno">3.1 </span>Introduction</h3><p><i>This section is non-normative.</i><div class="example">
1.1       ihickson  529: 
                    530:    <p>For example, if document A contains an <code>iframe</code>
                    531:    element that contains document B, and script in document A calls
                    532:    <code title="dom-window-postMessage-2"><a href="#dom-window-postmessage-2">postMessage()</a></code> on the
                    533:    <code>Window</code> object of document B, then a message event will
                    534:    be fired on that object, marked as originating from the
                    535:    <code>Window</code> of document A. The script in document A might
                    536:    look like:</p>
                    537: 
                    538:    <pre>var o = document.getElementsByTagName('iframe')[0];
                    539: o.contentWindow.postMessage('Hello world', 'http://b.example.org/');</pre>
                    540: 
                    541:    <p>To register an event handler for incoming events, the script
                    542:    would use <code title="">addEventListener()</code> (or similar
                    543:    mechanisms). For example, the script in document B might look
                    544:    like:</p>
                    545: 
                    546:    <pre>window.addEventListener('message', receiver, false);
                    547: function receiver(e) {
                    548:   if (e.origin == 'http://example.com') {
                    549:     if (e.data == 'Hello world') {
                    550:       e.source.postMessage('Hello', e.origin);
                    551:     } else {
                    552:       alert(e.data);
                    553:     }
                    554:   }
                    555: }</pre>
                    556: 
                    557:    <p>This script first checks the domain is the expected domain, and
                    558:    then looks at the message, which it either displays to the user, or
                    559:    responds to by sending a message back to the document which sent
                    560:    the message in the first place.</p>
                    561: 
1.10      ihickson  562:   </div><h3 id="security"><span class="secno">3.2 </span>Security</h3><div class="impl">
1.1       ihickson  563: 
1.10      ihickson  564:   <h4 id="authors"><span class="secno">3.2.1 </span>Authors</h4>
1.1       ihickson  565: 
                    566:   </div><p class="warning">Use of this API requires extra care to protect
                    567:   users from hostile entities abusing a site for their own
                    568:   purposes.<p>Authors should check the <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code> attribute to ensure
                    569:   that messages are only accepted from domains that they expect to
                    570:   receive messages from. Otherwise, bugs in the author's message
                    571:   handling code could be exploited by hostile sites.<p>Furthermore, even after checking the <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code> attribute, authors
                    572:   should also check that the data in question is of the expected
                    573:   format. Otherwise, if the source of the event has been attacked
                    574:   using a cross-site scripting flaw, further unchecked processing of
                    575:   information sent using the <code title="dom-window-postMessage-2"><a href="#dom-window-postmessage-2">postMessage()</a></code> method could
                    576:   result in the attack being propagated into the receiver.<p>Authors should not use the wildcard keyword (*) in the <var title="">targetOrigin</var> argument in messages that contain any
                    577:   confidential information, as otherwise there is no way to guarantee
                    578:   that the message is only delivered to the recipient to which it was
                    579:   intended.<div class="impl">
                    580: 
1.10      ihickson  581:   <h4 id="user-agents"><span class="secno">3.2.2 </span>User agents</h4>
1.1       ihickson  582: 
                    583:   <p>The integrity of this API is based on the inability for scripts
                    584:   of one <span>origin</span> to post arbitrary events (using <code title="">dispatchEvent()</code> or otherwise) to objects in other
                    585:   origins (those that are not the <span title="same
                    586:   origin">same</span>).</p>
                    587: 
                    588:   <p class="note">Implementors are urged to take extra care in the
                    589:   implementation of this feature. It allows authors to transmit
                    590:   information from one domain to another domain, which is normally
                    591:   disallowed for security reasons. It also requires that UAs be
                    592:   careful to allow access to certain properties but not others.</p>
                    593: 
1.10      ihickson  594:   </div><h3 id="posting-messages"><span class="secno">3.3 </span>Posting messages</h3><dl class="domintro"><dt><var title="">window</var> . <code title="dom-window-postMessage-2"><a href="#dom-window-postmessage-2">postMessage</a></code>(<var title="">message</var>, [ <var title="">ports</var>, ] <var title="">targetOrigin</var>)</dt>
1.1       ihickson  595: 
                    596:    <dd>
                    597: 
                    598:     <p>Posts a message, optionally with an array of ports, to the
                    599:     given window.</p>
                    600: 
                    601:     <p>If the origin of the target window doesn't match the given
                    602:     origin, the message is discarded, to avoid information leakage. To
                    603:     send the message to the target regardless of origin, set the
1.11      ihickson  604:     target origin to "<code title="">*</code>". To restrict the
                    605:     message to same-origin targets only, without needing to explicitly
                    606:     state the origin, set the target origin to "<code title="">/</code>".</p>
1.1       ihickson  607: 
                    608:     <p>Throws an <code>INVALID_STATE_ERR</code> if the <var title="">ports</var> array is not null and it contains either null
                    609:     entries or duplicate ports.</p>
                    610: 
                    611:    </dd>
                    612: 
                    613:   </dl><div class="impl">
                    614: 
                    615:   <p>When a script invokes the <dfn id="dom-window-postmessage-2" title="dom-window-postMessage-2"><code>postMessage(<var title="">message</var>, <var title="">targetOrigin</var>)</code></dfn> method (with only two
                    616:   arguments) on a <code>Window</code> object, the user agent must
                    617:   follow these steps:
                    618: 
                    619:   <ol><li>
                    620: 
                    621:     <p>If the value of the <var title="">targetOrigin</var> argument
1.11      ihickson  622:     is neither a single U+002A ASTERISK character (*), a single U+002F
                    623:     SOLIDUS character (/), nor an <span>absolute URL</span> with a
1.1       ihickson  624:     <code title="url-host-specific">&lt;host-specific&gt;</code>
1.11      ihickson  625:     component that is either empty or a single U+002F SOLIDUS
1.1       ihickson  626:     character (/), then throw a <code>SYNTAX_ERR</code> exception and
                    627:     abort the overall set of steps.</p>
                    628: 
                    629:    </li>
                    630: 
                    631:    <li>
                    632: 
                    633:     <p>Let <var title="">message clone</var> be the result of
                    634:     obtaining a <span>structured clone</span> of the <var title="">message</var> argument. If this throws an exception, then
                    635:     throw that exception and abort these steps.</p>
                    636: 
                    637:    </li>
                    638: 
                    639:    <li>
                    640: 
                    641:     <p>Return from the <code title="dom-window-postMessage-2"><a href="#dom-window-postmessage-2">postMessage()</a></code> method, but
                    642:     asynchronously continue running these steps.</p>
                    643: 
                    644:    </li>
                    645: 
                    646:    <li>
                    647: 
1.11      ihickson  648:     <p>If the <var title="">targetOrigin</var> argument is a single
                    649:     literal U+002F SOLIDUS character (/), and the
                    650:     <code>Document</code> of the <code>Window</code> object on which
                    651:     the method was invoked does not have the <span>same origin</span>
1.16    ! ihickson  652:     as the <span>entry script</span>'s <span title="script's
        !           653:     document">document</span>, then abort these steps silently.</p>
1.11      ihickson  654: 
                    655:     <p>Otherwise, if the <var title="">targetOrigin</var> argument is
                    656:     an <span>absolute URL</span>, and the <code>Document</code> of the
                    657:     <code>Window</code> object on which the method was invoked does
                    658:     not have the <span>same origin</span> as <var title="">targetOrigin</var>, then abort these steps silently.</p>
                    659: 
                    660:     <p>Otherwise, the <var title="">targetOrigin</var> argument is a
                    661:     single literal U+002A ASTERISK character (*), and no origin check
                    662:     is made.</p>
1.1       ihickson  663: 
                    664:    </li>
                    665: 
                    666:    <li>
                    667: 
                    668:     <p>Create an event that uses the <code><a href="#messageevent">MessageEvent</a></code>
                    669:     interface, with the event name <code title="event-message"><a href="#event-message">message</a></code>, which does not bubble, is
                    670:     not cancelable, and has no default action. The <code title="dom-MessageEvent-data"><a href="#dom-messageevent-data">data</a></code> attribute must be set to
                    671:     the value of <var title="">message clone</var>, the <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code> attribute must be
                    672:     set to the <span title="Unicode serialization of an
                    673:     origin">Unicode serialization</span> of the <span>origin</span> of
                    674:     the script that invoked the method, and the <code title="dom-MessageEvent-source"><a href="#dom-messageevent-source">source</a></code> attribute must be
                    675:     set to the <span>script's global object</span>.</p> <!--
                    676:     invariant: the global object is always a Window if the script can
                    677:     see this method -->
                    678: 
                    679:    </li>
                    680: 
                    681:    <li>
                    682: 
                    683:     <p><span>Queue a task</span> to dispatch the event created in the
                    684:     previous step at the <code>Window</code> object on which the
                    685:     method was invoked. The <span>task source</span> for this <span title="concept-task">task</span> is the <a href="#posted-message-task-source">posted message task
                    686:     source</a>.</p>
                    687: 
                    688:    </li>
                    689: 
                    690:   </ol></div><div class="impl">
                    691: 
1.10      ihickson  692:   <h3 id="posting-messages-with-message-ports"><span class="secno">3.4 </span>Posting messages with message ports</h3>
1.1       ihickson  693: 
                    694:   <p>When a script invokes the <dfn id="dom-window-postmessage-3" title="dom-window-postMessage-3"><code>postMessage(<var title="">message</var>, <var title="">ports</var>, <var title="">targetOrigin</var>)</code></dfn> method (with three
                    695:   arguments) on a <code>Window</code> object, the user agent must
                    696:   follow these steps:
                    697: 
                    698:   <ol><!-- EXCEPT WHERE NOTED, THESE STEPS ARE IDENTICAL TO THE PREVIOUS SECTION --><!-- one exception is the use of -3 instead of -2 in the xrefs --><li>
                    699: 
                    700:     <p>If the value of the <var title="">targetOrigin</var> argument
1.11      ihickson  701:     is neither a single U+002A ASTERISK character (*), a single U+002F
                    702:     SOLIDUS character (/), nor an <span>absolute URL</span> with a
1.1       ihickson  703:     <code title="url-host-specific">&lt;host-specific&gt;</code>
1.11      ihickson  704:     component that is either empty or a single U+002F SOLIDUS
1.1       ihickson  705:     character (/), then throw a <code>SYNTAX_ERR</code> exception and
                    706:     abort the overall set of steps.</p>
                    707: 
                    708:    </li>
                    709: 
                    710:    <li>
                    711: 
                    712:     <p>Let <var title="">message clone</var> be the result of
                    713:     obtaining a <span>structured clone</span> of the <var title="">message</var> argument. If this throws an exception, then
                    714:     throw that exception and abort these steps.</p>
                    715: 
                    716:    </li>
                    717: 
                    718:    <li> <!-- NEW STEP -->
                    719: 
                    720:     <p>If the <var title="">ports</var> argument is empty<!-- or null
                    721:     (if we make it nullable)-->, then act as if the method had just
                    722:     been <a href="#dom-window-postmessage-2" title="dom-window-postMessage-2">called with two
                    723:     arguments</a>, <var title="">message</var> and <var title="">targetOrigin</var>.</p>
                    724: 
                    725:    </li>
                    726: 
                    727:    <li> <!-- NEW STEP -->
                    728: 
                    729:     <p>If any of the entries in <var title="">ports</var> are null, if
                    730:     any <code><a href="#messageport">MessagePort</a></code> object is listed in <var title="">ports</var> more than once, or if any of the
                    731:     <code><a href="#messageport">MessagePort</a></code> objects listed in <var title="">ports</var> have already been cloned once before, then
                    732:     throw an <code>INVALID_STATE_ERR</code> exception.</p>
                    733: 
                    734:    </li>
                    735: 
                    736:    <li> <!-- NEW STEP -->
                    737: 
                    738:     <p>Let <var title="">new ports</var> be an empty array.</p>
                    739: 
                    740:     <p>For each port in <var title="">ports</var> in turn,
                    741:     obtain a new port by <a href="#clone-a-port" title="clone a port">cloning</a> the
                    742:     port with the <code>Window</code> object on which the method was
                    743:     invoked as the owner of the clone, and append the clone to the
                    744:     <var title="">new ports</var> array.</p>
                    745: <!--
                    746:     <p class="note">If the original <var title="">ports</var>
                    747:     array was empty, then the <var title="">new ports</var> array will
                    748:     also be empty.</p>
                    749: -->
                    750:    </li>
                    751: 
                    752:    <li>
                    753: 
                    754:     <p>Return from the <code title="dom-window-postMessage-3"><a href="#dom-window-postmessage-3">postMessage()</a></code> method, but
                    755:     asynchronously continue running these steps.</p>
                    756: 
                    757:    </li>
                    758: 
                    759:    <li>
                    760: 
1.11      ihickson  761:     <p>If the <var title="">targetOrigin</var> argument is a single
                    762:     literal U+002F SOLIDUS character (/), and the
                    763:     <code>Document</code> of the <code>Window</code> object on which
                    764:     the method was invoked does not have the <span>same origin</span>
1.16    ! ihickson  765:     as the <span>entry script</span>'s <span title="script's
        !           766:     document">document</span>, then abort these steps silently.</p>
1.11      ihickson  767: 
                    768:     <p>Otherwise, if the <var title="">targetOrigin</var> argument is
                    769:     an <span>absolute URL</span>, and the <code>Document</code> of the
                    770:     <code>Window</code> object on which the method was invoked does
                    771:     not have the <span>same origin</span> as <var title="">targetOrigin</var>, then abort these steps silently.</p>
                    772: 
                    773:     <p>Otherwise, the <var title="">targetOrigin</var> argument is a
                    774:     single literal U+002A ASTERISK character (*), and no origin check
                    775:     is made.</p>
1.1       ihickson  776: 
                    777:    </li>
                    778: 
                    779:    <li>
                    780: 
                    781:     <p>Create an event that uses the <code><a href="#messageevent">MessageEvent</a></code>
                    782:     interface, with the event name <code title="event-message"><a href="#event-message">message</a></code>, which does not bubble, is
                    783:     not cancelable, and has no default action. The <code title="dom-MessageEvent-data"><a href="#dom-messageevent-data">data</a></code> attribute must be set to
                    784:     the value of <var title="">message clone</var>, the <code title="dom-MessageEvent-origin"><a href="#dom-messageevent-origin">origin</a></code> attribute must be
                    785:     set to the <span title="Unicode serialization of an
                    786:     origin">Unicode serialization</span> of the <span>origin</span> of
                    787:     the script that invoked the method, and the <code title="dom-MessageEvent-source"><a href="#dom-messageevent-source">source</a></code> attribute must be
                    788:     set to the <span>script's global object</span>.</p> <!--
                    789:     invariant: the global object is always a Window if the script can
                    790:     see this method -->
                    791: 
                    792:    </li>
                    793: 
                    794:    <li> <!-- NEW STEP -->
                    795: 
                    796:     <p>Let the <code title="dom-MessageEvent-ports"><a href="#dom-messageevent-ports">ports</a></code> attribute
                    797:     of the event be the <var title="">new ports</var> array.</p>
                    798: 
                    799:    </li>
                    800: 
                    801:    <li>
                    802: 
                    803:     <p><span>Queue a task</span> to dispatch the event created in the
                    804:     previous step at the <code>Window</code> object on which the
                    805:     method was invoked. The <span>task source</span> for this <span title="concept-task">task</span> is the <a href="#posted-message-task-source">posted message task
                    806:     source</a>.</p>
                    807: 
                    808:    </li>
                    809: 
                    810:   </ol><p class="note">These steps, with the exception of the second and
                    811:   third steps and the penultimate step, are identical to those in the
                    812:   previous section.</p>
                    813: 
                    814:   <!-- v2: we can merge this section and the previous section when
                    815:   implementations have shipped postMessage(). Anne asked that these
                    816:   sections be kept separate so that implementors can avoid getting
                    817:   confused with the 'port' step. -->
                    818: 
1.10      ihickson  819:   </div><h2 id="channel-messaging"><span class="secno">4 </span><dfn>Channel messaging</dfn></h2><h3 id="introduction-0"><span class="secno">4.1 </span>Introduction</h3><p><i>This section is non-normative.</i><p>To enable independent pieces of code (e.g. running in different
1.1       ihickson  820:   <span title="browsing context">browsing contexts</span>) to
                    821:   communicate directly, authors can use <a href="#channel-messaging">channel
                    822:   messaging</a>.<p>Communication channels in this mechanisms are implemented as
                    823:   two-ways pipes, with a port at each end. Messages sent in one port
                    824:   are delivered at the other port, and vice-versa. Messages are
                    825:   asynchronous, and delivered as DOM events.<p>To create a connection (two "entangled" ports), the <code title="">MessageChannel()</code> constructor is called:<pre>var channel = new MessageChannel();</pre><p>One of the ports is kept as the local port, and the other port is
                    826:   sent to the remote code, e.g. using <code title="dom-window-postMessage-3"><a href="#dom-window-postmessage-3">postMessage()</a></code>:<pre>otherWindow.postMessage('hello', [channel.port2], 'http://example.com');</pre><p>To send messages, the <code title="dom-MessagpePort-postMessage">postMessage()</code> method on
                    827:   the port is used:<pre>channel.port1.postMessage('hello');</pre><p>To receive messages, one listens to <code title="event-message"><a href="#event-message">message</a></code> events:<pre>channel.port1.onmessage = handleMessage;
                    828: function handleMessage(event) {
                    829:   // message is in event.data
                    830:   // ...
1.10      ihickson  831: }</pre><h3 id="message-channels"><span class="secno">4.2 </span>Message channels</h3><pre class="idl">[<a href="#dom-messagechannel" title="dom-MessageChannel">Constructor</a>]
1.1       ihickson  832: interface <dfn id="messagechannel">MessageChannel</dfn> {
                    833:   readonly attribute <a href="#messageport">MessagePort</a> <a href="#dom-channel-port1" title="dom-channel-port1">port1</a>;
                    834:   readonly attribute <a href="#messageport">MessagePort</a> <a href="#dom-channel-port2" title="dom-channel-port2">port2</a>;
                    835: };</pre><dl class="domintro"><dt><var title="">channel</var> = new <code title="dom-MessageChannel"><a href="#dom-messagechannel">MessageChannel</a></code>()</dt>
                    836: 
                    837:    <dd>
                    838: 
                    839:     <p>Returns a new <code><a href="#messagechannel">MessageChannel</a></code> object with two new <code><a href="#messageport">MessagePort</a></code> objects.</p>
                    840: 
                    841:    </dd>
                    842: 
                    843:    <dt><var title="">channel</var> . <code title="dom-MessageChannel-port1">port1</code></dt>
                    844: 
                    845:    <dd>
                    846: 
                    847:     <p>Returns the first <code><a href="#messageport">MessagePort</a></code> object.</p>
                    848: 
                    849:    </dd>
                    850: 
                    851:    <dt><var title="">channel</var> . <code title="dom-MessageChannel-port2">port2</code></dt>
                    852: 
                    853:    <dd>
                    854: 
                    855:     <p>Returns the second <code><a href="#messageport">MessagePort</a></code> object.</p>
                    856: 
                    857:    </dd>
                    858: 
                    859:   </dl><div class="impl">
                    860: 
                    861:   <p>When the <dfn id="dom-messagechannel" title="dom-MessageChannel"><code>MessageChannel()</code></dfn>
                    862:   constructor is called, it must run the following algorithm:</p>
                    863: 
                    864:   <ol><li><p><a href="#create-a-new-messageport-object">Create a new <code>MessagePort</code> object</a>
                    865:    owned by the <span>script's global object</span>, and let <var title="">port1</var> be that object.</li>
                    866: 
                    867:    <li><p><a href="#create-a-new-messageport-object">Create a new <code>MessagePort</code> object</a>
                    868:    owned by the <span>script's global object</span>, and let <var title="">port2</var> be that object.</li>
                    869: 
                    870:    <li><p><a href="#entangle">Entangle</a> the <var title="">port1</var> and <var title="">port2</var> objects.</li>
                    871: 
                    872:    <li><p>Instantiate a new <code><a href="#messagechannel">MessageChannel</a></code> object, and
                    873:    let <var title="">channel</var> be that object.</li>
                    874: 
                    875:    <li><p>Let the <code title="dom-channel-port1"><a href="#dom-channel-port1">port1</a></code>
                    876:    attribute of the <var title="">channel</var> object be <var title="">port1</var>.</p>
                    877: 
                    878:    <li><p>Let the <code title="dom-channel-port2"><a href="#dom-channel-port2">port2</a></code>
                    879:    attribute of the <var title="">channel</var> object be <var title="">port2</var>.</p>
                    880: 
                    881:    <li><p>Return <var title="">channel</var>.</li>
                    882: 
                    883:   </ol><p>This constructor must be visible when the <span>script's global
                    884:   object</span> is either a <code>Window</code> object or an object
                    885:   implementing the <code>WorkerUtils</code> interface.</p>
                    886: 
                    887:   <p>The <dfn id="dom-channel-port1" title="dom-channel-port1"><code>port1</code></dfn> and
                    888:   <dfn id="dom-channel-port2" title="dom-channel-port2"><code>port2</code></dfn> attributes
                    889:   must return the values they were assigned when the
                    890:   <code><a href="#messagechannel">MessageChannel</a></code> object was created.</p>
                    891: 
1.10      ihickson  892:   </div><h3 id="message-ports"><span class="secno">4.3 </span>Message ports</h3><p>Each channel has two message ports. Data sent through one port is
1.1       ihickson  893:   received by the other port, and vice versa.<pre class="idl">typedef sequence&lt;MessagePort&gt; <dfn id="messageportarray">MessagePortArray</dfn>;
                    894: 
                    895: interface <dfn id="messageport">MessagePort</dfn> {
                    896: <!-- v2-onclose  readonly attribute boolean <span title="dom-MessagePort-active">active</span>;
                    897: -->  void <a href="#dom-messageport-postmessage" title="dom-MessagePort-postMessage">postMessage</a>(in any message, in optional <a href="#messageportarray">MessagePortArray</a> ports);<!--
                    898:   <span>MessagePort</span> <span title="dom-MessagePort-startConversation">startConversation</span>(in any message);-->
                    899:   void <a href="#dom-messageport-start" title="dom-MessagePort-start">start</a>();
                    900:   void <a href="#dom-messageport-close" title="dom-MessagePort-close">close</a>();
                    901: 
                    902:   // event handlers
                    903:            attribute <span>Function</span> <a href="#handler-messageport-onmessage" title="handler-MessagePort-onmessage">onmessage</a>;
                    904: };
                    905: <a href="#messageport">MessagePort</a> implements <span>EventTarget</span>;</pre><dl class="domintro"><!-- v2-onclose
                    906:    <dt><var title="">port</var> . <code title="dom-MessagePort-active">active</code></dt>
                    907: 
                    908:    <dd>
                    909: 
                    910:     <p>Returns true if the port is still active; otherwise, returns false.</p>
                    911: 
                    912:    </dd>
                    913: --><dt><var title="">port</var> . <code title="dom-MessagePort-poseMessage">postMessage</code>(<var title="">message</var> [, <var title="">ports</var>] )</dt>
                    914: 
                    915:    <dd>
                    916: 
                    917:     <p>Posts a message through the channel, optionally with the given
                    918:     ports.</p>
                    919: 
                    920:     <p>Throws an <code>INVALID_STATE_ERR</code> if the <var title="">ports</var> array is not null and it contains either null
                    921:     entries, duplicate ports, or the source or target port.</p>
                    922: 
                    923:    </dd>
                    924: 
                    925:    <dt><var title="">port</var> . <code title="dom-MessagePort-start"><a href="#dom-messageport-start">start</a></code>()</dt>
                    926: 
                    927:    <dd>
                    928: 
                    929:     <p>Begins dispatching messages received on the port.</p>
                    930: 
                    931:    </dd>
                    932: 
                    933:    <dt><var title="">port</var> . <code title="dom-MessagePort-close"><a href="#dom-messageport-close">close</a></code>()</dt>
                    934: 
                    935:    <dd>
                    936: 
                    937:     <p>Disconnects the port, so that it is no longer active.</p>
                    938: 
                    939:    </dd>
                    940: 
                    941:   </dl><div class="impl">
                    942: 
                    943:   <p>Each <code><a href="#messageport">MessagePort</a></code> object can be entangled with
                    944:   another (a symmetric relationship). Each <code><a href="#messageport">MessagePort</a></code>
                    945:   object also has a <span>task source</span> called the <dfn id="port-message-queue">port
                    946:   message queue</dfn>, initial empty. A <a href="#port-message-queue">port message
                    947:   queue</a> can be enabled or disabled, and is initially
                    948:   disabled. Once enabled, a port can never be disabled again (though
                    949:   messages in the queue can get moved to another queue or removed
                    950:   altogether, which has much the same effect).</p>
                    951: 
                    952:   <p>When the user agent is to <dfn id="create-a-new-messageport-object">create a new
                    953:   <code>MessagePort</code> object</dfn> owned by a <span>script's
                    954:   global object</span> object <var title="">owner</var>, it must
                    955:   instantiate a new <code><a href="#messageport">MessagePort</a></code> object, and let its owner
                    956:   be <var title="">owner</var>.</p>
                    957: 
                    958:   <hr><p>When the user agent is to <dfn id="entangle">entangle</dfn> two
                    959:   <code><a href="#messageport">MessagePort</a></code> objects, it must run the following
                    960:   steps:</p>
                    961: 
                    962:   <ol><li>
                    963: 
                    964:     <p>If one of the ports is already entangled, then disentangle it
                    965:     and the port that it was entangled with.</p>
                    966: 
                    967:     <p class="note">If those two previously entangled ports were the
                    968:     two ports of a <code><a href="#messagechannel">MessageChannel</a></code> object, then that
                    969:     <code><a href="#messagechannel">MessageChannel</a></code> object no longer represents an actual
                    970:     channel: the two ports in that object are no longer entangled.</p>
                    971: 
                    972:    </li>
                    973: 
                    974:    <li><p>Associate the two ports to be entangled, so that they form
                    975:    the two parts of a new channel. (There is no
                    976:    <code><a href="#messagechannel">MessageChannel</a></code> object that represents this
                    977:    channel.)</li>
                    978: 
                    979:   </ol><hr><p>When the user agent is to <dfn id="clone-a-port">clone a port</dfn> <var title="">original port</var>, with the clone being owned by <var title="">owner</var>, it must run the following steps, which return
                    980:   a new <code><a href="#messageport">MessagePort</a></code> object. These steps must be run
                    981:   atomically.</p>
                    982: 
                    983:   <ol><li><p><a href="#create-a-new-messageport-object">Create a new <code>MessagePort</code> object</a>
                    984:    owned by <var title="">owner</var>, and let <var title="">new
                    985:    port</var> be that object.</li>
                    986: 
                    987:    <li><p>Move all the events in the <a href="#port-message-queue">port message queue</a>
                    988:    of <var title="">original port</var> to the <a href="#port-message-queue">port message
                    989:    queue</a> of <var title="">new port</var>, if any, leaving the
                    990:    <var title="">new port</var>'s <a href="#port-message-queue">port message queue</a> in
                    991:    its initial disabled state.</li>
                    992: 
                    993:    <li>
                    994: 
                    995:     <p>If the <var title="">original port</var> is entangled with
                    996:     another port, then run these substeps:</p>
                    997: 
                    998:     <ol><li><p>Let the <var title="">remote port</var> be the port with
                    999:      which the <var title="">original port</var> is entangled.</li>
                   1000: 
                   1001:      <li><p><a href="#entangle">Entangle</a> the <var title="">remote port</var>
                   1002:      and <var title="">new port</var> objects. The <var title="">original port</var> object will be disentangled by this
                   1003:      process.</li>
                   1004: 
                   1005:     </ol></li>
                   1006: 
                   1007:    <li><p>Return <var title="">new port</var>. It is the
                   1008:    clone.</li>
                   1009: 
                   1010:   </ol><hr><!-- v2-onclose
                   1011:   <p>The <dfn title="dom-MessagePort-active"><code>active</code></dfn>
                   1012:   attribute must return true if the port is entangled, and false
                   1013:   otherwise.</p>
                   1014: 
                   1015:   <hr>
                   1016: --><p>The <dfn id="dom-messageport-postmessage" title="dom-MessagePort-postMessage"><code>postMessage()</code></dfn>
                   1017:   method, when called on a port <var title="">source port</var>, must
                   1018:   cause the user agent to run the following steps:</p>
                   1019: 
                   1020:   <ol><li><p>Let <var title="">target port</var> be the port with which
                   1021:    <var title="">source port</var> is entangled, if any.</li>
                   1022: 
                   1023:    <li><p>If the method was called with a second argument <var title="">ports</var> and that argument isn't null, then, if any of
                   1024:    the entries in <var title="">ports</var> are null, if any
                   1025:    <code><a href="#messageport">MessagePort</a></code> object is listed in <var title="">ports</var> more than once, if any of the
                   1026:    <code><a href="#messageport">MessagePort</a></code> objects listed in <var title="">ports</var> have already been cloned once before, or if
                   1027:    any of the entries in <var title="">ports</var> are either the <var title="">source port</var> or the <var title="">target port</var>
                   1028:    (if any), then throw an <code>INVALID_STATE_ERR</code>
                   1029:    exception.</li>
                   1030: 
                   1031:    <li><p>If there is no <var title="">target port</var> (i.e. if <var title="">source port</var> is not entangled), then abort these
                   1032:    steps.</li>
                   1033:    <!-- we don't raise an exception if there is no target port because
                   1034:    this can happen at a moment's notice. we don't return false because
                   1035:    if the port is _about_ to be closed, the message might not be
                   1036:    listened for anyway. -->
                   1037: 
                   1038:    <li><p>Create an event that uses the <code><a href="#messageevent">MessageEvent</a></code>
                   1039:    interface, with the name <code title="event-message"><a href="#event-message">message</a></code>, which does not bubble, is not
                   1040:    cancelable, and has no default action.</li>
                   1041: 
                   1042:    <li><p>Let <var title="">message</var> be the method's first
                   1043:    argument.</li>
                   1044: 
                   1045:    <li><p>Let <var title="">message clone</var> be the result of
                   1046:    obtaining a <span>structured clone</span> of <var title="">message</var>. If this throws an exception, then throw
                   1047:    that exception and abort these steps.</li>
                   1048: 
                   1049:    <li><p>Let the <code title="dom-MessageEvent-data"><a href="#dom-messageevent-data">data</a></code>
                   1050:    attribute of the event have the value of <var title="">message
                   1051:    clone</var>.</li>
                   1052: 
                   1053:    <li><p>If the method was called with a second argument <var title="">ports</var> and that argument isn't null, then run the
                   1054:    following substeps:</p>
                   1055: 
                   1056:     <ol><li>
                   1057: 
                   1058:       <p>Let <var title="">new ports</var> be an empty array.</p>
                   1059: 
                   1060:       <p>For each port in <var title="">ports</var> in turn,
                   1061:       obtain a new port by <a href="#clone-a-port" title="clone a port">cloning</a>
                   1062:       the port with the owner of the <var title="">target port</var>
                   1063:       as the owner of the clone, and append the clone to the <var title="">new ports</var> array.</p>
                   1064: 
                   1065:       <p class="note">If the original <var title="">ports</var>
                   1066:       array was empty, then the <var title="">new ports</var> array will
                   1067:       also be empty.</p>
                   1068: 
                   1069:      </li>
                   1070: 
                   1071:      <li><p>Let the <code title="dom-MessageEvent-ports"><a href="#dom-messageevent-ports">ports</a></code>
                   1072:      attribute of the event be the <var title="">new ports</var>
                   1073:      array.</li>
                   1074: 
                   1075:     </ol></li>
                   1076: 
                   1077:    <li><p>Add the event to the <a href="#port-message-queue">port message queue</a> of <var title="">target port</var>.</li>
                   1078: 
                   1079:   </ol><!--
                   1080:   <hr>
                   1081: 
                   1082:   <p>The <dfn
                   1083:   title="dom-MessagePort-startConversation"><code>startConversation(<var
                   1084:   title="">message</var>)</code></dfn> method is a convenience method
                   1085:   that simplifies create a new <code>MessageChannel</code> and
                   1086:   invoking <code
                   1087:   title="dom-MessagePort-postMessage">postMessage()</code> with one of
                   1088:   the new ports. When invoked on a port <var title="">source
                   1089:   port</var>, it must run the following steps:</p>
                   1090: 
                   1091:   <ol>
                   1092: 
                   1093:    <li><p>Let <var title="">message</var> be the method's first
                   1094:    argument.</p></li>
                   1095: 
                   1096:    <li><p><span>Create a new <code>MessagePort</code> object</span>
                   1097:    owned by the <span>script's global object</span>, and let <var
                   1098:    title="">port1</var> be that object.</p></li>
                   1099: 
                   1100:    <li><p>If the <var title="">source port</var> is not entangled with
                   1101:    another port, then return <var title="">port1</var> and abort these
                   1102:    steps.</p></li>
                   1103:    <!- - we don't raise an exception because this can happen moment's
                   1104:    notice. we don't return null because then we'd end up with
                   1105:    null derefs. better to just let the likely next postMessage call
                   1106:    fall on the floor. - ->
                   1107: 
                   1108:    <li><p>Let <var title="">target port</var> be the port with which
                   1109:    <var title="">source port</var> is entangled.</p></li>
                   1110: 
                   1111:    <li><p><span>Create a new <code>MessagePort</code> object</span>
                   1112:    owned by the owner of the <var title="">target port</var>, and let
                   1113:    <var title="">port2</var> be that object.</p></li>
                   1114: 
                   1115:    <li><p><span>Entangle</span> the <var title="">port1</var> and <var
                   1116:    title="">port2</var> objects.</p></li>
                   1117: 
                   1118:    <li><p>Create an event that uses the <code>MessageEvent</code>
                   1119:    interface, with the name <code
                   1120:    title="event-message">message</code>, which does not bubble, is not
                   1121:    cancelable, and has no default action.</p></li>
                   1122: 
                   1123:    <li><p>Let the <code title="dom-MessageEvent-data">data</code>
                   1124:    attribute of the event have the value of <var
                   1125:    title="">message</var>, the method's first argument.</p></li>
                   1126: 
                   1127:    <li><p>Let the <code
                   1128:    title="dom-MessageEvent-ports">ports</code> attribute
                   1129:    of the event be an array containing only <var
                   1130:    title="">port2</var>.</p></li>
                   1131: 
                   1132:    <li><p>Return <var title="">port1</var> from the method, but
                   1133:    continue with these steps.</p></li>
                   1134: 
                   1135:    <li><p>Add the event to the <span>port message queue</span> of <var
                   1136:    title="">target port</var>.</p></li>
                   1137: 
                   1138:   </ol>
                   1139: --><hr><p>The <dfn id="dom-messageport-start" title="dom-MessagePort-start"><code>start()</code></dfn>
                   1140:   method must enable its port's <a href="#port-message-queue">port message queue</a>, if it
                   1141:   is not already enabled.</p>
                   1142: 
                   1143:   <p>When a port's <a href="#port-message-queue">port message queue</a> is enabled, the
                   1144:   <span>event loop</span> must use it as one of its <span title="task
                   1145:   source">task sources</span>.</p>
                   1146: 
                   1147:   <p class="note">If the <code>Document</code> of the port's event
                   1148:   listeners' <span title="script's global object">global object</span>
                   1149:   is not <span>fully active</span>, then the messages are lost.</p>
                   1150:   <!-- because of the jump-to-entry-point algorithm first step -->
                   1151: 
                   1152:   <hr><p>The <dfn id="dom-messageport-close" title="dom-MessagePort-close"><code>close()</code></dfn>
                   1153:   method, when called on a port <var title="">local port</var> that is
                   1154:   entangled with another port, must cause the user agents to
                   1155:   disentangle the two ports. If the method is called on a port that is
                   1156:   not entangled, then the method must do nothing.</p>
                   1157: 
                   1158:   <hr><p>The following are the <span>event handlers</span> (and their
                   1159:   corresponding <span title="event handler event type">event handler
                   1160:   event types</span>) that must be supported, as IDL attributes, by
                   1161:   all objects implementing the <code><a href="#messageport">MessagePort</a></code> interface:</p>
                   1162: 
                   1163:   <table><thead><tr><th><span title="event handlers">Event handler</span> <th><span>Event handler event type</span>
                   1164:    <tbody><tr><td><dfn id="handler-messageport-onmessage" title="handler-MessagePort-onmessage"><code>onmessage</code></dfn> <td> <code title="event-message"><a href="#event-message">message</a></code>
                   1165:   </table><p>The first time a <code><a href="#messageport">MessagePort</a></code> object's <code title="handler-MessagePort-onmessage"><a href="#handler-messageport-onmessage">onmessage</a></code> IDL attribute
                   1166:   is set, the port's <a href="#port-message-queue">port message queue</a> must be enabled,
                   1167:   as if the <code title="dom-MessagePort-start"><a href="#dom-messageport-start">start()</a></code> method
                   1168:   had been called.</p>
                   1169: 
1.10      ihickson 1170:   </div><h4 id="ports-and-garbage-collection"><span class="secno">4.3.1 </span>Ports and garbage collection</h4><div class="impl">
1.1       ihickson 1171: 
                   1172:   <p>When a <code><a href="#messageport">MessagePort</a></code> object <var title="">o</var> is
                   1173:   entangled, user agents must either act as if <var title="">o</var>'s
                   1174:   entangled <code><a href="#messageport">MessagePort</a></code> object has a strong reference to
                   1175:   <var title="">o</var>, or as if <var title="">o</var>'s owner has a
                   1176:   strong reference to <var title="">o</var>.</p>
                   1177: 
                   1178:   <div class="note">
                   1179: 
                   1180:    <p>Thus, a message port can be received, given an event listener,
                   1181:    and then forgotten, and so long as that event listener could
                   1182:    receive a message, the channel will be maintained.</p>
                   1183: 
                   1184:    <p>Of course, if this was to occur on both sides of the channel,
                   1185:    then both ports could be garbage collected, since they would not be
                   1186:    reachable from live code, despite having a strong reference to each
                   1187:    other.</p>
                   1188: 
                   1189:   </div>
                   1190: 
                   1191:   <p>Furthermore, a <code><a href="#messageport">MessagePort</a></code> object must not be
                   1192:   garbage collected while there exists a message in a <span>task
                   1193:   queue</span> that is to be dispatched on that
                   1194:   <code><a href="#messageport">MessagePort</a></code> object, or while the
                   1195:   <code><a href="#messageport">MessagePort</a></code> object's <a href="#port-message-queue">port message queue</a> is
                   1196:   open and there exists a <code title="event-message"><a href="#event-message">message</a></code>
                   1197:   event in that queue.</p>
                   1198:   <!-- we might not need to explicitly say the first part if DOM
                   1199:   Events is fixed to say that events on a task queue prevent GC -->
                   1200: 
                   1201:   <!-- ports in the ports attribute of a MessageEvent that isn't
                   1202:   dispatched yet are safe because the MessageEvent is safe -->
                   1203: 
                   1204:   </div><p class="note">Authors are strongly encouraged to explicitly close
                   1205:   <code><a href="#messageport">MessagePort</a></code> objects to disentangle them, so that their
                   1206:   resources can be recollected. Creating many <code><a href="#messageport">MessagePort</a></code>
                   1207:   objects and discarding them without closing them can lead to high
1.8       ihickson 1208:   memory usage.<h2 class="no-num" id="references">References</h2><!--REFS--><p>All references are normative unless marked "Non-normative".</p><!-- Dates are only included for standards older than the Web,
                   1209:   because the newer ones keep changing. --><dl><dt id="refsDOMEVENTS">[DOMEVENTS]</dt>
1.1       ihickson 1210:    <!--
                   1211:    <dd><cite><a
                   1212:    href="http://www.w3.org/TR/DOM-Level-3-Events/">Document Object
                   1213:    Model (DOM) Level 3 Events Specification</a></cite>,
1.8       ihickson 1214:    B. H&ouml;hrmann, P. Le Hegaret, T. Pixley. W3C.</dd>
1.1       ihickson 1215:    -->
                   1216:    <dd><cite><a href="http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html">Document
                   1217:    Object Model (DOM) Level 3 Events Specification</a></cite>,
1.8       ihickson 1218:    D. Schepers. W3C.</dd>
1.1       ihickson 1219: 
                   1220:    <dt id="refsEVENTSOURCE">[EVENTSOURCE]</dt>
                   1221:    <!--
                   1222:    <dd><cite><a href="http://www.w3.org/TR/eventsource/">Server-Sent
1.8       ihickson 1223:    Events</a></cite>, I. Hickson. W3C.</dd>
1.1       ihickson 1224:    -->
                   1225:    <dd><cite><a href="http://dev.w3.org/html5/eventsource/">Server-Sent
1.8       ihickson 1226:    Events</a></cite>, I. Hickson. W3C.</dd>
1.1       ihickson 1227: 
1.6       ihickson 1228:    <dt id="refsHTML5">[HTML5]</dt>
1.8       ihickson 1229:    <dd><cite><a href="http://dev.w3.org/html5/spec/">HTML5</a></cite>,
                   1230:    I. Hickson, D. Hyatt. W3C.</dd>
1.1       ihickson 1231: 
                   1232:    <dt id="refsWEBSOCKET">[WEBSOCKET]</dt>
                   1233:    <!--
                   1234:    <dd><cite><a href="http://www.w3.org/TR/websockets/">The Web Sockets
1.8       ihickson 1235:    API</a></cite>, I. Hickson. W3C.</dd>
1.1       ihickson 1236:    -->
                   1237:    <dd><cite><a href="http://dev.w3.org/html5/websockets/">The Web Sockets
1.8       ihickson 1238:    API</a></cite>, I. Hickson. W3C.</dd>
1.1       ihickson 1239: 
1.6       ihickson 1240:   </dl><h2 class="no-num" id="acknowledgements">Acknowledgements</h2><p>For a full list of acknowledgements, please see the HTML5
                   1241:   specification. <a href="#refsHTML5">[HTML5]</a>

Webmaster