1 {{+bindTo:partials.standard_nacl_api}} 2 <h1>PPB_Messaging Struct Reference</h1> 3 <div id="doxygen-ref"> 4 {{- dummy div to appease doxygen -}} 5 <div> 6 <!-- Generated by Doxygen 1.7.6.1 --> 7 8 9 </div> 10 <!--header--> 11 <div class="contents"> 12 <!-- doxytag: class="PPB_Messaging" --><h2> 13 Data Fields</h2><table class="memberdecls"> 14 15 <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> 16 </table> 17 <hr /><a name="details" id="details"></a><h2>Detailed Description</h2> 18 <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> 19 </div><hr /><h2>Field Documentation</h2> 20 <a class="anchor" id="a7f0412c47b340d21c9c98be2e83dcc53"></a><!-- doxytag: member="PPB_Messaging::PostMessage" ref="a7f0412c47b340d21c9c98be2e83dcc53" args=")(PP_Instance instance, struct PP_Var message)" --> 21 <div class="memitem"> 22 <div class="memproto"> 23 <table class="memname"> 24 <tr> 25 <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> 26 </tr> 27 </table> 28 </div> 29 <div class="memdoc"> 30 <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> 31 <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> 32 <dl class="params"><dt><b>Parameters:</b></dt><dd> 33 <table class="params"> 34 <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> 35 <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> 36 </table> 37 </dd> 38 </dl> 39 <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> 40 <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> 41 <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> 42 <p><b>Example:</b></p> 43 <div class="fragment"><pre class="fragment"> <body> 44 <<span class="keywordtype">object</span> <span class="keywordtype">id</span>=<span class="stringliteral">"plugin"</span> 45 type=<span class="stringliteral">"application/x-ppapi-postMessage-example"</span>/> 46 <script type=<span class="stringliteral">"text/javascript"</span>> 47 var plugin = document.getElementById(<span class="stringliteral">'plugin'</span>); 48 plugin.addEventListener(<span class="stringliteral">"message"</span>, 49 <span class="keyword">function</span>(message) { alert(message.data); }, 50 <span class="keyword">false</span>); 51 </script> 52 </body> 53 </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> 54 <div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> hello_world[] = <span class="stringliteral">"Hello world!"</span>; 55 <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, 56 hello_world, 57 <span class="keyword">sizeof</span>(hello_world)); 58 ppb_messaging_interface->PostMessage(instance, hello_var); <span class="comment">// Copies var.</span> 59 ppb_var_interface->Release(hello_var); 60 </pre></div><p>The browser will pop-up an alert saying "Hello world!" </p> 61 </div> 62 </div> 63 <hr />The documentation for this struct was generated from the following file:<ul> 64 <li><a class="el" href="ppb__messaging_8h.html">ppb_messaging.h</a></li> 65 </ul> 66 </div><!-- contents --> 67 </div> 68 {{/partials.standard_nacl_api}} 69