1 /* Copyright (c) 2012 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.
7 * This file defines the <code>PPB_Messaging</code> interface implemented
8 * by the browser for sending messages to DOM elements associated with a
9 * specific module instance.
19 * The <code>PPB_Messaging</code> interface is implemented by the browser
20 * and is related to sending messages to JavaScript message event listeners on
21 * the DOM element associated with specific module instance.
23 interface PPB_Messaging
{
25 * PostMessage() asynchronously invokes any listeners for message events on
26 * the DOM element for the given module instance. A call to PostMessage()
27 * will not block while the message is processed.
29 * @param[in] instance A <code>PP_Instance</code> identifying one instance
31 * @param[in] message A <code>PP_Var</code> containing the data to be sent to
33 * <code>message</code> can be any <code>PP_Var</code> type except
34 * <code>PP_VARTYPE_OBJECT</code>. Array/Dictionary types are supported from
35 * Chrome M29 onward. All var types are copied when passing them to
38 * When passing array or dictionary <code>PP_Var</code>s, the entire reference
39 * graph will be converted and transferred. If the reference graph has cycles,
40 * the message will not be sent and an error will be logged to the console.
42 * Listeners for message events in JavaScript code will receive an object
43 * conforming to the HTML 5 <code>MessageEvent</code> interface.
44 * Specifically, the value of message will be contained as a property called
45 * data in the received <code>MessageEvent</code>.
47 * This messaging system is similar to the system used for listening for
48 * messages from Web Workers. Refer to
49 * <code>http://www.whatwg.org/specs/web-workers/current-work/</code> for
50 * further information.
52 * <strong>Example:</strong>
58 * type="application/x-ppapi-postMessage-example"/>
59 * <script type="text/javascript">
60 * var plugin = document.getElementById('plugin');
61 * plugin.addEventListener("message",
62 * function(message) { alert(message.data); },
69 * The module instance then invokes PostMessage() as follows:
73 * char hello_world[] = "Hello world!";
74 * PP_Var hello_var = ppb_var_interface->VarFromUtf8(instance,
76 * sizeof(hello_world));
77 * ppb_messaging_interface->PostMessage(instance, hello_var); // Copies var.
78 * ppb_var_interface->Release(hello_var);
82 * The browser will pop-up an alert saying "Hello world!"
84 void PostMessage
([in] PP_Instance instance
, [in] PP_Var
message);