32
32
#include " library/common/glfw/key_event_handler.h"
33
33
#include " library/common/glfw/keyboard_hook_handler.h"
34
34
#include " library/common/glfw/text_input_plugin.h"
35
+ #include " library/common/internal/incoming_message_dispatcher.h"
35
36
#include " library/common/internal/plugin_handler.h"
36
37
37
38
#ifdef __linux__
@@ -61,7 +62,11 @@ struct FlutterEmbedderState {
61
62
// The handle to the Flutter engine instance.
62
63
FlutterEngine engine;
63
64
64
- // The helper class managing plugin registration and messaging.
65
+ // Message dispatch manager for messages from the Flutter engine.
66
+ std::unique_ptr<flutter_desktop_embedding::IncomingMessageDispatcher>
67
+ message_dispatcher;
68
+
69
+ // The helper class managing plugin registration.
65
70
std::unique_ptr<flutter_desktop_embedding::PluginHandler> plugin_handler;
66
71
67
72
// Handlers for keyboard events from GLFW.
@@ -83,6 +88,18 @@ static FlutterEmbedderState *GetSavedEmbedderState(GLFWwindow *window) {
83
88
glfwGetWindowUserPointer (window));
84
89
}
85
90
91
+ // Converts a FlutterPlatformMessage to an equivalent FlutterEmbedderMessage.
92
+ static flutter_desktop_embedding::FlutterEmbedderMessage
93
+ ConvertToEmbedderMessage (const FlutterPlatformMessage &engine_message) {
94
+ flutter_desktop_embedding::FlutterEmbedderMessage embedder_message = {};
95
+ embedder_message.struct_size = sizeof (embedder_message);
96
+ embedder_message.channel = engine_message.channel ;
97
+ embedder_message.message = engine_message.message ;
98
+ embedder_message.message_size = engine_message.message_size ;
99
+ embedder_message.response_handle = engine_message.response_handle ;
100
+ return embedder_message;
101
+ }
102
+
86
103
// Returns the number of screen coordinates per inch for the main monitor.
87
104
// If the information is unavailable, returns a default value that assumes
88
105
// that a screen coordinate is one dp.
@@ -207,8 +224,10 @@ static void GLFWOnFlutterPlatformMessage(const FlutterPlatformMessage *message,
207
224
208
225
GLFWwindow *window = reinterpret_cast <GLFWwindow *>(user_data);
209
226
auto state = GetSavedEmbedderState (window);
210
- state->plugin_handler ->HandleMethodCallMessage (
211
- message, [window] { GLFWClearEventCallbacks (window); },
227
+
228
+ auto embedder_message = ConvertToEmbedderMessage (*message);
229
+ state->message_dispatcher ->HandleMessage (
230
+ embedder_message, [window] { GLFWClearEventCallbacks (window); },
212
231
[window] { GLFWAssignEventCallbacks (window); });
213
232
}
214
233
@@ -313,14 +332,6 @@ bool FlutterInit() {
313
332
314
333
void FlutterTerminate () { glfwTerminate (); }
315
334
316
- PluginRegistrar *GetRegistrarForPlugin (FlutterWindowRef flutter_window,
317
- const std::string &plugin_name) {
318
- // Currently, PluginHandler acts as the registrar for all plugins, so the
319
- // name is ignored. It is part of the API to reduce churn in the future when
320
- // aligning more closely with the Flutter registrar system.
321
- return flutter_window->plugin_handler .get ();
322
- }
323
-
324
335
FlutterWindowRef CreateFlutterWindow (
325
336
size_t initial_width, size_t initial_height, const std::string &assets_path,
326
337
const std::string &icu_data_path,
@@ -348,7 +359,9 @@ FlutterWindowRef CreateFlutterWindow(
348
359
state->window = window;
349
360
glfwSetWindowUserPointer (window, state);
350
361
state->engine = engine;
351
- state->plugin_handler = std::make_unique<PluginHandler>(engine);
362
+ state->message_dispatcher =
363
+ std::make_unique<IncomingMessageDispatcher>(state);
364
+ state->plugin_handler = std::make_unique<PluginHandler>(state);
352
365
353
366
// Set up the keyboard handlers.
354
367
state->keyboard_hook_handlers .push_back (
@@ -392,4 +405,38 @@ void FlutterWindowLoop(FlutterWindowRef flutter_window) {
392
405
glfwDestroyWindow (window);
393
406
}
394
407
408
+ void FlutterEmbedderSendMessage (FlutterWindowRef flutter_window,
409
+ const char *channel, const uint8_t *message,
410
+ const size_t message_size) {
411
+ FlutterPlatformMessage platform_message = {
412
+ sizeof (FlutterPlatformMessage),
413
+ channel,
414
+ message,
415
+ message_size,
416
+ };
417
+
418
+ FlutterEngineSendPlatformMessage (flutter_window->engine , &platform_message);
419
+ }
420
+
421
+ void FlutterEmbedderSendMessageResponse (
422
+ FlutterWindowRef flutter_window,
423
+ const FlutterEmbedderMessageResponseHandle *handle, const uint8_t *data,
424
+ size_t data_length) {
425
+ FlutterEngineSendPlatformMessageResponse (flutter_window->engine , handle, data,
426
+ data_length);
427
+ }
428
+
429
+ void FlutterEmbedderSetMessageCallback (FlutterWindowRef flutter_window,
430
+ const char *channel,
431
+ FlutterEmbedderMessageCallback callback,
432
+ void *user_data) {
433
+ flutter_window->message_dispatcher ->SetMessageCallback (channel, callback,
434
+ user_data);
435
+ }
436
+
437
+ void FlutterEmbedderEnableInputBlocking (FlutterWindowRef flutter_window,
438
+ const char *channel) {
439
+ flutter_window->message_dispatcher ->EnableInputBlockingForChannel (channel);
440
+ }
441
+
395
442
} // namespace flutter_desktop_embedding
0 commit comments