From 75c68e840435d210b4f419ae46ef8fc6e4cd12f4 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 14 Sep 2019 14:08:59 -0700 Subject: [PATCH 1/5] Adds PluginRegistry to the C++ client wrapper API Makes the plugin registration structure consistent with macOS. This will be used in generated plugin registrant files rather than a specific implemenation class, so this helps unblock the creation of generated registrants on Windows and Linux. --- .../cpp/client_wrapper/core_wrapper_files.gni | 1 + .../include/flutter/plugin_registry.h | 36 +++++++++++++++++++ .../flutter/flutter_window_controller.h | 12 +++---- .../include/flutter/flutter_view_controller.h | 12 +++---- 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h diff --git a/shell/platform/common/cpp/client_wrapper/core_wrapper_files.gni b/shell/platform/common/cpp/client_wrapper/core_wrapper_files.gni index 80750627b6b01..ce91be7866717 100644 --- a/shell/platform/common/cpp/client_wrapper/core_wrapper_files.gni +++ b/shell/platform/common/cpp/client_wrapper/core_wrapper_files.gni @@ -17,6 +17,7 @@ core_cpp_client_wrapper_includes = "include/flutter/method_codec.h", "include/flutter/method_result.h", "include/flutter/plugin_registrar.h", + "include/flutter/plugin_registry.h", "include/flutter/standard_message_codec.h", "include/flutter/standard_method_codec.h", ], diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h new file mode 100644 index 0000000000000..f47d35d45add8 --- /dev/null +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h @@ -0,0 +1,36 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ + +#include + +#include + +namespace flutter { + +// Vends PluginRegistrars for named plugins. +// +// Plugins are identified by unique string keys, typically the name of the +// plugin's main class. +class PluginRegistry { + public: + virtual ~PluginRegistry() = default; + + // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the + // given name. + // + // The name must be unique across the application. + virtual FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( + const std::string& plugin_name); + + // Prevent copying. + PluginRegistry(PluginRegistry const&) = delete; + PluginRegistry& operator=(PluginRegistry const&) = delete; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ diff --git a/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h b/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h index 95da9cb657fa2..b0372aa94d51b 100644 --- a/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h +++ b/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h @@ -14,6 +14,7 @@ #include "flutter_window.h" #include "plugin_registrar.h" +#include "plugin_registry.h" namespace flutter { @@ -68,13 +69,6 @@ class FlutterWindowController { const std::string& assets_path, const std::vector& arguments); - // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the - // given name. - // - // The name must be unique across the application. - FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( - const std::string& plugin_name); - // The FlutterWindow managed by this controller, if any. Returns nullptr // before CreateWindow is called, and after RunEventLoop returns; FlutterWindow* window() { return window_.get(); } @@ -89,6 +83,10 @@ class FlutterWindowController { // Deprecated. Use RunEventLoopWithTimeout. void RunEventLoop(); + // flutter::PluginRegistry: + FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( + const std::string& plugin_name) override; + private: // The path to the ICU data file. Set at creation time since it is the same // for any window created. diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index cdf782271e36c..32f6efea66fa6 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -11,6 +11,7 @@ #include #include "plugin_registrar.h" +#include "plugin_registry.h" namespace flutter { @@ -47,13 +48,6 @@ class FlutterViewController { FlutterViewController(FlutterViewController const&) = delete; FlutterViewController& operator=(FlutterViewController const&) = delete; - // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the - // given name. - // - // The name must be unique across the application. - FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( - const std::string& plugin_name); - // Return backing HWND for manipulation in host application. HWND GetNativeWindow(); @@ -61,6 +55,10 @@ class FlutterViewController { // loop. void ProcessMessages(); + // flutter::PluginRegistry: + FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( + const std::string& plugin_name) override; + private: // The path to the ICU data file. Set at creation time since it is the same // for any view created. From 7520d78c22811eb52133f886be903adec6b101fc Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 14 Sep 2019 14:12:43 -0700 Subject: [PATCH 2/5] Add to license file --- ci/licenses_golden/licenses_flutter | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index dbb8643280c0d..362a29f3bc854 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -684,6 +684,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_codec.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_result.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_message_codec.cc From 59e4af56280598d1e7af5c2b4ee2b454e3e9ab3c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 14 Sep 2019 15:27:36 -0700 Subject: [PATCH 3/5] Add missing inheritance --- .../include/flutter/flutter_window_controller.h | 4 ++-- .../client_wrapper/include/flutter/flutter_view_controller.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h b/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h index b0372aa94d51b..cd4bd58ed0d94 100644 --- a/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h +++ b/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h @@ -41,14 +41,14 @@ struct WindowProperties { // requires control of the application's event loop, and is thus useful // primarily for building a simple one-window shell hosting a Flutter // application. The final implementation and API will be very different. -class FlutterWindowController { +class FlutterWindowController : public PluginRegistry { public: // There must be only one instance of this class in an application at any // given time, as Flutter does not support multiple engines in one process, // or multiple views in one engine. explicit FlutterWindowController(const std::string& icu_data_path); - ~FlutterWindowController(); + virtual ~FlutterWindowController(); // Prevent copying. FlutterWindowController(FlutterWindowController const&) = delete; diff --git a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h index 32f6efea66fa6..69ce1bafdaf2b 100644 --- a/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h +++ b/shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h @@ -20,7 +20,7 @@ namespace flutter { // This is the primary wrapper class for the desktop C API. // If you use this class, you should not call any of the setup or teardown // methods in the C API directly, as this class will do that internally. -class FlutterViewController { +class FlutterViewController : public PluginRegistry { public: // There must be only one instance of this class in an application at any // given time, as Flutter does not support multiple engines in one process, @@ -42,7 +42,7 @@ class FlutterViewController { const std::string& assets_path, const std::vector& arguments); - ~FlutterViewController(); + virtual ~FlutterViewController(); // Prevent copying. FlutterViewController(FlutterViewController const&) = delete; From 0d980253cd525a1394aff64ab29f2c975b30c015 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 14 Sep 2019 18:13:27 -0700 Subject: [PATCH 4/5] Add default constructor --- .../common/cpp/client_wrapper/include/flutter/plugin_registry.h | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h index f47d35d45add8..04dd919e30021 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h @@ -17,6 +17,7 @@ namespace flutter { // plugin's main class. class PluginRegistry { public: + PluginRegistry() = default; virtual ~PluginRegistry() = default; // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the From 0702f8941ad567b4a3eb958a4327929b81cf8d3c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 14 Sep 2019 19:55:40 -0700 Subject: [PATCH 5/5] Make it abstract --- .../client_wrapper/include/flutter/plugin_registry.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h index 04dd919e30021..823fe1ac17e4d 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h @@ -20,16 +20,16 @@ class PluginRegistry { PluginRegistry() = default; virtual ~PluginRegistry() = default; + // Prevent copying. + PluginRegistry(PluginRegistry const&) = delete; + PluginRegistry& operator=(PluginRegistry const&) = delete; + // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the // given name. // // The name must be unique across the application. virtual FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( - const std::string& plugin_name); - - // Prevent copying. - PluginRegistry(PluginRegistry const&) = delete; - PluginRegistry& operator=(PluginRegistry const&) = delete; + const std::string& plugin_name) = 0; }; } // namespace flutter