Skip to content

Commit

Permalink
Migrate FlBinaryMessenger using embedder API instead of mock engine. (#…
Browse files Browse the repository at this point in the history
…57214)

This allows us to remove most of the remaining mock engine code.
  • Loading branch information
robert-ancell authored Dec 16, 2024
1 parent b94ce44 commit 61616ac
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 619 deletions.
40 changes: 25 additions & 15 deletions shell/platform/linux/fl_binary_messenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,9 @@ static gboolean fl_binary_messenger_platform_message_cb(
GBytes* message,
const FlutterPlatformMessageResponseHandle* response_handle,
void* user_data) {
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(user_data);

PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
g_hash_table_lookup(self->platform_message_handlers, channel));
if (handler == nullptr) {
return FALSE;
}

g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
fl_binary_messenger_response_handle_impl_new(self, response_handle);
handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
handler->message_handler_data);

return TRUE;
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
return fl_binary_messenger_handle_message(self, channel, message,
response_handle);
}

static void fl_binary_messenger_impl_dispose(GObject* object) {
Expand Down Expand Up @@ -487,6 +475,28 @@ G_MODULE_EXPORT void fl_binary_messenger_set_warns_on_channel_overflow(
self, channel, warns);
}

gboolean fl_binary_messenger_handle_message(
FlBinaryMessenger* messenger,
const gchar* channel,
GBytes* message,
const FlutterPlatformMessageResponseHandle* response_handle) {
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);

PlatformMessageHandler* handler = static_cast<PlatformMessageHandler*>(
g_hash_table_lookup(self->platform_message_handlers, channel));
if (handler == nullptr) {
return FALSE;
}

g_autoptr(FlBinaryMessengerResponseHandleImpl) handle =
fl_binary_messenger_response_handle_impl_new(self, response_handle);
handler->message_handler(FL_BINARY_MESSENGER(self), channel, message,
FL_BINARY_MESSENGER_RESPONSE_HANDLE(handle),
handler->message_handler_data);

return TRUE;
}

void fl_binary_messenger_shutdown(FlBinaryMessenger* self) {
g_return_if_fail(FL_IS_BINARY_MESSENGER(self));

Expand Down
19 changes: 19 additions & 0 deletions shell/platform/linux/fl_binary_messenger_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <glib-object.h>

#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"

G_BEGIN_DECLS
Expand All @@ -22,6 +23,24 @@ G_BEGIN_DECLS
*/
FlBinaryMessenger* fl_binary_messenger_new(FlEngine* engine);

/**
* fl_binary_messenger_handle_message:
* @messenger: an #FlBinaryMessenger.
* @channel: channel message received on.
* @message: message data.
* @response_handle: handle to provide to
* fl_engine_send_platform_message_response().
*
* Handles a message received from the engine. Available for testing purposes.
*
* Returns: %TRUE if the message is handled.
*/
gboolean fl_binary_messenger_handle_message(
FlBinaryMessenger* messenger,
const gchar* channel,
GBytes* message,
const FlutterPlatformMessageResponseHandle* response_handle);

/**
* fl_binary_messenger_shutdown:
* @messenger: an #FlBinaryMessenger.
Expand Down
Loading

0 comments on commit 61616ac

Please sign in to comment.