Handle one-way platform messages in the embedder library (flutter/engine#9331)

Messages sent to the embedder host may be one-way messages with no response
handler.  If the host calls FlutterEngineSendPlatformMessageResponse on a
one-way message, then just delete the message response handle.

Also update the documentation to indicate that
FlutterEngineSendPlatformMessageResponse must be called for all messages.
Previously the docs implied that some FlutterPlatformMessage objects may
have a null response_handle.  The embedder will now set a response_handle for
every message (even if the sender does not expect a response).
This commit is contained in:
Jason Simmons
2019-06-14 13:58:09 -07:00
committed by GitHub
parent 8c2cd91934
commit 6336502de9
3 changed files with 14 additions and 15 deletions

View File

@@ -842,11 +842,13 @@ FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
auto response = handle->message->response();
if (data_length == 0) {
response->CompleteEmpty();
} else {
response->Complete(std::make_unique<fml::DataMapping>(
std::vector<uint8_t>({data, data + data_length})));
if (response) {
if (data_length == 0) {
response->CompleteEmpty();
} else {
response->Complete(std::make_unique<fml::DataMapping>(
std::vector<uint8_t>({data, data + data_length})));
}
}
delete handle;

View File

@@ -373,11 +373,10 @@ typedef struct {
// The response handle on which to invoke
// |FlutterEngineSendPlatformMessageResponse| when the response is ready. This
// field is ignored for messages being sent from the embedder to the
// framework. If the embedder ever receives a message with a non-null response
// handle, that handle must always be used with a
// |FlutterEngineSendPlatformMessageResponse| call. If not, this is a memory
// leak. It is not safe to send multiple responses on a single response
// object.
// framework. |FlutterEngineSendPlatformMessageResponse| must be called for
// all messages received by the embedder. Failure to call
// |FlutterEngineSendPlatformMessageResponse| will cause a memory leak. It is
// not safe to send multiple responses on a single response object.
const FlutterPlatformMessageResponseHandle* response_handle;
} FlutterPlatformMessage;

View File

@@ -49,12 +49,10 @@ void PlatformViewEmbedder::HandlePlatformMessage(
return;
}
if (!message->response()) {
return;
}
if (platform_dispatch_table_.platform_message_response_callback == nullptr) {
message->response()->CompleteEmpty();
if (message->response()) {
message->response()->CompleteEmpty();
}
return;
}