OLD | NEW |
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
3 <html> | 3 <html> |
4 <!-- | 4 <!-- |
5 Copyright (c) 2012 The Chromium Authors. All rights reserved. | 5 Copyright (c) 2012 The Chromium Authors. All rights reserved. |
6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
7 found in the LICENSE file. | 7 found in the LICENSE file. |
8 --> | 8 --> |
9 <head> | 9 <head> |
| 10 <meta http-equiv="Pragma" content="no-cache" /> |
| 11 <meta http-equiv="Expires" content="-1" /> |
10 <title>File I/O Example</title> | 12 <title>File I/O Example</title> |
| 13 <script type="text/javascript"> |
| 14 naclModule = null; // Global application object. |
| 15 statusText = 'NO-STATUSES'; |
11 | 16 |
12 <script type="text/javascript"> | 17 function ExtractSearchParameter(name, def_value) { |
13 FileIoModule = null; // Global application object. | 18 var nameIndex = window.location.search.indexOf(name + "="); |
14 statusText = 'NO-STATUS'; | 19 if (nameIndex != -1) { |
15 | 20 var value = location.search.substring(nameIndex + name.length + 1); |
16 // Request file system space and indicate successful load | 21 var endIndex = value.indexOf("&"); |
17 function moduleDidLoad() { | 22 if (endIndex != -1) |
18 FileIoModule = document.getElementById('file_io'); | 23 value = value.substring(0, endIndex); |
| 24 return value; |
| 25 } |
| 26 return def_value; |
19 } | 27 } |
20 | 28 |
21 function createNaClModule() { | 29 function createNaClModule(name, tool, width, height) { |
22 // Dynamically generate this HTML: | |
23 // <embed name="nacl_module" | |
24 // id="file_io" | |
25 // width=0 height=0 | |
26 // src="file_io.nmf" | |
27 // type="application/x-nacl" /> | |
28 var listenerDiv = document.getElementById('listener'); | 30 var listenerDiv = document.getElementById('listener'); |
29 var naclModule = document.createElement('embed'); | 31 var naclModule = document.createElement('embed'); |
30 naclModule.setAttribute('name', 'nacl_module'); | 32 naclModule.setAttribute('name', 'nacl_module'); |
31 naclModule.setAttribute('id', 'file_io'); | 33 naclModule.setAttribute('id', 'file_io'); |
32 naclModule.setAttribute('width', 0); | 34 naclModule.setAttribute('width', width); |
33 naclModule.setAttribute('height', 0); | 35 naclModule.setAttribute('height',height); |
34 naclModule.setAttribute('src', 'file_io.nmf'); | 36 naclModule.setAttribute('src', tool + '/' + name + '.nmf'); |
35 naclModule.setAttribute('type', 'application/x-nacl'); | 37 naclModule.setAttribute('type', 'application/x-nacl'); |
36 listenerDiv.appendChild(naclModule); | 38 listenerDiv.appendChild(naclModule); |
37 } | 39 } |
38 | 40 |
| 41 // Indicate success when the NaCl module has loaded. |
| 42 function moduleDidLoad() { |
| 43 naclModule = document.getElementById('nacl_module'); |
| 44 updateStatus('SUCCESS'); |
| 45 } |
| 46 |
39 // If the page loads before the Native Client module loads, then set the | 47 // If the page loads before the Native Client module loads, then set the |
40 // status message indicating that the module is still loading. Otherwise, | 48 // status message indicating that the module is still loading. Otherwise, |
41 // do not change the status message. | 49 // do not change the status message. |
42 function pageDidLoad() { | 50 function pageDidLoad() { |
| 51 updateStatus('Page loaded.'); |
| 52 |
43 // Request file system space | 53 // Request file system space |
44 updateStatus('Allocating storage...'); | 54 updateStatus('Allocating storage...'); |
45 window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024, | 55 window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024, |
46 function(bytes) { | 56 function(bytes) { |
47 updateStatus('Allocated '+bytes+' bytes of persistant storage.'); | 57 updateStatus('Allocated '+bytes+' bytes of persistant storage.'); |
48 createNaClModule(); | 58 tool = ExtractSearchParameter('tool', 'newlib'); |
| 59 updateStatus('Creating embed: ' + tool); |
| 60 createNaClModule('hello_world', tool, 200, 200); |
49 }, | 61 }, |
50 function(e) { alert('Failed to allocate space') }); | 62 function(e) { alert('Failed to allocate space') }); |
51 } | 63 } |
52 | 64 |
53 // Set the global status message. If the element with id 'statusField' | 65 // Set the global status message. If the element with id 'statusField' |
54 // exists, then set its HTML to the status message as well. | 66 // exists, then set its HTML to the status message as well. |
55 // opt_message The message test. If this is null or undefined, then | 67 // opt_message The message test. If this is null or undefined, then |
56 // attempt to set the element with id 'statusField' to the value of | 68 // attempt to set the element with id 'statusField' to the value of |
57 // |statusText|. | 69 // |statusText|. |
58 function updateStatus(opt_message) { | 70 function updateStatus(opt_message) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 <button id="delete_but" onclick="deleteFile()" action="">Delete</button> | 174 <button id="delete_but" onclick="deleteFile()" action="">Delete</button> |
163 </div> | 175 </div> |
164 </p> | 176 </p> |
165 | 177 |
166 | 178 |
167 | 179 |
168 <h2>Status</h2> | 180 <h2>Status</h2> |
169 <div id="status_field">NO-STATUS</div> | 181 <div id="status_field">NO-STATUS</div> |
170 </body> | 182 </body> |
171 </html> | 183 </html> |
OLD | NEW |