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