未验证 提交 7685e080 编写于 作者: M Mouad Debbar 提交者: GitHub

[web] Guard the remaining calls to window.onPlatformMessage (#16791)

上级 9ac76ad5
......@@ -94,11 +94,13 @@ class BrowserHistory {
_setupFlutterEntry(_locationStrategy);
// 2. Send a 'popRoute' platform message so the app can handle it accordingly.
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(_popRouteMethodCall),
(_) {},
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(_popRouteMethodCall),
(_) {},
);
}
} else if (_isFlutterEntry(event.state)) {
// We get into this scenario when the user changes the url manually. It
// causes a new entry to be pushed on top of our "flutter" one. When this
......@@ -111,13 +113,15 @@ class BrowserHistory {
_userProvidedRouteName = null;
// Send a 'pushRoute' platform message so the app handles it accordingly.
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(
MethodCall('pushRoute', newRouteName),
),
(_) {},
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(
MethodCall('pushRoute', newRouteName),
),
(_) {},
);
}
} else {
// The user has pushed a new entry on top of our flutter entry. This could
// happen when the user modifies the hash part of the url directly, for
......
......@@ -68,6 +68,10 @@ class Keyboard {
static const JSONMessageCodec _messageCodec = JSONMessageCodec();
void _handleHtmlEvent(html.KeyboardEvent event) {
if (ui.window.onPlatformMessage == null) {
return;
}
if (_shouldIgnoreEvent(event)) {
return;
}
......
......@@ -819,44 +819,50 @@ class TextEditingChannel {
/// Sends the 'TextInputClient.updateEditingState' message to the framework.
void updateEditingState(int clientId, EditingState editingState) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall('TextInputClient.updateEditingState', <dynamic>[
clientId,
editingState.toFlutter(),
]),
),
_emptyCallback,
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall('TextInputClient.updateEditingState', <dynamic>[
clientId,
editingState.toFlutter(),
]),
),
_emptyCallback,
);
}
}
/// Sends the 'TextInputClient.performAction' message to the framework.
void performAction(int clientId, String inputAction) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.performAction',
<dynamic>[clientId, inputAction],
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.performAction',
<dynamic>[clientId, inputAction],
),
),
),
_emptyCallback,
);
_emptyCallback,
);
}
}
/// Sends the 'TextInputClient.onConnectionClosed' message to the framework.
void onConnectionClosed(int clientId) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.onConnectionClosed',
<dynamic>[clientId],
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.onConnectionClosed',
<dynamic>[clientId],
),
),
),
_emptyCallback,
);
_emptyCallback,
);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册