From b9f70908edaa980d0c8a611cb93b240c6909d41d Mon Sep 17 00:00:00 2001
From: "sbc@chromium.org"
 <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 18 Jun 2014 20:48:48 +0000
Subject: [NaCl SDK] create_html.py now adds PS_TTY_PREFIX attribute to NaCl
 embed.

This fixes tty output handling for ppapi_simple-based applications.

R=binji@chromium.org

Review URL: https://codereview.chromium.org/341893005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278167 0039d316-1c4b-4281-b951-d872f2087c98
---
 native_client_sdk/src/tools/create_html.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

(limited to 'native_client_sdk/src/tools/create_html.py')

diff --git a/native_client_sdk/src/tools/create_html.py b/native_client_sdk/src/tools/create_html.py
index 6b8a2df..64f6d89 100755
--- a/native_client_sdk/src/tools/create_html.py
+++ b/native_client_sdk/src/tools/create_html.py
@@ -27,11 +27,11 @@ HTML_TEMPLATE = '''\
 Sample html container for embedded NaCl module.  This file was auto-generated
 by the create_html tool which is part of the NaCl SDK.
 
-The embed tag is setup with ps_stdout and ps_stderr attributes which, for
-applications linked with ppapi_simple, will cause stdout and stderr to be sent
-to javascript via postMessage.  Also, the postMessage listener assumes that
-all messages sent via postMessage are strings to be displayed in the output
-textarea.
+The embed tag is setup with PS_STDOUT, PS_STDERR and PS_TTY_PREFIX attributes
+which, for applications linked with ppapi_simple, will cause stdout and stderr
+to be sent to javascript via postMessage.  Also, the postMessage listener
+assumes that all messages sent via postMessage are strings to be displayed in
+the output textarea.
 -->
 <html>
 <head>
@@ -46,8 +46,10 @@ textarea.
 
   <div id="listener">
     <embed id="nacl_module" name="%(module_name)s" src="%(nmf)s"
-           type="application/x-nacl" ps_stdout="/dev/tty" ps_stderr="/dev/tty"
-           width=640 height=480 />
+           type="application/x-nacl" width=640 height=480
+           PS_TTY_PREFIX="tty:"
+           PS_STDOUT="/dev/tty"
+           PS_STDERR="/dev/tty" >/
   </div>
 
   <p>Standard output/error:</p>
@@ -69,7 +71,11 @@ function addToStdout(message) {
 }
 
 function handleMessage(message) {
-  addToStdout(message.data)
+  var payload = message.data;
+  var prefix = "tty:";
+  if (typeof(payload) == 'string' && payload.indexOf(prefix) == 0) {
+    addToStdout(payload.slice(prefix.length));
+  }
 }
 
 function handleCrash(event) {
-- 
cgit v1.1