Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aefe104

Browse files
authored
Revert "Add deprecations to PlatformMessage stuff" (#42921)
Reverts #42580
1 parent a652aac commit aefe104

File tree

11 files changed

+105
-106
lines changed

11 files changed

+105
-106
lines changed

lib/ui/channel_buffers.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
// KEEP THIS SYNCHRONIZED WITH ../web_ui/lib/channel_buffers.dart
77
part of dart.ui;
88

9-
/// Deprecated. Migrate to [ChannelCallback] instead.
10-
///
119
/// Signature for [ChannelBuffers.drain]'s `callback` argument.
1210
///
1311
/// The first argument is the data sent by the plugin.
1412
///
1513
/// The second argument is a closure that, when called, will send messages
1614
/// back to the plugin.
17-
@Deprecated(
18-
'Migrate to ChannelCallback instead. '
19-
'This feature was deprecated after v3.11.0-20.0.pre.',
20-
)
15+
// TODO(ianh): deprecate this once the framework is migrated to [ChannelCallback].
2116
typedef DrainChannelCallback = Future<void> Function(ByteData? data, PlatformMessageResponseCallback callback);
2217

2318
/// Signature for [ChannelBuffers.setListener]'s `callback` argument.
@@ -382,19 +377,14 @@ class ChannelBuffers {
382377
}
383378
}
384379

