{{+bindTo:partials.standard_nacl_article}}

PPB_Messaging Struct Reference

Data Fields

void(* PostMessage )(PP_Instance instance, struct PP_Var message)

Detailed Description

The PPB_Messaging 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.


Field Documentation

void(* PPB_Messaging::PostMessage)(PP_Instance instance, struct PP_Var message)

PostMessage() asynchronously invokes any listeners for message events on the DOM element for the given module instance.

A call to PostMessage() will not block while the message is processed.

Parameters:
[in]instanceA PP_Instance identifying one instance of a module.
[in]messageA PP_Var containing the data to be sent to JavaScript. message can be any PP_Var type except PP_VARTYPE_OBJECT. Array/Dictionary types are supported from Chrome M29 onward. All var types are copied when passing them to JavaScript.

When passing array or dictionary PP_Vars, 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.

Listeners for message events in JavaScript code will receive an object conforming to the HTML 5 MessageEvent interface. Specifically, the value of message will be contained as a property called data in the received MessageEvent.

This messaging system is similar to the system used for listening for messages from Web Workers. Refer to http://www.whatwg.org/specs/web-workers/current-work/ for further information.

Example:

 <body>
   <object id="plugin"
           type="application/x-ppapi-postMessage-example"/>
   <script type="text/javascript">
     var plugin = document.getElementById('plugin');
     plugin.addEventListener("message",
                             function(message) { alert(message.data); },
                             false);
   </script>
 </body>

The module instance then invokes PostMessage() as follows:

  char hello_world[] = "Hello world!";
  PP_Var hello_var = ppb_var_interface->VarFromUtf8(instance,
                                                    hello_world,
                                                    sizeof(hello_world));
  ppb_messaging_interface->PostMessage(instance, hello_var); // Copies var.
  ppb_var_interface->Release(hello_var);

The browser will pop-up an alert saying "Hello world!"


The documentation for this struct was generated from the following file:
{{/partials.standard_nacl_article}}