blob: 5048d803e023d2ee5e9b2d4d686342dd02a7e52c [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9888f132011-03-23 21:07:152 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
[email protected]9b37f4802011-07-19 00:09:285
dmichael9be4c268e2014-09-26 20:39:336/* From ppb_messaging.idl modified Wed Sep 24 10:48:37 2014. */
[email protected]9b37f4802011-07-19 00:09:287
[email protected]5f2cb1c92011-04-08 21:36:238#ifndef PPAPI_C_PPB_MESSAGING_H_
9#define PPAPI_C_PPB_MESSAGING_H_
[email protected]9888f132011-03-23 21:07:1510
[email protected]9b37f4802011-07-19 00:09:2811#include "ppapi/c/pp_bool.h"
[email protected]9888f132011-03-23 21:07:1512#include "ppapi/c/pp_instance.h"
[email protected]9b37f4802011-07-19 00:09:2813#include "ppapi/c/pp_macros.h"
[email protected]4d4880322014-06-02 22:16:4114#include "ppapi/c/pp_resource.h"
[email protected]9b37f4802011-07-19 00:09:2815#include "ppapi/c/pp_stdint.h"
[email protected]9888f132011-03-23 21:07:1516#include "ppapi/c/pp_var.h"
[email protected]4d4880322014-06-02 22:16:4117#include "ppapi/c/ppp_message_handler.h"
[email protected]9888f132011-03-23 21:07:1518
[email protected]49aa13872011-08-17 20:45:5719#define PPB_MESSAGING_INTERFACE_1_0 "PPB_Messaging;1.0"
dmichael9be4c268e2014-09-26 20:39:3320#define PPB_MESSAGING_INTERFACE_1_2 "PPB_Messaging;1.2"
21#define PPB_MESSAGING_INTERFACE PPB_MESSAGING_INTERFACE_1_2
[email protected]49aa13872011-08-17 20:45:5722
[email protected]9888f132011-03-23 21:07:1523/**
24 * @file
[email protected]8dd1f5772011-07-06 15:37:2825 * This file defines the <code>PPB_Messaging</code> interface implemented
26 * by the browser for sending messages to DOM elements associated with a
27 * specific module instance.
[email protected]c7eb5172011-07-14 16:02:1928 */
29
[email protected]9b37f4802011-07-19 00:09:2830
[email protected]c7eb5172011-07-14 16:02:1931/**
[email protected]9888f132011-03-23 21:07:1532 * @addtogroup Interfaces
33 * @{
34 */
[email protected]9888f132011-03-23 21:07:1535/**
[email protected]8dd1f5772011-07-06 15:37:2836 * The <code>PPB_Messaging</code> interface is implemented by the browser
37 * and is related to sending messages to JavaScript message event listeners on
38 * the DOM element associated with specific module instance.
[email protected]9888f132011-03-23 21:07:1539 */
dmichael9be4c268e2014-09-26 20:39:3340struct PPB_Messaging_1_2 {
[email protected]9888f132011-03-23 21:07:1541 /**
[email protected]8dd1f5772011-07-06 15:37:2842 * PostMessage() asynchronously invokes any listeners for message events on
43 * the DOM element for the given module instance. A call to PostMessage()
44 * will not block while the message is processed.
[email protected]9888f132011-03-23 21:07:1545 *
[email protected]216326c2011-08-30 19:10:4046 * @param[in] instance A <code>PP_Instance</code> identifying one instance
[email protected]8dd1f5772011-07-06 15:37:2847 * of a module.
48 * @param[in] message A <code>PP_Var</code> containing the data to be sent to
49 * JavaScript.
[email protected]ce40e542013-05-22 00:48:5450 * <code>message</code> can be any <code>PP_Var</code> type except
51 * <code>PP_VARTYPE_OBJECT</code>. Array/Dictionary types are supported from
52 * Chrome M29 onward. All var types are copied when passing them to
53 * JavaScript.
54 *
55 * When passing array or dictionary <code>PP_Var</code>s, the entire reference
[email protected]b3e3595a9d2013-06-19 03:10:3656 * graph will be converted and transferred. If the reference graph has cycles,
57 * the message will not be sent and an error will be logged to the console.
[email protected]9888f132011-03-23 21:07:1558 *
[email protected]8585fd82011-05-13 23:11:5459 * Listeners for message events in JavaScript code will receive an object
[email protected]8dd1f5772011-07-06 15:37:2860 * conforming to the HTML 5 <code>MessageEvent</code> interface.
61 * Specifically, the value of message will be contained as a property called
62 * data in the received <code>MessageEvent</code>.
[email protected]8585fd82011-05-13 23:11:5463 *
[email protected]e2c2efab2011-05-31 20:27:1064 * This messaging system is similar to the system used for listening for
65 * messages from Web Workers. Refer to
[email protected]8dd1f5772011-07-06 15:37:2866 * <code>http://www.whatwg.org/specs/web-workers/current-work/</code> for
67 * further information.
[email protected]9888f132011-03-23 21:07:1568 *
[email protected]e2c2efab2011-05-31 20:27:1069 * <strong>Example:</strong>
[email protected]9888f132011-03-23 21:07:1570 *
[email protected]ca9bc122012-03-03 00:38:0271 * @code
[email protected]9888f132011-03-23 21:07:1572 *
73 * <body>
74 * <object id="plugin"
75 * type="application/x-ppapi-postMessage-example"/>
76 * <script type="text/javascript">
[email protected]8585fd82011-05-13 23:11:5477 * var plugin = document.getElementById('plugin');
[email protected]9071a3c2012-04-27 00:46:3278 * plugin.addEventListener("message",
[email protected]8585fd82011-05-13 23:11:5479 * function(message) { alert(message.data); },
80 * false);
[email protected]9888f132011-03-23 21:07:1581 * </script>
82 * </body>
83 *
[email protected]ca9bc122012-03-03 00:38:0284 * @endcode
[email protected]9888f132011-03-23 21:07:1585 *
[email protected]e2c2efab2011-05-31 20:27:1086 * The module instance then invokes PostMessage() as follows:
87 *
[email protected]ca9bc122012-03-03 00:38:0288 * @code
[email protected]e2c2efab2011-05-31 20:27:1089 *
[email protected]9888f132011-03-23 21:07:1590 * char hello_world[] = "Hello world!";
[email protected]a47a6fe2011-06-27 07:33:5191 * PP_Var hello_var = ppb_var_interface->VarFromUtf8(instance,
92 * hello_world,
93 * sizeof(hello_world));
94 * ppb_messaging_interface->PostMessage(instance, hello_var); // Copies var.
95 * ppb_var_interface->Release(hello_var);
[email protected]9888f132011-03-23 21:07:1596 *
[email protected]ca9bc122012-03-03 00:38:0297 * @endcode
[email protected]e2c2efab2011-05-31 20:27:1098 *
99 * The browser will pop-up an alert saying "Hello world!"
[email protected]9888f132011-03-23 21:07:15100 */
101 void (*PostMessage)(PP_Instance instance, struct PP_Var message);
[email protected]4d4880322014-06-02 22:16:41102 /**
[email protected]4d4880322014-06-02 22:16:41103 * Registers a handler for receiving messages from JavaScript. If a handler
104 * is registered this way, it will replace PPP_Messaging, and all messages
105 * sent from JavaScript via postMessage and postMessageAndAwaitResponse will
106 * be dispatched to <code>handler</code>.
107 *
108 * The function calls will be dispatched via <code>message_loop</code>. This
109 * means that the functions will be invoked on the thread to which
110 * <code>message_loop</code> is attached, when <code>message_loop</code> is
111 * run. It is illegal to pass the main thread message loop;
112 * RegisterMessageHandler will return PP_ERROR_WRONG_THREAD in that case.
[email protected]e87640bd2014-06-18 16:44:00113 * If you quit <code>message_loop</code> before calling Unregister(),
114 * the browser will not be able to call functions in the plugin's message
115 * handler any more. That could mean missing some messages or could cause a
116 * leak if you depend on Destroy() to free hander data. So you should,
117 * whenever possible, Unregister() the handler prior to quitting its event
118 * loop.
[email protected]4d4880322014-06-02 22:16:41119 *
120 * Attempting to register a message handler when one is already registered
121 * will cause the current MessageHandler to be unregistered and replaced. In
122 * that case, no messages will be sent to the "default" message handler
123 * (PPP_Messaging). Messages will stop arriving at the prior message handler
124 * and will begin to be dispatched at the new message handler.
125 *
126 * @param[in] instance A <code>PP_Instance</code> identifying one instance
127 * of a module.
128 * @param[in] user_data A pointer the plugin may choose to use when handling
129 * calls to functions within PPP_MessageHandler. The browser will pass this
130 * same pointer when invoking functions within PPP_MessageHandler.
131 * @param[in] handler The plugin-provided set of functions for handling
132 * messages.
133 * @param[in] message_loop Represents the message loop on which
134 * PPP_MessageHandler functions should be invoked.
135 * @return PP_OK on success, or an error from pp_errors.h.
136 */
137 int32_t (*RegisterMessageHandler)(
138 PP_Instance instance,
139 void* user_data,
Dave Michael970fa0cf2014-09-17 20:56:10140 const struct PPP_MessageHandler_0_2* handler,
[email protected]4d4880322014-06-02 22:16:41141 PP_Resource message_loop);
142 /**
[email protected]4d4880322014-06-02 22:16:41143 * Unregisters the current message handler for <code>instance</code> if one
144 * is registered. After this call, the message handler (if one was
145 * registered) will have "Destroy" called on it and will receive no further
146 * messages after that point. After that point, all messages sent from
147 * JavaScript using postMessage() will be dispatched to PPP_Messaging (if
148 * the plugin supports PPP_MESSAGING_INTERFACE). Attempts to call
149 * postMessageAndAwaitResponse() from JavaScript will fail.
150 *
151 * Attempting to unregister a message handler when none is registered has no
152 * effect.
153 *
154 * @param[in] instance A <code>PP_Instance</code> identifying one instance
155 * of a module.
156 */
157 void (*UnregisterMessageHandler)(PP_Instance instance);
158};
159
dmichael9be4c268e2014-09-26 20:39:33160typedef struct PPB_Messaging_1_2 PPB_Messaging;
161
[email protected]4d4880322014-06-02 22:16:41162struct PPB_Messaging_1_0 {
163 void (*PostMessage)(PP_Instance instance, struct PP_Var message);
[email protected]9888f132011-03-23 21:07:15164};
165/**
166 * @}
167 */
168
[email protected]5f2cb1c92011-04-08 21:36:23169#endif /* PPAPI_C_PPB_MESSAGING_H_ */
[email protected]9b37f4802011-07-19 00:09:28170