dom/tests/mochitest/whatwg/postMessage_chrome_helper.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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