[android_webview] Call super.onMeasure in AwTestContainerView.
[chromium-blink-merge.git] / native_client_sdk / doc_generated / overview.html
blob7886ddcbc6878fac0790a6502687a7e6428cebdb
1 {{+bindTo:partials.standard_nacl_article}}
3 <section id="technical-overview">
4 <span id="overview"></span><h1 id="technical-overview"><span id="overview"></span>Technical Overview</h1>
5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap">
7 <li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
8 <li><a class="reference internal" href="#why-use-native-client" id="id3">Why use Native Client?</a></li>
9 <li><a class="reference internal" href="#common-use-cases" id="id4">Common use cases</a></li>
10 <li><p class="first"><a class="reference internal" href="#how-native-client-works" id="id5">How Native Client works</a></p>
11 <ul class="small-gap">
12 <li><a class="reference internal" href="#security" id="id6">Security</a></li>
13 <li><a class="reference internal" href="#portability" id="id7">Portability</a></li>
14 <li><a class="reference internal" href="#toolchains" id="id8">Toolchains</a></li>
15 </ul>
16 </li>
17 <li><p class="first"><a class="reference internal" href="#native-client-in-a-web-application" id="id9">Native Client in a web application</a></p>
18 <ul class="small-gap">
19 <li><a class="reference internal" href="#pepper-plugin-api" id="id10">Pepper Plugin API</a></li>
20 </ul>
21 </li>
22 <li><a class="reference internal" href="#versioning" id="id11">Versioning</a></li>
23 <li><a class="reference internal" href="#where-to-start" id="id12">Where to start</a></li>
24 </ul>
26 </div><h2 id="introduction">Introduction</h2>
27 <p><strong>Native Client</strong> (NaCl) is an open-source technology for running native
28 compiled code in the browser, with the goal of maintaining the portability
29 and safety that users expect from web applications. Native Client expands web
30 programming beyond JavaScript, enabling developers to enhance their web
31 applications using their preferred language. This document describes some of
32 the key benefits and common use cases of Native Client.</p>
33 <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,
34 Linux, 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 developers create web
35 applications that use NaCl and run in Chrome across multiple platforms.</p>
36 <p>A web application that uses Native Client generally consists of a combination of
37 JavaScript, HTML, CSS, and a NaCl module that is written in a language supported
38 by the SDK. The NaCl SDK currently supports C and C++; as compilers for
39 additional languages are developed, the SDK will be updated to support those
40 languages as well.</p>
41 <img alt="/native-client/images/web-app-with-nacl.png" src="/native-client/images/web-app-with-nacl.png" />
42 <h2 id="why-use-native-client">Why use Native Client?</h2>
43 <p>Native Client open-source technology is designed to run compiled code
44 securely inside a browser at near-native speeds. Native Client puts web
45 applications on the same playing field as desktop software&#8212;it provides the
46 means to fully harness the client&#8217;s computational resources for applications
47 such as 3D games, multimedia editors, CAD modeling,
48 client-side data analytics, and interactive simulations.
49 Native Client also aims to give C and C++ (and eventually other languages) the
50 same level of portability and safety that JavaScript provides on the web today.</p>
51 <p>Important benefits of Native Client include:</p>
52 <ul class="small-gap">
53 <li><strong>Graphics, audio, and much more:</strong> Running native code modules that render 2D
54 and 3D graphics, play audio, respond to mouse and keyboard events, run on
55 multiple threads, and access memory directly&#8212;all without requiring
56 the user to install a plugin.</li>
57 <li><strong>Portability:</strong> Writing your applications once and running them on operating
58 systems (Windows, Linux, Mac, and Chrome OS) and CPU architectures (x86 and
59 ARM).</li>
60 <li><strong>Easy migration path to the web:</strong> Leveraging years of work in existing
61 desktop applications. Native Client makes the transition from the desktop to a
62 web application significantly easier because it supports C and C++.</li>
63 <li><strong>Security:</strong> Protecting the user&#8217;s system from malicious or buggy
64 applications through Native Client&#8217;s double sandbox model. This model offers
65 the safety of traditional web applications without sacrificing performance and
66 without requiring users to install a plugin.</li>
67 <li><strong>Performance:</strong> Running at speeds comparable to desktop applications (within
68 5-15% of native speed). Native Client also allows applications to harness all
69 available CPU cores via a threading API; this enables demanding applications
70 such as console-quality games to run inside the browser.</li>
71 </ul>
72 <h2 id="common-use-cases">Common use cases</h2>
73 <p>Typical use cases for Native Client include the following:</p>
74 <ul class="small-gap">
75 <li><strong>Existing software components:</strong> With support for C and C++, Native
76 Client lets you to reuse existing software modules in web applications. You
77 don&#8217;t need to rewrite and debug code that already works.</li>
78 <li><strong>Legacy desktop applications:</strong> Native Client provides a smooth migration
79 path from desktop applications to the web. You can port and recompile existing
80 code for the computation engine of your application directly to Native Client,
81 and need rebuild only the user interface and event handling portions for the
82 browser.</li>
83 <li><strong>Heavy computation in enterprise applications:</strong> Native Client can handle the
84 number crunching required by large-scale enterprise applications. To ensure
85 protection of user data, Native Client enables you to build complex
86 cryptographic algorithms directly into the browser so that unencrypted data
87 never goes out over the network.</li>
88 <li><strong>Multimedia applications:</strong> Codecs for processing sounds, images, and movies
89 can be added to the browser in a Native Client module.</li>
90 <li><strong>Games:</strong> Native Client lets web applications run at close to native
91 speed, reuse existing multithreaded/multicore C/C++ code bases, and
92 access low-latency audio, networking APIs, and OpenGL ES with programmable
93 shaders. Native Client is a natural fit for running a physics engine or
94 artificial intelligence module that powers a sophisticated web game.
95 Native Client also enables applications to run unchanged across
96 many platforms.</li>
97 <li><strong>Any application that requires acceleration</strong>: Native Client fits seamlessly
98 into web applications&#8212;it&#8217;s up to you to decide to what extent to use it.
99 Use of Native Client covers the full spectrum from complete applications to
100 small optimized routines that accelerate vital parts of web applications.</li>
101 </ul>
102 <h2 id="how-native-client-works"><span id="link-how-nacl-works"></span>How Native Client works</h2>
103 <p>Native Client is an umbrella name for a set of related software components that
104 provide a way to develop C/C++ applications and run them securely on the web.</p>
105 <p>At a high level, Native Client consists of:</p>
106 <ul class="small-gap">
107 <li><strong>Toolchains</strong>: Collections of development tools (compilers, linkers, etc.)
108 that transform C/C++ code to Native Client modules.</li>
109 <li><strong>Runtime components</strong>: components embedded in the browser or other
110 host platforms that allow execution of Native Client modules
111 securely and efficiently.</li>
112 </ul>
113 <p>The following diagram shows how these components interact:</p>
114 <img alt="/native-client/images/nacl-pnacl-component-diagram.png" src="/native-client/images/nacl-pnacl-component-diagram.png" />
115 <p>The left side of the diagram shows how to use Portable Native Client
116 (PNaCl, pronounced &#8220;pinnacle&#8221;). Developers use the PNaCl toolchain
117 to produce a single, portable (<strong>pexe</strong>) module. At runtime, a translator
118 built into the browser translates the pexe into native code for the
119 relevant client architecture. Translation occurs before any code is executed.</p>
120 <p>The right side of the diagram shows how to use (non-portable) Native Client.
121 Developers use a nacl-gcc based toolchain to produce multiple
122 architecture-dependent (<strong>nexe</strong>) modules, which are packaged into an
123 application. At runtime, the browser decides which nexe to load based
124 on the architecture of the client machine.</p>
125 <h3 id="security">Security</h3>
126 <p>Since Native Client permits the execution of native code on client machines,
127 special security measures have to be implemented:</p>
128 <ul class="small-gap">
129 <li>The NaCl sandbox ensures that code accesses system resources only through
130 safe, whitelisted APIs, and operates within its limits without attempting to
131 interfere with other code running either within the browser or outside it.</li>
132 <li>The NaCl validator statically analyzes code prior to running it
133 to make sure it only uses code and data patterns that are permitted and safe.</li>
134 </ul>
135 <p>The above security measures are in addition to the existing sandbox in the
136 Chrome browser&#8212;the Native Client module always executes in a process with
137 restricted permissions. The only interaction between this process and the
138 outside world is through sanctioned browser interfaces. Because of the
139 combination of the NaCl sandbox and the Chrome sandbox, we say that
140 Native Client employs a double sandbox design.</p>
141 <h3 id="portability">Portability</h3>
142 <p>Portable Native Client (PNaCl, prounounced &#8220;pinnacle&#8221;) employs state-of-the-art
143 compiler technology to compile C/C++ source code to a portable bitcode
144 executable (<strong>pexe</strong>). PNaCl bitcode is an OS- and architecture-independent
145 format that can be freely distributed on the web and <a class="reference internal" href="#link-nacl-in-web-apps"><em>embedded in web
146 applications</em></a>.</p>
147 <p>The PNaCl translator is a component embedded in the Chrome browser; its task is
148 to run pexe modules. Internally, the translator compiles a pexe to a nexe
149 (a native executable for the client platform&#8217;s architecture), and then executes
150 the nexe within the Native Client sandbox as described above. It also uses
151 intelligent caching to avoid re-compiling the pexe if it was previously compiled
152 on the client&#8217;s browser.</p>
153 <p>Native Client also supports the execution of nexe modules directly in the
154 browser. However, since nexes contain architecture-specific machine code,
155 they are not allowed to be distributed on the open web&#8212;they can only be
156 used as part of applications and extensions that are installed from the
157 Chrome Web Store.</p>
158 <p>For more details on the difference between NaCl and PNaCl, see
159 <a class="reference internal" href="/native-client/nacl-and-pnacl.html"><em>NaCl and PNaCl</em></a>.</p>
160 <h3 id="toolchains"><span id="id1"></span>Toolchains</h3>
161 <p>A toolchain is a set of tools used to create an application from a set of
162 source files. In the case of Native Client, a toolchain consists of a compiler,
163 linker, assembler and other tools that are used to convert an
164 application written in C/C++ into a module that is loadable by the browser.</p>
165 <p>The Native Client SDK provides two toolchains:</p>
166 <ul class="small-gap">
167 <li>a <strong>PNaCl toolchain</strong> for generating portable NaCl modules (pexe files)</li>
168 <li>a <strong>gcc-based toolchain (nacl-gcc)</strong> for generating non-portable NaCl modules
169 (nexe files)</li>
170 </ul>
171 <p>The PNaCl toolchain is recommended for most applications. The nacl-gcc
172 toolchain should only be used for applications that will not be distributed
173 on the open web.</p>
174 <h2 id="native-client-in-a-web-application"><span id="link-nacl-in-web-apps"></span>Native Client in a web application</h2>
175 <p id="application-files">A Native Client application consists of a set of files:</p>
176 <ul class="small-gap">
177 <li><strong>HTML</strong>, <strong>CSS</strong>, and <strong>JavaScript</strong> files, as in any modern web
178 application. The JavaScript code is responsible for communicating with the
179 NaCl module.</li>
180 <li>A <strong>pexe</strong> (portable NaCl) file. This module uses the <a class="reference internal" href="#link-pepper"><em>Pepper</em></a> API, which provides the bridge to JavaScript and
181 browser resources.</li>
182 <li>A Native Client <strong>manifest</strong> file that specifies the pexe to load, along with
183 some loading options. This manifest file is embedded into the HTML page
184 through an <code>&lt;embed&gt;</code> tag, as shown in the figure below.</li>
185 </ul>
186 <img alt="/native-client/images/nacl-in-a-web-app.png" src="/native-client/images/nacl-in-a-web-app.png" />
187 <p>For more details, see <a class="reference internal" href="/native-client/devguide/coding/application-structure.html"><em>Application Structure</em></a>.</p>
188 <h3 id="pepper-plugin-api"><span id="link-pepper"></span>Pepper Plugin API</h3>
189 <p>The Pepper Plugin API (PPAPI), called <strong>Pepper</strong> for convenience, is an
190 open-source, cross-platform C/C++ API for web browser plugins. From the point
191 of view of Native Client, Pepper allows a C/C++ module to communicate with
192 the hosting browser and get access to system-level functions in a safe and
193 portable way. One of the security constraints in Native Client is that modules
194 cannot make any OS-level calls directly. Pepper provides analogous APIs that
195 modules can target instead.</p>
196 <p>You can use the Pepper APIs to gain access to the full array of browser
197 capabilities, including:</p>
198 <ul class="small-gap">
199 <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>
200 <li><a class="reference internal" href="/native-client/devguide/coding/file-io.html"><em>Doing file I/O</em></a>.</li>
201 <li><a class="reference internal" href="/native-client/devguide/coding/audio.html"><em>Playing audio</em></a>.</li>
202 <li><a class="reference internal" href="/native-client/devguide/coding/3D-graphics.html"><em>Rendering 3D graphics</em></a>.</li>
203 </ul>
204 <p>Pepper includes both a C API and a C++ API. The C++ API is a set of bindings
205 written on top of the C API. For additional information about Pepper, see
206 <a class="reference external" href="http://code.google.com/p/ppapi/wiki/Concepts">Pepper Concepts</a>.</p>
207 <h2 id="versioning">Versioning</h2>
208 <p>Chrome is released on a six week cycle, and developer versions of Chrome are
209 pushed to the public beta channel three weeks before each release. As with any
210 software, each release of Chrome may include changes to Native Client and the
211 Pepper interfaces that may require modification to existing applications.
212 However, modules compiled for one version of Pepper/Chrome should work with
213 subsequent versions of Pepper/Chrome. The SDK includes multiple versions of the
214 Pepper APIs to help developers make adjustments to API changes and take
215 advantage of new features: <a class="reference external" href="/native-client/pepper_stable">stable</a>, <a class="reference external" href="/native-client/pepper_beta">beta</a> and <a class="reference external" href="/native-client/pepper_dev">dev</a>.</p>
216 <h2 id="where-to-start">Where to start</h2>
217 <p>The <a class="reference internal" href="/native-client/quick-start.html"><em>Quick Start</em></a> document provides links to downloads and
218 documentation that should help you get started with developing and distributing
219 Native Client applications.</p>
220 </section>
222 {{/partials.standard_nacl_article}}