Skip to content

Commit fb3bfbc

Browse files
Simplify loading data into perfetto iFrame (#4580)
1 parent 89e8203 commit fb3bfbc

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

packages/devtools_app/lib/src/screens/performance/panes/timeline_events/perfetto/_perfetto_controller_web.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,11 @@ class PerfettoController extends DisposableController
134134
}
135135

136136
void _postMessage(dynamic message) async {
137-
final callback = () {
138-
_perfettoIFrame.contentWindow!.postMessage(
139-
message,
140-
_perfettoUrl,
141-
);
142-
};
143-
if (_perfettoIFrame.contentWindow != null) {
144-
callback.call();
145-
} else {
146-
late StreamSubscription? onLoad;
147-
onLoad = _perfettoIFrame.onLoad.listen((event) {
148-
assert(
149-
_perfettoIFrame.contentWindow != null,
150-
'Something went wrong. The iFrame\'s contentWindow is null after the'
151-
' onLoad event.',
152-
);
153-
callback.call();
154-
onLoad?.cancel();
155-
onLoad = null;
156-
});
157-
}
137+
await _perfettoIFrameReady();
138+
_perfettoIFrame.contentWindow!.postMessage(
139+
message,
140+
_perfettoUrl,
141+
);
158142
}
159143

160144
void _postMessageWithId(String id, {Map<String, dynamic> args = const {}}) {
@@ -177,6 +161,17 @@ class PerfettoController extends DisposableController
177161
}
178162
}
179163

164+
Future<void> _perfettoIFrameReady() async {
165+
if (_perfettoIFrame.contentWindow == null) {
166+
await _perfettoIFrame.onLoad.first;
167+
assert(
168+
_perfettoIFrame.contentWindow != null,
169+
'Something went wrong. The iFrame\'s contentWindow is null after the'
170+
' onLoad event.',
171+
);
172+
}
173+
}
174+
180175
Future<void> _pingPerfettoUntilReady() async {
181176
while (!_perfettoReady.isCompleted) {
182177
await Future.delayed(const Duration(microseconds: 100), () async {

0 commit comments

Comments
 (0)