|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>postMessage chrome message receiver</title> |
|
5 <script type="application/javascript"> |
|
6 var gPrePath = ""; |
|
7 |
|
8 function receiveMessage(evt) |
|
9 { |
|
10 if (evt.data.substring(0,9) == "chrome://") { |
|
11 gPrePath = evt.data; |
|
12 respond("path-is-set"); |
|
13 } else { |
|
14 // Content cannot post to chrome without privileges |
|
15 try { |
|
16 window.parent.postMessage("SHOULD NOT GET THIS!", "*"); |
|
17 } |
|
18 catch (ex) { |
|
19 } |
|
20 |
|
21 var msg = "post-to-content-response"; |
|
22 |
|
23 if (evt.source !== null) |
|
24 msg += " wrong-source(" + evt.source + ")"; |
|
25 if (!evt.isTrusted) |
|
26 msg += " unexpected-untrusted-event"; |
|
27 if (evt.type !== "message") |
|
28 msg += " wrong-type(" + evt.type + ")"; |
|
29 if (evt.origin !== gPrePath) |
|
30 msg += " wrong-origin(" + evt.origin + ")"; |
|
31 if (evt.data !== "post-to-content") |
|
32 msg += " wrong-message(" + evt.data + ")"; |
|
33 |
|
34 respond(msg); |
|
35 } |
|
36 } |
|
37 |
|
38 function respond(msg) |
|
39 { |
|
40 SpecialPowers.wrap(window).parent.postMessage(msg, "*"); |
|
41 } |
|
42 |
|
43 window.addEventListener("message", receiveMessage, false); |
|
44 </script> |
|
45 </head> |
|
46 <body> |
|
47 <h1 id="domain">example.org</h1> |
|
48 </body> |
|
49 </html> |