Adding NaCl Modules to Applications


This topic describes how to embed an existing Native Client module in a Smart TV application.


Related Info


The Native Client (NaCl) technology and the Tizen Studio allow you to embed an existing NaCl module in your application. A previously-compiled Native Client module can be needed in a project for various reasons, for example due to security requirements, when the module's source code is already compiled and cannot be modified.

Prerequisites

To embed an existing NaCl module, you need the following files:

  • Compiled NaCl modules (".nexe" files) for the desired architectures
  • Manifest file pointing to the ".nexe" files

You also need information on the module's functionality and API.

Embedding a Module

To embed a module, you must implement the following parts in the JavaScript/HTML5 component of the application:

  • HTML embed element on the Web page
  • JavaScript listeners for handling load, crash, and message events
  • Path to the manifest file

The following steps use the Hello World in C++ tutorial module. When the module is successfully loaded, it waits for incoming messages and, when it receives one, sends back the text "Echo from NaCl:" along with the original message text.

  1. In the Tizen Studio, create an empty NaCl project.

  2. Build the project to create the makefile definitions needed to package the application.

  3. When implementing an existing NaCl module, the source files and build result from the empty project are not needed. Delete the built ".nexe", ".pexe", and ".nmf" files from the "CurrentBin" folder, and the existing C++ source files from the "src" folder.

  4. Copy the ".nexe" file you want to implement to the project's "CurrentBin" folder.

  5. In the "CurrentBin" folder, create a ".nmf" manifest file pointing to the module location.

    {
      "files": {},
      "program": {
        "arm": {
          "url": "hello_world_module.nexe"
        },
      }
    }
    
  6. Implement communication with the NaCl module in the "project.js" file.

    1. In the exampleSpecificActionAfterNaclLoad() method, send a message to the module using the postMessage() method:
    document.getElementById("nacl_module").postMessage("Hello World from JS");
    
    1. To see the message returned by the module, unlock the logs area:
    var uses_logging = true;
    
    1. To print the received message in the logs area and scroll the log, in the "communication.js" file, at the end of the handleNaClMessage() method, add the following code:
    logs.value += message;
    logs.scrollTop = logs.scrollHeight;
    
  7. Build and launch the package.