blob: 60f3722702afa1cea75dc126df608f9ae8ec55db [file] [log] [blame]
<!DOCTYPE html>
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
<title>Hello, World!</title>
<script type="text/javascript">
helloWorldModule = null; // Global application object.
statusText = 'NO-STATUS';
// Indicate success when the NaCl module has loaded.
function moduleDidLoad() {
helloWorldModule = document.getElementById('hello_world');
// Handle a message coming from the NaCl module.
function handleMessage(message_event) {
// If the page loads before the Native Client module loads, then set the
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
function pageDidLoad() {
if (helloWorldModule == null) {
} else {
// It's possible that the Native Client module onload event fired
// before the page's onload event. In this case, the status message
// will reflect 'SUCCESS', but won't be displayed. This call will
// display the current message.
// Set the global status message. If the element with id 'statusField'
// exists, then set its HTML to the status message as well.
// opt_message The message test. If this is null or undefined, then
// attempt to set the element with id 'statusField' to the value of
// |statusText|.
function updateStatus(opt_message) {
if (opt_message)
statusText = opt_message;
var statusField = document.getElementById('statusField');
if (statusField) {
statusField.innerHTML = statusText;
<body onload="pageDidLoad()">
<h1>Native Client Simple Module</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
and a 'message' event listener attached. This wrapping method is used
instead of attaching the event listeners directly to the <EMBED> element to
ensure that the listeners are active before the NaCl module 'load' event
fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
pp::Instance.PostMessage() (in C++) from within the initialization code in
your NaCl module.
The src points to a manifest file, which provides the Native Client plug-in
a mapping between architecture and NaCl Executable (NEXE).
We use a non-zero sized embed to give Chrome space to place the bad plug-in
graphic, if there is a problem.
<div id="listener">
<script type="text/javascript">
var listener = document.getElementById('listener')
listener.addEventListener('load', moduleDidLoad, true);
listener.addEventListener('message', handleMessage, true);
<embed name="nacl_module"
width=200 height=200
type="application/x-nacl" />