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