+CONSOLE MESSAGE: Unable to post message to http://127.0.0.1:8000. Recipient has origin http://localhost:8000.
+
CONSOLE MESSAGE: Unable to post message to http://localhost:9090. Recipient has origin http://localhost:8000.
CONSOLE MESSAGE: Unable to post message to http://localhost. Recipient has origin http://localhost:8000.
waiting...
Error sending message to null. Error: SYNTAX_ERR: DOM Exception 12
Error sending message to undefined. Error: SYNTAX_ERR: DOM Exception 12
+Error sending message to //. Error: SYNTAX_ERR: DOM Exception 12
Received message: data="Received message: data="Trying origin=http://localhost:8000" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
Received message: data="Received message: data="Trying origin=http://localhost:8000/" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
Received message: data="Received message: data="Trying origin=http://localhost:8000/foo" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
Received message: data="Received message: data="Trying origin=http://localhost:8000/foo?bar#baz" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
Received message: data="Received message: data="Trying origin=http://user:pass@localhost:8000/foo?bar#baz" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
Received message: data="Received message: data="Trying origin=*" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
+Received message: data="Received message: data="Trying origin=/" origin="http://127.0.0.1:8000"" origin="http://127.0.0.1:8000"
Received message: data="Received message: data="done" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
}
function test() {
- var iframe = document.getElementById('child');
- var win = iframe.contentWindow;
+ var winLocalhost = document.getElementById('iframe-localhost').contentWindow;
+ var win127= document.getElementById('iframe-127').contentWindow;
// Should succeed:
- tryPostMessage(win, "http://localhost:8000");
- tryPostMessage(win, "http://localhost:8000/");
- tryPostMessage(win, "http://localhost:8000/foo");
- tryPostMessage(win, "http://localhost:8000/foo?bar");
- tryPostMessage(win, "http://localhost:8000/foo?bar#baz");
- tryPostMessage(win, "http://user:pass@localhost:8000/foo?bar#baz");
- tryPostMessage(win, "*");
+ tryPostMessage(winLocalhost, "http://localhost:8000");
+ tryPostMessage(winLocalhost, "http://localhost:8000/");
+ tryPostMessage(winLocalhost, "http://localhost:8000/foo");
+ tryPostMessage(winLocalhost, "http://localhost:8000/foo?bar");
+ tryPostMessage(winLocalhost, "http://localhost:8000/foo?bar#baz");
+ tryPostMessage(winLocalhost, "http://user:pass@localhost:8000/foo?bar#baz");
+ tryPostMessage(winLocalhost, "*");
+ tryPostMessage(win127, "/");
// Should fail:
- tryPostMessage(win, "http://localhost:9090");
- tryPostMessage(win, "http://localhost");
- tryPostMessage(win, "https://localhost");
- tryPostMessage(win, "https://localhost:8000");
- tryPostMessage(win, "http://www.example.com");
+ tryPostMessage(winLocalhost, "/");
+ tryPostMessage(winLocalhost, "http://localhost:9090");
+ tryPostMessage(winLocalhost, "http://localhost");
+ tryPostMessage(winLocalhost, "https://localhost");
+ tryPostMessage(winLocalhost, "https://localhost:8000");
+ tryPostMessage(winLocalhost, "http://www.example.com");
// Should throw syntax error:
- tryPostMessage(win, null);
- tryPostMessage(win, undefined);
+ tryPostMessage(winLocalhost, null);
+ tryPostMessage(winLocalhost, undefined);
+ tryPostMessage(win127, "//");
- win.postMessage('done', '*');
+ winLocalhost.postMessage('done', '*');
}
</script>
<body onload="test()">
<div>window.location.href = <script>document.write(window.location.href);</script></div>
<div><iframe src="http://localhost:8000/security/postMessage/resources/post-message-listener.html"
- id="child" width="800" height="300" style="border: 1px solid black;">
-</iframe></div>
+ id="iframe-localhost" width="800" height="300" style="border: 1px solid black;">
+</iframe><iframe src="http://127.0.0.1:8000/security/postMessage/resources/post-message-listener.html"
+ id="iframe-127" width="800" height="300" style="border: 1px solid black;"></iframe>
<div id="result">waiting...</div>
</body>
</html>
if (!isCurrentlyDisplayedInFrame())
return;
+ Document* sourceDocument = source->document();
+
// Compute the target origin. We need to do this synchronously in order
// to generate the SYNTAX_ERR exception correctly.
RefPtr<SecurityOrigin> target;
- if (targetOrigin != "*") {
+ if (targetOrigin == "/") {
+ if (!sourceDocument)
+ return;
+ target = sourceDocument->securityOrigin();
+ } else if (targetOrigin != "*") {
target = SecurityOrigin::createFromString(targetOrigin);
// It doesn't make sense target a postMessage at a unique origin
// because there's no way to represent a unique origin in a string.
// Capture the source of the message. We need to do this synchronously
// in order to capture the source of the message correctly.
- Document* sourceDocument = source->document();
if (!sourceDocument)
return;
String sourceOrigin = sourceDocument->securityOrigin()->toString();