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