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

Side by Side Diff: native_client_sdk/src/examples/hello_world_newlib/hello_world_c.html

Issue 9370041: Clean up examples (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright (c) 2011 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
11 <script type="text/javascript">
12 helloWorldModule = null; // Global application object.
13 statusText = 'NO-STATUS';
14
15 // Indicate success when the NaCl module has loaded.
16 function moduleDidLoad() {
17 helloWorldModule = document.getElementById('hello_world');
18 updateStatus('SUCCESS');
19 }
20
21 // Handle a message coming from the NaCl module.
22 function handleMessage(message_event) {
23 alert(message_event.data);
24 }
25
26 // If the page loads before the Native Client module loads, then set the
27 // status message indicating that the module is still loading. Otherwise,
28 // do not change the status message.
29 function pageDidLoad() {
30 // Set the focus on the text input box. Doing this means you can press
31 // return as soon as the page loads, and it will fire the reversetText()
32 // function.
33 document.forms.helloForm.inputBox.focus();
34 if (helloWorldModule == null) {
35 updateStatus('LOADING...');
36 } else {
37 // It's possible that the Native Client module onload event fired
38 // before the page's onload event. In this case, the status message
39 // will reflect 'SUCCESS', but won't be displayed. This call will
40 // display the current message.
41 updateStatus();
42 }
43 }
44
45 function fortyTwo() {
46 helloWorldModule.postMessage('fortyTwo');
47 }
48
49 function reverseText() {
50 // Grab the text from the text box, pass it into reverseText()
51 var inputBox = document.forms.helloForm.inputBox;
52 helloWorldModule.postMessage('reverseText:' + inputBox.value);
53 // Note: a |false| return tells the <form> tag to cancel the GET action
54 // when submitting the form.
55 return false;
56 }
57
58 // Set the global status message. If the element with id 'statusField'
59 // exists, then set its HTML to the status message as well.
60 // opt_message The message test. If this is null or undefined, then
61 // attempt to set the element with id 'statusField' to the value of
62 // |statusText|.
63 function updateStatus(opt_message) {
64 if (opt_message)
65 statusText = opt_message;
66 var statusField = document.getElementById('statusField');
67 if (statusField) {
68 statusField.innerHTML = statusText;
69 }
70 }
71 </script>
72 </head>
73 <body onload="pageDidLoad()">
74
75 <h1>Native Client Simple Module</h1>
76 <p>
77 <form name="helloForm"
78 action=""
79 method="get"
80 onsubmit="return reverseText()">
81 <input type="text" id="inputBox" name="inputBox" value="Hello world" /><p/>
82 <input type="button" value="Call fortyTwo()" onclick="fortyTwo()" />
83 <input type="submit" value="Call reverseText()" />
84 </form>
85 <!-- Load the published .nexe. This includes the 'src' attribute which
86 shows how to load multi-architecture modules. Each entry in the "nexes"
87 object in the .nmf manifest file is a key-value pair: the key is the runtime
88 ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
89 To load the debug versions of your .nexes, set the 'src' attribute to the
90 _dbg.nmf version of the manifest file.
91
92 Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
93 and a 'message' event listener attached. This wrapping method is used
94 instead of attaching the event listeners directly to the <EMBED> element to
95 ensure that the listeners are active before the NaCl module 'load' event
96 fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
97 pp::Instance.PostMessage() (in C++) from within the initialization code in
98 your NaCl module.
99 -->
100 <div id="listener">
101 <script type="text/javascript">
102 var listener = document.getElementById('listener')
103 listener.addEventListener('load', moduleDidLoad, true);
104 listener.addEventListener('message', handleMessage, true);
105 </script>
106
107 <embed name="nacl_module"
108 id="hello_world"
109 width=0 height=0
110 src="hello_world_c.nmf"
111 type="application/x-nacl" />
112 </div>
113
114 </p>
115
116 <p>If the module is working correctly, a click on the "Call fortyTwo()" button
117 should open a popup dialog containing <b>42</b> as its value.</p>
118
119 <p> Clicking on the "Call reverseText()" button
120 should open a popup dialog containing the textbox contents and its reverse
121 as its value.</p>
122
123 <h2>Status</h2>
124 <div id="statusField">NO-STATUS</div>
125 </body>
126 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698