diff --git a/shell/platform/common/client_wrapper/basic_message_channel_unittests.cc b/shell/platform/common/client_wrapper/basic_message_channel_unittests.cc index f38595c8c165a..1ace6f03aee60 100644 --- a/shell/platform/common/client_wrapper/basic_message_channel_unittests.cc +++ b/shell/platform/common/client_wrapper/basic_message_channel_unittests.cc @@ -28,6 +28,10 @@ class TestBinaryMessenger : public BinaryMessenger { last_message_handler_ = handler; } + void Resize(const std::string& channel, int64_t newSize) override {} + + void SetWarnsOnOverflow(const std::string& channel, bool warns) override {} + std::string last_message_handler_channel() { return last_message_handler_channel_; } diff --git a/shell/platform/common/client_wrapper/binary_messenger_impl.h b/shell/platform/common/client_wrapper/binary_messenger_impl.h index 65586656e7c75..a119285526b76 100644 --- a/shell/platform/common/client_wrapper/binary_messenger_impl.h +++ b/shell/platform/common/client_wrapper/binary_messenger_impl.h @@ -36,6 +36,12 @@ class BinaryMessengerImpl : public BinaryMessenger { void SetMessageHandler(const std::string& channel, BinaryMessageHandler handler) override; + // |flutter::BinaryMessenger| + void Resize(const std::string& channel, int64_t newSize) override; + + // |flutter::BinaryMessenger| + void SetWarnsOnOverflow(const std::string& channel, bool warns) override; + private: // Handle for interacting with the C API. FlutterDesktopMessengerRef messenger_; diff --git a/shell/platform/common/client_wrapper/core_implementations.cc b/shell/platform/common/client_wrapper/core_implementations.cc index 1eb5a5898117d..90bdcb89593c6 100644 --- a/shell/platform/common/client_wrapper/core_implementations.cc +++ b/shell/platform/common/client_wrapper/core_implementations.cc @@ -127,6 +127,15 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel, ForwardToHandler, message_handler); } +void BinaryMessengerImpl::Resize(const std::string& channel, int64_t newSize) { + FlutterDesktopMessengerResize(messenger_, channel.c_str(), newSize); +} + +void BinaryMessengerImpl::SetWarnsOnOverflow(const std::string& channel, + bool warns) { + // TODO(bleroux). +} + // ========== engine_method_result.h ========== namespace internal { diff --git a/shell/platform/common/client_wrapper/event_channel_unittests.cc b/shell/platform/common/client_wrapper/event_channel_unittests.cc index 0d68b10c83a5b..0db1beb6575b6 100644 --- a/shell/platform/common/client_wrapper/event_channel_unittests.cc +++ b/shell/platform/common/client_wrapper/event_channel_unittests.cc @@ -29,6 +29,10 @@ class TestBinaryMessenger : public BinaryMessenger { last_message_handler_ = handler; } + void Resize(const std::string& channel, int64_t newSize) override {} + + void SetWarnsOnOverflow(const std::string& channel, bool warns) override {} + std::string last_message_handler_channel() { return last_message_handler_channel_; } diff --git a/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h b/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h index d552b499ee233..4b14234c995b4 100644 --- a/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h +++ b/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h @@ -45,6 +45,19 @@ class BinaryMessenger { // existing handler. virtual void SetMessageHandler(const std::string& channel, BinaryMessageHandler handler) = 0; + + // Adjusts the number of messages that will get buffered when sending messages + // to channels that aren't fully set up yet. For example, the engine isn't + // running yet or the channel's message handler isn't set up on the Dart side + // yet. + virtual void Resize(const std::string& channel, int64_t newSize) = 0; + + // Defines whether the channel should show warning messages when discarding + // messages due to overflow. + // + // When |warns| is false, the channel is expected to overflow and warning + // messages will not be shown. + virtual void SetWarnsOnOverflow(const std::string& channel, bool warns) = 0; }; } // namespace flutter diff --git a/shell/platform/common/client_wrapper/method_channel_unittests.cc b/shell/platform/common/client_wrapper/method_channel_unittests.cc index 55c4529edd581..ea94f2a891b2a 100644 --- a/shell/platform/common/client_wrapper/method_channel_unittests.cc +++ b/shell/platform/common/client_wrapper/method_channel_unittests.cc @@ -32,6 +32,10 @@ class TestBinaryMessenger : public BinaryMessenger { last_message_handler_ = handler; } + void Resize(const std::string& channel, int64_t newSize) override {} + + void SetWarnsOnOverflow(const std::string& channel, bool warns) override {} + bool send_called() { return send_called_; } BinaryReply last_reply_handler() { return last_reply_handler_; } diff --git a/shell/platform/common/client_wrapper/testing/stub_flutter_api.cc b/shell/platform/common/client_wrapper/testing/stub_flutter_api.cc index 28b01d70ea209..449d41a065760 100644 --- a/shell/platform/common/client_wrapper/testing/stub_flutter_api.cc +++ b/shell/platform/common/client_wrapper/testing/stub_flutter_api.cc @@ -159,3 +159,7 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable( } return result; } + +void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger, + const char* channel, + int64_t newSize) {} diff --git a/shell/platform/common/public/flutter_messenger.h b/shell/platform/common/public/flutter_messenger.h index b364a573bec39..b8315c4f537b8 100644 --- a/shell/platform/common/public/flutter_messenger.h +++ b/shell/platform/common/public/flutter_messenger.h @@ -137,6 +137,11 @@ FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger); FLUTTER_EXPORT void FlutterDesktopMessengerUnlock( FlutterDesktopMessengerRef messenger); +FLUTTER_EXPORT void FlutterDesktopMessengerResize( + FlutterDesktopMessengerRef messenger, + const char* channel, + int64_t newSize); + #if defined(__cplusplus) } // extern "C" #endif diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 554a2745baf2f..90410f6aace5a 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -224,6 +224,10 @@ void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) { messenger->GetMutex().unlock(); } +void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger, + const char* channel, + int64_t newSize) {} + // Retrieves state bag for the window in question from the GLFWWindow. static FlutterDesktopWindowControllerState* GetWindowController( GLFWwindow* window) { diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index fd3071d898505..17845c587e465 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -13,7 +13,10 @@ #include #include +#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" #include "flutter/shell/platform/common/incoming_message_dispatcher.h" #include "flutter/shell/platform/common/path_utils.h" #include "flutter/shell/platform/embedder/embedder.h" @@ -27,6 +30,8 @@ static_assert(FLUTTER_ENGINE_VERSION == 1, ""); +static constexpr char kControlChannelName[] = "dev.flutter/channel-buffer"; + // Returns the engine corresponding to the given opaque API handle. static flutter::FlutterWindowsEngine* EngineFromHandle( FlutterDesktopEngineRef ref) { @@ -381,3 +386,24 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable( return TextureRegistrarFromHandle(texture_registrar) ->MarkTextureFrameAvailable(texture_id); } + +void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger, + const char* channel, + int64_t newSize) { + auto binaryMessenger = + std::make_unique(messenger); + auto controlChannel = + std::make_unique>( + binaryMessenger.release(), kControlChannelName, + &flutter::StandardMethodCodec::GetInstance()); + + const flutter::StandardMethodCodec& codec = + flutter::StandardMethodCodec::GetInstance(); + flutter::MethodCall<> call( + "resize", + std::make_unique(flutter::EncodableList{ + flutter::EncodableValue(channel), + flutter::EncodableValue(newSize), + })); + auto encoded = codec.EncodeMethodCall(call); +} diff --git a/shell/platform/windows/testing/test_binary_messenger.h b/shell/platform/windows/testing/test_binary_messenger.h index 9b7f2c9b043f1..885a4bff7902d 100644 --- a/shell/platform/windows/testing/test_binary_messenger.h +++ b/shell/platform/windows/testing/test_binary_messenger.h @@ -64,6 +64,10 @@ class TestBinaryMessenger : public BinaryMessenger { } } + void Resize(const std::string& channel, int64_t newSize) override {} + + void SetWarnsOnOverflow(const std::string& channel, bool warns) override {} + private: // Handler to call for SendMessage. SendHandler send_handler_;