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

Unified Diff: native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js

Issue 22503002: [NaCl SDK] Earth demo modifications for gonacl PNaCl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge master Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js
diff --git a/native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js b/native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js
index 9abdc0eedbcf38cd3cef7217c849ad94952064bf..f43e4a72c2f874ba3c4dc41b68fac040c4579999 100644
--- a/native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js
+++ b/native_client_sdk/src/gonacl_appengine/static/pnacl-demo/example.js
@@ -66,6 +66,7 @@ function createNaClModule(name, width, height, attrs) {
function attachDefaultListeners() {
var listenerDiv = document.getElementById('listener');
listenerDiv.addEventListener('load', moduleDidLoad, true);
+ listenerDiv.addEventListener('error', moduleLoadError, true);
listenerDiv.addEventListener('progress', moduleLoadProgress, true);
listenerDiv.addEventListener('message', handleMessage, true);
listenerDiv.addEventListener('crash', handleCrash, true);
@@ -102,9 +103,16 @@ function moduleDidLoad() {
bar.value = 100;
bar.max = 100;
naclModule = document.getElementById('nacl_module');
- updateStatus('RUNNING');
+ hideStatus();
+}
+
+function hideStatus() {
+ document.getElementById('statusField').style.display = 'none';
+ document.getElementById('progress').style.display = 'none';
+}
- setAuxElementsVisibility(true);
+function moduleLoadError(event) {
+ updateStatus('Load failed.');
}
/**
@@ -113,6 +121,8 @@ function moduleDidLoad() {
* @param {Object} event
*/
function moduleLoadProgress(event) {
+ document.getElementById('progress').style.display = 'block';
+
var loadPercent = 0.0;
var bar = document.getElementById('progress');
bar.max = 100;
@@ -139,53 +149,6 @@ function startsWith(s, prefix) {
}
/**
- * Add a message to an element with id "log".
- *
- * This function is used by the default "log:" message handler.
- *
- * @param {string} message The message to log.
- */
-function logMessage(message) {
- document.getElementById('log').textContent = logMessageArray.join('');
- console.log(message);
-}
-
-var defaultMessageTypes = {
- 'alert': alert,
- 'log': logMessage
-};
-
-/**
- * Called when the NaCl module sends a message to JavaScript (via
- * PPB_Messaging.PostMessage())
- *
- * This event listener is registered in createNaClModule above.
- *
- * @param {Event} message_event A message event. message_event.data contains
- * the data sent from the NaCl module.
- */
-function handleMessage(message_event) {
- if (typeof message_event.data === 'string') {
- for (var type in defaultMessageTypes) {
- if (defaultMessageTypes.hasOwnProperty(type)) {
- if (startsWith(message_event.data, type + ':')) {
- func = defaultMessageTypes[type];
- func(message_event.data.slice(type.length + 1));
- return;
- }
- }
- }
- }
-
- if (typeof window.handleMessage !== 'undefined') {
- window.handleMessage(message_event);
- return;
- }
-
- logMessage('Unhandled message: ' + message_event.data + '\n');
-}
-
-/**
* Called when the DOM content has loaded; i.e. the page's document is fully
* parsed. At this point, we can safely query any elements in the document via
* document.querySelector, document.getElementById, etc.
@@ -196,11 +159,7 @@ function handleMessage(message_event) {
* @param {Object} attrs Optional dictionary of additional attributes.
*/
function domContentLoaded(name, width, height, attrs) {
- // 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.
- setAuxElementsVisibility(false);
- updateStatus('Page loaded.');
+ updateStatus('Loading...');
if (!browserSupportsPNaCl()) {
updateStatus('Browser does not support PNaCl or PNaCl is disabled');
} else if (naclModule == null) {
@@ -228,25 +187,20 @@ function domContentLoaded(name, width, height, attrs) {
function updateStatus(opt_message) {
var statusField = document.getElementById('statusField');
if (statusField) {
- statusField.innerHTML = opt_message;
- }
-}
-
-function postThreadFunc(numThreads) {
- return function() {
- naclModule.postMessage({'message' : 'set_threads',
- 'value' : numThreads});
+ statusField.style.display = 'block';
+ statusField.textContent = opt_message;
}
}
// Add event listeners after the NaCl module has loaded. These listeners will
// forward messages to the NaCl module via postMessage()
function attachListeners() {
- var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32];
- for (var i = 0; i < threads.length; i++) {
- document.getElementById('radio' + i).addEventListener('click',
- postThreadFunc(threads[i]));
- }
+ document.getElementById('threadCount').addEventListener('change',
+ function() {
+ var value = parseInt(document.getElementById('threadCount').value);
+ naclModule.postMessage({'message': 'set_threads',
+ 'value': value});
+ });
document.getElementById('zoomRange').addEventListener('change',
function() {
var value = parseFloat(document.getElementById('zoomRange').value);

Powered by Google App Engine
This is Rietveld 408576698