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

Commit 61616ac

Browse files
Migrate FlBinaryMessenger using embedder API instead of mock engine. (#57214)
This allows us to remove most of the remaining mock engine code.
1 parent b94ce44 commit 61616ac

File tree

4 files changed

+364
-619
lines changed

4 files changed

+364
-619
lines changed

shell/platform/linux/fl_binary_messenger.cc

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,9 @@ static gboolean fl_binary_messenger_platform_message_cb(
155155
GBytes* message,
156156
const FlutterPlatformMessageResponseHandle* response_handle,
157157
void* user_data) {
158-
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(user_data);
159-
160-
PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
161-
g_hash_table_lookup(self->platform_message_handlers, channel));
162-
if (handler == nullptr) {
163-
return FALSE;
164-
}
165-
166-
g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
167-
fl_binary_messenger_response_handle_impl_new(self, response_handle);
168-
handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
169-
FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
170-
handler->message_handler_data);
171-
172-
return TRUE;
158+
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
159+
return fl_binary_messenger_handle_message(self, channel, message,
160+
response_handle);
173161
}
174162

175163
static void fl_binary_messenger_impl_dispose(GObject* object) {
@@ -487,6 +475,28 @@ G_MODULE_EXPORT void fl_binary_messenger_set_warns_on_channel_overflow(
487475
self, channel, warns);
488476
}
489477

478+
gboolean fl_binary_messenger_handle_message(
479+
FlBinaryMessenger* messenger,
480+
const gchar* channel,
481+
GBytes* message,
482+
const FlutterPlatformMessageResponseHandle* response_handle) {
483+
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
484+
485+
PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
486+
g_hash_table_lookup(self->platform_message_handlers, channel));
487+
if (handler == nullptr) {
488+
return FALSE;
489+
}
490+
491+
g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
492+
fl_binary_messenger_response_handle_impl_new(self, response_handle);
493+
handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
494+
FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
495+
handler->message_handler_data);
496+
497+
return TRUE;
498+
}
499+
490500
void fl_binary_messenger_shutdown(FlBinaryMessenger* self) {
491501
g_return_if_fail(FL_IS_BINARY_MESSENGER(self));
492502

shell/platform/linux/fl_binary_messenger_private.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <glib-object.h>
99

10+
#include "flutter/shell/platform/embedder/embedder.h"
1011
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
1112

1213
G_BEGIN_DECLS
@@ -22,6 +23,24 @@ G_BEGIN_DECLS
2223
*/
2324
FlBinaryMessenger* fl_binary_messenger_new(FlEngine* engine);
2425

26+
/**
27+
* fl_binary_messenger_handle_message:
28+
* @messenger: an #FlBinaryMessenger.
29+
* @channel: channel message received on.
30+
* @message: message data.
31+
* @response_handle: handle to provide to
32+
* fl_engine_send_platform_message_response().
33+
*
34+
* Handles a message received from the engine. Available for testing purposes.
35+
*
36+
* Returns: %TRUE if the message is handled.
37+
*/
38+
gboolean fl_binary_messenger_handle_message(
39+
FlBinaryMessenger* messenger,
40+
const gchar* channel,
41+
GBytes* message,
42+
const FlutterPlatformMessageResponseHandle* response_handle);
43+
2544
/**
2645
* fl_binary_messenger_shutdown:
2746
* @messenger: an #FlBinaryMessenger.

0 commit comments

Comments
 (0)