github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/test/ppapi/network.html (about) 1 <!DOCTYPE html> 2 <html> 3 <!-- 4 Copyright (c) 2013 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>Network Test</title> 10 <script type="text/javascript"> 11 FileIOModule = null; // Global application object. 12 statusText = 'NO-STATUS'; 13 14 // Indicate load success. 15 function moduleDidLoad() { 16 FileIOModule = document.getElementById('fileIO'); 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 (FileIOModule == 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 <link rel="chrome-application-definition" href="manifest.json"> 58 </head> 59 <body onload="pageDidLoad()"> 60 <h1>Network Test</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="network" 84 width=640 height=480 85 src="network.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>