OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 |
| 4 <!-- |
| 5 Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. |
| 8 --> |
| 9 |
| 10 <head> |
| 11 |
| 12 <title>hello_tutorial</title> |
| 13 |
| 14 <script type="text/javascript"> |
| 15 HelloTutorialModule = null; // Global application object. |
| 16 statusText = 'NO-STATUS'; |
| 17 |
| 18 // Indicate load success. |
| 19 function moduleDidLoad() { |
| 20 HelloTutorialModule = document.getElementById('hello_tutorial'); |
| 21 updateStatus('SUCCESS'); |
| 22 } |
| 23 |
| 24 // The 'message' event handler. This handler is fired when the NaCl module |
| 25 // posts a message to the browser by calling PPB_Messaging.PostMessage() |
| 26 // (in C) or pp::Instance.PostMessage() (in C++). This implementation |
| 27 // simply displays the content of the message in an alert panel. |
| 28 function handleMessage(message_event) { |
| 29 alert(message_event.data); |
| 30 } |
| 31 |
| 32 // If the page loads before the Native Client module loads, then set the |
| 33 // status message indicating that the module is still loading. Otherwise, |
| 34 // do not change the status message. |
| 35 function pageDidLoad() { |
| 36 if (HelloTutorialModule == null) { |
| 37 updateStatus('LOADING...'); |
| 38 } else { |
| 39 // It's possible that the Native Client module onload event fired |
| 40 // before the page's onload event. In this case, the status message |
| 41 // will reflect 'SUCCESS', but won't be displayed. This call will |
| 42 // display the current message. |
| 43 updateStatus(); |
| 44 } |
| 45 } |
| 46 |
| 47 // Set the global status message. If the element with id 'statusField' |
| 48 // exists, then set its HTML to the status message as well. |
| 49 // opt_message The message test. If this is null or undefined, then |
| 50 // attempt to set the element with id 'statusField' to the value of |
| 51 // |statusText|. |
| 52 function updateStatus(opt_message) { |
| 53 if (opt_message) |
| 54 statusText = opt_message; |
| 55 var statusField = document.getElementById('status_field'); |
| 56 if (statusField) { |
| 57 statusField.innerHTML = statusText; |
| 58 } |
| 59 } |
| 60 </script> |
| 61 </head> |
| 62 <body onload="pageDidLoad()"> |
| 63 |
| 64 <h1>Native Client Module HelloTutorial</h1> |
| 65 <p> |
| 66 <!-- TODO(eliben): PNaCl-ize: |
| 67 Load the published .nexe. This includes the 'nacl' attribute which |
| 68 shows how to load multi-architecture modules. Each entry in the "nexes" |
| 69 object in the .nmf manifest file is a key-value pair: the key is the |
| 70 instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL |
| 71 for the desired NaCl module. |
| 72 |
| 73 Note: Since this NaCl module does not use any real-estate in the browser, |
| 74 it's width and height are set to 0. |
| 75 |
| 76 Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' |
| 77 and a 'message' event listener attached. This wrapping method is used |
| 78 instead of attaching the event listeners directly to the <EMBED> element to |
| 79 ensure that the listeners are active before the NaCl module 'load' event |
| 80 fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or |
| 81 pp::Instance.PostMessage() (in C++) from within the initialization code in |
| 82 your NaCl module. |
| 83 --> |
| 84 <div id="listener"> |
| 85 <script type="text/javascript"> |
| 86 var listener = document.getElementById('listener'); |
| 87 listener.addEventListener('load', moduleDidLoad, true); |
| 88 listener.addEventListener('message', handleMessage, true); |
| 89 </script> |
| 90 |
| 91 <embed |
| 92 id="hello_tutorial" |
| 93 width=0 height=0 |
| 94 src="hello_tutorial.nmf" |
| 95 type="application/x-pnacl" /> |
| 96 </div> |
| 97 </p> |
| 98 |
| 99 <h2>Status</h2> |
| 100 <div id="status_field">NO-STATUS</div> |
| 101 </body> |
| 102 </html> |
OLD | NEW |