diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-17 12:00:37 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-17 12:00:37 +0000 |
commit | fe41e54bac57a74c96c0c356de45b036616a2dad (patch) | |
tree | 9ea1493348d0f9e536585eeaa0655de7f50b25e9 /native_client_sdk | |
parent | 300548c65ec0b83ab7076ccf890c1fa0b6899ad9 (diff) | |
download | chromium_src-fe41e54bac57a74c96c0c356de45b036616a2dad.zip chromium_src-fe41e54bac57a74c96c0c356de45b036616a2dad.tar.gz chromium_src-fe41e54bac57a74c96c0c356de45b036616a2dad.tar.bz2 |
Auto generate make: Remove XXX.html
To support automatically generating the projects, we need to differentiate
between various versions of the projects such as newlib, glibc, pnacl, etc...
To do this, we automatically generate an index_<TOOLCHAIN>.html per version
as well as an index.html which redirects to the default toolchain.
While this CL looks large, is actually very formulaic
1- remove examples/*/*.nmf - it's now autogenerated
2- remove examples/*/*.html - it's now generated from index.html
3- Add index.html
4- Copy comments from examples/index.html into each example.dsc
(To allow us to autogenerate the main index eventually)
The interesting changes are:
Add redirect.html to create a default index.html
Moved common setup code into common.js
TBR=binji@chromium.org
BUG=130618
Review URL: https://chromiumcodereview.appspot.com/10554022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
73 files changed, 1071 insertions, 1177 deletions
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py index 847b459..d2c91be 100755 --- a/native_client_sdk/src/build_tools/generate_make.py +++ b/native_client_sdk/src/build_tools/generate_make.py @@ -31,7 +31,7 @@ def Replace(text, replacements): return text -def WriteMakefile(srcpath, dstpath, replacements): +def WriteReplaced(srcpath, dstpath, replacements): text = open(srcpath, 'rb').read() text = Replace(text, replacements) open(dstpath, 'wb').write(text) @@ -61,11 +61,13 @@ def GenerateCopyList(desc): # Add sources for each target for target in desc['TARGETS']: sources.extend(target['SOURCES']) - if target['TYPE'] == 'main': - sources.append(desc['NAME'] + '.html') # And HTML and data files sources.extend(desc.get('DATA', [])) + + if desc['DEST'] == 'examples': + sources.append('common.js') + return sources @@ -150,7 +152,7 @@ def GenerateNEXE(target, tool): object_sets.append('$(%s)' % replace['<OBJS>']) objs = ' '.join(object_sets) - link_rule = BUILD_RULES[tool]['nexe'] + link_rule = BUILD_RULES[tool][ target['TYPE'] ] replace = BuildToolDict(tool, name, arch, 'nexe', OBJS=objs) rules += Replace(link_rule, replace) return rules @@ -355,6 +357,28 @@ def IsNexe(desc): return False +def ProcessHTML(srcroot, dstroot, desc, toolchains): + name = desc['NAME'] + outdir = os.path.join(dstroot, desc['DEST'], name) + + srcfile = os.path.join(srcroot, 'index.html') + tools = GetPlatforms(toolchains, desc['TOOLS']) + for tool in tools: + dstfile = os.path.join(outdir, 'index_%s.html' % tool); + print 'Writting from %s to %s' % (srcfile, dstfile) + replace = { + '<NAME>': name, + '<TITLE>': desc['TITLE'], + '<tc>': tool + } + WriteReplaced(srcfile, dstfile, replace) + + replace['<tc>'] = tools[0] + srcfile = os.path.join(SDK_SRC_DIR, 'build_tools', 'redirect.html') + dstfile = os.path.join(outdir, 'index.html') + WriteReplaced(srcfile, dstfile, replace) + + def LoadProject(filename, toolchains): """Generate a Master Makefile that builds all examples. @@ -386,13 +410,14 @@ def ProcessProject(srcroot, dstroot, desc, toolchains): name = desc['NAME'] out_dir = os.path.join(dstroot, desc['DEST'], name) buildbot_common.MakeDir(out_dir) - srcdirs = desc.get('SEARCH', ['.']) + srcdirs = desc.get('SEARCH', ['.', '..']) # Copy sources to example directory sources = GenerateCopyList(desc) for src_name in sources: src_file = FindFile(src_name, srcroot, srcdirs) if not src_file: + ErrorMsgFunc('Failed to find: ' + src_name) return (None, None) dst_file = os.path.join(out_dir, src_name) buildbot_common.CopyFile(src_file, dst_file) @@ -402,11 +427,15 @@ def ProcessProject(srcroot, dstroot, desc, toolchains): else: template=os.path.join(SCRIPT_DIR, 'library.mk') - # Add Makefile - repdict = GenerateReplacements(desc, toolchains) - make_path = os.path.join(out_dir, 'Makefile') - WriteMakefile(template, make_path, repdict) + tools = [] + for tool in desc['TOOLS']: + if tool in toolchains: + tools.append(tool) + # Add Makefile and make.bat + repdict = GenerateReplacements(desc, tools) + make_path = os.path.join(out_dir, 'Makefile') + WriteReplaced(template, make_path, repdict) outdir = os.path.dirname(os.path.abspath(make_path)) pepperdir = os.path.dirname(os.path.dirname(outdir)) AddMakeBat(pepperdir, outdir) @@ -416,7 +445,7 @@ def ProcessProject(srcroot, dstroot, desc, toolchains): def GenerateExamplesMakefile(in_path, out_path, examples): """Generate a Master Makefile that builds all examples. """ replace = { '__PROJECT_LIST__' : SetVar('PROJECTS', examples) } - WriteMakefile(in_path, out_path, replace) + WriteReplaced(in_path, out_path, replace) outdir = os.path.dirname(os.path.abspath(out_path)) pepperdir = os.path.dirname(outdir) @@ -465,8 +494,11 @@ def main(argv): if not ProcessProject(srcroot, options.dstroot, desc, toolchains): ErrorExit('\n*** Failed to process project: %s ***' % filename) + # if this is an example, do the HTML files as well if desc['DEST'] == 'examples': examples.append(desc['NAME']) + ProcessHTML(srcroot, options.dstroot, desc, toolchains) + if options.master: master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') diff --git a/native_client_sdk/src/build_tools/make_rules.py b/native_client_sdk/src/build_tools/make_rules.py index 7dc0bc3..ec0e30d 100755 --- a/native_client_sdk/src/build_tools/make_rules.py +++ b/native_client_sdk/src/build_tools/make_rules.py @@ -25,8 +25,8 @@ GLIBC_PATHS+=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib PNACL_DEFAULTS = """ PNACL_CC?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang -c -PNACL_CXX?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang -c -PNACL_LINK?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang +PNACL_CXX?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++ -c +PNACL_LINK?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++ PNACL_DUMP?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/objdump TRANSLATE:=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-translate """ @@ -72,8 +72,10 @@ PNACL_NMF:=<tc>/<proj>_x86_32.nexe <tc>/<proj>_x86_64.nexe <tc>/<proj>_arm.nexe """ SO_LINK_RULE = """ -<tc>/<proj>_<ARCH>.<ext> : <OBJS> +<tc>/<proj>_<ARCH>.so : <OBJS> <TAB>$(<LINK>) -o $@ $^ <MACH> -shared $(<PROJ>_LDFLAGS) +GLIBC_REMAP+= -n <proj>_<ARCH>.so,<proj>.so +<TC>_NMF+=<tc>/<proj>_<ARCH>.so """ @@ -120,8 +122,8 @@ BUILD_RULES = { 'DEFS': NEWLIB_DEFAULTS, 'CC' : NEXE_CC_RULE, 'CXX' : NEXE_CC_RULE, - 'nexe' : NEXE_LINK_RULE, 'nmf' : NMF_RULE, + 'main': NEXE_LINK_RULE, 'so' : None, }, 'glibc' : { @@ -129,8 +131,8 @@ BUILD_RULES = { 'DEFS': GLIBC_DEFAULTS, 'CC': NEXE_CC_RULE, 'CXX': NEXE_CC_RULE, - 'nexe': NEXE_LINK_RULE, 'nmf' : GLIBC_NMF_RULE, + 'main': NEXE_LINK_RULE, 'so': SO_LINK_RULE, }, 'pnacl' : { @@ -138,8 +140,8 @@ BUILD_RULES = { 'DEFS': PNACL_DEFAULTS, 'CC': NEXE_CC_RULE, 'CXX': NEXE_CC_RULE, - 'nexe': PEXE_LINK_RULE, 'nmf' : NMF_RULE, + 'main': PEXE_LINK_RULE, 'so': None, }, } diff --git a/native_client_sdk/src/build_tools/redirect.html b/native_client_sdk/src/build_tools/redirect.html new file mode 100644 index 0000000..10d7074 --- /dev/null +++ b/native_client_sdk/src/build_tools/redirect.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <meta http-equiv="Refresh" content="0;url=index_<tc>.html" /> +</head> +<body> + Redirecting to default example: <tc> +</body> +</html> diff --git a/native_client_sdk/src/examples/common.js b/native_client_sdk/src/examples/common.js new file mode 100644 index 0000000..cedb470b --- /dev/null +++ b/native_client_sdk/src/examples/common.js @@ -0,0 +1,76 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +naclModule = null; // Global application object. +statusText = 'NO-STATUSES'; + +function extractSearchParameter(name, def_value) { + var nameIndex = window.location.search.indexOf(name + "="); + if (nameIndex != -1) { + var value = location.search.substring(nameIndex + name.length + 1); + var endIndex = value.indexOf("&"); + if (endIndex != -1) + value = value.substring(0, endIndex); + return value; + } + return def_value; +} + +function createNaClModule(name, tool, width, height) { + var listenerDiv = document.getElementById('listener'); + var naclModule = document.createElement('embed'); + naclModule.setAttribute('name', 'nacl_module'); + naclModule.setAttribute('id', 'nacl_module'); + naclModule.setAttribute('width', width); + naclModule.setAttribute('height',height); + naclModule.setAttribute('src', tool + '/' + name + '.nmf'); + naclModule.setAttribute('type', 'application/x-nacl'); + listenerDiv.appendChild(naclModule); +} + +// Indicate success when the NaCl module has loaded. +function moduleDidLoad() { + naclModule = document.getElementById('nacl_module'); + updateStatus('SUCCESS'); +} + +// Handle a message coming from the NaCl module. +function handleMessage(message_event) { + alert(message_event.data); +} + +// If the page loads before the Native Client module loads, then set the +// status message indicating that the module is still loading. Otherwise, +// do not change the status message. +function pageDidLoad(name, tool, width, height) { + updateStatus('Page loaded.'); + if (naclModule == null) { + updateStatus('Creating embed: ' + tool) + width = typeof width !== 'undefined' ? width : 200; + height = typeof height !== 'undefined' ? height : 200; + createNaClModule(name, tool, width, height) + } else { + // It's possible that the Native Client module onload event fired + // before the page's onload event. In this case, the status message + // will reflect 'SUCCESS', but won't be displayed. This call will + // display the current message. + updateStatus('Waiting.'); + } +} + +// Set the global status message. If the element with id 'statusField' +// exists, then set its HTML to the status message as well. +// opt_message The message test. If this is null or undefined, then +// attempt to set the element with id 'statusField' to the value of +// |statusText|. +function updateStatus(opt_message) { + if (opt_message) { + statusText = opt_message; + } + var statusField = document.getElementById('statusField'); + if (statusField) { + statusField.innerHTML = statusText; + } +} + diff --git a/native_client_sdk/src/examples/debugging/example.dsc b/native_client_sdk/src/examples/debugging/example.dsc index a6b1a03..ee269db 100644 --- a/native_client_sdk/src/examples/debugging/example.dsc +++ b/native_client_sdk/src/examples/debugging/example.dsc @@ -17,6 +17,12 @@ 'POST': 'include Makefile.inc\n', 'DATA': ['Makefile.inc'], 'DEST': 'examples', - 'NAME': 'debugging' + 'NAME': 'debugging', + 'TITLE': 'Debugging', + 'DESC': """ +Debugging example shows how to use developer only features to enable +catching an exception, and then using that to create a stacktrace.""", + 'INFO': 'Debugging, Stacktraces.' + } diff --git a/native_client_sdk/src/examples/debugging/hello_world.nmf b/native_client_sdk/src/examples/debugging/hello_world.nmf deleted file mode 100644 index 78df8e1..0000000 --- a/native_client_sdk/src/examples/debugging/hello_world.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "hello_world_x86_64.nexe"}, - "x86-32": {"url": "hello_world_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/debugging/debugging.html b/native_client_sdk/src/examples/debugging/index.html index 65b66da..6254eb5 100644 --- a/native_client_sdk/src/examples/debugging/debugging.html +++ b/native_client_sdk/src/examples/debugging/index.html @@ -138,7 +138,7 @@ cChrome executable.</li> <embed name="nacl_module" id="hello_world" width=100 height=100 - src="hello_world.nmf" + src="<tc>/debugging.nmf" type="application/x-nacl" /> </div> <hr> diff --git a/native_client_sdk/src/examples/dlopen/dlopen.html b/native_client_sdk/src/examples/dlopen/dlopen.html deleted file mode 100644 index 69a93d9..0000000 --- a/native_client_sdk/src/examples/dlopen/dlopen.html +++ /dev/null @@ -1,118 +0,0 @@ -<!DOCTYPE html> -<html> - <!-- - Copyright (c) 2012 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <meta http-equiv="Pragma" content="no-cache" /> - <meta http-equiv="Expires" content="-1" /> - <title>Magic Eightball</title> - <script type="text/javascript"> - naclModule = null; // Global application object. - statusText = 'NO-STATUSES'; - - function ExtractSearchParameter(name, def_value) { - var nameIndex = window.location.search.indexOf(name + "="); - if (nameIndex != -1) { - var value = location.search.substring(nameIndex + name.length + 1); - var endIndex = value.indexOf("&"); - if (endIndex != -1) - value = value.substring(0, endIndex); - return value; - } - return def_value; - } - - function createNaClModule(name, tool, width, height) { - var listenerDiv = document.getElementById('listener'); - var naclModule = document.createElement('embed'); - naclModule.setAttribute('name', 'nacl_module'); - naclModule.setAttribute('id', 'nacl_module'); - naclModule.setAttribute('width', width); - naclModule.setAttribute('height',height); - naclModule.setAttribute('src', tool + '/' + name + '.nmf'); - naclModule.setAttribute('type', 'application/x-nacl'); - listenerDiv.appendChild(naclModule); - } - - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - updateStatus('SUCCESS'); - naclModule = document.getElementById('nacl_module'); - } - - function handleMessage(message_event) { - updateStatus(message_event.data); - } - - function pageDidUnload() { - clearInterval(paintInterval); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - updateStatus('Page loaded.'); - if (naclModule == null) { - tool = ExtractSearchParameter('tool', 'glibc'); - updateStatus('Creating embed: ' + tool) - createNaClModule('dlopen', tool, 100, 100) - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus('Waiting.'); - } - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('statusField'); - var answerLog = document.getElementById('answerlog'); - if (statusField) { - statusField.innerHTML = statusText; - } - if (answerLog) { - answerLog.innerHTML += (opt_message +"<br />"); - } - } - - function askBall() - { - naclModule = document.getElementById('nacl_module'); - var consolec = document.getElementById('consolec'); - updateStatus('ASK: ' + consolec.value); - naclModule.postMessage('query'); - return false; - } - </script> -</head> -<body id="bodyId" onload="pageDidLoad()"> - <h2>Status: <code id="statusField">NO-STATUS</code></h2> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - <h1>The Magic 8 Ball </h1> - </div> - <br /> - <div>Eightball loaded, type a question below, press the button, and get a response.</div> - <input type="text" id="consolec" value=""/> - <input type="button" id="button" value="ASK!" onclick="return askBall()"/> - </form> -<br /> -<div id="answerlog"></div> -</body> -</html> diff --git a/native_client_sdk/src/examples/dlopen/example.dsc b/native_client_sdk/src/examples/dlopen/example.dsc index f1e2d34..141180d 100644 --- a/native_client_sdk/src/examples/dlopen/example.dsc +++ b/native_client_sdk/src/examples/dlopen/example.dsc @@ -17,5 +17,13 @@ ], 'DEST': 'examples', 'NAME': 'dlopen', + 'TITLE': 'Dynamic Library Open', + 'DESC': """ +The dlopen example demonstrates how build dynamic libraries and then +open and use them at runtime. When the page loads, type in a question and +hit enter or click the ASK! button. The question and answer will be +displayed in the page under the text entry box. Shared libraries are only +available with the GLIBC toolchain.""", + 'INFO': 'Teaching focus: Using shared objects' } diff --git a/native_client_sdk/src/examples/dlopen/index.html b/native_client_sdk/src/examples/dlopen/index.html new file mode 100644 index 0000000..001005b --- /dev/null +++ b/native_client_sdk/src/examples/dlopen/index.html @@ -0,0 +1,76 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript" > + function handleMessage(message_event) { + updateStatus(message_event.data); + } + + function updateStatus(opt_message) { + if (opt_message) { + statusText = opt_message; + } + var statusField = document.getElementById('statusField'); + var answerLog = document.getElementById('answerlog'); + if (statusField) { + statusField.innerHTML = statusText; + } + if (answerLog) { + answerLog.innerHTML += (opt_message +"<br>"); + } + } + + function askBall() + { + naclModule = document.getElementById('nacl_module'); + var consolec = document.getElementById('consolec'); + updateStatus('ASK: ' + consolec.value); + naclModule.postMessage('query'); + return false; + } + </script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> + <h1>The Magic 8 Ball </h1> + </div> + <br /> + <div>Eightball loaded, type a question below, press the button, and get a response.</div> + <input type="text" id="consolec" value=""/> + <input type="button" id="button" value="ASK!" onclick="return askBall()"/> + </div> + <div id="answerlog"></div> +</body> +</html> diff --git a/native_client_sdk/src/examples/file_histogram/example.dsc b/native_client_sdk/src/examples/file_histogram/example.dsc index 4ab6a91..13d3f7b 100644 --- a/native_client_sdk/src/examples/file_histogram/example.dsc +++ b/native_client_sdk/src/examples/file_histogram/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'file_histogram', @@ -9,5 +9,12 @@ ], 'DEST': 'examples', 'NAME': 'file_histogram', + 'TITLE': 'File Histogram.', + 'DESC': """ +The File Histogram example demonstrates prompting the user for a file, +passing the file contents to NativeClient as a VarArrayBuffer, then drawing a +histogram representing the contents of the file to a 2D square. +""", + 'INFO': 'Teaching focus: VarArrayBuffer, 2D, File input.' } diff --git a/native_client_sdk/src/examples/file_histogram/file_histogram.html b/native_client_sdk/src/examples/file_histogram/file_histogram.html deleted file mode 100644 index 23c523b..0000000 --- a/native_client_sdk/src/examples/file_histogram/file_histogram.html +++ /dev/null @@ -1,132 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> - <!-- - Copyright (c) 2012 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <title>File Histogram</title> - - <script type="text/javascript"> - FileHistogramModule = null; // Global application object. - statusText = 'NO-STATUS'; - - // Indicate load success. - function moduleDidLoad() { - FileHistogramModule = document.getElementById('file_histogram'); - updateStatus('SUCCESS'); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - if (FileHistogramModule == null) { - updateStatus('LOADING...'); - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus(); - } - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('status_field'); - if (statusField) { - statusField.innerHTML = statusText; - } - } - - function postFileContents(file) { - var reader = new FileReader(); - reader.onload = function(load_event) { - if (FileHistogramModule) - FileHistogramModule.postMessage(load_event.target.result); - } - reader.readAsArrayBuffer(file); - } - - // Handle a file being dropped on to the plugin's rectangle. - function handleFileDrop(dropEvent) { - if (!dropEvent.dataTransfer || !dropEvent.dataTransfer.files) - return; - dropEvent.stopPropagation(); - dropEvent.preventDefault(); - var files = dropEvent.dataTransfer.files; - for(var i = 0; i < files.length; ++i) - postFileContents(files[i]); - } - - // Handle a file being chosen from the <input type=file...> tag. - function handleFileInput() { - var file_input = document.getElementById("FileInput"); - var files = file_input.files; - for(var i = 0; i < files.length; ++i) - postFileContents(files[i]); - } - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>File Histogram example</h1> -This example demonstrates the use of VarArrayBuffer, as well as a way to allow -the user to provide one or more files to your Native Client application. -<p> -Select one or more files by clicking "Choose Files", or Drag and drop one or -more files on to the square below. The embedded NaCl instance will read each -file in order and display a histogram representing its contents. -<p> - <!-- Load the published .nexe. This includes the 'nacl' attribute which - shows how to load multi-architecture modules. Each entry in the "nexes" - object in the .nmf manifest file is a key-value pair: the key is the - instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL - for the desired NaCl module. - To load the debug versions of your .nexes, set the 'nacl' attribute to the - _dbg.nmf version of the manifest file. - - Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'drop' event listener attached. This wrapping method is used instead of - attaching the event listeners directly to the <EMBED> element to ensure that - the listeners are active before the NaCl module 'load' event fires. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener'); - listener.addEventListener('load', moduleDidLoad, true); - // The "drop" event fires when the user drops something (such as a file) - // on to the target element (in this case, listener). - listener.addEventListener('drop', handleFileDrop, true); - </script> - - <embed name="nacl_module" - id="file_histogram" - width=256 height=256 - src="file_histogram.nmf" - type="application/x-nacl" /> - <form name="FileInput" - action="" - method="" - onsubmit="handleFileInput()"> - <input type="file" - id="FileInput" - onchange="this.form.onsubmit()" - multiple> - </form> - </div> -</p> - -<h2>Status</h2> -<div id="status_field">NO-STATUS</div> -</body> -</html> diff --git a/native_client_sdk/src/examples/file_histogram/file_histogram.nmf b/native_client_sdk/src/examples/file_histogram/file_histogram.nmf deleted file mode 100644 index 75bf0d9..0000000 --- a/native_client_sdk/src/examples/file_histogram/file_histogram.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "file_histogram_x86_64.nexe"}, - "x86-32": {"url": "file_histogram_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/file_histogram/index.html b/native_client_sdk/src/examples/file_histogram/index.html new file mode 100644 index 0000000..91fc346 --- /dev/null +++ b/native_client_sdk/src/examples/file_histogram/index.html @@ -0,0 +1,81 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type ="text/javascript" > + function postFileContents(file) { + var reader = new FileReader(); + reader.onload = function(load_event) { + if (naclModule) + naclModule.postMessage(load_event.target.result); + } + reader.readAsArrayBuffer(file); + } + + // Handle a file being dropped on to the plugin's rectangle. + function handleFileDrop(dropEvent) { + if (!dropEvent.dataTransfer || !dropEvent.dataTransfer.files) + return; + dropEvent.stopPropagation(); + dropEvent.preventDefault(); + var files = dropEvent.dataTransfer.files; + for(var i = 0; i < files.length; ++i) + postFileContents(files[i]); + } + + // Handle a file being chosen from the <input type=file...> tag. + function handleFileInput() { + var file_input = document.getElementById("FileInput"); + var files = file_input.files; + for(var i = 0; i < files.length; ++i) + postFileContents(files[i]); + return false; + } + </script> + +</head> +<body onload="pageDidLoad('<NAME>', '<tc>', 256, 256)"> + +<h1>Native Client Simple Module</h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + listener.addEventListener('drop', handleFileDrop, true); + </script> + <form name="FileInput" + action="" + method="" + onsubmit="return handleFileInput()"> + <input type="file" + id="FileInput" + onchange="this.form.onsubmit()" + multiple> + </form> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/file_io/example.dsc b/native_client_sdk/src/examples/file_io/example.dsc index 965932b..588b71b 100644 --- a/native_client_sdk/src/examples/file_io/example.dsc +++ b/native_client_sdk/src/examples/file_io/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'file_io', @@ -8,6 +8,11 @@ } ], 'DEST': 'examples', - 'NAME': 'file_io' + 'NAME': 'file_io', + 'TITLE': 'File I/O', + 'DESC': """ +The File IO example demonstrates saving, loading, and deleting files +from the persistent file store.""", + 'INFO': 'Teaching focus: File input and output.' } diff --git a/native_client_sdk/src/examples/file_io/file_io.html b/native_client_sdk/src/examples/file_io/file_io.html deleted file mode 100644 index 8ce0934..0000000 --- a/native_client_sdk/src/examples/file_io/file_io.html +++ /dev/null @@ -1,182 +0,0 @@ -<!DOCTYPE html> -<html> - <!-- - Copyright (c) 2012 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <meta http-equiv="Pragma" content="no-cache" /> - <meta http-equiv="Expires" content="-1" /> - <title>File I/O Example</title> - <script type="text/javascript"> - naclModule = null; // Global application object. - statusText = 'NO-STATUSES'; - - function ExtractSearchParameter(name, def_value) { - var nameIndex = window.location.search.indexOf(name + "="); - if (nameIndex != -1) { - var value = location.search.substring(nameIndex + name.length + 1); - var endIndex = value.indexOf("&"); - if (endIndex != -1) - value = value.substring(0, endIndex); - return value; - } - return def_value; - } - - function createNaClModule(name, tool, width, height) { - var listenerDiv = document.getElementById('listener'); - var naclModule = document.createElement('embed'); - naclModule.setAttribute('name', 'nacl_module'); - naclModule.setAttribute('id', 'file_io'); - naclModule.setAttribute('width', width); - naclModule.setAttribute('height',height); - naclModule.setAttribute('src', tool + '/' + name + '.nmf'); - naclModule.setAttribute('type', 'application/x-nacl'); - listenerDiv.appendChild(naclModule); - } - - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - naclModule = document.getElementById('nacl_module'); - updateStatus('SUCCESS'); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - updateStatus('Page loaded.'); - - // Request file system space - updateStatus('Allocating storage...'); - window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024, - function(bytes) { - updateStatus('Allocated '+bytes+' bytes of persistant storage.'); - tool = ExtractSearchParameter('tool', 'newlib'); - updateStatus('Creating embed: ' + tool); - createNaClModule('hello_world', tool, 200, 200); - }, - function(e) { alert('Failed to allocate space') }); - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('status_field'); - if (statusField) { - statusField.innerHTML = statusText; - statusField.style.color = "black"; - } - } - - function loadFile() { - if (FileIoModule) { - var fileName = document.getElementById('file_name').value; - - // Package a message using a simple protocol containing: - // instruction file_name_length file_name - var msg = "ld " + fileName.length + " " + fileName; - FileIoModule.postMessage(msg); - } - } - - function saveFile() { - if (FileIoModule) { - var fileName = document.getElementById('file_name').value; - var fileText = document.getElementById('file_editor').value; - - // Package a message using a simple protocol containing: - // instruction file_name_length file_name file_contents - var msg = "sv " + fileName.length + " " + fileName + " " + fileText; - FileIoModule.postMessage(msg); - } - } - - function deleteFile() { - if (FileIoModule) { - var fileName = document.getElementById('file_name').value; - - // Package a message using a simple protocol containing: - // instruction file_name_length file_name - var msg = "de " + fileName.length + " " + fileName; - FileIoModule.postMessage(msg); - } - } - - function handleMessage(message_event) { - var messageParts = message_event.data.split("|", 3); - - if (messageParts[0] == "ERR") { - updateStatus(messageParts[1]); - document.getElementById('status_field').style.color = "red"; - } - else if(messageParts[0] == "STAT") { - updateStatus(messageParts[1]); - } - else if (messageParts[0] == "DISP") { - // Display the message in the file edit box - document.getElementById('file_editor').value = messageParts[1]; - } - else if (messageParts[0] == "READY") { - var statusField = document.getElementById('status_field'); - updateStatus(statusField.innerHTML + ' Ready!'); - } - } - - - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>File I/O example</h1> -This example demonstrates the use of the persistent file system -<p> -The window below allows creating and editing files in the file store. -<p> - <!-- Load the published .nexe. This includes the 'nacl' attribute which - shows how to load multi-architecture modules. Each entry in the "nexes" - object in the .nmf manifest file is a key-value pair: the key is the - instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL - for the desired NaCl module. - To load the debug versions of your .nexes, set the 'nacl' attribute to the - _dbg.nmf version of the manifest file. - - Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element - to ensure that the listeners are active before the NaCl module 'load' - event fires. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener'); - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - - <textarea id="file_editor" - cols="40" - rows="10" - wrap="hard" - placeholder="Enter some text to save in a file..."></textarea> - <br>File Name - <input type="text" id="file_name" action=""/> - <button id="save_but" onclick="saveFile()" action="">Save</button> - <button id="load_but" onclick="loadFile()" action="">Load</button> - <button id="delete_but" onclick="deleteFile()" action="">Delete</button> - </div> -</p> - - - -<h2>Status</h2> -<div id="status_field">NO-STATUS</div> -</body> -</html> diff --git a/native_client_sdk/src/examples/file_io/file_io.nmf b/native_client_sdk/src/examples/file_io/file_io.nmf deleted file mode 100644 index 4864849..0000000 --- a/native_client_sdk/src/examples/file_io/file_io.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "file_io_x86_64.nexe"}, - "x86-32": {"url": "file_io_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/file_io/index.html b/native_client_sdk/src/examples/file_io/index.html new file mode 100644 index 0000000..6455157 --- /dev/null +++ b/native_client_sdk/src/examples/file_io/index.html @@ -0,0 +1,105 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript" > + function loadFile() { + if (naclModule) { + var fileName = document.getElementById('file_name').value; + + // Package a message using a simple protocol containing: + // instruction file_name_length file_name + var msg = "ld " + fileName.length + " " + fileName; + naclModule.postMessage(msg); + } + } + + function saveFile() { + if (naclModule) { + var fileName = document.getElementById('file_name').value; + var fileText = document.getElementById('file_editor').value; + + // Package a message using a simple protocol containing: + // instruction file_name_length file_name file_contents + var msg = "sv " + fileName.length + " " + fileName + " " + fileText; + naclModule.postMessage(msg); + } + } + + function deleteFile() { + if (naclModule) { + var fileName = document.getElementById('file_name').value; + + // Package a message using a simple protocol containing: + // instruction file_name_length file_name + var msg = "de " + fileName.length + " " + fileName; + naclModule.postMessage(msg); + } + } + + function handleMessage(message_event) { + var messageParts = message_event.data.split("|", 3); + + if (messageParts[0] == "ERR") { + updateStatus(messageParts[1]); + document.getElementById('status_field').style.color = "red"; + } + else if(messageParts[0] == "STAT") { + updateStatus(messageParts[1]); + } + else if (messageParts[0] == "DISP") { + // Display the message in the file edit box + document.getElementById('file_editor').value = messageParts[1]; + } + else if (messageParts[0] == "READY") { + var statusField = document.getElementById('status_field'); + updateStatus(statusField.innerHTML + ' Ready!'); + } + } + </script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + <textarea id="file_editor" + cols="40" + rows="10" + wrap="hard" + placeholder="Enter some text to save in a file..."></textarea> + <br>File Name + <input type="text" id="file_name" action=""/> + <button id="save_but" onclick="saveFile()" action="">Save</button> + <button id="load_but" onclick="loadFile()" action="">Load</button> + <button id="delete_but" onclick="deleteFile()" action="">Delete</button> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/example.dsc b/native_client_sdk/src/examples/fullscreen_tumbler/example.dsc index 9b35b45..eb45d6d 100644 --- a/native_client_sdk/src/examples/fullscreen_tumbler/example.dsc +++ b/native_client_sdk/src/examples/fullscreen_tumbler/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'tumbler', @@ -34,5 +34,13 @@ ], 'DEST': 'examples', 'NAME': 'fullscreen_tumbler', + 'TITLE': 'Interactive Cube Example', + 'DESC': """ +This is a modified version of the Tumbler example above that supports +full-screen display. It is in every way identical to Tumbler in +functionality, except that it adds the ability to switch to/from +full-screen display by pressing the Enter key. +""", + 'INFO': 'Teaching focus: Full-screen.' } diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/fullscreen_tumbler.nmf b/native_client_sdk/src/examples/fullscreen_tumbler/fullscreen_tumbler.nmf deleted file mode 100644 index cfd0e9b..0000000 --- a/native_client_sdk/src/examples/fullscreen_tumbler/fullscreen_tumbler.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "fullscreen_tumbler_x86_64.nexe"}, - "x86-32": {"url": "fullscreen_tumbler_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/fullscreen_tumbler.html b/native_client_sdk/src/examples/fullscreen_tumbler/index.html index 880acc4..558ac2dc 100644 --- a/native_client_sdk/src/examples/fullscreen_tumbler/fullscreen_tumbler.html +++ b/native_client_sdk/src/examples/fullscreen_tumbler/index.html @@ -1,13 +1,14 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> - <head> - <title>Interactive Cube Fullscreen Example</title> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> <script type="text/javascript"> // Provide the tumbler namespace tumbler = {}; @@ -33,8 +34,8 @@ isValidBrowser = checker.getIsValidBrowser(); browserSupportStatus = checker.getBrowserSupportStatus(); </script> - </head> - <body id="bodyId"> +</head> + <body id="bodyId"> <h1>Interactive Cube Example</h1> <p> The Native Client module executed in this page draws a 3D cube @@ -54,4 +55,4 @@ } </script> </body> -</HTML> +</html> diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.js b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.js index e620dc5..de8c2bf 100644 --- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.js +++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.js @@ -127,7 +127,7 @@ tumbler.Application.prototype.run = function(opt_contentDivName) { // attribute to the _dbg.nmf version of the manifest file. contentDiv.innerHTML = '<embed id="' + tumbler.Application.DomIds_.MODULE + '" ' - + 'src=fullscreen_tumbler.nmf ' + + 'src=newlib/tumbler.nmf ' + 'type="application/x-nacl" ' + 'width="480" height="480" />' } diff --git a/native_client_sdk/src/examples/gamepad/example.dsc b/native_client_sdk/src/examples/gamepad/example.dsc index 3f17d36..d7d5541 100644 --- a/native_client_sdk/src/examples/gamepad/example.dsc +++ b/native_client_sdk/src/examples/gamepad/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'gamepad', @@ -9,5 +9,11 @@ ], 'DEST': 'examples', 'NAME': 'gamepad', + 'TITLE': 'Gamepad Example.', + 'DESC': """ +Attached gamepad values should appear, left to right, once they've been +interacted with. Buttons, esp triggers are analog. +""", + 'INFO': 'Gamepad interface.' } diff --git a/native_client_sdk/src/examples/gamepad/gamepad.html b/native_client_sdk/src/examples/gamepad/gamepad.html deleted file mode 100644 index 65c0fff..0000000 --- a/native_client_sdk/src/examples/gamepad/gamepad.html +++ /dev/null @@ -1,24 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> - <!-- - Copyright (c) 2012 The Native Client Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> - <head> - <title>Gamepad example</title> - </head> - <body id="bodyId"> - - <p> Attached gamepad values should appear, left to right, once they've been - interacted with. Buttons, esp triggers are analog (alpha). </p> - - <embed - name="nacl_module" - id="gamepad" - width=800 height=200 - src="gamepad.nmf" - type="application/x-nacl" /> - </body> -</html> diff --git a/native_client_sdk/src/examples/gamepad/gamepad.nmf b/native_client_sdk/src/examples/gamepad/gamepad.nmf deleted file mode 100644 index 53e3b97..0000000 --- a/native_client_sdk/src/examples/gamepad/gamepad.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "gamepad_x86_64.nexe"}, - "x86-32": {"url": "gamepad_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/gamepad/index.html b/native_client_sdk/src/examples/gamepad/index.html new file mode 100644 index 0000000..7271198 --- /dev/null +++ b/native_client_sdk/src/examples/gamepad/index.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>', '800', '200')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/geturl/example.dsc b/native_client_sdk/src/examples/geturl/example.dsc index 728fb52..91423eb 100644 --- a/native_client_sdk/src/examples/geturl/example.dsc +++ b/native_client_sdk/src/examples/geturl/example.dsc @@ -1,8 +1,8 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { - 'NAME' : 'gamepad', + 'NAME' : 'geturl', 'TYPE' : 'main', 'SOURCES' : ['geturl.cc', 'geturl_handler.cc', 'geturl_handler.h'], } @@ -10,5 +10,12 @@ 'DATA': ['geturl_success.html'], 'DEST': 'examples', 'NAME': 'geturl', + 'TITLE': 'Get URL', + 'DESC': """ +The Get URL example demonstrates fetching an URL and then displaying +its contents. Clicking the GetURL button will cause a geturl_success.html +file to get loaded asynchronously, then displayed in a text box when the +load completes.""", + 'INFO': 'Teaching focus: URL loading.' } diff --git a/native_client_sdk/src/examples/geturl/geturl.html b/native_client_sdk/src/examples/geturl/geturl.html deleted file mode 100644 index ca96cf1..0000000 --- a/native_client_sdk/src/examples/geturl/geturl.html +++ /dev/null @@ -1,125 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> - <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <title>Get URL</title> - - <script type="text/javascript"> - geturlModule = null; // Global application object. - statusText = 'NO-STATUS'; - - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - geturlModule = document.getElementById('geturl'); - updateStatus('SUCCESS'); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - if (geturl == null) { - updateStatus('LOADING...'); - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus(); - } - } - - // Called from the NaCl module via PostMessage(). The message data - // contains a URL followed by a '\n' separator character and the result - // text. The result test itself can contain '\n' characters, only the first - // '\n' is considered when separating the message parameters. - function handleMessage(message_event) { - var logElt = document.getElementById('general_output'); - // Find the first line break. This separates the URL data from the - // result text. Note that the result text can contain any number of - // '\n' characters, so split() won't work here. - var url = message_event.data; - var result = ''; - var eol_pos = message_event.data.indexOf("\n"); - if (eol_pos != -1) { - url = message_event.data.substring(0, eol_pos); - if (eol_pos < message_event.data.length - 1) { - result = message_event.data.substring(eol_pos + 1); - } - } - logElt.textContent += 'FULLY QUALIFIED URL: ' + url + '\n'; - logElt.textContent += 'RESULT:\n' + result + '\n'; - } - - function loadUrl() { - geturlModule.postMessage('getUrl:geturl_success.html'); - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // @param opt_message The message text. If this is null or undefined, then - // attempt to set the element with id 'status_field' to the value of - // @a statusText. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('status_field'); - if (statusField) { - statusField.innerHTML = statusText; - } - } - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>Native Client GetURL Module</h1> -<p> -<table border=5 cellpadding=5% summary="A title and a result log"> - <tr> - <td valign=top><pre id='general_output' class='notrun'></pre></td> - </tr> -</table> - - <form name="geturl_form" action="" method="get"> - <input type="button" value="Get URL" onclick="loadUrl()"/> - </form> - - <!-- Load the published .nexe. This includes the 'src' attribute which - shows how to load multi-architecture modules. Each entry in the "nexes" - object in the .nmf manifest file is a key-value pair: the key is the runtime - ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module. - To load the debug versions of your .nexes, set the 'src' attribute to the - _dbg.nmf version of the manifest file. - - Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element to - ensure that the listeners are active before the NaCl module 'load' event - fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or - pp::Instance.PostMessage() (in C++) from within the initialization code in - your NaCl module. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - - <embed name="nacl_module" - id="geturl" - width=0 height=0 - src="geturl.nmf" - type="application/x-nacl" /> - </div> -</p> - -<h2>Module loading status</h2> -<div id="status_field">NO-STATUS</div> -</body> -</html> diff --git a/native_client_sdk/src/examples/geturl/geturl.nmf b/native_client_sdk/src/examples/geturl/geturl.nmf deleted file mode 100644 index 936e301..0000000 --- a/native_client_sdk/src/examples/geturl/geturl.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "geturl_x86_64.nexe"}, - "x86-32": {"url": "geturl_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/geturl/geturl_handler.cc b/native_client_sdk/src/examples/geturl/geturl_handler.cc index 8b758cf..ebb450c 100644 --- a/native_client_sdk/src/examples/geturl/geturl_handler.cc +++ b/native_client_sdk/src/examples/geturl/geturl_handler.cc @@ -11,12 +11,6 @@ #include "geturl_handler.h" -namespace { -bool IsError(int32_t result) { - return ((PP_OK != result) && (PP_OK_COMPLETIONPENDING != result)); -} -} // namespace - GetURLHandler* GetURLHandler::Create(pp::Instance* instance, const std::string& url) { return new GetURLHandler(instance, url); diff --git a/native_client_sdk/src/examples/geturl/index.html b/native_client_sdk/src/examples/geturl/index.html new file mode 100644 index 0000000..f47522b --- /dev/null +++ b/native_client_sdk/src/examples/geturl/index.html @@ -0,0 +1,72 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript" > + function loadUrl() { + naclModule.postMessage('getUrl:geturl_success.html'); + } + + function handleMessage(message_event) { + var logElt = document.getElementById('general_output'); + // Find the first line break. This separates the URL data from the + // result text. Note that the result text can contain any number of + // '\n' characters, so split() won't work here. + var url = message_event.data; + var result = ''; + var eol_pos = message_event.data.indexOf("\n"); + if (eol_pos != -1) { + url = message_event.data.substring(0, eol_pos); + if (eol_pos < message_event.data.length - 1) { + result = message_event.data.substring(eol_pos + 1); + } + } + logElt.textContent += 'FULLY QUALIFIED URL: ' + url + '\n'; + logElt.textContent += 'RESULT:\n' + result + '\n'; + } + </script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> +<p> +<table border=5 cellpadding=5% summary="A title and a result log"> + <tr> + <td valign=top><pre id='general_output' class='notrun'></pre></td> + </tr> +</table> +<form name="geturl_form" action="" method="get"> + <input type="button" value="Get URL" onclick="loadUrl()"/> +</form> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/hello_world/hello_world.html b/native_client_sdk/src/examples/hello_world/hello_world.html deleted file mode 100644 index 982fe7a..0000000 --- a/native_client_sdk/src/examples/hello_world/hello_world.html +++ /dev/null @@ -1,109 +0,0 @@ -<!DOCTYPE html> -<html> - <!-- - Copyright (c) 2012 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <meta http-equiv="Pragma" content="no-cache" /> - <meta http-equiv="Expires" content="-1" /> - <title>Hello, World!</title> - <script type="text/javascript"> - naclModule = null; // Global application object. - statusText = 'NO-STATUSES'; - - function ExtractSearchParameter(name, def_value) { - var nameIndex = window.location.search.indexOf(name + "="); - if (nameIndex != -1) { - var value = location.search.substring(nameIndex + name.length + 1); - var endIndex = value.indexOf("&"); - if (endIndex != -1) - value = value.substring(0, endIndex); - return value; - } - return def_value; - } - - function createNaClModule(name, tool, width, height) { - var listenerDiv = document.getElementById('listener'); - var naclModule = document.createElement('embed'); - naclModule.setAttribute('name', 'nacl_module'); - naclModule.setAttribute('id', 'file_io'); - naclModule.setAttribute('width', width); - naclModule.setAttribute('height',height); - naclModule.setAttribute('src', tool + '/' + name + '.nmf'); - naclModule.setAttribute('type', 'application/x-nacl'); - listenerDiv.appendChild(naclModule); - } - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - naclModule = document.getElementById('nacl_module'); - updateStatus('SUCCESS'); - } - - // Handle a message coming from the NaCl module. - function handleMessage(message_event) { - alert(message_event.data); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - updateStatus('Page loaded.'); - if (naclModule == null) { - tool = ExtractSearchParameter('tool', 'newlib'); - updateStatus('Creating embed: ' + tool) - createNaClModule('hello_world', tool, 200, 200) - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus('Waiting.'); - } - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('statusField'); - if (statusField) { - statusField.innerHTML = statusText; - } - } - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>Native Client Simple Module</h1> -<h2>Status: <code id="statusField">NO-STATUS</code></h2> - <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element to - ensure that the listeners are active before the NaCl module 'load' event - fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or - pp::Instance.PostMessage() (in C++) from within the initialization code in - your NaCl module. - - The src points to a manifest file, which provides the Native Client plug-in - a mapping between architecture and NaCl Executable (NEXE). - - We use a non-zero sized embed to give Chrome space to place the bad plug-in - graphic, if there is a problem. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - </div> -</body> -</html> diff --git a/native_client_sdk/src/examples/hello_world/hello_world.nmf b/native_client_sdk/src/examples/hello_world/hello_world.nmf deleted file mode 100644 index 78df8e1..0000000 --- a/native_client_sdk/src/examples/hello_world/hello_world.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "hello_world_x86_64.nexe"}, - "x86-32": {"url": "hello_world_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/hello_world/index.html b/native_client_sdk/src/examples/hello_world/index.html new file mode 100644 index 0000000..c0586bd --- /dev/null +++ b/native_client_sdk/src/examples/hello_world/index.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/hello_world_gles/example.dsc b/native_client_sdk/src/examples/hello_world_gles/example.dsc index 13076162..48d16fa 100644 --- a/native_client_sdk/src/examples/hello_world_gles/example.dsc +++ b/native_client_sdk/src/examples/hello_world_gles/example.dsc @@ -1,8 +1,8 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { - 'NAME' : 'hello_world', + 'NAME' : 'hello_world_gles', 'TYPE' : 'main', 'SOURCES' : ['hello_world.cc', 'matrix.cc', 'matrix.h'], 'CXXFLAGS': [ @@ -20,5 +20,12 @@ ], 'DEST': 'examples', 'NAME': 'hello_world_gles', + 'TITLE': 'Hello World GLES 2.0', + 'DESC': """ +The Hello World GLES 2.0 example demonstrates how to create a 3D cube +that rotates. This is a simpler example than the tumbler example, and +written in C. It loads the assets using URLLoader.""", + 'INFO': 'Teaching focus: 3D graphics, URL Loader.' } + diff --git a/native_client_sdk/src/examples/hello_world_gles/hello_world_gles.html b/native_client_sdk/src/examples/hello_world_gles/hello_world_gles.html deleted file mode 100644 index 1cdf716..0000000 --- a/native_client_sdk/src/examples/hello_world_gles/hello_world_gles.html +++ /dev/null @@ -1,87 +0,0 @@ -<!DOCTYPE html> -<html> - <!-- - Copyright (c) 2012 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> -<head> - <title>Hello, World!</title> - <script type="text/javascript"> - helloWorldModule = null; // Global application object. - statusText = 'NO-STATUS'; - - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - helloWorldModule = document.getElementById('hello_world'); - updateStatus('SUCCESS'); - } - - // Handle a message coming from the NaCl module. - function handleMessage(message_event) { - alert(message_event.data); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - if (helloWorldModule == null) { - updateStatus('LOADING...'); - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus(); - } - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('statusField'); - if (statusField) { - statusField.innerHTML = statusText; - } - } - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>Native Client Simple Module</h1> -<h2>Status: <code id="statusField">NO-STATUS</code></h2> - <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element to - ensure that the listeners are active before the NaCl module 'load' event - fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or - pp::Instance.PostMessage() (in C++) from within the initialization code in - your NaCl module. - - The src points to a manifest file, which provides the Native Client plug-in - a mapping between architecture and NaCl Executable (NEXE). - - We use a non-zero sized embed to give Chrome space to place the bad plug-in - graphic, if there is a problem. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - - <embed name="nacl_module" - id="hello_world" - width=640 height=480 - src="hello_world_gles.nmf" - type="application/x-nacl" /> - </div> -</body> -</html> diff --git a/native_client_sdk/src/examples/hello_world_gles/index.html b/native_client_sdk/src/examples/hello_world_gles/index.html new file mode 100644 index 0000000..19dc438 --- /dev/null +++ b/native_client_sdk/src/examples/hello_world_gles/index.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>', 640, 480)"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/hello_world_gles/matrix.h b/native_client_sdk/src/examples/hello_world_gles/matrix.h index 54db6d8..7db7985 100644 --- a/native_client_sdk/src/examples/hello_world_gles/matrix.h +++ b/native_client_sdk/src/examples/hello_world_gles/matrix.h @@ -33,4 +33,5 @@ void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat); void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg, Matrix_t mat); void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat); -#endif // EXAMPLES_HELLO_WORLD_GLES_MATRIX_H
\ No newline at end of file +#endif // EXAMPLES_HELLO_WORLD_GLES_MATRIX_H + diff --git a/native_client_sdk/src/examples/hello_world_interactive/example.dsc b/native_client_sdk/src/examples/hello_world_interactive/example.dsc index dd52ac9..c59e619 100644 --- a/native_client_sdk/src/examples/hello_world_interactive/example.dsc +++ b/native_client_sdk/src/examples/hello_world_interactive/example.dsc @@ -1,8 +1,8 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { - 'NAME' : 'hello_world', + 'NAME' : 'hello_world_interactive', 'TYPE' : 'main', 'SOURCES' : [ 'hello_world.cc', @@ -13,5 +13,13 @@ ], 'DEST': 'examples', 'NAME': 'hello_world_interactive', + 'TITLE': 'Interactive Hello World in C++', + 'DESC': """ +The Interactive Hello World C++ example demonstrates the basic structure +of all Native Client applications. This example loads a Native Client module +which uses two way interaction with JavaScript whenever a button is clicked. +The NaCl module will respond with the number 42 or the reversed version of the +string in the text box when the appropriate button is clicked.""", + 'INFO': 'Basic HTML, JavaScript, C++ PPAPI, and Messaging API.', } diff --git a/native_client_sdk/src/examples/hello_world_interactive/hello_world.nmf b/native_client_sdk/src/examples/hello_world_interactive/hello_world.nmf deleted file mode 100644 index 78df8e1..0000000 --- a/native_client_sdk/src/examples/hello_world_interactive/hello_world.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "hello_world_x86_64.nexe"}, - "x86-32": {"url": "hello_world_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/hello_world_interactive/index.html b/native_client_sdk/src/examples/hello_world_interactive/index.html new file mode 100644 index 0000000..561fd2e --- /dev/null +++ b/native_client_sdk/src/examples/hello_world_interactive/index.html @@ -0,0 +1,63 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript"> + function fortyTwo() { + naclModule.postMessage('fortyTwo'); + } + + function reverseText() { + updateStatus('Reversing'); + // Grab the text from the text box, pass it into reverseText() + var inputBox = document.getElementById('inputBox'); + naclModule.postMessage('reverseText:' + inputBox.value); + // Note: a |false| return tells the <form> tag to cancel the GET action + // when submitting the form. + return false; + } + </script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1>Native Client Simple Module</h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> + <div> + <textarea id="inputBox" name="inputBox" rows="4" cols="50">Hello World</textarea> + <div/> + <table> + <button id="fortyTwoButton" onclick="fortyTwo()">Call fortyTwo()</button> + <button id="reverseTextButton" onclick="reverseText()">Call reverseText()</button> + <table/> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/index.html b/native_client_sdk/src/examples/index.html index c400f42..06ead20 100644 --- a/native_client_sdk/src/examples/index.html +++ b/native_client_sdk/src/examples/index.html @@ -43,27 +43,15 @@ simple way to build a NaCl application using See the link for further information. </p></dd> <dl> - <dt><a href="hello_world_newlib/hello_world.html"> - Hello World (NEWLIB)</a></dt> + <dt><a href="hello_world/index.html">Hello World</a></dt> <dd>The Hello World In C example demonstrates the basic structure of all Native Client applications. This example loads a Native Client module. The page tracks the status of the module as it load. On a successful load, the module will post a message containing the string "Hello World" back to JavaScript which will display it as an alert. - <p>Teaching focus: Basic HTML, JavaScript, and module architecture.</p> - </dd> - <dt><a href="hello_world_glibc/hello_world.html"> - Hello World (GLIBC)</a></dt> - <dd>The Hello World (GLIBC) example is identical to the one above, with the - exception that it used the GLIBC toolchain which uses Shared Objects. The use - of Shared Objects means a more complicated manifest file (NMF) which is needed - to allow the application to find the libraries. The NMF is automatically - generated as part of the build process, by scanning the application for - dependencies. - <p>Teaching focus: Basic HTML, JavaScript, Shared Objects, and module - architecture.</p> - </dd> - <dt><a href="hello_world_interactive/hello_world.html"> + <p>Teaching focus: Basic HTML, JavaScript, and module architecture.</p> + </dd> + <dt><a href="hello_world_interactive/index.html"> Interactive Hello World in C++</a></dt> <dd>The Interactive Hello World C++ example demonstrates the basic structure of all Native Client applications. This example loads a Native Client module @@ -77,44 +65,51 @@ See the link for further information. <h3>Common APIs</h3> <dd><p>The following set of examples illustrate various Pepper APIs including audio, 2D, 3D, file I/O, input and urls.</p></dd> -<dt><a href="sine_synth/sine_synth.html">Sine Wave Synthesizer</a></dt> + <dt><a href="sine_synth/index.html">Sine Wave Synthesizer</a></dt> <dd> The Sine Wave Synthesizer example demonstrates playing sound (a sine wave). Enter the desired frequency and hit play to start, stop to end. The frequency box will display "Loading, please wait." while the module loads. <p>Teaching focus: Audio.</p> </dd> -<dt><a href="input_events/input_events.html">Input Events</a></dt> + + <dt><a href="input_events/index.html">Input Events</a></dt> <dd> The Input Events example demonstrates how to handle events triggered by the user. This example allows a user to interact with a square representing a module instance. Events are displayed on the screen as the user clicks, scrolls, types, inside or outside of the square. - - <p>Teaching focus: Keyboard and mouse input, view change, and focus events.</p> + <p>Teaching focus: Keyboard and mouse input, view change, and focus events.</p> </dd> - <dt><a href="pi_generator/pi_generator.html">Pi Generator</a></dt> + + <dt><a href="pi_generator/index.html">Pi Generator</a></dt> <dd> The Pi Generator example demonstrates creating a helper thread that estimate pi using the Monte Carlo method while randomly putting 1,000,000,000 points inside a 2D square that shares two sides with a quarter circle. - - <p>Teaching focus: Thread creation, 2D graphics, view change events.</p> + <p>Teaching focus: Thread creation, 2D graphics, view change events.</p> </dd> - <dt><a href="tumbler/tumbler.html">Tumbler</a></dt> + + <dt><a href="tumbler/index.html">Tumbler</a></dt> <dd> The Tumbler example demonstrates how to create a 3D cube that you can rotate with your mouse while pressing the left mouse button. This example creates a 3D context and draws to it using OpenGL ES. The JavaScript implements a virtual trackball interface to map mouse movements into 3D rotations using simple 3D vector math and quaternions. - - <p>Teaching focus: 3D graphics</p> + <p>Teaching focus: 3D graphics</p> + </dd> + + <dt><a href="hello_world_gles/index.html">Hello World GLES 2.0</a></dt> + <dd> The Hello World GLES 2.0 example demonstrates how to create a 3D cube + that rotates. This is a simpler example than the tumbler example, and + written in C. It loads the assets using URLLoader. + <p>Teaching focus: 3D graphics, URL Loader</p> </dd> - <dt><a href="geturl/geturl.html">Get URL</a></dt> + + <dt><a href="geturl/index.html">Get URL</a></dt> <dd> The Get URL example demonstrates fetching an URL and then displaying its contents. - - <p>Teaching focus: URL loading.</p> + <p>Teaching focus: URL loading.</p> </dd> - <dt><a href="file_io/file_io.html">File I/O</a></dt> + <dt><a href="file_io/index.html">File I/O</a></dt> <dd> The File IO example demonstrates saving, loading, and deleting files from the persistent file store. @@ -125,7 +120,7 @@ audio, 2D, 3D, file I/O, input and urls.</p></dd> <dd><p>The following set of examples illustrate various common concepts such as showing load progress, using Shared Objects (dynamic libraries), mulithreading...</p></dd> -<dt><a href="dlopen/dlopen.html">Dynamic Library Open (GLIBC)</a></dt> +<dt><a href="dlopen/index.html">Dynamic Library Open (GLIBC)</a></dt> <dd> The dlopen example demonstrates how build dynamic libraries and then open and use them at runtime. When the page loads, type in a question and hit enter or click the ASK! button. The question and answer will be @@ -141,14 +136,14 @@ mulithreading...</p></dd> <p>Teaching focus: Progress event handling.</p> </dd> -<dt><a href="pong/pong.html">Pong</a></dt> +<dt><a href="pong/index.html">Pong</a></dt> <dd> The Pong example demonstrates how to create a basic 2D video game and how to store application information in a local persistent file. This game uses up and down arrow keyboard input events to move the paddle. <p>Teaching focus: File I/O, 2D graphics, input events.</p> </dd> - <dt><a href="multithreaded_input_events/mt_input_events.html">Multi-threaded + <dt><a href="multithreaded_input_events/index.html">Multi-threaded Input Events</a></dt> <dd>The Multithreaded Input Events example combines HTML, Javascript, and C++ (the C++ is compiled to create a .nexe file). @@ -159,7 +154,7 @@ mulithreading...</p></dd> result of the worker thread to the browser. <p>Teaching focus: Multithreaded event handling.</p> </dd> - <dt><a href="fullscreen_tumbler/fullscreen_tumbler.html">Full-screen + <dt><a href="fullscreen_tumbler/index.html">Full-screen Tumbler</a></dt> <dd>This is a modified version of the Tumbler example above that supports full-screen display. It is in every way identical to Tumbler in @@ -167,21 +162,21 @@ mulithreading...</p></dd> full-screen display by pressing the Enter key. <p>Teaching focus: Full-screen</p> </dd> - <dt><a href="mouselock/mouselock.html">Mouse Lock</a></dt> + <dt><a href="mouselock/index.html">Mouse Lock</a></dt> <dd> The Mouselock example demonstrates how to use the MouseLock API to hide the mouse cursor. Mouse lock is only available in full-screen mode. You can lock and unlock the mouse while in full-screen mode by pressing the Enter key. <p>Teaching focus: Mouse lock, Full-screen</p> </dd> - <dt><a href="websocket/websocket.html">Websocket</a></dt> + <dt><a href="websocket/index.html">Websocket</a></dt> <dd> The Websocket example demonstrates how to use the Websocket API. The user first connects to the test server: ws://html5rocks.websocket.org/echo by clicking on the 'Connect'' button. Then hitting Send' will cause the app to send the message to the server and retrieve the reply. <p>Teaching focus: Websockets</p> </dd> - <dt><a href="file_histogram/file_histogram.html">Get URL</a></dt> + <dt><a href="file_histogram/index.html">File Histogram</a></dt> <dd> The File Histogram example demonstrates prompting the user for a file, passing the file contents to NativeClient as a VarArrayBuffer, then drawing a histogram representing the contents of the file to a 2D square. diff --git a/native_client_sdk/src/examples/input_events/example.dsc b/native_client_sdk/src/examples/input_events/example.dsc index 2fb44b3..b7dff21 100644 --- a/native_client_sdk/src/examples/input_events/example.dsc +++ b/native_client_sdk/src/examples/input_events/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'input_events', @@ -9,5 +9,12 @@ ], 'DEST': 'examples', 'NAME': 'input_events', + 'TITLE': 'Input Events', + 'DESC': """ +The Input Events example demonstrates how to handle events triggered by +the user. This example allows a user to interact with a square representing a +module instance. Events are displayed on the screen as the user clicks, +scrolls, types, inside or outside of the square.""", + 'INFO': 'Keyboard and mouse input, view change, and focus events.' } diff --git a/native_client_sdk/src/examples/input_events/input_events.html b/native_client_sdk/src/examples/input_events/index.html index 3f1695d..6ed42a8 100644 --- a/native_client_sdk/src/examples/input_events/input_events.html +++ b/native_client_sdk/src/examples/input_events/index.html @@ -1,13 +1,14 @@ <!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> <head> - <title>Input Events</title> - + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> <script type="text/javascript"> var kMaxArraySize = 20; var messageArray = new Array(); @@ -30,7 +31,7 @@ </script> </head> <body> -<h1>InputEvent Handling Example</h1> +<h1><TITLE></h1> <div id="listener"> <script type="text/javascript"> $('listener').addEventListener('message', receiveMessage, true); @@ -39,7 +40,7 @@ <embed name="nacl_module" id="event_module" width=400 height=400 - src="input_events.nmf" + src="<tc>/<NAME>.nmf" type="application/x-nacl" style="background-color:gray" /> </div> diff --git a/native_client_sdk/src/examples/input_events/input_events.nmf b/native_client_sdk/src/examples/input_events/input_events.nmf deleted file mode 100644 index ab4392f..0000000 --- a/native_client_sdk/src/examples/input_events/input_events.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "input_events_x86_64.nexe"}, - "x86-32": {"url": "input_events_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/load_progress/example.dsc b/native_client_sdk/src/examples/load_progress/example.dsc index 04ca5cc..1d66c0a 100644 --- a/native_client_sdk/src/examples/load_progress/example.dsc +++ b/native_client_sdk/src/examples/load_progress/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'load_progress', @@ -10,5 +10,13 @@ 'DATA': ['check_browser.js'], 'DEST': 'examples', 'NAME': 'load_progress', + 'TITLE': 'Load Progress', + 'DESC': """ +The Load Progress example demonstrates how to listen for and handle +events that occur while a NaCl module loads. This example listens for +different load event types and dispatches different events to their +respective handler. This example also checks for valid browser version and +shows how to calculate and display loading progress.""", + 'INFO': 'Progress event handling.' } diff --git a/native_client_sdk/src/examples/load_progress/load_progress.html b/native_client_sdk/src/examples/load_progress/index.html index d9a09c6..45594b4 100644 --- a/native_client_sdk/src/examples/load_progress/load_progress.html +++ b/native_client_sdk/src/examples/load_progress/index.html @@ -1,7 +1,7 @@ <!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> @@ -196,7 +196,7 @@ <embed name="nacl_module" id="load_progress" width=0 height=0 - src="load_progress.nmf" + src="<tc>/load_progress.nmf" type="application/x-nacl" /> <script type="text/javascript"> diff --git a/native_client_sdk/src/examples/load_progress/load_progress.nmf b/native_client_sdk/src/examples/load_progress/load_progress.nmf deleted file mode 100644 index 4018ead..0000000 --- a/native_client_sdk/src/examples/load_progress/load_progress.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "load_progress_x86_64.nexe"}, - "x86-32": {"url": "load_progress_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/mouselock/example.dsc b/native_client_sdk/src/examples/mouselock/example.dsc index 1ee44cc..056cf4a 100644 --- a/native_client_sdk/src/examples/mouselock/example.dsc +++ b/native_client_sdk/src/examples/mouselock/example.dsc @@ -9,6 +9,13 @@ ], 'DATA': ['check_browser.js'], 'DEST': 'examples', - 'NAME': 'mouselock' + 'NAME': 'mouselock', + 'TITLE': 'Mouse Lock', + 'DESC': """ +The Mouselock example demonstrates how to use the MouseLock API to hide +the mouse cursor. Mouse lock is only available in full-screen mode. You can +lock and unlock the mouse while in full-screen mode by pressing the Enter key. +""", + 'INFO': 'Teaching focus: Mouse lock, Full-screen.' } diff --git a/native_client_sdk/src/examples/mouselock/index.html b/native_client_sdk/src/examples/mouselock/index.html new file mode 100644 index 0000000..addf617 --- /dev/null +++ b/native_client_sdk/src/examples/mouselock/index.html @@ -0,0 +1,79 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>', 300, 300)"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <h1>Full-screen and Mouse-lock Example</h1> + <ul> + <li>There are two different kinds of fullscreen mode: "tab fullscreen" and + "browser fullscreen". + <ul> + <li>Tab fullscreen refers to when a tab enters fullscreen mode via the + JS or Pepper fullscreen API.</li> + <li>Browser fullscreen refers to the user putting the browser itself + into fullscreen mode from the UI (e.g., pressing F11).</li> + </ul> + <span style="font-weight:bold"> + NOTE: Mouse lock is only allowed in "tab fullscreen" mode. + </span> + </li> + <li>Lock mouse: + <ul> + <li>left click in the grey box; or</li> + <li>right click in the box to ensure that it is focused and + then press Enter key. (You could verify that the tooltip window is + dismissed properly by this second approach.)</li> + </ul> + </li> + <li>Unlock mouse voluntarily (i.e., NaCl module unlocks mouse): + <ul> + <li>press Enter.</li> + </ul> + </li> + <li>Unlock mouse involuntarily (i.e. Chrome unlocks mouse): + <ul> + <li>lose focus; or</li> + <li>press Esc key; or</li> + <li>exit from the "tab fullscreen" mode.</li> + </ul> + </li> + </ul> + <p>Clicking the mouse inside the grey square takes the NaCl module to/from + combined fullscreen and mouselock mode.</p> + <p>While in fullscreen, pressing Enter will exit/enter mouse lock mode.</p> + + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/mouselock/mouselock.html b/native_client_sdk/src/examples/mouselock/mouselock.html deleted file mode 100644 index 7a4ba3f..0000000 --- a/native_client_sdk/src/examples/mouselock/mouselock.html +++ /dev/null @@ -1,108 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> -<!-- -Copyright (c) 2011 The Chromium Authors. All rights reserved. -Use of this source code is governed by a BSD-style license that can be -found in the LICENSE file. ---> -<head> - <meta http-equiv="Pragma" content="no-cache" /> - <meta http-equiv="Expires" content="-1" /> - <script type="text/javascript" src="check_browser.js"></script> - <script> - // Check for Native Client support in the browser before the DOM loads. - var isValidBrowser = false; - var browserSupportStatus = 0; - // Fullscreen and mouselock support is in Chrome version 16. - var CHROME_MINIMUM_VERSION = 16; - - var checker = new browser_version.BrowserChecker( - CHROME_MINIMUM_VERSION, - navigator["appVersion"], - navigator["plugins"]); - checker.checkBrowser(); - - isValidBrowser = checker.getIsValidBrowser(); - browserSupportStatus = checker.getBrowserSupportStatus(); - - function handleMessage(message_event) { - console.log(message_event.data); - } - </script> - <title>Full-screen and Mouse-lock Example</title> -</head> -<body title="This tooltip should not be shown if the mouse is locked."> - <h1>Full-screen and Mouse-lock Example</h1> - <ul> - <li>There are two different kinds of fullscreen mode: "tab fullscreen" and - "browser fullscreen". - <ul> - <li>Tab fullscreen refers to when a tab enters fullscreen mode via the - JS or Pepper fullscreen API.</li> - <li>Browser fullscreen refers to the user putting the browser itself - into fullscreen mode from the UI (e.g., pressing F11).</li> - </ul> - <span style="font-weight:bold"> - NOTE: Mouse lock is only allowed in "tab fullscreen" mode. - </span> - </li> - <li>Lock mouse: - <ul> - <li>left click in the grey box; or</li> - <li>right click in the box to ensure that it is focused and - then press Enter key. (You could verify that the tooltip window is - dismissed properly by this second approach.)</li> - </ul> - </li> - <li>Unlock mouse voluntarily (i.e., NaCl module unlocks mouse): - <ul> - <li>press Enter.</li> - </ul> - </li> - <li>Unlock mouse involuntarily (i.e. Chrome unlocks mouse): - <ul> - <li>lose focus; or</li> - <li>press Esc key; or</li> - <li>exit from the "tab fullscreen" mode.</li> - </ul> - </li> - </ul> - <p>Clicking the mouse inside the grey square takes the NaCl module to/from - combined fullscreen and mouselock mode.</p> - <p>While in fullscreen, pressing Enter will exit/enter mouse lock mode.</p> - <!-- Load the published .nexe. This includes the 'src' attribute which - shows how to load multi-architecture modules. Each entry in the "nexes" - object in the .nmf manifest file is a key-value pair: the key is the runtime - ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module. - To load the debug versions of your .nexes, set the 'src' attribute to the - _dbg.nmf version of the manifest file. - - Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element to - ensure that the listeners are active before the NaCl module 'load' event - fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or - pp::Instance.PostMessage() (in C++) from within the initialization code in - your NaCl module. - --> - <div id="listener"> - <script type="text/javascript"> - if (browserSupportStatus == - browser_version.BrowserChecker.StatusValues.CHROME_VERSION_TOO_OLD) { - alert('This example will only work on Chrome version ' + - CHROME_MINIMUM_VERSION + - ' or later.'); - } else { - var listener = document.getElementById('listener') - listener.addEventListener('message', handleMessage, true); - // Create two instances of the NaCl module. - listener.innerHTML = '<embed id="mouselock_view" ' + - 'type="application/x-nacl" ' + - 'src="mouselock.nmf" ' + - 'width="300" height="300" />'; - } - </script> - </div> -</body> -</html> diff --git a/native_client_sdk/src/examples/mouselock/mouselock.nmf b/native_client_sdk/src/examples/mouselock/mouselock.nmf deleted file mode 100644 index 8c69546..0000000 --- a/native_client_sdk/src/examples/mouselock/mouselock.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "mouselock_x86_64.nexe"}, - "x86-32": {"url": "mouselock_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/multithreaded_input_events/example.dsc b/native_client_sdk/src/examples/multithreaded_input_events/example.dsc index 88fb13e..48f3c3b 100644 --- a/native_client_sdk/src/examples/multithreaded_input_events/example.dsc +++ b/native_client_sdk/src/examples/multithreaded_input_events/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'mt_input_events', @@ -15,5 +15,15 @@ ], 'DEST': 'examples', 'NAME': 'mt_input_events', + 'TITLE': 'Multi-threaded Input Events', + 'DESC': """ +The Multithreaded Input Events example combines HTML, Javascript, +and C++ (the C++ is compiled to create a .nexe file). +The C++ shows how to handle input events in a multi-threaded application. +The main thread converts input events to non-pepper events and puts them on +a queue. The worker thread pulls them off of the queue, converts them to a +string, and then uses CallOnMainThread so that PostMessage can be send the +result of the worker thread to the browser.""", + 'INFO': 'Multithreaded event handling.' } diff --git a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.html b/native_client_sdk/src/examples/multithreaded_input_events/index.html index 7e85e1c..70f7c48 100644 --- a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.html +++ b/native_client_sdk/src/examples/multithreaded_input_events/index.html @@ -1,7 +1,7 @@ <!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> @@ -54,7 +54,7 @@ <embed name="nacl_module" id="event_module" width=400 height=400 - src="mt_input_events.nmf" + src="<tc>/mt_input_events.nmf" type="application/x-nacl" style="background-color:gray" /> </div> diff --git a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.nmf b/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.nmf deleted file mode 100644 index 347bdff..0000000 --- a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "mt_input_events_x86_64.nexe"}, - "x86-32": {"url": "mt_input_events_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/pi_generator/example.dsc b/native_client_sdk/src/examples/pi_generator/example.dsc index 00016f4..306fca1 100644 --- a/native_client_sdk/src/examples/pi_generator/example.dsc +++ b/native_client_sdk/src/examples/pi_generator/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'pi_generator', @@ -13,5 +13,11 @@ ], 'DEST': 'examples', 'NAME': 'pi_generator', + 'TITLE': 'Monte Carlo Estimate for Pi', + 'DESC': """ +The Pi Generator example demonstrates creating a helper thread that +estimate pi using the Monte Carlo method while randomly putting 1,000,000,000 +points inside a 2D square that shares two sides with a quarter circle.""", + 'INFO': 'Thread creation, 2D graphics, view change events.' } diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.html b/native_client_sdk/src/examples/pi_generator/index.html index 399944a..ca24580 100644 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.html +++ b/native_client_sdk/src/examples/pi_generator/index.html @@ -1,8 +1,7 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> @@ -72,7 +71,7 @@ <embed name="nacl_module" id="piGenerator" width=200 height=200 - src="pi_generator.nmf" + src="<tc>/pi_generator.nmf" type="application/x-nacl" /> </div> <br /> diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.nmf b/native_client_sdk/src/examples/pi_generator/pi_generator.nmf deleted file mode 100644 index 62d8d39..0000000 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "pi_generator_x86_64.nexe"}, - "x86-32": {"url": "pi_generator_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/pong/example.dsc b/native_client_sdk/src/examples/pong/example.dsc index 3df89f0..e698737 100644 --- a/native_client_sdk/src/examples/pong/example.dsc +++ b/native_client_sdk/src/examples/pong/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'pong', @@ -15,5 +15,11 @@ ], 'DEST': 'examples', 'NAME': 'pong', + 'TITLE': 'Pong', + 'DESC': """ +The Pong example demonstrates how to create a basic 2D video game and +how to store application information in a local persistent file. This game +uses up and down arrow keyboard input events to move the paddle.""", + 'INFO': 'File I/O, 2D graphics, input events.' } diff --git a/native_client_sdk/src/examples/pong/index.html b/native_client_sdk/src/examples/pong/index.html new file mode 100644 index 0000000..37fa878 --- /dev/null +++ b/native_client_sdk/src/examples/pong/index.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript" > + var paintInterval = null; + function pageDidUnload() { + clearInterval(paintInterval); + } + function resetScore() { + naclModule.postMessage("resetScore"); + } + </script> +</head> +<body onunload="pageDidUnload()" onload="pageDidLoad('<NAME>', '<tc>', 800, 600)"> +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + window.webkitStorageInfo.requestQuota(PERSISTENT, 1024); + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> + <p id="score"></p> + <button onclick="resetScore()">Reset score</button> + <p id="error_log"></p> +</body> +</html> diff --git a/native_client_sdk/src/examples/pong/pong.html b/native_client_sdk/src/examples/pong/pong.html deleted file mode 100644 index 19f95a9..0000000 --- a/native_client_sdk/src/examples/pong/pong.html +++ /dev/null @@ -1,74 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> - <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. - --> - <head> - <title>Pong</title> - <script type="text/javascript"> - var pong = null; - var paintInterval = null; - - // Handle a message coming from the NaCl module. The message payload is - // assumed to contain the current game score. Update the score text - // display with this value. - // Note that errors are also sent to this handler. A message starting - // with 'ERROR' is considered an error, all other strings are assumed - // to be scores. - function handleMessage(message_event) { - if (message_event.data.indexOf('ERROR') == 0) { - document.getElementById('error_log').innerHTML = message_event.data; - } else { - document.getElementById('score').innerHTML = message_event.data; - } - } - - function pageDidUnload() { - clearInterval(paintInterval); - } - function resetScore() { - pong = document.getElementById('pong'); - pong.postMessage("resetScore"); - } - </script> - </head> - <body id="bodyId" onunload="pageDidUnload()"> - <h1>Pong</h1> - <!-- Load the published .nexe. This includes the 'src' attribute which - shows how to load multi-architecture modules. Each entry in the "nexes" - object in the .nmf manifest file is a key-value pair: the key is the - runtime ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl - module. To load the debug versions of your .nexes, set the 'src' - attribute to the _dbg.nmf version of the manifest file. - - Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' - and a 'message' event listener attached. This wrapping method is used - instead of attaching the event listeners directly to the <EMBED> element to - ensure that the listeners are active before the NaCl module 'load' event - fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or - pp::Instance.PostMessage() (in C++) from within the initialization code in - your NaCl module. - --> - <div id="listener"> - <script type="text/javascript"> - window.webkitStorageInfo.requestQuota(PERSISTENT, 1024); - var listener = document.getElementById('listener') - listener.addEventListener('message', handleMessage, true); - </script> - - <embed name="nacl_module" - id="pong" - width=800 height=600 - src="pong.nmf" - type="application/x-nacl" /> - </div> - <br /> - <p id="score"> - </p> - <button onclick="resetScore()">Reset score</button> - <p id="error_log"></p> - </body> -</html> diff --git a/native_client_sdk/src/examples/pong/pong.nmf b/native_client_sdk/src/examples/pong/pong.nmf deleted file mode 100644 index fd250d2..0000000 --- a/native_client_sdk/src/examples/pong/pong.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "pong_x86_64.nexe"}, - "x86-32": {"url": "pong_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/sine_synth/example.dsc b/native_client_sdk/src/examples/sine_synth/example.dsc index 43e7f29..6bd2245 100644 --- a/native_client_sdk/src/examples/sine_synth/example.dsc +++ b/native_client_sdk/src/examples/sine_synth/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'sine_synth', @@ -9,5 +9,11 @@ ], 'DEST': 'examples', 'NAME': 'sine_synth', + 'TITLE': 'Sine Wave Synthesizer', + 'DESC': """ +The Sine Wave Synthesizer example demonstrates playing sound (a sine +wave). Enter the desired frequency and hit play to start, stop to end. The +frequency box will display "Loading, please wait." while the module loads.""", + 'INFO': 'Audio.' } diff --git a/native_client_sdk/src/examples/sine_synth/index.html b/native_client_sdk/src/examples/sine_synth/index.html new file mode 100644 index 0000000..9fba6dc --- /dev/null +++ b/native_client_sdk/src/examples/sine_synth/index.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html> + <!-- + Copyright (c) 2012 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. + --> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> + <script type="text/javascript" src="common.js"></script> + <script type="text/javascript" > + function toggleSound(flag) { + naclModule.postMessage('setFrequency:' + + document.getElementById('frequency_field').value); + if (flag) { + naclModule.postMessage('playSound'); + } else { + naclModule.postMessage('stopSound'); + } + } + + function changeFrequency(freq) { + naclModule.postMessage('setFrequency:' + freq); + } + </script> +</head> +<body onload="pageDidLoad('<NAME>', '<tc>')"> + +<h1><TITLE></h1> +<h2>Status: <code id="statusField">NO-STATUS</code></h2> + <p>Click the button to start and stop the sine wave playing.</p> + <button onclick="toggleSound(true)">Play</button> + <button onclick="toggleSound(false)">Stop</button> + <p>Enter the frequency of the sine wave:</p> + <input type="text" size="15" id="frequency_field" + value="#undef" onchange="changeFrequency(this.value)" /> + + <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' + and a 'message' event listener attached. This wrapping method is used + instead of attaching the event listeners directly to the <EMBED> element to + ensure that the listeners are active before the NaCl module 'load' event + fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or + pp::Instance.PostMessage() (in C++) from within the initialization code in + your NaCl module. + + The src points to a manifest file, which provides the Native Client plug-in + a mapping between architecture and NaCl Executable (NEXE). + + We use a non-zero sized embed to give Chrome space to place the bad plug-in + graphic, if there is a problem. + --> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + </div> +</body> +</html> diff --git a/native_client_sdk/src/examples/sine_synth/sine_synth.nmf b/native_client_sdk/src/examples/sine_synth/sine_synth.nmf deleted file mode 100644 index f778455..0000000 --- a/native_client_sdk/src/examples/sine_synth/sine_synth.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "sine_synth_x86_64.nexe"}, - "x86-32": {"url": "sine_synth_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/tumbler/example.dsc b/native_client_sdk/src/examples/tumbler/example.dsc index 3c12588..19d184a 100644 --- a/native_client_sdk/src/examples/tumbler/example.dsc +++ b/native_client_sdk/src/examples/tumbler/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib'], 'TARGETS': [ { 'NAME' : 'tumbler', @@ -33,5 +33,13 @@ ], 'DEST': 'examples', 'NAME': 'tumbler', + 'TITLE': 'Tumbler', + 'DESC': """ +The Tumbler example demonstrates how to create a 3D cube that you can +rotate with your mouse while pressing the left mouse button. This example +creates a 3D context and draws to it using OpenGL ES. The JavaScript +implements a virtual trackball interface to map mouse movements into 3D +rotations using simple 3D vector math and quaternions.""", + 'INFO': '3D graphics' } diff --git a/native_client_sdk/src/examples/tumbler/tumbler.html b/native_client_sdk/src/examples/tumbler/index.html index 95ae946..f2bee02 100644 --- a/native_client_sdk/src/examples/tumbler/tumbler.html +++ b/native_client_sdk/src/examples/tumbler/index.html @@ -1,13 +1,14 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> - <head> - <title>Interactive Cube Example</title> +<head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <title><TITLE></title> <script type="text/javascript"> // Provide the tumbler namespace tumbler = {}; @@ -17,8 +18,8 @@ <script type="text/javascript" src="tumbler.js"></script> <script type="text/javascript" src="vector3.js"></script> <script type="text/javascript" src="trackball.js"></script> - </head> - <body id="bodyId"> +</head> + <body id="bodyId"> <h1>Interactive Cube Example</h1> <p> The Native Client module executed in this page draws a 3D cube @@ -30,4 +31,4 @@ tumbler.application.run('tumbler_view'); </script> </body> -</HTML> +</html> diff --git a/native_client_sdk/src/examples/tumbler/tumbler.js b/native_client_sdk/src/examples/tumbler/tumbler.js index fe7616e..0c2a31b 100644 --- a/native_client_sdk/src/examples/tumbler/tumbler.js +++ b/native_client_sdk/src/examples/tumbler/tumbler.js @@ -127,7 +127,7 @@ tumbler.Application.prototype.run = function(opt_contentDivName) { // attribute to the _dbg.nmf version of the manifest file. contentDiv.innerHTML = '<embed id="' + tumbler.Application.DomIds_.MODULE + '" ' - + 'src=tumbler.nmf ' + + 'src=newlib/tumbler.nmf ' + 'type="application/x-nacl" ' + 'width="480" height="480" />' } diff --git a/native_client_sdk/src/examples/tumbler/tumbler.nmf b/native_client_sdk/src/examples/tumbler/tumbler.nmf deleted file mode 100644 index 0ac6302..0000000 --- a/native_client_sdk/src/examples/tumbler/tumbler.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "tumbler_x86_64.nexe"}, - "x86-32": {"url": "tumbler_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/examples/websocket/example.dsc b/native_client_sdk/src/examples/websocket/example.dsc index 79d0ea0..7943b99 100644 --- a/native_client_sdk/src/examples/websocket/example.dsc +++ b/native_client_sdk/src/examples/websocket/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'pnacl'], 'TARGETS': [ { 'NAME' : 'websocket', @@ -9,5 +9,12 @@ ], 'DEST': 'examples', 'NAME': 'websocket', + 'TITLE': 'Websocket', + 'DESC': """ +The Websocket example demonstrates how to use the Websocket API. The +user first connects to the test server: ws://html5rocks.websocket.org/echo by +clicking on the 'Connect'' button. Then hitting Send' will cause the app to +send the message to the server and retrieve the reply.""", + 'INFO': 'Websockets' } diff --git a/native_client_sdk/src/examples/websocket/websocket.html b/native_client_sdk/src/examples/websocket/index.html index d2db565..96a2064 100644 --- a/native_client_sdk/src/examples/websocket/websocket.html +++ b/native_client_sdk/src/examples/websocket/index.html @@ -60,7 +60,7 @@ </head> <body onload="pageDidLoad()"> -<h1>WebSocket API Example</h1> +<h1><TITLE></h1> <p> <form action="#" onsubmit="doConnect(); return false;"> <input type="text" id="url" @@ -89,7 +89,7 @@ <embed name="nacl_module" id="websocket" width=0 height=0 - src="websocket.nmf" + src="<tc>/websocket.nmf" type="application/x-nacl" /> </div> </p> diff --git a/native_client_sdk/src/examples/websocket/websocket.nmf b/native_client_sdk/src/examples/websocket/websocket.nmf deleted file mode 100644 index 189344a..0000000 --- a/native_client_sdk/src/examples/websocket/websocket.nmf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "program": { - "x86-64": {"url": "websocket_x86_64.nexe"}, - "x86-32": {"url": "websocket_x86_32.nexe"} - } -} diff --git a/native_client_sdk/src/tools/create_nmf.py b/native_client_sdk/src/tools/create_nmf.py index da6924c..eb004c4 100755 --- a/native_client_sdk/src/tools/create_nmf.py +++ b/native_client_sdk/src/tools/create_nmf.py @@ -38,7 +38,7 @@ ARCH_LOCATION = { NAME_ARCH_MAP = { '32.nexe': 'x86-32', - '64.nexe': 'x64-64', + '64.nexe': 'x86-64', 'arm.nexe': 'arm' } |