OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <!-- | |
4 Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
5 Use of this source code is governed by a BSD-style license that can be | |
6 found in the LICENSE file. | |
7 --> | |
8 <head> | |
9 <title>Hello, World!</title> | |
10 <script type="text/javascript"> | |
11 helloWorldModule = null; // Global application object. | |
12 statusText = 'NO-STATUS'; | |
13 | |
14 // Indicate success when the NaCl module has loaded. | |
15 function moduleDidLoad() { | |
16 helloWorldModule = document.getElementById('hello_world'); | |
17 updateStatus('SUCCESS'); | |
18 } | |
19 | |
20 // Handle a message coming from the NaCl module. | |
21 function handleMessage(message_event) { | |
22 alert(message_event.data); | |
23 } | |
24 | |
25 // If the page loads before the Native Client module loads, then set the | |
26 // status message indicating that the module is still loading. Otherwise, | |
27 // do not change the status message. | |
28 function pageDidLoad() { | |
29 if (helloWorldModule == null) { | |
30 updateStatus('LOADING...'); | |
31 } else { | |
32 // It's possible that the Native Client module onload event fired | |
33 // before the page's onload event. In this case, the status message | |
34 // will reflect 'SUCCESS', but won't be displayed. This call will | |
35 // display the current message. | |
36 updateStatus(); | |
37 } | |
38 } | |
39 | |
40 // Set the global status message. If the element with id 'statusField' | |
41 // exists, then set its HTML to the status message as well. | |
42 // opt_message The message test. If this is null or undefined, then | |
43 // attempt to set the element with id 'statusField' to the value of | |
44 // |statusText|. | |
45 function updateStatus(opt_message) { | |
46 if (opt_message) | |
47 statusText = opt_message; | |
48 var statusField = document.getElementById('statusField'); | |
49 if (statusField) { | |
50 statusField.innerHTML = statusText; | |
51 } | |
52 } | |
53 </script> | |
54 </head> | |
55 <body onload="pageDidLoad()"> | |
56 | |
57 <h1>Native Client Simple Module</h1> | |
58 <h2>Status: <code id="statusField">NO-STATUS</code></h2> | |
59 <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' | |
60 and a 'message' event listener attached. This wrapping method is used | |
61 instead of attaching the event listeners directly to the <EMBED> element to | |
62 ensure that the listeners are active before the NaCl module 'load' event | |
63 fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or | |
64 pp::Instance.PostMessage() (in C++) from within the initialization code in | |
65 your NaCl module. | |
66 | |
67 The src points to a manifest file, which provides the Native Client plug-in | |
68 a mapping between architecture and NaCl Executable (NEXE). | |
69 | |
70 We use a non-zero sized embed to give Chrome space to place the bad plug-in | |
71 graphic, if there is a problem. | |
72 --> | |
73 <div id="listener"> | |
74 <script type="text/javascript"> | |
75 var listener = document.getElementById('listener') | |
76 listener.addEventListener('load', moduleDidLoad, true); | |
77 listener.addEventListener('message', handleMessage, true); | |
78 </script> | |
79 | |
80 <embed name="nacl_module" | |
81 id="hello_world" | |
82 width=200 height=200 | |
83 src="hello_world.nmf" | |
84 type="application/x-nacl" /> | |
85 </div> | |
86 </body> | |
87 </html> | |
OLD | NEW |