15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){{+bindTo:partials.standard_nacl_article}} 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<section id="technical-overview"> 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<span id="overview"></span><h1 id="technical-overview"><span id="overview"></span>Technical Overview</h1> 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<div class="contents local" id="contents" style="display: none"> 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#why-use-native-client" id="id7">Why use Native Client?</a></li> 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#benefits-of-native-client" id="id8">Benefits of Native Client</a></li> 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#common-use-cases" id="id9">Common use cases</a></li> 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><p class="first"><a class="reference internal" href="#how-native-client-works" id="id10">How Native Client works</a></p> 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#toolchains" id="id11">Toolchains</a></li> 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#security" id="id12">Security</a></li> 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#portability" id="id13">Portability</a></li> 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</li> 171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><p class="first"><a class="reference internal" href="#structure-of-a-web-application" id="id14">Structure of a web application</a></p> 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#pepper-plug-in-api" id="id15">Pepper plug-in API</a></li> 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</li> 221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><a class="reference internal" href="#where-to-start" id="id16">Where to start</a></li> 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</div><p><strong>Native Client</strong> (NaCl) is an open-source technology for running native 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)compiled code in the browser, with the goal of maintaining the portability 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)and safety that users expect from web applications. Native Client expands web 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciprogramming beyond JavaScript, enabling you to enhance your web applications 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciusing your preferred language. This document describes some of the key benefits 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciand common use cases of Native Client.</p> 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Google has implemented the open-source <a class="reference external" href="http://www.chromium.org/nativeclient">Native Client project</a> in the Chrome browser on Windows, Mac, 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciLinux, and Chrome OS. The <a class="reference internal" href="/native-client/sdk/download.html"><em>Native Client Software Development Kit (SDK)</em></a>, itself an open-source project, lets you create web applications 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccithat use NaCl and run in Chrome across multiple platforms.</p> 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>A Native Client web application consists of JavaScript, HTML, CSS, and a NaCl 351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccimodule written in a language supported by the SDK. The NaCl SDK currently 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccisupports C and C++; as compilers for additional languages are developed, the SDK 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciwill be updated.</p> 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<div class="figure"> 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<img alt="A web application with and without Native Client" src="/native-client/images/web-app-with-nacl.png" /> 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p class="caption">A web application with and without Native Client</p> 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</div> 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>Native Client comes in two flavors: traditional (NaCl) and portable (PNaCl). 431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTraditional, which must be distributed through the Chrome Web Store lets you 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitarget a specific hardware platform. Portable can run on the open web. A 451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibitcode file that can be loaded from any web server is downloaded to a client 461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccimachine and converted to hardware-specific code before any execution. For 471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccidetails, see <a class="reference internal" href="/native-client/nacl-and-pnacl.html"><em>NaCl and PNaCl</em></a>.</p> 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h2 id="why-use-native-client"><span id="id1"></span>Why use Native Client?</h2> 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Native Client open-source technology is designed to run compiled code 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccisecurely inside a browser at near-native speeds. Native Client gives web 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciapplications some advantages of desktop software. Specifically, it provides the 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccimeans to fully harness the client’s computational resources for applications 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccisuch as:</p> 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>3D games</li> 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>multimedia editors</li> 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>CAD modeling</li> 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>client-side data analytics</li> 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>interactive simulations.</li> 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</ul> 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>Native Client gives C and C++ (and other languages targeting it) the same level 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciof portability and safety as JavaScript.</p> 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h2 id="benefits-of-native-client"><span id="id2"></span>Benefits of Native Client</h2> 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>Benefits of Native Client include:</p> 651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<ul class="small-gap"> 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Graphics, audio, and much more:</strong> Running native code modules that render 2D 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)and 3D graphics, play audio, respond to mouse and keyboard events, run on 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccimultiple threads, and access memory directly—all without requiring the user 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccito install a plug-in.</li> 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Portability:</strong> Writing your applications once and running them on multiple 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccioperating systems (Windows, Linux, Mac, and Chrome OS) and CPU architectures 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci(x86 and ARM).</li> 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Easy migration path to the web:</strong> Leveraging years of work in existing 741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccidesktop applications. Native Client makes the transition from the desktop to 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccia web application significantly easier because it supports C and C++.</li> 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Security:</strong> Protecting the user’s system from malicious or buggy 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciapplications through Native Client’s double sandbox model. This model offers 781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccithe safety of traditional web applications without sacrificing performance 791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciand without requiring users to install a plug-in.</li> 801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Performance:</strong> Running at speeds within 5% to 15% of a native desktop 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciapplication. Native Client also allows applications to harness all available 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCPU cores via a threading API. This enables demanding applications such as 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconsole-quality games to run inside the browser.</li> 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h2 id="common-use-cases"><span id="id3"></span>Common use cases</h2> 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Typical use cases for Native Client include the following:</p> 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Existing software components:</strong> Native Client lets you repurpose existing 891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciC and C++ software in web applications. You don’t need to rewrite and debug 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccicode that already works. It also lets your application take advantage of 911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccithings the browser does well such as handling user interaction and processing 921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccievents. You can also take advantage of the latest developments in HTML5.</li> 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><strong>Legacy desktop applications:</strong> Native Client provides a smooth migration 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)path from desktop applications to the web. You can port and recompile existing 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)code for the computation engine of your application directly to Native Client, 961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciand need rebuild only the user interface and event handling portions for the 971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibrowser.</li> 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><strong>Heavy computation in enterprise applications:</strong> Native Client can handle the 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)number crunching required by large-scale enterprise applications. To ensure 1001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciprotection of user data, Native Client lets you run complex cryptographic 1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccialgorithms directly in the browser so that unencrypted data never goes out 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciover the network.</li> 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><strong>Multimedia applications:</strong> Codecs for processing sounds, images, and movies 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)can be added to the browser in a Native Client module.</li> 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><strong>Games:</strong> Native Client lets web applications run at close to native 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)speed, reuse existing multithreaded/multicore C/C++ code bases, and 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)access low-latency audio, networking APIs, and OpenGL ES with programmable 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)shaders. Native Client is a natural fit for running a physics engine or 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)artificial intelligence module that powers a sophisticated web game. 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Native Client also enables applications to run unchanged across 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)many platforms.</li> 1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Any application that requires acceleration:</strong> Native Client fits seamlessly 1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciinto web applications. It’s up to you to decide to what extent to use it. 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Use of Native Client covers the full spectrum from complete applications to 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccismall optimized routines that accelerate vital parts of web applications.</li> 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)<h2 id="how-native-client-works"><span id="link-how-nacl-works"></span>How Native Client works</h2> 1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>Native Client is an umbrella name for a set of related software components for 1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccideveloping C/C++ applications and running them securely on the web. At a high 1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccilevel, Native Client consists of:</p> 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 1221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Toolchains:</strong> collections of development tools (compilers, linkers, etc.) 1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccithat transform C/C++ code to Portable Native Client modules or Native Client 1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccimodules.</li> 1251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>Runtime components:</strong> components embedded in the browser or other host 1261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciplatforms that allow execution of Native Client modules securely and 1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciefficiently.</li> 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>The following diagram shows how these components interact:</p> 1301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<div class="figure"> 1311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<img alt="The Native Client toolchains and their outputs" src="/native-client/images/nacl-pnacl-component-diagram.png" /> 1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p class="caption">The Native Client toolchains and their outputs</p> 1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</div> 1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h3 id="toolchains"><span id="id4"></span>Toolchains</h3> 1351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>A Native Client toolchain consists of a compiler, a linker, an assembler and 1361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciother tools that are used to convert C/C++ source code into a module that is 1371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciloadable by a browser.</p> 1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>The Native Client SDK provides two toolchains:</p> 1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<ul class="small-gap"> 1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>The left side of the diagram shows <strong>Portable Native Client</strong> (PNaCl, 1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccipronounced “pinnacle”). An LLVM based toolchain produces a single, portable 1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci(<strong>pexe</strong>) module. At runtime an ahead-of-time (AOT) translator, built into 1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccithe browser, translates the pexe into native code for the relevant client 1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciarchitecture.</li> 1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>The right side of the diagram shows <strong>(non-portable) Native Client</strong>. A GCC 1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibased toolchain produces multiple architecture-dependent (<strong>nexe</strong>) modules, 1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciwhich are packaged into an application. At runtime the browser determines 1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciwhich nexe to load based on the architecture of the client machine.</li> 1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</ul> 1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>The PNaCl toolchain is recommended for most applications. The NaCl-GCC 1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitoolchain should only be used for applications that won’t be distributed on the 1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciopen web.</p> 1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h3 id="security"><span id="id5"></span>Security</h3> 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Since Native Client permits the execution of native code on client machines, 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)special security measures have to be implemented:</p> 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li>The NaCl sandbox ensures that code accesses system resources only through 1581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccisafe, whitelisted APIs, and operates within its limits without attempting to 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)interfere with other code running either within the browser or outside it.</li> 1601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li>The NaCl validator statically analyzes code before running it to make sure it 1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccionly uses code and data patterns that are permitted and safe.</li> 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>These security measures are in addition to the existing sandbox in the 1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciChrome browser. The Native Client module always executes in a process with 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)restricted permissions. The only interaction between this process and the 1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccioutside world is through defined browser interfaces. Because of the 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)combination of the NaCl sandbox and the Chrome sandbox, we say that 1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciNative Client employs a <strong>double sandbox</strong> design.</p> 1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h3 id="portability"><span id="id6"></span>Portability</h3> 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Portable Native Client (PNaCl, prounounced “pinnacle”) employs state-of-the-art 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)compiler technology to compile C/C++ source code to a portable bitcode 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)executable (<strong>pexe</strong>). PNaCl bitcode is an OS- and architecture-independent 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)format that can be freely distributed on the web and <a class="reference internal" href="#link-nacl-in-web-apps"><em>embedded in web 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)applications</em></a>.</p> 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>The PNaCl translator is a component embedded in the Chrome browser; its task is 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)to run pexe modules. Internally, the translator compiles a pexe to a nexe 1771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci(described above), and then executes the nexe within the Native Client sandbox 1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccias described above. The translator uses intelligent caching to avoid 1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccire-compiling the pexe if it was previously compiled on the client’s browser.</p> 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>Native Client also supports the execution of nexe modules directly in the 1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibrowser. However, since nexes contain architecture-specific machine code, they 1821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciare not allowed to be distributed on the open web. They can only be used as part 1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciof applications and extensions that are installed from the Chrome Web Store.</p> 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>For more details on the difference between NaCl and PNaCl, see 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<a class="reference internal" href="/native-client/nacl-and-pnacl.html"><em>NaCl and PNaCl</em></a>.</p> 1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h2 id="structure-of-a-web-application"><span id="link-nacl-in-web-apps"></span>Structure of a web application</h2> 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p id="application-files">A Native Client application consists of a set of files:</p> 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 1891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><p class="first"><strong>HTML and CSS:</strong> The HTML file tells the browser where to find the manifest 1901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci(nmf file) through the embed tag.</p> 1911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<pre class="prettyprint"> 1921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<embed name="mygame" src="mygame.nmf" type="application/x-pnacl" /> 1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</pre> 1941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</li> 1951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><p class="first"><strong>Manifest:</strong> The manifest identifies the module to load and specifies 1961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccioptions. For example, “mygame.nmf” might look like this:</p> 1971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<pre class="prettyprint"> 1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci{... 1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ... 2001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci "url": "mygame.pexe", 2011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 2021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</pre> 2031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</li> 2041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<li><strong>pexe (portable NaCl file):</strong> A compiled Native Client module. It uses the 2051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<a class="reference internal" href="#link-pepper"><em>Pepper API</em></a>, which provides a bridge to JavaScript and 2061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciother browser resources.</li> 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 2081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<div class="figure"> 2091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<img alt="Structure of a web application" src="/native-client/images/nacl-in-a-web-app.png" /> 2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p class="caption">Structure of a web application</p> 2111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci</div> 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>For more details, see <a class="reference internal" href="/native-client/devguide/coding/application-structure.html"><em>Application Structure</em></a>.</p> 2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<h3 id="pepper-plug-in-api"><span id="link-pepper"></span>Pepper plug-in API</h3> 2141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>The Pepper plug-in API (PPAPI), called <strong>Pepper</strong> for convenience, is an 2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciopen-source, cross-platform C/C++ API for web browser plug-ins. Pepper allows a 2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciC/C++ module to communicate with the hosting browser and to access system-level 2171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccifunctions in a safe and portable way. One of the security constraints in Native 2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciClient is that modules cannot make OS-level calls. Pepper provides analogous 2191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciAPIs that modules can use instead.</p> 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>You can use the Pepper APIs to gain access to the full array of browser 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)capabilities, including:</p> 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<ul class="small-gap"> 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><a class="reference internal" href="/native-client/devguide/coding/message-system.html"><em>Talking to the JavaScript code in your application</em></a> from the C++ code in your NaCl module.</li> 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><a class="reference internal" href="/native-client/devguide/coding/file-io.html"><em>Doing file I/O</em></a>.</li> 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><a class="reference internal" href="/native-client/devguide/coding/audio.html"><em>Playing audio</em></a>.</li> 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<li><a class="reference internal" href="/native-client/devguide/coding/3D-graphics.html"><em>Rendering 3D graphics</em></a>.</li> 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)</ul> 2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci<p>Pepper includes both a <a class="reference internal" href="/native-client/c-api.html"><em>C API</em></a> and a <a class="reference internal" href="/native-client/cpp-api.html"><em>C++ API</em></a>. 2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciThe C++ API is a set of bindings written on top of the C API. For additional 2301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciinformation about Pepper, see <a class="reference external" href="http://code.google.com/p/ppapi/wiki/Concepts">Pepper Concepts</a>.</p> 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<h2 id="where-to-start">Where to start</h2> 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)<p>The <a class="reference internal" href="/native-client/quick-start.html"><em>Quick Start</em></a> document provides links to downloads and 2331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccidocumentation to help you get started with developing and distributing Native 2341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciClient applications.</p> 2355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)</section> 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){{/partials.standard_nacl_article}} 238