diff --git a/pkgs/dartpad_ui/lib/embed.dart b/pkgs/dartpad_ui/lib/embed.dart index 97736d3a7..129b9f05c 100644 --- a/pkgs/dartpad_ui/lib/embed.dart +++ b/pkgs/dartpad_ui/lib/embed.dart @@ -11,7 +11,7 @@ import 'model.dart'; /// Listen to frame messages if embedded as an iFrame /// to accept injected snippets. void handleEmbedMessage(AppServices services, {bool runOnInject = false}) { - final parent = web.window.parent; + final parent = web.window.parentCrossOrigin; if (parent == null) return; web.window.addEventListener( diff --git a/pkgs/dartpad_ui/lib/execution/frame.dart b/pkgs/dartpad_ui/lib/execution/frame.dart index 795f96c9e..71b30573c 100644 --- a/pkgs/dartpad_ui/lib/execution/frame.dart +++ b/pkgs/dartpad_ui/lib/execution/frame.dart @@ -9,7 +9,6 @@ import 'dart:js_interop'; import 'package:web/web.dart' as web; import '../model.dart'; -import 'frame_utils.dart'; class ExecutionServiceImpl implements ExecutionService { final StreamController _stdoutController = @@ -134,12 +133,14 @@ require(["dartpad_main", "dart_sdk"], function(dartpad_main, dart_sdk) { } Future _send(String command, Map params) { - final message = { - 'command': command, - ...params, - }.jsify(); // TODO: Use dartpad.dev instead of '*'? - _frame.safelyPostMessage(message, '*'); + _frame.contentWindowCrossOrigin?.postMessage( + { + 'command': command, + ...params, + }.jsify(), + '*'.toJS, + ); return Future.value(); } diff --git a/pkgs/dartpad_ui/lib/execution/frame_utils.dart b/pkgs/dartpad_ui/lib/execution/frame_utils.dart deleted file mode 100644 index 969bcb4b5..000000000 --- a/pkgs/dartpad_ui/lib/execution/frame_utils.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:js_interop'; -import 'dart:js_interop_unsafe'; - -import 'package:web/web.dart'; - -/// Extensions to work around Dart compiler issues that result in calls that -/// sandboxed iframes error on. -/// -/// If the compilers are adjusted to handle this case or `package:web` provides -/// a helper for this, switch to that. -/// -/// Tracked in https://github.com/dart-lang/sdk/issues/54443. -extension HTMLIFrameElementExtension on HTMLIFrameElement { - /// Send the specified [message] to this iframe, configured with the specified - /// [optionsOrTargetOrigin]. - void safelyPostMessage( - JSAny? message, - String optionsOrTargetOrigin, - ) { - // Uses unsafe calls to prevent the Dart web compilers from - // inserting type or null checks that access restricted properties. - (this as JSObject) - .getProperty('contentWindow'.toJS) - .callMethod('postMessage'.toJS, message, optionsOrTargetOrigin.toJS); - } -} diff --git a/pkgs/dartpad_ui/pubspec.yaml b/pkgs/dartpad_ui/pubspec.yaml index 1ed61446c..563e01c55 100644 --- a/pkgs/dartpad_ui/pubspec.yaml +++ b/pkgs/dartpad_ui/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: split_view: ^3.2.1 url_launcher: ^6.3.0 vtable: ^0.4.0 - web: ^1.0.0 + web: ^1.1.0 dev_dependencies: flutter_test: