1 {{+bindTo:partials.standard_nacl_article}}
2 <h1>PPB_Messaging Struct Reference</h1>
4 <!-- Generated by Doxygen 1.7.6.1 -->
10 <!-- doxytag: class="PPB_Messaging" --><h2>
11 Data Fields</h2><table class="memberdecls">
13 <tr><td class="memItemLeft" align="right" valign="top">void(* </td><td class="memItemRight" valign="bottom"><a class="el" href="struct_p_p_b___messaging__1__0.html#a7f0412c47b340d21c9c98be2e83dcc53">PostMessage</a> )(<a class="el" href="group___typedefs.html#ga89b662403e6a687bb914b80114c0d19d">PP_Instance</a> instance, struct <a class="el" href="struct_p_p___var.html">PP_Var</a> message)</td></tr>
15 <hr /><a name="details" id="details"></a><h2>Detailed Description</h2>
16 <div class="textblock"><p>The <code>PPB_Messaging</code> interface is implemented by the browser and is related to sending messages to JavaScript message event listeners on the DOM element associated with specific module instance. </p>
17 </div><hr /><h2>Field Documentation</h2>
18 <a class="anchor" id="a7f0412c47b340d21c9c98be2e83dcc53"></a><!-- doxytag: member="PPB_Messaging::PostMessage" ref="a7f0412c47b340d21c9c98be2e83dcc53" args=")(PP_Instance instance, struct PP_Var message)" -->
20 <div class="memproto">
21 <table class="memname">
23 <td class="memname">void(* <a class="el" href="struct_p_p_b___messaging__1__0.html#a7f0412c47b340d21c9c98be2e83dcc53">PPB_Messaging::PostMessage</a>)(<a class="el" href="group___typedefs.html#ga89b662403e6a687bb914b80114c0d19d">PP_Instance</a> instance, struct <a class="el" href="struct_p_p___var.html">PP_Var</a> message)</td>
28 <p><a class="el" href="struct_p_p_b___messaging__1__0.html#a7f0412c47b340d21c9c98be2e83dcc53" title="PostMessage() asynchronously invokes any listeners for message events on the DOM element for the give...">PostMessage()</a> asynchronously invokes any listeners for message events on the DOM element for the given module instance. </p>
29 <p>A call to <a class="el" href="struct_p_p_b___messaging__1__0.html#a7f0412c47b340d21c9c98be2e83dcc53" title="PostMessage() asynchronously invokes any listeners for message events on the DOM element for the give...">PostMessage()</a> will not block while the message is processed.</p>
30 <dl class="params"><dt><b>Parameters:</b></dt><dd>
31 <table class="params">
32 <tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>A <code>PP_Instance</code> identifying one instance of a module. </td></tr>
33 <tr><td class="paramdir">[in]</td><td class="paramname">message</td><td>A <code><a class="el" href="struct_p_p___var.html" title="The PP_VAR struct is a variant data type and can contain any value of one of the types named in the P...">PP_Var</a></code> containing the data to be sent to JavaScript. <code>message</code> can be any <code><a class="el" href="struct_p_p___var.html" title="The PP_VAR struct is a variant data type and can contain any value of one of the types named in the P...">PP_Var</a></code> type except <code>PP_VARTYPE_OBJECT</code>. Array/Dictionary types are supported from Chrome M29 onward. All var types are copied when passing them to JavaScript.</td></tr>
37 <p>When passing array or dictionary <code><a class="el" href="struct_p_p___var.html" title="The PP_VAR struct is a variant data type and can contain any value of one of the types named in the P...">PP_Var</a></code>s, the entire reference graph will be converted and transferred. If the reference graph has cycles, the message will not be sent and an error will be logged to the console.</p>
38 <p>Listeners for message events in JavaScript code will receive an object conforming to the HTML 5 <code>MessageEvent</code> interface. Specifically, the value of message will be contained as a property called data in the received <code>MessageEvent</code>.</p>
39 <p>This messaging system is similar to the system used for listening for messages from Web Workers. Refer to <code><a href="http://www.whatwg.org/specs/web-workers/current-work/">http://www.whatwg.org/specs/web-workers/current-work/</a></code> for further information.</p>
40 <p><b>Example:</b></p>
41 <div class="fragment"><pre class="fragment"> <body>
42 <<span class="keywordtype">object</span> <span class="keywordtype">id</span>=<span class="stringliteral">"plugin"</span>
43 type=<span class="stringliteral">"application/x-ppapi-postMessage-example"</span>/>
44 <script type=<span class="stringliteral">"text/javascript"</span>>
45 var plugin = document.getElementById(<span class="stringliteral">'plugin'</span>);
46 plugin.addEventListener(<span class="stringliteral">"message"</span>,
47 <span class="keyword">function</span>(message) { alert(message.data); },
48 <span class="keyword">false</span>);
51 </pre></div><p>The module instance then invokes <a class="el" href="struct_p_p_b___messaging__1__0.html#a7f0412c47b340d21c9c98be2e83dcc53" title="PostMessage() asynchronously invokes any listeners for message events on the DOM element for the give...">PostMessage()</a> as follows:</p>
52 <div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> hello_world[] = <span class="stringliteral">"Hello world!"</span>;
53 <a class="code" href="struct_p_p___var.html" title="The PP_VAR struct is a variant data type and can contain any value of one of the types named in the P...">PP_Var</a> hello_var = ppb_var_interface->VarFromUtf8(instance,
55 <span class="keyword">sizeof</span>(hello_world));
56 ppb_messaging_interface->PostMessage(instance, hello_var); <span class="comment">// Copies var.</span>
57 ppb_var_interface->Release(hello_var);
58 </pre></div><p>The browser will pop-up an alert saying "Hello world!" </p>
61 <hr />The documentation for this struct was generated from the following file:<ul>
62 <li><a class="el" href="ppb__messaging_8h.html">ppb_messaging.h</a></li>
64 </div><!-- contents -->
65 {{/partials.standard_nacl_article}}