OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2011 The Chromium 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 PPAPI_C_DEV_PPB_MESSAGING_DEV_H_ |
| 6 #define PPAPI_C_DEV_PPB_MESSAGING_DEV_H_ |
| 7 |
| 8 #include "ppapi/c/pp_instance.h" |
| 9 #include "ppapi/c/pp_var.h" |
| 10 |
| 11 #define PPB_MESSAGING_DEV_INTERFACE_0_1 "PPB_Messaging(Dev);0.1" |
| 12 |
| 13 #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 |
| 14 |
| 15 /** |
| 16 * @file |
| 17 * This file defines the PPB_Messaging_Dev interface implemented by the browser |
| 18 * and containing pointers to functions that are specific to a module instance |
| 19 * and related to sending messages. |
| 20 * |
| 21 * @addtogroup Interfaces |
| 22 * @{ |
| 23 */ |
| 24 |
| 25 /** |
| 26 * The PPB_Messaging_Dev interface contains pointers to functions related to |
| 27 * sending messages for a specific module instance. |
| 28 */ |
| 29 struct PPB_Messaging_Dev { |
| 30 /** |
| 31 * @a PostMessage is a pointer to a function which asynchronously invokes the |
| 32 * onmessage handler on the DOM element for the given module instance, if one |
| 33 * exists. @a message is a PP_Var containing the data to be sent to |
| 34 * JavaScript. Currently, it can have an int32_t, double, bool, or string |
| 35 * value (objects are not currently supported.) |
| 36 * |
| 37 * The onmessage handler in JavaScript code will receive an object conforming |
| 38 * to the MessageEvent interface. In particular, the value of @a message will |
| 39 * be contained as a property called @a data in the received MessageEvent. |
| 40 * This is analogous to listening for messages from Web Workers. |
| 41 * |
| 42 * See: |
| 43 * http://www.whatwg.org/specs/web-workers/current-work/ |
| 44 * |
| 45 * For example: |
| 46 * |
| 47 * \verbatim |
| 48 * |
| 49 * <body> |
| 50 * <object id="plugin" |
| 51 * type="application/x-ppapi-postMessage-example"/> |
| 52 * <script type="text/javascript"> |
| 53 * document.getElementById('plugin').onmessage = function(message) { |
| 54 * alert(message.data); |
| 55 * } |
| 56 * </script> |
| 57 * </body> |
| 58 * |
| 59 * \endverbatim |
| 60 * |
| 61 * If the module instance then invokes @a PostMessage() as follows: |
| 62 * <code> |
| 63 * char hello_world[] = "Hello world!"; |
| 64 * PP_Var hello_var = ppb_var_if->VarFromUtf8(instance, |
| 65 * hello_world, |
| 66 * sizeof(hello_world)); |
| 67 * ppb_messaging_if->PostMessage(instance, hello_var); |
| 68 * </code> |
| 69 * |
| 70 * The browser will pop-up an alert saying "Hello world!". |
| 71 */ |
| 72 void (*PostMessage)(PP_Instance instance, struct PP_Var message); |
| 73 }; |
| 74 /** |
| 75 * @} |
| 76 */ |
| 77 |
| 78 #endif /* PPAPI_C_DEV_PPB_MESSAGING_DEV_H_ */ |
| 79 |
OLD | NEW |