385-
/// Deprecated. Migrate to [setListener] instead.
386-
///
387380
/// Remove and process all stored messages for a given channel.
388381
///
389382
/// This should be called once a channel is prepared to handle messages
390383
/// (i.e. when a message handler is set up in the framework).
391384
///
392385
/// The messages are processed by calling the given `callback`. Each message
393386
/// is processed in its own microtask.
394-
@Deprecated(
395-
'Migrate to setListener instead. '
396-
'This feature was deprecated after v3.11.0-20.0.pre.',
397-
)
387+
// TODO(ianh): deprecate once framework uses [setListener].
398388
Future<void> drain(String name, DrainChannelCallback callback) async {
399389
final _Channel? channel = _channels[name];
400390
while (channel != null && !channel._queue.isEmpty) {

lib/ui/platform_dispatcher.dart

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,8 @@ typedef SemanticsActionEventCallback = void Function(SemanticsActionEvent action
4141
/// [PlatformDispatcher.onPlatformMessage].
4242
typedef PlatformMessageResponseCallback = void Function(ByteData? data);
4343

44-
/// Deprecated. Migrate to [ChannelBuffers.setListener] instead.
45-
///
4644
/// Signature for [PlatformDispatcher.onPlatformMessage].
47-
@Deprecated(
48-
'Migrate to ChannelBuffers.setListener instead. '
49-
'This feature was deprecated after v3.11.0-20.0.pre.',
50-
)
45+
// TODO(ianh): deprecate once framework uses [ChannelBuffers.setListener].
5146
typedef PlatformMessageCallback = void Function(String name, ByteData? data, PlatformMessageResponseCallback? callback);
5247

5348
// Signature for _setNeedsReportTimings.
@@ -656,8 +651,6 @@ class PlatformDispatcher {
656651
@Native<Void Function(Int64)>(symbol: 'PlatformConfigurationNativeApi::RegisterBackgroundIsolate')
657652
external static void __registerBackgroundIsolate(int rootIsolateId);
658653

659-
/// Deprecated. Migrate to [ChannelBuffers.setListener] instead.
660-
///
661654
/// Called whenever this platform dispatcher receives a message from a
662655
/// platform-specific plugin.
663656
///
@@ -671,17 +664,11 @@ class PlatformDispatcher {
671664
///
672665
/// The framework invokes this callback in the same zone in which the callback
673666
/// was set.
674-
@Deprecated(
675-
'Migrate to ChannelBuffers.setListener instead. '
676-
'This feature was deprecated after v3.11.0-20.0.pre.',
677-
)
667+
// TODO(ianh): Deprecate onPlatformMessage once the framework is moved over
668+
// to using channel buffers exclusively.
678669
PlatformMessageCallback? get onPlatformMessage => _onPlatformMessage;
679670
PlatformMessageCallback? _onPlatformMessage;
680671
Zone _onPlatformMessageZone = Zone.root;
681-
@Deprecated(
682-
'Migrate to ChannelBuffers.setListener instead. '
683-
'This feature was deprecated after v3.11.0-20.0.pre.',
684-
)
685672
set onPlatformMessage(PlatformMessageCallback? callback) {
686673
_onPlatformMessage = callback;
687674
_onPlatformMessageZone = Zone.current;

lib/ui/window.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,6 @@ class SingletonFlutterWindow extends FlutterView {
787787
platformDispatcher.sendPlatformMessage(name, data, callback);
788788
}
789789

790-
/// Deprecated. Migrate to [ChannelBuffers.setListener] instead.
791-
///
792790
/// Called whenever this window receives a message from a platform-specific
793791
/// plugin.
794792
///
@@ -804,15 +802,8 @@ class SingletonFlutterWindow extends FlutterView {
804802
///
805803
/// The framework invokes this callback in the same zone in which the
806804
/// callback was set.
807-
@Deprecated(
808-
'Migrate to ChannelBuffers.setListener instead. '
809-
'This feature was deprecated after v3.11.0-20.0.pre.',
810-
)
805+
// TODO(ianh): deprecate once framework uses [ChannelBuffers.setListener].
811806
PlatformMessageCallback? get onPlatformMessage => platformDispatcher.onPlatformMessage;
812-
@Deprecated(
813-
'Migrate to ChannelBuffers.setListener instead. '
814-
'This feature was deprecated after v3.11.0-20.0.pre.',
815-
)
816807
set onPlatformMessage(PlatformMessageCallback? callback) {
817808
platformDispatcher.onPlatformMessage = callback;
818809
}

testing/dart/channel_buffers_test.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ void main() {
3131
called = true;
3232
}
3333
buffers.push(channel, data, callback);
34-
// Ignoring the deprecated member use because we're specifically testing
35-
// deprecated API.
36-
// ignore: deprecated_member_use
3734
await buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
3835
expect(drainedData, equals(data));
3936
assert(!called);
@@ -55,9 +52,6 @@ void main() {
5552

5653
// Ignoring the returned future because the completion of the drain is
5754
// communicated using the `completer`.
58-
// Ignoring the deprecated member use because we're specifically testing
59-
// deprecated API.
60-
// ignore: deprecated_member_use
6155
buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
6256
log.add('callback');
6357
completer.complete();
@@ -83,9 +77,6 @@ void main() {
8377
_resize(buffers, channel, 0);
8478
buffers.push(channel, data, callback);
8579
bool didCall = false;
86-
// Ignoring the deprecated member use because we're specifically testing
87-
// deprecated API.
88-
// ignore: deprecated_member_use
8980
await buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
9081
didCall = true;
9182
});
@@ -96,9 +87,6 @@ void main() {
9687
const String channel = 'foo';
9788
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
9889
bool didCall = false;
99-
// Ignoring the deprecated member use because we're specifically testing
100-
// deprecated API.
101-
// ignore: deprecated_member_use
10290
await buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
10391
didCall = true;
10492
});
@@ -119,9 +107,6 @@ void main() {
119107
buffers.push(channel, three, callback);
120108
buffers.push(channel, four, callback);
121109
int counter = 0;
122-
// Ignoring the deprecated member use because we're specifically testing
123-
// deprecated API.
124-
// ignore: deprecated_member_use
125110
await buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
126111
switch (counter) {
127112
case 0:
@@ -147,9 +132,6 @@ void main() {
147132
buffers.push(channel, two, callback);
148133
_resize(buffers, channel, 1);
149134
int counter = 0;
150-
// Ignoring the deprecated member use because we're specifically testing
151-
// deprecated API.
152-
// ignore: deprecated_member_use
153135
await buffers.drain(channel, (ByteData? drainedData, ui.PlatformMessageResponseCallback drainedCallback) async {
154136
switch (counter) {
155137
case 0:

testing/dart/observatory/vmservice_methods_test.dart

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,12 @@ void main() {
7474
fail('This test must not be run with --disable-vm-service.');
7575
}
7676

77-
final Completer<String> completer = Completer<String>();
78-
ui.channelBuffers.setListener(
79-
'flutter/system',
80-
(ByteData? data, ui.PlatformMessageResponseCallback callback) {
81-
final ByteBuffer buffer = data!.buffer;
82-
final Uint8List list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
83-
completer.complete(utf8.decode(list));
84-
},
85-
);
77+
final Completer<PlatformResponse> completer = Completer<PlatformResponse>();
78+
ui.PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, ui.PlatformMessageResponseCallback? callback) {
79+
final ByteBuffer buffer = data!.buffer;
80+
final Uint8List list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
81+
completer.complete(PlatformResponse(name: name, contents: utf8.decode(list)));
82+
};
8683

8784
vmService = await vmServiceConnectUri(
8885
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
@@ -97,11 +94,13 @@ void main() {
9794
expect(fontChangeResponse.type, 'Success');
9895
expect(
9996
await completer.future,
100-
'{"type":"fontsChange"}',
97+
const PlatformResponse(
98+
name: 'flutter/system',
99+
contents: '{"type":"fontsChange"}',
100+
),
101101
);
102102
} finally {
103103
await vmService?.dispose();
104-
ui.channelBuffers.clearListener('flutter/system');
105104
}
106105
});
107106
}
@@ -122,3 +121,22 @@ Future<String?> getIsolateId(vms.VmService vmService) async {
122121
}
123122
return null;
124123
}
124+
125+
class PlatformResponse {
126+
const PlatformResponse({
127+
required this.name,
128+
required this.contents,
129+
});
130+
131+
final String name;
132+
final String contents;
133+
134+
@override
135+
bool operator ==(Object other) =>
136+
other is PlatformResponse &&
137+
other.name == name &&
138+
other.contents == contents;
139+
140+
@override
141+
int get hashCode => Object.hash(name, contents);
142+
}

testing/dart/text_test.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,20 @@ void testTextRange() {
195195

196196
void testLoadFontFromList() {
197197
test('loadFontFromList will send platform message after font is loaded', () async {
198+
final PlatformMessageCallback? oldHandler = PlatformDispatcher.instance.onPlatformMessage;
199+
late String actualName;
198200
late String message;
199-
channelBuffers.setListener(
200-
'flutter/system',
201-
(ByteData? data, PlatformMessageResponseCallback? callback) {
202-
assert(data != null);
203-
final Uint8List list = data!.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
204-
message = utf8.decode(list);
205-
},
206-
);
201+
PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, PlatformMessageResponseCallback? callback) {
202+
assert(data != null);
203+
actualName = name;
204+
final Uint8List list = data!.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
205+
message = utf8.decode(list);
206+
};
207207
final Uint8List fontData = Uint8List(0);
208208
await loadFontFromList(fontData, fontFamily: 'fake');
209+
PlatformDispatcher.instance.onPlatformMessage = oldHandler;
210+
expect(actualName, 'flutter/system');
209211
expect(message, '{"type":"fontsChange"}');
210-
channelBuffers.clearListener('flutter/system');
211212
});
212213
}
213214

testing/scenario_app/lib/main.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ void main() {
1717
// FlutterView to the _view property.
1818
assert(PlatformDispatcher.instance.implicitView != null);
1919
PlatformDispatcher.instance
20+
..onPlatformMessage = _handlePlatformMessage
2021
..onBeginFrame = _onBeginFrame
2122
..onDrawFrame = _onDrawFrame
2223
..onMetricsChanged = _onMetricsChanged
2324
..onPointerDataPacket = _onPointerDataPacket
2425
..scheduleFrame();
25-
channelBuffers.setListener('driver', _handleDriverMessage);
26-
channelBuffers.setListener('write_timeline', _handleWriteTimelineMessage);
2726

2827
final FlutterView view = PlatformDispatcher.instance.implicitView!;
2928
// Asserting that this is greater than zero since this app runs on different
@@ -42,8 +41,7 @@ void main() {
4241
/// The FlutterView into which the [Scenario]s will be rendered.
4342
FlutterView get _view => PlatformDispatcher.instance.implicitView!;
4443

45-
void _handleDriverMessage(ByteData? data, PlatformMessageResponseCallback? callback) {
46-
final Map<String, dynamic> call = json.decode(utf8.decode(data!.buffer.asUint8List())) as Map<String, dynamic>;
44+
void _handleDriverMessage(Map<String, dynamic> call) {
4745
final String? methodName = call['method'] as String?;
4846
switch (methodName) {
4947
case 'set_scenario':
@@ -54,9 +52,23 @@ void _handleDriverMessage(ByteData? data, PlatformMessageResponseCallback? callb
5452
}
5553
}
5654

57-
Future<void> _handleWriteTimelineMessage(ByteData? data, PlatformMessageResponseCallback? callback) async {
58-
final String timelineData = await _getTimelineData();
59-
callback!(Uint8List.fromList(utf8.encode(timelineData)).buffer.asByteData());
55+
Future<void> _handlePlatformMessage(
56+
String name, ByteData? data, PlatformMessageResponseCallback? callback) async {
57+
if (data != null) {
58+
print('$name = ${utf8.decode(data.buffer.asUint8List())}');
59+
} else {
60+
print(name);
61+
}
62+
63+
switch (name) {
64+
case 'driver':
65+
_handleDriverMessage(json.decode(utf8.decode(data!.buffer.asUint8List())) as Map<String, dynamic>);
66+
case 'write_timeline':
67+
final String timelineData = await _getTimelineData();
68+
callback!(Uint8List.fromList(utf8.encode(timelineData)).buffer.asByteData());
69+
default:
70+
currentScenario?.onPlatformMessage(name, data, callback);
71+
}
6072
}
6173

6274
Future<String> _getTimelineData() async {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:typed_data';
6+
import 'dart:ui';
7+
8+
import 'scenario.dart';
9+
10+
/// Echo platform messages back to the sender.
11+
mixin PlatformEchoMixin on Scenario {
12+
/// Handle a platform message.
13+
@override
14+
void onPlatformMessage(
15+
String name,
16+
ByteData? data,
17+
PlatformMessageResponseCallback? callback,
18+
) {
19+
view.platformDispatcher.sendPlatformMessage(name, data, null);
20+
}
21+
}

testing/scenario_app/lib/src/platform_view.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario
422422
required this.secondId,
423423
}) {
424424
_nextFrame = _firstFrame;
425-
channelBuffers.setListener('flutter/lifecycle', _onPlatformMessage);
426425
}
427426

428427
/// The platform view identifier to use for the first platform view.
@@ -505,10 +504,15 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario
505504

506505
String _lastLifecycleState = '';
507506

508-
void _onPlatformMessage(
507+
@override
508+
void onPlatformMessage(
509+
String name,
509510
ByteData? data,
510511
PlatformMessageResponseCallback? callback,
511512
) {
513+
if (name != 'flutter/lifecycle') {
514+
return;
515+
}
512516
final String message = utf8.decode(data!.buffer.asUint8List());
513517
if (_lastLifecycleState == 'AppLifecycleState.inactive' &&
514518
message == 'AppLifecycleState.resumed') {
@@ -518,12 +522,6 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario
518522

519523
_lastLifecycleState = message;
520524
}
521-
522-
@override
523-
void unmount() {
524-
channelBuffers.clearListener('flutter/lifecycle');
525-
super.unmount();
526-
}
527525
}
528526

529527
/// Platform view with clip rect.

0 commit comments

Comments
 (0)