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_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ 6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ 7 8 #include "flutter/fml/macros.h" 9 #include "flutter/fml/task_runner.h" 10 #include "flutter/lib/ui/window/platform_message_response.h" 11 12 namespace flutter { 13 14 //------------------------------------------------------------------------------ 15 /// @brief The platform message response subclass for responses to messages 16 /// from the embedder to the framework. Message responses are 17 /// fulfilled by the framework. 18 class EmbedderPlatformMessageResponse : public PlatformMessageResponse { 19 public: 20 using Callback = std::function<void(const uint8_t* data, size_t size)>; 21 22 //---------------------------------------------------------------------------- 23 /// @param[in] runner The task runner on which to execute the callback. 24 /// The response will be initiated by the framework on 25 /// the UI thread. 26 /// @param[in] callback The callback that communicates to the embedder the 27 /// contents of the response sent by the framework back 28 /// to the emebder. 29 EmbedderPlatformMessageResponse(fml::RefPtr<fml::TaskRunner> runner, 30 Callback callback); 31 32 //---------------------------------------------------------------------------- 33 /// @brief Destroys the message response. Can be called on any thread. 34 /// Does not execute unfulfilled callbacks. 35 /// 36 ~EmbedderPlatformMessageResponse() override; 37 38 private: 39 fml::RefPtr<fml::TaskRunner> runner_; 40 Callback callback_; 41 42 // |PlatformMessageResponse| 43 void Complete(std::unique_ptr<fml::Mapping> data) override; 44 45 // |PlatformMessageResponse| 46 void CompleteEmpty() override; 47 48 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderPlatformMessageResponse); 49 }; 50 51 } // namespace flutter 52 53 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ 54