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 SHELL_COMMON_PLATFORM_MESSAGE_HANDLER_H_ |
6 | #define SHELL_COMMON_PLATFORM_MESSAGE_HANDLER_H_ |
7 | |
8 | #include <memory> |
9 | |
10 | #include "flutter/fml/mapping.h" |
11 | |
12 | namespace flutter { |
13 | |
14 | class PlatformMessage; |
15 | |
16 | /// An interface over the ability to handle PlatformMessages that are being sent |
17 | /// from Flutter to the host platform. |
18 | class PlatformMessageHandler { |
19 | public: |
20 | virtual ~PlatformMessageHandler() = default; |
21 | |
22 | /// Ultimately sends the PlatformMessage to the host platform. |
23 | /// This method is invoked on the ui thread. |
24 | virtual void HandlePlatformMessage( |
25 | std::unique_ptr<PlatformMessage> message) = 0; |
26 | |
27 | /// Returns true if the platform message will ALWAYS be dispatched to the |
28 | /// platform thread. |
29 | /// |
30 | /// Platforms that support Background Platform Channels will return |
31 | /// false. |
32 | virtual bool DoesHandlePlatformMessageOnPlatformThread() const = 0; |
33 | |
34 | /// Performs the return procedure for an associated call to |
35 | /// HandlePlatformMessage. |
36 | /// This method should be thread-safe and able to be invoked on any thread. |
37 | virtual void InvokePlatformMessageResponseCallback( |
38 | int response_id, |
39 | std::unique_ptr<fml::Mapping> mapping) = 0; |
40 | |
41 | /// Performs the return procedure for an associated call to |
42 | /// HandlePlatformMessage where there is no return value. |
43 | /// This method should be thread-safe and able to be invoked on any thread. |
44 | virtual void InvokePlatformMessageEmptyResponseCallback(int response_id) = 0; |
45 | }; |
46 | } // namespace flutter |
47 | |
48 | #endif // SHELL_COMMON_PLATFORM_MESSAGE_HANDLER_H_ |
49 | |