@@ -34,6 +34,7 @@ extern const intptr_t kPlatformStrongDillSize;
3434#include " flutter/shell/common/switches.h"
3535#include " flutter/shell/platform/embedder/embedder.h"
3636#include " flutter/shell/platform/embedder/embedder_engine.h"
37+ #include " flutter/shell/platform/embedder/embedder_platform_message_response.h"
3738#include " flutter/shell/platform/embedder/embedder_safe_access.h"
3839#include " flutter/shell/platform/embedder/embedder_task_runner.h"
3940#include " flutter/shell/platform/embedder/embedder_thread_host.h"
@@ -818,19 +819,68 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
818819 return LOG_EMBEDDER_ERROR (kInvalidArguments );
819820 }
820821
822+ const FlutterPlatformMessageResponseHandle* response_handle =
823+ SAFE_ACCESS (flutter_message, response_handle, nullptr );
824+
825+ fml::RefPtr<flutter::PlatformMessageResponse> response;
826+ if (response_handle->message ) {
827+ response = response_handle->message ->response ();
828+ }
829+
821830 auto message = fml::MakeRefCounted<flutter::PlatformMessage>(
822831 flutter_message->channel ,
823832 std::vector<uint8_t >(
824833 flutter_message->message ,
825834 flutter_message->message + flutter_message->message_size ),
826- nullptr );
835+ response );
827836
828837 return reinterpret_cast <flutter::EmbedderEngine*>(engine)
829838 ->SendPlatformMessage (std::move (message))
830839 ? kSuccess
831840 : LOG_EMBEDDER_ERROR (kInvalidArguments );
832841}
833842
843+ FlutterEngineResult FlutterPlatformMessageCreateResponseHandle (
844+ FlutterEngine engine,
845+ FlutterDataCallback data_callback,
846+ void * user_data,
847+ FlutterPlatformMessageResponseHandle** response_out) {
848+ if (engine == nullptr || data_callback == nullptr ||
849+ response_out == nullptr ) {
850+ return LOG_EMBEDDER_ERROR (kInvalidArguments );
851+ }
852+
853+ flutter::EmbedderPlatformMessageResponse::Callback response_callback =
854+ [user_data, data_callback](const uint8_t * data, size_t size) {
855+ data_callback (data, size, user_data);
856+ };
857+
858+ auto platform_task_runner = reinterpret_cast <flutter::EmbedderEngine*>(engine)
859+ ->GetTaskRunners ()
860+ .GetPlatformTaskRunner ();
861+
862+ auto handle = new FlutterPlatformMessageResponseHandle ();
863+
864+ handle->message = fml::MakeRefCounted<flutter::PlatformMessage>(
865+ " " , // The channel is empty and unused as the response handle is going to
866+ // referenced directly in the |FlutterEngineSendPlatformMessage| with
867+ // the container message discarded.
868+ fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
869+ std::move (platform_task_runner), response_callback));
870+ *response_out = handle;
871+ return kSuccess ;
872+ }
873+
874+ FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle (
875+ FlutterEngine engine,
876+ FlutterPlatformMessageResponseHandle* response) {
877+ if (engine == nullptr || response == nullptr ) {
878+ return LOG_EMBEDDER_ERROR (kInvalidArguments );
879+ }
880+ delete response;
881+ return kSuccess ;
882+ }
883+
834884FlutterEngineResult FlutterEngineSendPlatformMessageResponse (
835885 FlutterEngine engine,
836886 const FlutterPlatformMessageResponseHandle* handle,
0 commit comments