Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Creates simple HTML for running a NaCl module. | 6 """Creates simple HTML for running a NaCl module. |
| 7 | 7 |
| 8 This script is designed to make the process of creating running | 8 This script is designed to make the process of creating running |
| 9 Native Client executables in the browers simple by creating | 9 Native Client executables in the browers simple by creating |
| 10 boilderplate a .html (and optionally a .nmf) file for a given | 10 boilderplate a .html (and optionally a .nmf) file for a given |
| 11 Native Client executable (.nexe). | 11 Native Client executable (.nexe). |
| 12 | 12 |
| 13 If the script if given a .nexe file it will produce both html | 13 If the script if given a .nexe file it will produce both html |
| 14 the nmf files. If it is given an nmf it will only create | 14 the nmf files. If it is given an nmf it will only create |
| 15 the html file. | 15 the html file. |
| 16 """ | 16 """ |
| 17 | 17 |
| 18 import optparse | 18 import optparse |
| 19 import os | 19 import os |
| 20 import sys | 20 import sys |
| 21 import subprocess | 21 import subprocess |
| 22 | 22 |
| 23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 24 HTML_TEMPLATE = '''\ | 24 HTML_TEMPLATE = '''\ |
| 25 <!DOCTYPE html> | 25 <!DOCTYPE html> |
| 26 <!-- | 26 <!-- |
| 27 Sample html container for embedded NaCl module. This file was auto-generated | 27 Sample html container for embedded NaCl module. This file was auto-generated |
| 28 by the create_html tool which is part of the NaCl SDK. | 28 by the create_html tool which is part of the NaCl SDK. |
| 29 | 29 |
| 30 The embed tag is setup with ps_stdout and ps_stderr attributes which, for | 30 The embed tag is setup with PS_STDOUT, PS_STDERR and PS_TTY_PREFIX attributes |
| 31 applications linked with ppapi_simple, will cause stdout and stderr to be sent | 31 which, for applications linked with ppapi_simple, will cause stdout and stderr |
| 32 to javascript via postMessage. Also, the postMessage listener assumes that | 32 to be sent to javascript via postMessage. Also, the postMessage listener |
| 33 all messages sent via postMessage are strings to be displayed in the output | 33 assumes that all messages sent via postMessage are strings to be displayed in |
| 34 textarea. | 34 the output textarea. |
| 35 --> | 35 --> |
| 36 <html> | 36 <html> |
| 37 <head> | 37 <head> |
| 38 <meta http-equiv="Pragma" content="no-cache"> | 38 <meta http-equiv="Pragma" content="no-cache"> |
| 39 <meta http-equiv="Expires" content="-1"> | 39 <meta http-equiv="Expires" content="-1"> |
| 40 <title>%(title)s</title> | 40 <title>%(title)s</title> |
| 41 | 41 |
| 42 </head> | 42 </head> |
| 43 <body> | 43 <body> |
| 44 <h2>Native Client Module: %(module_name)s</h2> | 44 <h2>Native Client Module: %(module_name)s</h2> |
| 45 <p>Status: <code id="status">Loading</code></p> | 45 <p>Status: <code id="status">Loading</code></p> |
| 46 | 46 |
| 47 <div id="listener"> | 47 <div id="listener"> |
| 48 <embed id="nacl_module" name="%(module_name)s" src="%(nmf)s" | 48 <embed id="nacl_module" name="%(module_name)s" src="%(nmf)s" |
| 49 type="application/x-nacl" ps_stdout="/dev/tty" ps_stderr="/dev/tty" | 49 type="application/x-nacl" width=640 height=480 |
| 50 width=640 height=480 /> | 50 PS_TTY_PREFIX="tty:" |
| 51 PS_STDOUT="/dev/tty" | |
| 52 PS_STDERR="/dev/tty" >/ | |
| 51 </div> | 53 </div> |
| 52 | 54 |
| 53 <p>Standard output/error:</p> | 55 <p>Standard output/error:</p> |
| 54 <textarea id="stdout" rows="25" cols="80"> | 56 <textarea id="stdout" rows="25" cols="80"> |
| 55 </textarea> | 57 </textarea> |
| 56 | 58 |
| 57 <script> | 59 <script> |
| 58 listenerDiv = document.getElementById("listener") | 60 listenerDiv = document.getElementById("listener") |
| 59 stdout = document.getElementById("stdout") | 61 stdout = document.getElementById("stdout") |
| 60 nacl_module = document.getElementById("nacl_module") | 62 nacl_module = document.getElementById("nacl_module") |
| 61 | 63 |
| 62 function updateStatus(message) { | 64 function updateStatus(message) { |
| 63 document.getElementById("status").innerHTML = message | 65 document.getElementById("status").innerHTML = message |
| 64 } | 66 } |
| 65 | 67 |
| 66 function addToStdout(message) { | 68 function addToStdout(message) { |
| 67 stdout.value += message; | 69 stdout.value += message; |
| 68 stdout.scrollTop = stdout.scrollHeight; | 70 stdout.scrollTop = stdout.scrollHeight; |
| 69 } | 71 } |
| 70 | 72 |
| 71 function handleMessage(message) { | 73 function handleMessage(message) { |
| 72 addToStdout(message.data) | 74 var payload = message.data; |
| 75 var prefix = "tty:"; | |
|
binji
2014/06/18 20:43:32
I'd like to remove this message format as well (st
Sam Clegg
2014/06/18 20:48:38
Agreed.
| |
| 76 if (typeof(payload) == 'string' && payload.indexOf(prefix) == 0) { | |
| 77 addToStdout(payload.slice(prefix.length)); | |
| 78 } | |
| 73 } | 79 } |
| 74 | 80 |
| 75 function handleCrash(event) { | 81 function handleCrash(event) { |
| 76 updateStatus("Crashed/exited with status: " + nacl_module.exitStatus) | 82 updateStatus("Crashed/exited with status: " + nacl_module.exitStatus) |
| 77 } | 83 } |
| 78 | 84 |
| 79 function handleLoad(event) { | 85 function handleLoad(event) { |
| 80 updateStatus("Loaded") | 86 updateStatus("Loaded") |
| 81 } | 87 } |
| 82 | 88 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 if __name__ == '__main__': | 196 if __name__ == '__main__': |
| 191 try: | 197 try: |
| 192 rtn = main(sys.argv[1:]) | 198 rtn = main(sys.argv[1:]) |
| 193 except Error, e: | 199 except Error, e: |
| 194 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) | 200 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) |
| 195 rtn = 1 | 201 rtn = 1 |
| 196 except KeyboardInterrupt: | 202 except KeyboardInterrupt: |
| 197 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) | 203 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) |
| 198 rtn = 1 | 204 rtn = 1 |
| 199 sys.exit(rtn) | 205 sys.exit(rtn) |
| OLD | NEW |