Chromium Code Reviews| Index: lib/src/runner/browser/static/host.dart |
| diff --git a/lib/src/runner/browser/static/host.dart b/lib/src/runner/browser/static/host.dart |
| index 4b6673b13eefe5cb5c8609dd4a1942f180ef3ab2..292f529c4c8e466ed95b6a91b986e4a71bfe72e0 100644 |
| --- a/lib/src/runner/browser/static/host.dart |
| +++ b/lib/src/runner/browser/static/host.dart |
| @@ -106,31 +106,31 @@ StreamChannel _connectToIframe(String url) { |
| var inputController = new StreamController(sync: true); |
| var outputController = new StreamController(sync: true); |
| - iframe.onLoad.first.then((_) { |
| - // TODO(nweiz): use MessageChannel once Firefox supports it |
| - // (http://caniuse.com/#search=MessageChannel). |
| - |
| - // Send an initial command to give the iframe something to reply to. |
| - iframe.contentWindow.postMessage( |
| - {"command": "connect"}, |
| - window.location.origin); |
| - |
| - window.onMessage.listen((message) { |
| - // A message on the Window can theoretically come from any website. It's |
| - // very unlikely that a malicious site would care about hacking someone's |
| - // unit tests, let alone be able to find the test server while it's |
| - // running, but it's good practice to check the origin anyway. |
| - if (message.origin != window.location.origin) return; |
| - |
| - // TODO(nweiz): Stop manually checking href here once issue 22554 is |
| - // fixed. |
| - if (message.data["href"] != iframe.src) return; |
| - |
| - message.stopPropagation(); |
| - inputController.add(message.data["data"]); |
| - }); |
| - outputController.stream.listen((message) => |
| + // Use this to avoid sending a message to the iframe before it's sent a |
| + // message to us. This ensures that no messages get dropped on the floor. |
| + var readyCompleter = new Completer(); |
| + |
| + // TODO(nweiz): use MessageChannel once Firefox supports it |
| + // (http://caniuse.com/#search=MessageChannel). |
| + window.onMessage.listen((message) { |
| + // A message on the Window can theoretically come from any website. It's |
| + // very unlikely that a malicious site would care about hacking someone's |
| + // unit tests, let alone be able to find the test server while it's |
| + // running, but it's good practice to check the origin anyway. |
| + if (message.origin != window.location.origin) return; |
| + |
| + // TODO(nweiz): Stop manually checking href here once issue 22554 is |
| + // fixed. |
| + if (message.data["href"] != iframe.src) return; |
| + |
| + message.stopPropagation(); |
| + inputController.add(message.data["data"]); |
| + readyCompleter.complete(); |
| + }); |
| + |
| + outputController.stream.listen((message) { |
|
kevmoo
2015/04/13 20:36:24
readyCompleter.future.then?
nweiz
2015/04/13 20:39:08
Done.
|
| + readyCompleter.then((_) => |
| iframe.contentWindow.postMessage(message, window.location.origin)); |
| }); |