-
Notifications
You must be signed in to change notification settings - Fork 4
/
155.txt
358 lines (282 loc) · 16.9 KB
/
155.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
[2]
[[Web Applications 1.0]] の、他の[[ドメイン]]の[[文書]]に[[メッセージ]]を送る機能。
* 仕様書
[REFS[
- [18] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#crossDocumentMessages>
]REFS]
* 引数
[22] 第1引数には、投函したいメッセージを指定します。ただし、そのものではなく、
[[構造化クローン]]が投函されることになります。メッセージとしては任意の [[JavaScript]]
の値を指定できます。
[25] 第2引数には、投函先の[[起源]]を指定します。投函先が実際には異なる[[起源]]なら、
メッセージは無視されます (エラーにもなりません)。
[26] [[起源]]は、次のいずれかの値を指定できます。
[FIG(list)[
- [20] [[絶対URL]] は、その [[URL]] の[[起源]]を表します。
- [28] [CODE[[[/]]]] は、送信元の[[文書]]と[[同じ起源]]を表します。
[[同じ起源]]同士でも、異なる[[起源]]の場合と同じように投函できます。
その場合でもやはりメッセージは[[構造化クローン]]が引き渡されます。
- [27] [CODE[[[*]]]] は、任意の[[起源]]を表します。
[[著者]]は、機密情報を含むメッセージの場合、対象の起源として
[CODE[[[*]]]] を指定する[['''べきではありません''']] [SRC[>>18]]。
]FIG]
[29] [[相対URL]]は指定できません。
[EG[
[30] 例えば [CODE[https://hoge.example/foo/bar]] を指定すると、
[CODE[https://hoge.example]] 下の任意の[[文書]]などが受信できます。
]EG]
[31] 第3引数には、 [CODE[[[Transferable]]]] の[[配列]]を指定できます。
該当するものがなければ、省略できます。
* 処理
[21] [CODE(DOMi)@en[[[Window]]]] [[インターフェイス]]の
[CODE(DOMm)@en[[[postMessage]]]] [[メソッド]]は、
次のようにしなければ[['''なりません''']] [SRC[>>18]]。
[FIG(steps)[
= 必須の第1引数を [CODE[[[any]]]]、
必須の第2引数を [CODE[[[DOMString]]]]、
省略可能の第3引数を [CODE[[[sequence]]<[[Transferable]]>]]
として解釈します。
= 第2引数の値が
[FIG(list)[
- [CODE[[[*]]]]
- [CODE[[[/]]]]
- [[絶対URL]]
]FIG]
... のいずれでもなければ、 [CODE(JS)@en[[[SyntaxError]]]] [[例外]]を[[投げ]]、
ここで停止します。
= [VAR[new ports]] を、空の[[配列]]に設定します。
= [VAR[transfer map]] を、空の[[写像]]群に設定します。
= 第3引数が指定されていれば、
== 同じ [CODE(DOMi)@en[[[Transferable]]]] が重複して指定されていれば、
[CODE(JS)@en[[[DataCloneError]]]] [[例外]]を[[投げ]]、ここで停止します。
== [CODE(DOMi)@en[[[Transferable]]]] のいずれかが [[neutered]] であれば、
[CODE(JS)@en[[[DataCloneError]]]] [[例外]]を[[投げ]]、ここで停止します。
== 各 [CODE(DOMi)@en[[[Transferable]]]] について、
=== [VAR[transfer map]] に、本 [CODE(DOMi)@en[[[Transferable]]]] から新しい
placeholder object への[[写像]]を追加します。
=== 本 [CODE(DOMi)@en[[[Transferable]]]] が [CODE(DOMi)@en[[[MessagePort]]]] なら、
[VAR[new ports]] の末尾に placeholder object を追加します。
= 第1引数の[[構造化クローン]]を得ます。 [[transfer map]] には [VAR[transfer map]]
を使います。成功すれば、 [VAR[message clone]] を、実行結果に設定します。
[[例外]]が投げられたなら、[[伝播]]させ、ここで停止します。
= 第3引数が指定されていれば、
== [VAR[new owner]] を、[[文脈オブジェクト]]の[[環境設定群オブジェクト]]とします。
== 各 [CODE(DOMi)@en[[[Transferable]]]] について、
=== [VAR[new owner]] へと [[transfer]] し、新しいオブジェクトを得ます。
=== [VAR[new ports]] と [VAR[message clone]] に本オブジェクトの placeholder object
があれば、それを新しいオブジェクトに置き換えます。
= [VAR[new ports]] を[[読み取り専用配列]]にします。
= [CODE(DOMm)@en[[[postMessage]]]] [[メソッド]]はここで終わります。
= [[並列に]]実行します。
== 第1引数で指定されたのが [CODE[/]] の場合、
=== [[文脈オブジェクト]]の [CODE(DOMi)@en[[[Window]]]] [[オブジェクト]]の
[CODE(DOMi)@en[[[Document]]]] が[[入口設定群オブジェクト]]の[[有責文書]]と[[同じ起源]]でなければ、
ここで停止します。
== 第1引数で指定されたのが[[絶対URL]] の場合、
=== [[文脈オブジェクト]]の [CODE(DOMi)@en[[[Window]]]] [[オブジェクト]]の
[CODE(DOMi)@en[[[Document]]]] がその [[URL]] と[[同じ起源]]でなければ、
ここで停止します。
== [[イベント]]を作成します。
[FIG(list members)[
[FIGCAPTION[
[[イベント]]
]FIGCAPTION]
:[[インターフェイス]]:[CODE(DOMi)@en[[[MessageEvent]]]]
:[[イベント型]]:[CODE(DOMe)@en[[[message]]]]
:[[イベント対象]]:[[対象オブジェクト]]
:[[trusted]]:[[真]]
:[[bubbles]]:[[偽]]
:[[cancelable]]:[[偽]]
:[[既定動作]]:なし
:[CODE(DOMa)@en[[[data]]]]:[VAR[message clone]]
:[CODE(DOMa)@en[[[origin]]]]:[[現職設定群オブジェクト]]の[[起源]]の[[Unicode直列化]]
:[CODE(DOMa)@en[[[source]]]]:[[現職設定群オブジェクト]]の[[大域オブジェクト]]の
[CODE(DOMi)@en[[[WindowProxy]]]] [[オブジェクト]]
:[CODE(DOMa)@en[[[ports]]]]:[VAR[new ports]]
]FIG]
== [[タスク]]を[[タスクキュー]]に追加します。
[FIG(list members)[
[FIGCAPTION[
[[タスク]]
]FIGCAPTION]
:[[タスク源]]:[[投稿済みメッセージタスク源]]
:処理:
[FIG(steps)[
= 作成した[[イベント]]を [[dispatch]] します。
]FIG]
]FIG]
]FIG]
;; [19] [VAR[new ports]] は [VAR[new owner]] の環境の[[配列]]と思われます。
[33] 送信したメッセージは、 [CODE(DOMi)@en[[[Window]]]] の [CODE(DOMe)@en[[[message]]]]
[[イベント]]として受信することができます。
;; [CODE(DOMe)@en[[[message]]]] を参照。
* 歴史
** 登場
[14] 最初 [[Web Applications 1.0]] に追加された時は [CODE(DOMi)@en[[[Document]]]]
[[オブジェクト]]に属していました。
[15] しかし[[同一起源ポリシー]]に関する検査が複雑になるとして、より「外側」
である [CODE(DOMi)@en[[[Window]]]] [[オブジェクト]]へと移動されました。
[16] [[Opera]] ははじめに [CODE(DOMi)@en[[[Document]]]] [[オブジェクト]]に実装しましたが、
後に [CODE(DOMi)@en[[[Window]]]] [[オブジェクト]]に移動しました。
他の[[Webブラウザー]]ははじめから [CODE(DOMi)@en[[[Window]]]]
[[オブジェクト]]に実装しました。
[17] [CODE(DOMm)@en[[[postMessage]]]] は [[HTML5]] の新機能の中では最も早期に実装されたものの一つでした。
** 実装開始
- [51] [[IE]] 8+ (2009/3) [SRC[>>52]]
- [54] [[Gecko]] 1.9+ / [[Firefox]] 3+ (2008/6) [SRC[>>55]]
- [56] [[WebKit]] 2007年末+ [SRC[>>59]]
-- [57] [[Chrome]] 4+ (2010/1) [SRC[>>58]]
-- [63] [[Safari]] 4+ (2009/6) [SRC[>>64]]
- [60] [[Opera]]
-- [62] [CODE(DOMi)@en[[[Document]]]] (旧仕様): 9+ (2006/6) [SRC[>>59]]
-- [61] [CODE(DOMi)@en[[[Window]]]]: 9.5+ (2008/6) [SRC[>>59]]
[REFS[
- [52] [CITE@en-us[postMessage Method (window, Window Constructor)]] ([TIME[2011-04-24 11:40:59 +09:00]] 版) <http://msdn.microsoft.com/library/cc197015.aspx>
- [53] [CITE@ja-jp[Internet Explorer 8 のクロス ドキュメント メッセージングの概要]] ([TIME[2011-04-24 11:40:25 +09:00]] 版) <http://msdn.microsoft.com/ja-jp/library/cc511311(v=vs.85).aspx>
- [55] [CITE@ja[window.postMessage - MDC Doc Center]] ([TIME[2011-04-24 11:42:47 +09:00]] 版) <https://developer.mozilla.org/ja/DOM/window.postMessage>
- [58] [CITE[Google Chrome 4で注目したいセキュリティ強化の新機能 - ITmedia エンタープライズ]] ([TIME[2011-04-24 11:47:11 +09:00]] 版) <http://www.itmedia.co.jp/enterprise/articles/1001/29/news021.html>
- [59] [CITE[サーバーサイド技術を使わないクロスドメイン通信補足 - 0xFF]] ([TIME[2011-04-24 11:48:45 +09:00]] 版) <http://d.hatena.ne.jp/os0x/20080409/1207732715>
- [64] [CITE@en[Browser Variation of the Hub Reference Implementation (Illustrative) - MemberWiki]] ([TIME[2009-12-19 12:40:31 +09:00]] 版) <http://www.openajax.org/member/wiki/Browser_Variation_of_the_Hub_Reference_Implementation_(Illustrative)#HTML_5_postMessage>
]REFS]
**
[1]
[CITE[Cross-document messaging in Opera - Arve Bersvendsen]] <http://virtuelvis.com/archives/2005/12/cross-document-messaging>
[50]
[[Opera 8]] β にはありませんでしたが、 [[Opera 8.5]]
では実装されていました。
[3]
[CITE[The cross-document messaging APIs]] ([[Ian Hickson <ian@...>]] 著, [CODE[2007-08-09 00:51:36 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11634>
[4]
[CITE[Index of /specs/dom/messages]] ([CODE[2008-02-13 01:58:34 +09:00]] 版) <http://www.hixie.ch/specs/dom/messages/>
[23]
[CITE[Fixed a security problem with postMessage()]] ([[Ian Hickson <ian@...>]] 著, [CODE[2008-02-12 20:03:46 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13237>
([[名無しさん]])
[24]
[CITE[IE Team Feedback on HTML 5.0 Cross Document Messaging]] ([[Sunava Dutta <sunavad@...>]] 著, [CODE[2008-02-22 03:18:40 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13320>
[32]
[CITE[postMessage() issues]] ([[Ian Hickson <ian@...>]] 著, [CODE[2008-04-16 00:10:07 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13716>
[38]
[CITE[postMessage feedback]] ([[Ian Hickson <ian@...>]] 著, [CODE[2008-04-24 23:49:56 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13867>
[39] [CITE@en[(X)HTML5 Tracking]]
([TIME[2010-01-09 14:12:17 +09:00]] 版)
<http://html5.org/tools/web-apps-tracker?from=4547&to=4548>
[40] [CITE@en-US-x-Hixie[HTML5 Communications]]
([TIME[2010-01-09 10:10:53 +09:00]] 版)
<http://dev.w3.org/html5/postmsg/Overview.html>
[41] [CITE[IRC logs: freenode / #whatwg / 20100212]]
([TIME[2010-02-14 11:17:32 +09:00]] 版)
<http://krijnhoetmer.nl/irc-logs/whatwg/20100212#l-271>
[42] [CITE@en-US[David Baron's weblog: setTimeout with a shorter delay]]
([TIME[2010-03-16 08:44:54 +09:00]] 版)
<http://dbaron.org/log/20100309-faster-timeouts>
[43] [CITE['''['''whatwg''']''' postMessage's target origin argument can be a full URL in some implementations]]
([TIME[2010-08-11 10:18:42 +09:00]] 版)
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-August/027848.html>
[44] [CITE@en[HTML5 Revision Tracker]]
([TIME[2010-08-11 23:17:32 +09:00]] 版)
<http://html5.org/tools/web-apps-tracker?from=5276&to=5277>
[45] [CITE[''''''[''''''whatwg'''''']'''''' postMessage's target origin argument can be a full URL in some implementations]]
( ([TIME[2010-11-16 08:52:44 +09:00]] 版))
<http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-November/029037.html>
[46] [CITE@en[Web Applications 1.0 r5682 Revert r5277's removal of '/' as a magic value to postMessage(), since it has useful use cases. Paths in absolute URLs are still ignored without raising an exception.]]
( ([TIME[2010-11-16 08:25:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=5681&to=5682>
[47] [CITE@en-US-x-Hixie[HTML5 Web Messaging]]
( ([TIME[2010-11-19 05:40:25 +09:00]] 版))
<http://www.w3.org/TR/2010/WD-webmessaging-20101118/>
[48] [CITE[IE で postMessage 的実装をちゃんとやる - 冬通りに消え行く制服ガールは、夢物語にリアルを求めない。 - subtech]]
( ([TIME[2010-12-07 22:02:13 +09:00]] 版))
<http://subtech.g.hatena.ne.jp/cho45/20101207/1291719344>
[49] [CITE@en-US-x-Hixie[HTML5 Web Messaging]]
( ([TIME[2011-03-17 23:58:26 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-webmessaging-20110317/>
[65] [CITE@en[Web Applications 1.0 r6690 Make postMessage() accept the second and third arguments in either order. Compat with WebKit and hopefully solves the difficulty people have about remembering which goes first.]]
( ([TIME[2011-10-18 06:47:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6689&to=6690>
[66] [CITE@en[Web Applications 1.0 r6691 Revert last checkin. My testing was bogus.]]
( ([TIME[2011-10-18 07:09:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6690&to=6691>
[67] [CITE@en-US-x-Hixie[HTML5 Web Messaging]]
( ([TIME[2011-10-19 02:36:24 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-webmessaging-20111020/>
[68] [CITE@ja[IE 6/7 で文書間通信を実現するための一案: Days on the Moon]]
( ([TIME[2011-12-10 00:17:35 +09:00]] 版))
<http://nanto.asablo.jp/blog/2011/12/08/6237308>
[69] [CITE@en-US-x-Hixie[HTML5 Web Messaging]]
( ([TIME[2012-03-12 22:06:22 +09:00]] 版))
<http://www.w3.org/TR/2012/WD-webmessaging-20120313/>
[70] [CITE@en-US-x-Hixie[HTML5 Web Messaging]]
( ([TIME[2012-05-01 21:47:11 +09:00]] 版))
<http://www.w3.org/TR/2012/CR-webmessaging-20120501/>
[71] [CITE[Securing Frame Communication in Browsers]]
( ([TIME[2008-05-15 01:03:44 +09:00]] 版))
<http://seclab.stanford.edu/websec/frames/post-message.pdf>
[72] [CITE@en[Compound Document by Reference Framework 1.0]]
( ([TIME[2010-08-17 16:50:04 +09:00]] 版))
<http://www.w3.org/TR/CDR/#event-propagation>
[73] [CITE@en[Interview with Ian Hickson, HTML editor | HTML5 Doctor]]
( ([TIME[2013-01-13 18:27:28 +09:00]] 版))
<http://html5doctor.com/interview-with-ian-hickson-html-editor/>
[74] [CITE@en[RemoteDocumentMessaging - WHATWG Wiki]]
( ([TIME[2013-06-24 05:31:29 +09:00]] 版))
<http://wiki.whatwg.org/wiki/RemoteDocumentMessaging>
[75] [CITE[IRC logs: freenode / #whatwg / 20130621]]
( ([TIME[2013-06-24 19:18:13 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20130621#l-585>
[76] [CITE[''''''[''''''whatwg'''''']'''''' web messaging - postMessage]]
( ([TIME[2013-09-13 00:52:56 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-September/040800.html>
[77] [CITE@en[Web Applications 1.0 r8247 The bulk of this is editorial: refactoring how scripts are defined so that all the common stuff is in a shared 'settings object' rather than being duplicated per script. But this also cleans up how postMessage() interacts with the event loop and a few other things I've since forgotten.]]
( ([TIME[2013-10-31 08:18:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8246&to=8247>
[78] [CITE@en[Web Applications 1.0 r8741 Try to explain why postMessage()'s privacy implications aren't actually anything new]]
( ([TIME[2014-09-04 08:43:00 +09:00]] 版))
<http://html5.org/r/8741>
[79] [CITE[JavaScript - WebWorkersで巨大データ転送の不思議 - Qiita]]
( ([TIME[2014-09-05 02:14:11 +09:00]] 版))
<http://qiita.com/Quramy/items/8c12e6c3ad208c97c99a>
[5] [CITE@en[CfC: publish Proposed Recommendation of Web Messaging; deadline March 28]]
([[Arthur Barstow]] 著, [TIME[2015-03-21 21:52:25 +09:00]] 版)
<https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0848.html>
[6] [CITE[Part2 - browsersec - Browser Security Handbook, part 2 - Browser Security Handbook - Google Project Hosting]]
([TIME[2015-03-31 16:38:48 +09:00]] 版)
<https://code.google.com/p/browsersec/wiki/Part2#Gaps_in_DOM_access_control>
[FIG(quote)[
[FIGCAPTION[
[7] [CITE@en[YuzuJS/setImmediate]]
([TIME[2015-04-01 12:18:25 +09:00]] 版)
<https://github.com/YuzuJS/setImmediate>
]FIGCAPTION]
> Note that Internet Explorer 8 includes a synchronous version of postMessage. We detect this, or any other such synchronous implementation, and fall back to another trick.
]FIG]
[8] [CITE@en-US[HTML5 Web Messaging]]
( ([TIME[2015-04-07 00:52:40 +09:00]] 版))
<http://www.w3.org/TR/2015/PR-webmessaging-20150407/>
[9] [CITE@en-US[HTML5 Web Messaging]]
( ([TIME[2015-05-18 22:30:14 +09:00]] 版))
<http://www.w3.org/TR/2015/REC-webmessaging-20150519/>
[10] [CITE@en[Errata/WebMessaging - WEBAPPS]]
([TIME[2015-05-11 23:07:22 +09:00]] 版)
<https://www.w3.org/2008/webapps/wiki/Errata/WebMessaging>
[11] [CITE@en[All Results]]
([TIME[2015-05-19 23:43:52 +09:00]] 版)
<https://w3c.github.io/test-results/webmessaging/all>
[FIG(quote)[
[FIGCAPTION[
[12] [CITE@en-US[HTML5 Web Messaging]]
([TIME[2015-05-18 22:30:14 +09:00]] 版)
<http://www.w3.org/TR/2015/REC-webmessaging-20150519/>
]FIGCAPTION]
> Open Bugs 27128
]FIG]
[FIG(quote)[
[FIGCAPTION[
[13] [CITE@en-US[HTML5 Web Messaging]]
([TIME[2015-05-18 22:30:14 +09:00]] 版)
<http://www.w3.org/TR/2015/REC-webmessaging-20150519/>
]FIGCAPTION]
> Open Bugs 18242
]FIG]
[34] [CITE@en[PSA: Change the Latest Editor's Drafts of WebStorage, WebWorkers, WebMessaging, Server-Sent Events and WebSockets]]
([[Xiaoqian Wu]] 著, [TIME[2015-10-20 02:52:22 +09:00]] 版)
<https://lists.w3.org/Archives/Public/public-webapps/2015OctDec/0099.html>