github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/test/ppapi/basic_debug.html (about) 1 <!DOCTYPE html> 2 <html> 3 <!-- 4 Copyright (c) 2014 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>message</title> 10 <script type="text/javascript"> 11 MessageModule = null; // Global application object. 12 statusText = 'NO-STATUS'; 13 14 // Indicate load success. 15 function moduleDidLoad() { 16 MessageModule = document.getElementById('message'); 17 updateStatus('SUCCESS'); 18 } 19 20 // The 'message' event handler. This handler is fired when the NaCl module 21 // posts a message to the browser by calling PPB_Messaging.PostMessage() 22 // (in C) or pp::Instance.PostMessage() (in C++). This implementation 23 // simply displays the content of the message in an alert panel. 24 function handleMessage(message_event) { 25 console.log(message_event.data); 26 } 27 28 // If the page loads before the Native Client module loads, then set the 29 // status message indicating that the module is still loading. Otherwise, 30 // do not change the status message. 31 function pageDidLoad() { 32 if (MessageModule == null) { 33 updateStatus('LOADING...'); 34 } else { 35 // It's possible that the Native Client module onload event fired 36 // before the page's onload event. In this case, the status message 37 // will reflect 'SUCCESS', but won't be displayed. This call will 38 // display the current message. 39 updateStatus(); 40 } 41 } 42 43 // Set the global status message. If the element with id 'statusField' 44 // exists, then set its HTML to the status message as well. 45 // opt_message The message test. If this is null or undefined, then 46 // attempt to set the element with id 'statusField' to the value of 47 // |statusText|. 48 function updateStatus(opt_message) { 49 if (opt_message) 50 statusText = opt_message; 51 var statusField = document.getElementById('statusField'); 52 if (statusField) { 53 statusField.innerHTML = statusText; 54 } 55 } 56 </script> 57 </head> 58 <body onload="pageDidLoad()"> 59 <h1>Hello World Demo</h1> 60 <p> 61 Click on the image to zoom in. 62 </p> 63 <p> 64 <!-- 65 Load the published nexe. 66 67 Note: The <embed> element is wrapped inside a <div>, which has both a 'load' 68 and a 'message' event listener attached. This wrapping method is used 69 instead of attaching the event listeners directly to the <embed> element to 70 ensure that the listeners are active before the NaCl module 'load' event 71 fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or 72 pp::Instance.PostMessage() (in C++) from within the initialization code in 73 your module. 74 --> 75 <div id="listener"> 76 <script type="text/javascript"> 77 var listener = document.getElementById('listener'); 78 listener.addEventListener('load', moduleDidLoad, true); 79 listener.addEventListener('message', handleMessage, true); 80 </script> 81 82 <embed id="message" 83 width=640 height=480 84 src="message_debug.nmf" 85 type="application/x-nacl" /> 86 </div> 87 </p> 88 89 <h2>Status <code id="statusField">NO-STATUS</code></h2> 90 </body> 91 </html>