diff --git a/content_handler/runtime_holder.cc b/content_handler/runtime_holder.cc index db58800124fc5561bb90386d56fed7f8bf83a140..16511a0aa5fb70b470d6c5652a3be0b4a1dac799 100644 --- a/content_handler/runtime_holder.cc +++ b/content_handler/runtime_holder.cc @@ -147,6 +147,11 @@ void RuntimeHolder::Render(std::unique_ptr layer_tree) { void RuntimeHolder::UpdateSemantics(std::vector update) {} +void RuntimeHolder::HandlePlatformMessage( + ftl::RefPtr message) { + message->InvokeCallbackWithError(); +} + void RuntimeHolder::DidCreateMainIsolate(Dart_Isolate isolate) { blink::MojoServices::Create(isolate, nullptr, nullptr, std::move(root_bundle_)); diff --git a/content_handler/runtime_holder.h b/content_handler/runtime_holder.h index b9e974ee34b15f6a3ccc180a4b5bd964bdc20d9a..e752e4ca50d0d69058d6cd81a4d9ae5fe514c35e 100644 --- a/content_handler/runtime_holder.h +++ b/content_handler/runtime_holder.h @@ -40,6 +40,8 @@ class RuntimeHolder : public blink::RuntimeDelegate, void ScheduleFrame() override; void Render(std::unique_ptr layer_tree) override; void UpdateSemantics(std::vector update) override; + void HandlePlatformMessage( + ftl::RefPtr message) override; void DidCreateMainIsolate(Dart_Isolate isolate) override; // |mozart::InputListener| implementation: diff --git a/lib/ui/ui_dart_state.h b/lib/ui/ui_dart_state.h index 599ff0fa38e38488c97be2a65339c86b81ec92ef..3fd60d8cc14e29ded24bf5abf5d1d5e0ee4e5924 100644 --- a/lib/ui/ui_dart_state.h +++ b/lib/ui/ui_dart_state.h @@ -8,7 +8,6 @@ #include #include "dart/runtime/include/dart_api.h" -#include "flutter/lib/ui/window/platform_message.h" #include "flutter/sky/engine/wtf/RefPtr.h" #include "lib/ftl/build_config.h" #include "lib/tonic/dart_persistent_value.h" @@ -49,14 +48,6 @@ class UIDartState : public tonic::DartState { DartJniIsolateData* jni_data(); #endif - void set_platform_message_sink(PlatformMessage::Sink sink) { - platform_message_sink_ = std::move(sink); - } - - const PlatformMessage::Sink& platform_message_sink() const { - return platform_message_sink_; - } - void set_font_selector(PassRefPtr selector); PassRefPtr font_selector(); @@ -68,7 +59,6 @@ class UIDartState : public tonic::DartState { std::string debug_name_; std::unique_ptr mojo_services_; std::unique_ptr window_; - PlatformMessage::Sink platform_message_sink_; RefPtr font_selector_; #if defined(OS_ANDROID) diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index b0f67893dc5f177495ba4872629b5204126b1c05..5c881f50b332ac34d61cf2d615a345e8b5995c3a 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -55,11 +55,9 @@ void SendPlatformMessage(Dart_Handle window, auto message = ftl::MakeRefCounted( name, std::vector(buffer, buffer + data.length_in_bytes()), tonic::DartPersistentValue(dart_state, callback)); - if (const auto& sink = dart_state->platform_message_sink()) { - sink(std::move(message)); - } else { - message->InvokeCallbackWithError(); - } + + UIDartState::Current()->window()->client()->HandlePlatformMessage( + std::move(message)); } void _SendPlatformMessage(Dart_NativeArguments args) { diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index 4f955559d1c7e952b9d6885fd26bae068c047026..81c43c0a120447b71e0d1911b2a50be91dc7df05 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -6,6 +6,7 @@ #define FLUTTER_LIB_UI_WINDOW_WINDOW_H_ #include "flutter/lib/ui/semantics/semantics_update.h" +#include "flutter/lib/ui/window/platform_message.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/services/engine/sky_engine.mojom.h" #include "lib/ftl/time/time_point.h" @@ -23,6 +24,7 @@ class WindowClient { virtual void ScheduleFrame() = 0; virtual void Render(Scene* scene) = 0; virtual void UpdateSemantics(SemanticsUpdate* update) = 0; + virtual void HandlePlatformMessage(ftl::RefPtr message) = 0; protected: virtual ~WindowClient(); diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index f9a586180df72f4fb8a22ed5e6e6d5ee278517f1..72e7b31cf2930f82e4e68bf83d98a068d6d36c75 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -117,6 +117,11 @@ void RuntimeController::UpdateSemantics(SemanticsUpdate* update) { client_->UpdateSemantics(update->takeNodes()); } +void RuntimeController::HandlePlatformMessage( + ftl::RefPtr message) { + client_->HandlePlatformMessage(std::move(message)); +} + void RuntimeController::DidCreateSecondaryIsolate(Dart_Isolate isolate) { client_->DidCreateSecondaryIsolate(isolate); } diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 3a6d271d4a0a4561fbbbc4022661b5c5c2938bce..ae80327fefbb466e6cea8cb737c8429cf2cee420 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -56,6 +56,7 @@ class RuntimeController : public WindowClient, public IsolateClient { void ScheduleFrame() override; void Render(Scene* scene) override; void UpdateSemantics(SemanticsUpdate* update) override; + void HandlePlatformMessage(ftl::RefPtr message) override; void DidCreateSecondaryIsolate(Dart_Isolate isolate) override; diff --git a/runtime/runtime_delegate.h b/runtime/runtime_delegate.h index 738e1694127d7c266f40a62fe36343292f7fa61a..5c3125fbb4d497c1637c2b352a7ec8e80155261f 100644 --- a/runtime/runtime_delegate.h +++ b/runtime/runtime_delegate.h @@ -11,6 +11,7 @@ #include "dart/runtime/include/dart_api.h" #include "flutter/flow/layers/layer_tree.h" #include "flutter/lib/ui/semantics/semantics_node.h" +#include "flutter/lib/ui/window/platform_message.h" namespace blink { @@ -19,6 +20,7 @@ class RuntimeDelegate { virtual void ScheduleFrame() = 0; virtual void Render(std::unique_ptr layer_tree) = 0; virtual void UpdateSemantics(std::vector update) = 0; + virtual void HandlePlatformMessage(ftl::RefPtr message) = 0; virtual void DidCreateMainIsolate(Dart_Isolate isolate); virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate); diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 5b91d189b50b8fd75b434e68601bf1e48cec2b48..08663d2a2f0a7c112ee4d7b64c0dfa75b58f6f06 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -360,4 +360,14 @@ void Engine::UpdateSemantics(std::vector update) { })); } +void Engine::HandlePlatformMessage( + ftl::RefPtr message) { + blink::Threads::Platform()->PostTask([ + platform_view = platform_view_, message = std::move(message) + ]() mutable { + if (platform_view) + platform_view->HandlePlatformMessage(std::move(message)); + }); +} + } // namespace shell diff --git a/shell/common/engine.h b/shell/common/engine.h index 5df02596748ce1d2fb8c907e95462e87c99ab860..17a3acd838c431b4cc88f378b05c594f93d3200f 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -79,6 +79,8 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate { void ScheduleFrame() override; void Render(std::unique_ptr layer_tree) override; void UpdateSemantics(std::vector update) override; + void HandlePlatformMessage( + ftl::RefPtr message) override; void DidCreateMainIsolate(Dart_Isolate isolate) override; void DidCreateSecondaryIsolate(Dart_Isolate isolate) override; diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index e5ee631be849162eea82d9a6c57ca5518a1bf4e0..afe8778bd434a6d5ee06f98ea2bf158324888219 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -116,6 +116,11 @@ ftl::WeakPtr PlatformView::GetWeakPtr() { void PlatformView::UpdateSemantics(std::vector update) {} +void PlatformView::HandlePlatformMessage( + ftl::RefPtr message) { + message->InvokeCallbackWithError(); +} + void PlatformView::SetupResourceContextOnIOThread() { ftl::AutoResetWaitableEvent latch; diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index 76dd7a223798305fbdd894b76675c9dad29758b8..163045208ffa179682fa513702ede67e4c6dacf3 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -53,6 +53,8 @@ class PlatformView { virtual bool ResourceContextMakeCurrent() = 0; virtual void UpdateSemantics(std::vector update); + virtual void HandlePlatformMessage( + ftl::RefPtr message); Rasterizer& rasterizer() { return *rasterizer_; } Engine& engine() { return *engine_; } diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h index 66c0b1d31f343ead22662525f91f237c7f79d191..7b51d9e6da0149f16070f260bfa6527d601b2a1f 100644 --- a/shell/platform/android/platform_view_android.h +++ b/shell/platform/android/platform_view_android.h @@ -28,7 +28,10 @@ class PlatformViewAndroid : public PlatformView { void Detach(JNIEnv* env, jobject obj); - void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface, jint backgroundColor); + void SurfaceCreated(JNIEnv* env, + jobject obj, + jobject jsurface, + jint backgroundColor); void SurfaceChanged(JNIEnv* env, jobject obj, jint width, jint height); @@ -55,6 +58,9 @@ class PlatformViewAndroid : public PlatformView { void UpdateSemantics(std::vector update) override; + void HandlePlatformMessage( + ftl::RefPtr message) override; + void RunFromSource(const std::string& main, const std::string& packages, const std::string& assets_directory) override; @@ -80,8 +86,6 @@ class PlatformViewAndroid : public PlatformView { jobject* pixels_out, SkISize* size_out); - void HandlePlatformMessage(ftl::RefPtr message); - FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid); };