158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)<!DOCTYPE html>
258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)<html>
358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  <!--
40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Copyright (c) 2013 The Chromium Authors. All rights reserved.
558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  Use of this source code is governed by a BSD-style license that can be
658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  found in the LICENSE file.
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  -->
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)<head>
958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  <title>hello_tutorial</title>
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  <script type="text/javascript">
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    HelloTutorialModule = null;  // Global application object.
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    statusText = 'NO-STATUS';
1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // Indicate load success.
1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    function moduleDidLoad() {
1858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      HelloTutorialModule = document.getElementById('hello_tutorial');
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      updateStatus('SUCCESS');
2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // The 'message' event handler.  This handler is fired when the NaCl module
2358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // posts a message to the browser by calling PPB_Messaging.PostMessage()
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // (in C) or pp::Instance.PostMessage() (in C++).  This implementation
2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // simply displays the content of the message in an alert panel.
2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    function handleMessage(message_event) {
2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      alert(message_event.data);
2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // If the page loads before the Native Client module loads, then set the
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // status message indicating that the module is still loading.  Otherwise,
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // do not change the status message.
3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    function pageDidLoad() {
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      if (HelloTutorialModule == null) {
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        updateStatus('LOADING...');
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      } else {
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // It's possible that the Native Client module onload event fired
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // before the page's onload event.  In this case, the status message
3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // will reflect 'SUCCESS', but won't be displayed.  This call will
4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // display the current message.
4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        updateStatus();
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      }
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // Set the global status message.  If the element with id 'statusField'
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // exists, then set its HTML to the status message as well.
4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // opt_message The message test.  If this is null or undefined, then
4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // attempt to set the element with id 'statusField' to the value of
4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    // |statusText|.
5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    function updateStatus(opt_message) {
5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      if (opt_message)
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        statusText = opt_message;
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      var statusField = document.getElementById('statusField');
5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      if (statusField) {
5558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        statusField.innerHTML = statusText;
5658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      }
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  </script>
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)</head>
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)<body onload="pageDidLoad()">
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  <h1>NaCl C++ Tutorial: Getting Started</h1>
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  <p>
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    <!--
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    Load the published pexe.
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    Note: Since this module does not use any real-estate in the browser, its
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    width and height are set to 0.
6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    Note: The <embed> element is wrapped inside a <div>, which has both a 'load'
70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    and a 'message' event listener attached.  This wrapping method is used
71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    instead of attaching the event listeners directly to the <embed> element to
72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    ensure that the listeners are active before the NaCl module 'load' event
73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    fires.  This also allows you to use PPB_Messaging.PostMessage() (in C) or
74d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    pp::Instance.PostMessage() (in C++) from within the initialization code in
75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    your module.
76d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    -->
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    <div id="listener">
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      <script type="text/javascript">
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        var listener = document.getElementById('listener');
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        listener.addEventListener('load', moduleDidLoad, true);
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        listener.addEventListener('message', handleMessage, true);
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      </script>
8358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      <embed id="hello_tutorial"
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)             width=0 height=0
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)             src="hello_tutorial.nmf"
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)             type="application/x-pnacl" />
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    </div>
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  </p>
9058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  <h2>Status <code id="statusField">NO-STATUS</code></h2>
9258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)</body>
9358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)</html>
94