| OLD | NEW |
| 1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
| 2 | 2 |
| 3 <section id="messaging-system"> | 3 <section id="messaging-system"> |
| 4 <span id="message-system"></span><h1 id="messaging-system"><span id="message-sys
tem"></span>Messaging System</h1> | 4 <span id="message-system"></span><h1 id="messaging-system"><span id="message-sys
tem"></span>Messaging System</h1> |
| 5 <div class="contents local" id="contents" style="display: none"> | 5 <div class="contents local" id="contents" style="display: none"> |
| 6 <ul class="small-gap"> | 6 <ul class="small-gap"> |
| 7 <li><a class="reference internal" href="#reference-information" id="id2">Referen
ce information</a></li> | 7 <li><a class="reference internal" href="#reference-information" id="id2">Referen
ce information</a></li> |
| 8 <li><p class="first"><a class="reference internal" href="#introduction-to-the-me
ssaging-system" id="id3">Introduction to the messaging system</a></p> | 8 <li><p class="first"><a class="reference internal" href="#introduction-to-the-me
ssaging-system" id="id3">Introduction to the messaging system</a></p> |
| 9 <ul class="small-gap"> | 9 <ul class="small-gap"> |
| 10 <li><a class="reference internal" href="#design-of-the-messaging-system" id="id4
">Design of the messaging system</a></li> | 10 <li><a class="reference internal" href="#design-of-the-messaging-system" id="id4
">Design of the messaging system</a></li> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 <aside class="note"> | 41 <aside class="note"> |
| 42 The “Hello, World” example for getting started with NaCl is used her
e to | 42 The “Hello, World” example for getting started with NaCl is used her
e to |
| 43 illustrate basic programming techniques. You can find this code in | 43 illustrate basic programming techniques. You can find this code in |
| 44 the <code>/getting_started/part2</code> directory in the Native Client SDK downl
oad. | 44 the <code>/getting_started/part2</code> directory in the Native Client SDK downl
oad. |
| 45 </aside> | 45 </aside> |
| 46 <section id="reference-information"> | 46 <section id="reference-information"> |
| 47 <h2 id="reference-information">Reference information</h2> | 47 <h2 id="reference-information">Reference information</h2> |
| 48 <p>For reference information related to the Pepper messaging API, see the | 48 <p>For reference information related to the Pepper messaging API, see the |
| 49 following documentation:</p> | 49 following documentation:</p> |
| 50 <ul class="small-gap"> | 50 <ul class="small-gap"> |
| 51 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/classpp_1_1_instance">pp::Instance class</a> HandleMessage(), Post
Message())</li> | 51 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp
_1_1_instance">pp::Instance class</a> |
| 52 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/classpp_1_1_module">pp::Module class</a></li> | 52 HandleMessage(), PostMessage())</li> |
| 53 <li><a class="reference external" href="https://developers.google.com/native-cli
ent/peppercpp/classpp_1_1_var">pp::Var class</a></li> | 53 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp
_1_1_module">pp::Module class</a></li> |
| 54 <li><a class="reference external" href="/native-client/pepper_stable/cpp/classpp
_1_1_var">pp::Var class</a></li> |
| 54 </ul> | 55 </ul> |
| 55 </section><section id="introduction-to-the-messaging-system"> | 56 </section><section id="introduction-to-the-messaging-system"> |
| 56 <h2 id="introduction-to-the-messaging-system">Introduction to the messaging syst
em</h2> | 57 <h2 id="introduction-to-the-messaging-system">Introduction to the messaging syst
em</h2> |
| 57 <p>Native Client modules and JavaScript communicate by sending messages | 58 <p>Native Client modules and JavaScript communicate by sending messages to each |
| 58 to each other. The most basic form of a message is a string. Messages | 59 other. The most basic form of a message is a string. Messages support many |
| 59 support many JavaScript types, including ints, arrays, array buffers, | 60 JavaScript types, including ints, arrays, array buffers, and dictionaries (see |
| 60 and dictionaries (see <a class="reference external" href="https://developers.goo
gle.com/native-client/peppercpp/classpp_1_1_var">pp::Var</a>, | 61 <a class="reference external" href="h/native-client/pepper_stable/cpp/classpp_1_
1_var">pp::Var</a>, |
| 61 <a class="reference external" href="https://developers.google.com/native-client/
peppercpp/classpp_1_1_var_array_buffer">pp:VarArrayBuffer</a>, | 62 <a class="reference external" href="/native-client/pepper_stable/cpp/classpp_1_1
_var_array_buffer">pp:VarArrayBuffer</a>, and the |
| 62 and the general <a class="reference external" href="https://developers.google.co
m/native-client/pepperc/struct_p_p_b___messaging__1__0">messaging system documen
tation</a>). | 63 general <a class="reference external" href="/native-client/pepper_stable/c/struc
t_p_p_b___messaging__1__0">messaging system documentation</a>). It’s up t
o |
| 63 It’s up to you to decide on the type of message and define how to | 64 you to decide on the type of message and define how to process the messages on |
| 64 process the messages on both the JavaScript and Native Client | 65 both the JavaScript and Native Client side. For the “Hello, World” e
xample, we |
| 65 side. For the “Hello, World” example, we will work with string-typed | 66 will work with string-typed messages only.</p> |
| 66 messages only.</p> | |
| 67 <p>When JavaScript posts a message to the Native Client module, the | 67 <p>When JavaScript posts a message to the Native Client module, the |
| 68 Pepper <code>HandleMessage()</code> function is invoked on the module | 68 Pepper <code>HandleMessage()</code> function is invoked on the module |
| 69 side. Similarly, the Native Client module can post a message to | 69 side. Similarly, the Native Client module can post a message to |
| 70 JavaScript, and this message triggers a JavaScript event listener for | 70 JavaScript, and this message triggers a JavaScript event listener for |
| 71 <code>message</code> events in the DOM. (See the W3C specification on | 71 <code>message</code> events in the DOM. (See the W3C specification on |
| 72 <a class="reference external" href="http://www.w3.org/TR/DOM-Level-2-Events/even
ts.html">Document Object Model Events</a> for more | 72 <a class="reference external" href="http://www.w3.org/TR/DOM-Level-2-Events/even
ts.html">Document Object Model Events</a> for more |
| 73 information.) In the “Hello, World” example, the JavaScript function
s for | 73 information.) In the “Hello, World” example, the JavaScript function
s for |
| 74 posting and handling messages are named <code>postMessage()</code> and | 74 posting and handling messages are named <code>postMessage()</code> and |
| 75 <code>handleMessage()</code> (but any names could be used). On the Native Client | 75 <code>handleMessage()</code> (but any names could be used). On the Native Client |
| 76 C++ side, the Pepper Library functions for posting and handling | 76 C++ side, the Pepper Library functions for posting and handling |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 </pre> | 166 </pre> |
| 167 </section></section><section id="native-client-module"> | 167 </section></section><section id="native-client-module"> |
| 168 <h3 id="native-client-module">Native Client module</h3> | 168 <h3 id="native-client-module">Native Client module</h3> |
| 169 <p>The C++ code in the Native Client module of the “Hello, World” ex
ample:</p> | 169 <p>The C++ code in the Native Client module of the “Hello, World” ex
ample:</p> |
| 170 <ol class="arabic simple"> | 170 <ol class="arabic simple"> |
| 171 <li>Implements <code>pp::Instance::HandleMessage()</code> to handle messages sen
t | 171 <li>Implements <code>pp::Instance::HandleMessage()</code> to handle messages sen
t |
| 172 by the JavaScript.</li> | 172 by the JavaScript.</li> |
| 173 <li>Processes incoming messages. This example simply checks that JavaScript | 173 <li>Processes incoming messages. This example simply checks that JavaScript |
| 174 has sent a “hello” message and not some other message.</li> | 174 has sent a “hello” message and not some other message.</li> |
| 175 <li>Calls <code>PostMessage()</code> to send an acknowledgement back to the | 175 <li>Calls <code>PostMessage()</code> to send an acknowledgement back to the Java
Script |
| 176 JavaScript code. The acknowledgement is a string in the form of a <code>Var</co
de> | 176 code. The acknowledgement is a string in the form of a <code>Var</code> that th
e |
| 177 that the JavaScript code can process. In general, a <code>pp::Var</code> can be | 177 JavaScript code can process. In general, a <code>pp::Var</code> can be several |
| 178 several JavaScript types, see the | 178 JavaScript types, see the <a class="reference external" href="/native-client/pep
per_stable/c/struct_p_p_b___messaging__1__0">messaging system documentation</a>.
</li> |
| 179 <a class="reference external" href="https://developers.google.com/native-client/
pepperc/struct_p_p_b___messaging__1__0">messaging system documentation</a>.</li> | |
| 180 </ol> | 179 </ol> |
| 181 <pre class="prettyprint"> | 180 <pre class="prettyprint"> |
| 182 class HelloTutorialInstance : public pp::Instance { | 181 class HelloTutorialInstance : public pp::Instance { |
| 183 public: | 182 public: |
| 184 // ... | 183 // ... |
| 185 | 184 |
| 186 // === Step 1: Implement the HandleMessage function. === | 185 // === Step 1: Implement the HandleMessage function. === |
| 187 virtual void HandleMessage(const pp::Var& var_message) { | 186 virtual void HandleMessage(const pp::Var& var_message) { |
| 188 | 187 |
| 189 // === Step 2: Process the incoming message. === | 188 // === Step 2: Process the incoming message. === |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 pp::VarArray keys = dictionary.GetKeys(); | 366 pp::VarArray keys = dictionary.GetKeys(); |
| 368 // ... | 367 // ... |
| 369 } else { | 368 } else { |
| 370 // ... | 369 // ... |
| 371 } | 370 } |
| 372 } | 371 } |
| 373 </pre> | 372 </pre> |
| 374 </section></section></section> | 373 </section></section></section> |
| 375 | 374 |
| 376 {{/partials.standard_nacl_article}} | 375 {{/partials.standard_nacl_article}} |
| OLD | NEW |