blob: 0610c5ed4eb0175755ddf56fc609e617a2942c90 [file] [log] [blame]
// 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.
/// @file
/// This example demonstrates loading and running a very simple NaCl
/// module. To load the NaCl module, the browser first looks for the
/// CreateModule() factory method (at the end of this file). It calls
/// CreateModule() once to load the module code from your .nexe. After the
/// .nexe code is loaded, CreateModule() is not called again.
/// Once the .nexe code is loaded, the browser then calls the
/// LoadProgressModule::CreateInstance()
/// method on the object returned by CreateModule(). It calls CreateInstance()
/// each time it encounters an <embed> tag that references your NaCl module.
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
namespace load_progress {
/// The Instance class. One of these exists for each instance of your NaCl
/// module on the web page. The browser will ask the Module object to create
/// a new Instance for each occurrence of the <embed> tag that has these
/// attributes:
/// <pre>
/// type="application/x-nacl"
/// nacl="hello_world.nmf"
/// </pre>
class LoadProgressInstance : public pp::Instance {
explicit LoadProgressInstance(PP_Instance instance)
: pp::Instance(instance) {}
virtual ~LoadProgressInstance() {}
/// The Module class. The browser calls the CreateInstance() method to create
/// an instance of your NaCl module on the web page. The browser creates a new
/// instance for each <embed> tag with
/// <code>type="application/x-nacl"</code>.
class LoadProgressModule : public pp::Module {
LoadProgressModule() : pp::Module() {}
virtual ~LoadProgressModule() {}
/// Create and return a HelloWorldInstance object.
/// @param[in] instance a handle to a plug-in instance.
/// @return a newly created HelloWorldInstance.
/// @note The browser is responsible for calling @a delete when done.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new LoadProgressInstance(instance);
} // namespace load_progress
namespace pp {
/// Factory function called by the browser when the module is first loaded.
/// The browser keeps a singleton of this module. It calls the
/// CreateInstance() method on the object you return to make instances. There
/// is one instance per <embed> tag on the page. This is the main binding
/// point for your NaCl module with the browser.
/// @return new LoadProgressModule.
/// @note The browser is responsible for deleting returned @a Module.
Module* CreateModule() {
return new load_progress::LoadProgressModule();
} // namespace pp