1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRAR_H_ 6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRAR_H_ 7 8 #include <memory> 9 #include <set> 10 #include <string> 11 12 #include <flutter_plugin_registrar.h> 13 14 #include "binary_messenger.h" 15 16 namespace flutter { 17 18 class Plugin; 19 20 // A object managing the registration of a plugin for various events. 21 // 22 // Currently this class has very limited functionality, but is expected to 23 // expand over time to more closely match the functionality of 24 // the Flutter mobile plugin APIs' plugin registrars. 25 class PluginRegistrar { 26 public: 27 // Creates a new PluginRegistrar. |core_registrar| and the messenger it 28 // provides must remain valid as long as this object exists. 29 explicit PluginRegistrar(FlutterDesktopPluginRegistrarRef core_registrar); 30 31 virtual ~PluginRegistrar(); 32 33 // Prevent copying. 34 PluginRegistrar(PluginRegistrar const&) = delete; 35 PluginRegistrar& operator=(PluginRegistrar const&) = delete; 36 37 // Returns the messenger to use for creating channels to communicate with the 38 // Flutter engine. 39 // 40 // This pointer will remain valid for the lifetime of this instance. messenger()41 BinaryMessenger* messenger() { return messenger_.get(); } 42 43 // Takes ownership of |plugin|. 44 // 45 // Plugins are not required to call this method if they have other lifetime 46 // management, but this is a convient place for plugins to be owned to ensure 47 // that they stay valid for any registered callbacks. 48 void AddPlugin(std::unique_ptr<Plugin> plugin); 49 50 // Enables input blocking on the given channel name. 51 // 52 // If set, then the parent window should disable input callbacks 53 // while waiting for the handler for messages on that channel to run. 54 void EnableInputBlockingForChannel(const std::string& channel); 55 56 private: 57 // Handle for interacting with the C API's registrar. 58 FlutterDesktopPluginRegistrarRef registrar_; 59 60 std::unique_ptr<BinaryMessenger> messenger_; 61 62 // Plugins registered for ownership. 63 std::set<std::unique_ptr<Plugin>> plugins_; 64 }; 65 66 // A plugin that can be registered for ownership by a PluginRegistrar. 67 class Plugin { 68 public: 69 virtual ~Plugin() = default; 70 }; 71 72 } // namespace flutter 73 74 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRAR_H_ 75