Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions shell/platform/linux/fl_binary_messenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ struct _FlBinaryMessengerResponseHandle {
const FlutterPlatformMessageResponseHandle* response_handle;
};

static void engine_weak_notify_cb(gpointer user_data, GObject* object) {
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
self->engine = nullptr;
}

static FlBinaryMessengerResponseHandle* response_handle_new(
const FlutterPlatformMessageResponseHandle* response_handle) {
FlBinaryMessengerResponseHandle* handle =
Expand All @@ -64,6 +59,14 @@ static void response_handle_free(FlBinaryMessengerResponseHandle* handle) {
g_free(handle);
}

G_DEFINE_AUTOPTR_CLEANUP_FUNC(FlBinaryMessengerResponseHandle,
response_handle_free);

static void engine_weak_notify_cb(gpointer user_data, GObject* object) {
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
self->engine = nullptr;
}

static gboolean fl_binary_messenger_platform_message_callback(
FlEngine* engine,
const gchar* channel,
Expand Down Expand Up @@ -145,12 +148,15 @@ G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
g_return_val_if_fail(response_handle != nullptr, FALSE);

// Take reference to ensure it is freed
g_autoptr(FlBinaryMessengerResponseHandle) owned_response_handle =
response_handle;

if (self->engine == nullptr)
return TRUE;

gboolean result = fl_engine_send_platform_message_response(
self->engine, response_handle->response_handle, response, error);
response_handle_free(response_handle);
self->engine, owned_response_handle->response_handle, response, error);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct _FlBinaryMessengerResponseHandle FlBinaryMessengerResponseHandle;
* @messenger: a #FlBinaryMessenger
* @channel: channel message received on
* @message: message content received from Dart
* @response_handle: a handle to respond to the message with
* @response_handle: (transfer full): a handle to respond to the message with
* @user_data: (closure): data provided when registering this callback
*
* Function called when platform messages are received. The receiver must
Expand Down Expand Up @@ -74,7 +74,8 @@ void fl_binary_messenger_set_message_handler_on_channel(
/**
* fl_binary_messenger_send_response:
* @binary_messenger: a #FlBinaryMessenger
* @response_handle: handle that was provided in a #FlBinaryMessengerCallback
* @response_handle: (transfer full): handle that was provided in a
* #FlBinaryMessengerCallback
* @response: (allow-none): response to send or %NULL for an empty response
* @error: (allow-none): #GError location to store the error occurring, or %NULL
* to ignore
Expand Down