Skip to content

Commit

Permalink
Drop support for legacy iframe communication
Browse files Browse the repository at this point in the history
Closes #2065

All known iframe side implementations have been updated to send the
`'port'` message with an immediately available channel over the map and
the extra window message.

Move some still relevant `assert` into the implementation for the
current approach.
  • Loading branch information
natebosch committed Sep 21, 2023
1 parent 8191a35 commit 16e52d0
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions pkgs/test/tool/host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,15 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
dom.window.console.log('Connecting channel for suite $suiteUrl');
// The frame is starting and sending a port to forward for the suite.
final port = message.ports.first;
assert(!_domSubscriptions.containsKey(id));
_domSubscriptions[id] =
dom.Subscription(port, 'message', allowInterop((event) {
controller.local.sink.add((event as dom.MessageEvent).data);
}));
port.start();

_subscriptions[id] = controller.local.stream.listen(port.postMessage);
case {'ready': true}:
// This message indicates that the iframe is actively listening for
// events, so the message channel's second port can now be transferred.
var channel = dom.createMessageChannel();
assert(!_domSubscriptions.containsKey(id));
_domSubscriptions[id] = dom.Subscription(channel.port1, 'message',
allowInterop((dom.Event event) {
controller.local.sink.add((event as dom.MessageEvent).data['data']);
}));

assert(!_subscriptions.containsKey(id));
_subscriptions[id] =
controller.local.stream.listen(channel.port1.postMessage);
channel
..port2.start()
..port1.start();
// TODO(#1758): This is a work around for a crash in package:build.
js_util.callMethod(
js_util.getProperty(iframe, 'contentWindow'), 'postMessage', [
'port',
dom.window.location.origin,
[channel.port2]
]);
_subscriptions[id] = controller.local.stream.listen(port.postMessage);
case {'exception': true, 'data': final data}:
// This message from `dart.js` indicates that an exception occurred
// loading the test.
Expand Down

0 comments on commit 16e52d0

Please sign in to comment.