Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: examples/hello_world/hello_world.html

Issue 7029032: Port hello_world (C++) to use postMessage. (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« examples/hello_world/hello_world.cc ('K') | « examples/hello_world/hello_world.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/hello_world/hello_world.html
===================================================================
--- examples/hello_world/hello_world.html (revision 858)
+++ examples/hello_world/hello_world.html (working copy)
@@ -12,11 +12,21 @@
helloWorldModule = null; // Global application object.
statusText = 'NO-STATUS';
+ // When the NaCl module has loaded, hook up an event listener to handle
+ // message coming from it, and then indicate success.
function moduleDidLoad() {
helloWorldModule = document.getElementById('hello_world');
+ // Add a message handler that accespts messages coming from the NaCl
Matt Ball 2011/05/18 16:12:22 accespts -> accepts
David Springer 2011/05/18 18:01:42 Done.
+ // module.
+ helloWorldModule.addEventListener('message', handleMessage, false);
updateStatus('SUCCESS');
}
+ // Handle a message coming from the NaCl module.
+ function handleMessage(message_event) {
+ alert(message_event.data);
+ }
+
// If the page loads before the Native Client module loads, then set the
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
@@ -38,7 +48,7 @@
function fortyTwo() {
try {
- alert(helloWorldModule.fortyTwo());
+ helloWorldModule.postMessage('fortyTwo');
} catch(e) {
alert(e.message);
}
@@ -48,7 +58,7 @@
try {
// Grab the text from the text box, pass it into reverseText()
var inputBox = document.forms.helloForm.inputBox;
- alert(helloWorldModule.reverseText(inputBox.value));
+ helloWorldModule.postMessage('reverseText:' + inputBox.value);
} catch(e) {
alert(e.message);
}
@@ -90,6 +100,11 @@
('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
To load the debug versions of your .nexes, set the 'src' attribute to the
_dbg.nmf version of the manifest file.
+
+ Note that the <EMBED> element is wrapped inside a <DIV>, which has a 'load'
+ event listener attached. This method is used instead of attaching the 'load'
+ event listener directly to the <EMBED> element to ensure that the listener
+ is active before the NaCl module 'load' even fires.
-->
<div id="listener">
<script type="text/javascript">
« examples/hello_world/hello_world.cc ('K') | « examples/hello_world/hello_world.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698