dom/tests/mochitest/whatwg/postMessage_chrome_helper.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4   <title>postMessage chrome message receiver</title>
     5   <script type="application/javascript">
     6     var gPrePath = "";
     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         }
    21         var msg = "post-to-content-response";
    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 + ")";
    34         respond(msg);
    35       }
    36     }
    38     function respond(msg)
    39     {
    40       SpecialPowers.wrap(window).parent.postMessage(msg, "*");
    41     }
    43     window.addEventListener("message", receiveMessage, false);
    44   </script>
    45 </head>
    46 <body>
    47 <h1 id="domain">example.org</h1>
    48 </body>
    49 </html>

mercurial