Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | /* Copyright 2014 The Chromium Authors |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
dmichael | 9be4c268e | 2014-09-26 20:39:33 | [diff] [blame] | 6 | /* From ppp_message_handler.idl modified Wed Sep 24 10:48:49 2014. */ |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 7 | |
| 8 | #ifndef PPAPI_C_PPP_MESSAGE_HANDLER_H_ |
| 9 | #define PPAPI_C_PPP_MESSAGE_HANDLER_H_ |
| 10 | |
| 11 | #include "ppapi/c/pp_bool.h" |
| 12 | #include "ppapi/c/pp_instance.h" |
| 13 | #include "ppapi/c/pp_macros.h" |
| 14 | #include "ppapi/c/pp_stdint.h" |
| 15 | #include "ppapi/c/pp_var.h" |
| 16 | |
| 17 | /** |
| 18 | * @file |
| 19 | * This file defines the <code>PPP_MessageHandler</code> interface that plugins |
| 20 | * can implement and register using PPB_Messaging::RegisterMessageHandler in |
| 21 | * order to handle messages sent from JavaScript via postMessage() or |
| 22 | * postMessageAndAwaitResponse(). |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * @addtogroup Interfaces |
| 28 | * @{ |
| 29 | */ |
| 30 | /** |
| 31 | * The <code>PPP_MessageHandler</code> interface is implemented by the plugin |
| 32 | * if the plugin wants to receive messages from a thread other than the main |
| 33 | * Pepper thread, or if the plugin wants to handle blocking messages which |
| 34 | * JavaScript may send via postMessageAndAwaitResponse(). |
| 35 | * |
| 36 | * This interface struct should not be returned by PPP_GetInterface; instead it |
| 37 | * must be passed as a parameter to PPB_Messaging::RegisterMessageHandler. |
| 38 | */ |
dmichael | 9be4c268e | 2014-09-26 20:39:33 | [diff] [blame] | 39 | struct PPP_MessageHandler_0_2 { |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 40 | /** |
| 41 | * Invoked as a result of JavaScript invoking postMessage() on the plugin's |
| 42 | * DOM element. |
| 43 | * |
| 44 | * @param[in] instance A <code>PP_Instance</code> identifying one instance |
| 45 | * of a module. |
| 46 | * @param[in] user_data is the same pointer which was provided by a call to |
dmichael | b873791 | 2014-09-18 18:00:29 | [diff] [blame] | 47 | * RegisterMessageHandler(). |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 48 | * @param[in] message A copy of the parameter that JavaScript provided to |
| 49 | * postMessage(). |
| 50 | */ |
| 51 | void (*HandleMessage)(PP_Instance instance, |
[email protected] | e87640bd | 2014-06-18 16:44:00 | [diff] [blame] | 52 | void* user_data, |
Dave Michael | 970fa0cf | 2014-09-17 20:56:10 | [diff] [blame] | 53 | const struct PP_Var* message); |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 54 | /** |
| 55 | * Invoked as a result of JavaScript invoking postMessageAndAwaitResponse() |
| 56 | * on the plugin's DOM element. |
| 57 | * |
dmichael | b873791 | 2014-09-18 18:00:29 | [diff] [blame] | 58 | * NOTE: JavaScript execution is blocked during the duration of this call. |
| 59 | * Hence, the plugin should respond as quickly as possible. For this reason, |
| 60 | * blocking completion callbacks are disallowed while handling a blocking |
| 61 | * message. |
| 62 | * |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 63 | * @param[in] instance A <code>PP_Instance</code> identifying one instance |
| 64 | * of a module. |
| 65 | * @param[in] user_data is the same pointer which was provided by a call to |
dmichael | b873791 | 2014-09-18 18:00:29 | [diff] [blame] | 66 | * RegisterMessageHandler(). |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 67 | * @param[in] message is a copy of the parameter that JavaScript provided |
dmichael | b873791 | 2014-09-18 18:00:29 | [diff] [blame] | 68 | * to postMessageAndAwaitResponse(). |
Dave Michael | 970fa0cf | 2014-09-17 20:56:10 | [diff] [blame] | 69 | * @param[out] response will be copied to a JavaScript object which is |
dmichael | b873791 | 2014-09-18 18:00:29 | [diff] [blame] | 70 | * returned as the result of postMessageAndAwaitResponse() to the invoking |
Dave Michael | 970fa0cf | 2014-09-17 20:56:10 | [diff] [blame] | 71 | * |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 72 | */ |
Dave Michael | 970fa0cf | 2014-09-17 20:56:10 | [diff] [blame] | 73 | void (*HandleBlockingMessage)(PP_Instance instance, |
| 74 | void* user_data, |
| 75 | const struct PP_Var* message, |
| 76 | struct PP_Var* response); |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 77 | /** |
| 78 | * Invoked when the handler object is no longer needed. After this, no more |
| 79 | * calls will be made which pass this same value for <code>instance</code> |
| 80 | * and <code>user_data</code>. |
| 81 | * |
| 82 | * @param[in] instance A <code>PP_Instance</code> identifying one instance |
| 83 | * of a module. |
| 84 | * @param[in] user_data is the same pointer which was provided by a call to |
| 85 | * RegisterMessageHandler. |
| 86 | */ |
| 87 | void (*Destroy)(PP_Instance instance, void* user_data); |
| 88 | }; |
dmichael | 9be4c268e | 2014-09-26 20:39:33 | [diff] [blame] | 89 | |
| 90 | typedef struct PPP_MessageHandler_0_2 PPP_MessageHandler; |
[email protected] | 4d488032 | 2014-06-02 22:16:41 | [diff] [blame] | 91 | /** |
| 92 | * @} |
| 93 | */ |
| 94 | |
| 95 | #endif /* PPAPI_C_PPP_MESSAGE_HANDLER_H_ */ |
| 96 | |