2008-01-29 17:31:29 -08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>postMessage chrome message receiver</title>
|
|
|
|
<script type="application/javascript">
|
|
|
|
function receiveMessage(evt)
|
|
|
|
{
|
|
|
|
// Content cannot post to chrome without privileges
|
2008-05-02 12:26:47 -07:00
|
|
|
window.parent.postMessage("SHOULD NOT GET THIS!", "*");
|
|
|
|
|
2008-01-29 17:31:29 -08:00
|
|
|
var msg = "post-to-content-response";
|
|
|
|
|
|
|
|
if (evt.source !== null)
|
|
|
|
msg += " wrong-source(" + evt.source + ")";
|
|
|
|
if (!evt.isTrusted)
|
|
|
|
msg += " unexpected-untrusted-event";
|
|
|
|
if (evt.type !== "message")
|
|
|
|
msg += " wrong-type(" + evt.type + ")";
|
2008-02-26 19:48:54 -08:00
|
|
|
if (evt.origin !== "chrome://mochikit")
|
|
|
|
msg += " wrong-origin(" + evt.origin + ")";
|
2008-01-29 17:31:29 -08:00
|
|
|
if (evt.data !== "post-to-content")
|
|
|
|
msg += " wrong-message(" + evt.data + ")";
|
|
|
|
|
|
|
|
respond(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function respond(msg)
|
|
|
|
{
|
|
|
|
// ...so get privileges and test that this works with privileges
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
2008-05-02 12:26:47 -07:00
|
|
|
window.parent.postMessage(msg, "*");
|
2008-01-29 17:31:29 -08:00
|
|
|
}
|
|
|
|
|
2008-05-02 12:26:47 -07:00
|
|
|
window.addEventListener("message", receiveMessage, false);
|
2008-01-29 17:31:29 -08:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1 id="domain">example.org</h1>
|
|
|
|
</body>
|
|
|
|
</html>
|