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