Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: native_client_sdk/src/doc/overview.rst

Issue 581643004: Copy edit Learn Basics section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 .. _overview: 1 .. _overview:
2 2
3 ################## 3 ##################
4 Technical Overview 4 Technical Overview
5 ################## 5 ##################
6 6
7 .. contents:: 7 .. contents::
8 :local: 8 :local:
9 :backlinks: none 9 :backlinks: none
10 :depth: 2 10 :depth: 2
11 11
12 Introduction
13 ============
14
15 **Native Client** (NaCl) is an open-source technology for running native 12 **Native Client** (NaCl) is an open-source technology for running native
16 compiled code in the browser, with the goal of maintaining the portability 13 compiled code in the browser, with the goal of maintaining the portability
17 and safety that users expect from web applications. Native Client expands web 14 and safety that users expect from web applications. Native Client expands web
18 programming beyond JavaScript, enabling developers to enhance their web 15 programming beyond JavaScript, enabling you to enhance your web applications
19 applications using their preferred language. This document describes some of 16 using your preferred language. This document describes some of the key benefits
20 the key benefits and common use cases of Native Client. 17 and common use cases of Native Client.
21 18
22 Google has implemented the open-source `Native Client project 19 Google has implemented the open-source `Native Client project
23 <http://www.chromium.org/nativeclient>`_ in the Chrome browser on Windows, Mac, 20 <http://www.chromium.org/nativeclient>`_ in the Chrome browser on Windows, Mac,
24 Linux, and Chrome OS. The :doc:`Native Client Software Development Kit (SDK) 21 Linux, and Chrome OS. The :doc:`Native Client Software Development Kit (SDK)
25 <sdk/download>`, itself an open-source project, lets developers create web 22 <sdk/download>`, itself an open-source project, lets you create web applications
26 applications that use NaCl and run in Chrome across multiple platforms. 23 that use NaCl and run in Chrome across multiple platforms.
27 24
28 A web application that uses Native Client generally consists of a combination of 25 A Native Client web application consists of JavaScript, HTML, CSS, and a NaCl
29 JavaScript, HTML, CSS, and a NaCl module that is written in a language supported 26 module written in a language supported by the SDK. The NaCl SDK currently
30 by the SDK. The NaCl SDK currently supports C and C++; as compilers for 27 supports C and C++; as compilers for additional languages are developed, the SDK
31 additional languages are developed, the SDK will be updated to support those 28 will be updated.
32 languages as well.
33 29
34 .. image:: /images/web-app-with-nacl.png 30 .. figure:: /images/web-app-with-nacl.png
31 :alt: A web application with and without Native Client
32
33 A web application with and without Native Client
34
35 Native Client comes in two flavors: traditional (NaCl) and portable (PNaCl).
36 Traditional, which must be distributed through the Chrome Web Store lets you
37 target a specific hardware platform. Portable can run on any Chrome browser. A
38 bitcode file that can be loaded from any web server is downloaded to a client
39 machine and converted to hardware-specific code before any execution. For
40 details, see :doc:`NaCl and PNaCl </nacl-and-pnacl>`.
41
42 .. _why-use-native-client:
35 43
36 Why use Native Client? 44 Why use Native Client?
37 ====================== 45 ======================
38 46
39 Native Client open-source technology is designed to run compiled code 47 Native Client open-source technology is designed to run compiled code
40 securely inside a browser at near-native speeds. Native Client puts web 48 securely inside a browser at near-native speeds. Native Client gives web
41 applications on the same playing field as desktop software---it provides the 49 applications some advantages of desktop software. Specifically, it provides the
42 means to fully harness the client's computational resources for applications 50 means to fully harness the client's computational resources for applications
43 such as 3D games, multimedia editors, CAD modeling, 51 such as:
44 client-side data analytics, and interactive simulations. 52
53 - 3D games
54 - multimedia editors
55 - CAD modeling
56 - client-side data analytics
57 - interactive simulations.
58
45 Native Client also aims to give C and C++ (and eventually other languages) the 59 Native Client also aims to give C and C++ (and eventually other languages) the
46 same level of portability and safety that JavaScript provides on the web today. 60 same level of portability as JavaScript, but with greater safety.
binji 2014/09/18 17:58:38 not quite right; we shouldn't claim to be safer th
jpmedley 2014/09/18 19:03:00 I reversed this. Now I want to play devil's advoca
47 61
48 Important benefits of Native Client include: 62 .. _benefits-of-native-client:
63
64 Benefits of Native Client
65 =========================
66
67 Benefits of Native Client include:
49 68
50 * **Graphics, audio, and much more:** Running native code modules that render 2D 69 * **Graphics, audio, and much more:** Running native code modules that render 2D
51 and 3D graphics, play audio, respond to mouse and keyboard events, run on 70 and 3D graphics, play audio, respond to mouse and keyboard events, run on
52 multiple threads, and access memory directly---all without requiring 71 multiple threads, and access memory directly---all without requiring the user
53 the user to install a plugin. 72 to install a plug-in.
54 * **Portability:** Writing your applications once and running them on operating 73 * **Portability:** Writing your applications once and running them on multiple
55 systems (Windows, Linux, Mac, and Chrome OS) and CPU architectures (x86 and 74 operating systems (Windows, Linux, Mac, and Chrome OS) and CPU architectures
56 ARM). 75 (x86 and ARM).
57 * **Easy migration path to the web:** Leveraging years of work in existing 76 * **Easy migration path to the web:** Leveraging years of work in existing
58 desktop applications. Native Client makes the transition from the desktop to a 77 desktop applications. Native Client makes the transition from the desktop to
59 web application significantly easier because it supports C and C++. 78 a web application significantly easier because it supports C and C++.
60 * **Security:** Protecting the user's system from malicious or buggy 79 * **Security:** Protecting the user's system from malicious or buggy
61 applications through Native Client's double sandbox model. This model offers 80 applications through Native Client's double sandbox model. This model offers
62 the safety of traditional web applications without sacrificing performance and 81 the safety of traditional web applications without sacrificing performance
63 without requiring users to install a plugin. 82 and without requiring users to install a plug-in.
64 * **Performance:** Running at speeds comparable to desktop applications (within 83 * **Performance:** Running at speeds within 5% to 15% of a native desktop
65 5-15% of native speed). Native Client also allows applications to harness all 84 application. Native Client also allows applications to harness all available
66 available CPU cores via a threading API; this enables demanding applications 85 CPU cores via a threading API. This enables demanding applications such as
67 such as console-quality games to run inside the browser. 86 console-quality games to run inside the browser.
68 87
88 .. _common-use-cases:
89
69 Common use cases 90 Common use cases
70 ================ 91 ================
71 92
72 Typical use cases for Native Client include the following: 93 Typical use cases for Native Client include the following:
73 94
74 * **Existing software components:** With support for C and C++, Native 95 * **Existing software components:** Native Client lets you to repurpose existing
binji 2014/09/18 17:58:38 remove "to"
jpmedley 2014/09/18 19:03:00 Done.
75 Client lets you to reuse existing software modules in web applications. You 96 C and C++ software in web applications. You don't need to rewrite and debug
76 don't need to rewrite and debug code that already works. 97 code that already works.
77 * **Legacy desktop applications:** Native Client provides a smooth migration 98 * **Legacy desktop applications:** Native Client provides a smooth migration
78 path from desktop applications to the web. You can port and recompile existing 99 path from desktop applications to the web. You can port and recompile existing
79 code for the computation engine of your application directly to Native Client, 100 code for the computation engine of your application directly to Native Client,
80 and need rebuild only the user interface and event handling portions for the 101 and need rebuild only the user interface and event handling portions for the
81 browser. 102 browser.
103 * **Existing functionality:** Native Client allows you to embed existing
binji 2014/09/18 17:58:38 I'm not sure I understand what this first means by
jpmedley 2014/09/18 19:03:00 I don't remember what I was thinking that day. I'l
104 functionality in a web page. This lets your application take advantage of
105 things the browser does well such as handling user interaction and processing
106 events. You can also take advantage of the latest developments in HTML5.
82 * **Heavy computation in enterprise applications:** Native Client can handle the 107 * **Heavy computation in enterprise applications:** Native Client can handle the
83 number crunching required by large-scale enterprise applications. To ensure 108 number crunching required by large-scale enterprise applications. To ensure
84 protection of user data, Native Client enables you to build complex 109 protection of user data, Native Client lets you run complex cryptographic
85 cryptographic algorithms directly into the browser so that unencrypted data 110 algorithms directly in the browser so that unencrypted data never goes out
86 never goes out over the network. 111 over the network.
87 * **Multimedia applications:** Codecs for processing sounds, images, and movies 112 * **Multimedia applications:** Codecs for processing sounds, images, and movies
88 can be added to the browser in a Native Client module. 113 can be added to the browser in a Native Client module.
89 * **Games:** Native Client lets web applications run at close to native 114 * **Games:** Native Client lets web applications run at close to native
90 speed, reuse existing multithreaded/multicore C/C++ code bases, and 115 speed, reuse existing multithreaded/multicore C/C++ code bases, and
91 access low-latency audio, networking APIs, and OpenGL ES with programmable 116 access low-latency audio, networking APIs, and OpenGL ES with programmable
92 shaders. Native Client is a natural fit for running a physics engine or 117 shaders. Native Client is a natural fit for running a physics engine or
93 artificial intelligence module that powers a sophisticated web game. 118 artificial intelligence module that powers a sophisticated web game.
94 Native Client also enables applications to run unchanged across 119 Native Client also enables applications to run unchanged across
95 many platforms. 120 many platforms.
96 * **Any application that requires acceleration**: Native Client fits seamlessly 121 * **Any application that requires acceleration:** Native Client fits seamlessly
97 into web applications---it's up to you to decide to what extent to use it. 122 into web applications. It's up to you to decide to what extent to use it.
98 Use of Native Client covers the full spectrum from complete applications to 123 Use of Native Client covers the full spectrum from complete applications to
99 small optimized routines that accelerate vital parts of web applications. 124 small optimized routines that accelerate vital parts of web applications.
100 125
101 .. _link_how_nacl_works: 126 .. _link_how_nacl_works:
102 127
103 How Native Client works 128 How Native Client works
104 ======================= 129 =======================
105 130
106 Native Client is an umbrella name for a set of related software components that 131 Native Client is an umbrella name for a set of related software components for
107 provide a way to develop C/C++ applications and run them securely on the web. 132 developing C/C++ applications and running them securely on the web. At a high
133 level, Native Client consists of:
108 134
109 At a high level, Native Client consists of: 135 * **Toolchains:** collections of development tools (compilers, linkers, etc.)
110 136 that transform C/C++ code to Portable Native Client modules or Native Client
111 * **Toolchains**: Collections of development tools (compilers, linkers, etc.) 137 modules.
112 that transform C/C++ code to Native Client modules. 138 * **Runtime components:** components embedded in the browser or other host
113 * **Runtime components**: components embedded in the browser or other 139 platforms that allow execution of Native Client modules securely and
114 host platforms that allow execution of Native Client modules 140 efficiently.
115 securely and efficiently.
116 141
117 The following diagram shows how these components interact: 142 The following diagram shows how these components interact:
118 143
119 .. image:: /images/nacl-pnacl-component-diagram.png 144 .. figure:: /images/nacl-pnacl-component-diagram.png
145 :alt: The Native Client toolchains and their outputs
146
147 The Native Client toolchains and their outputs
120 148
121 The left side of the diagram shows how to use Portable Native Client 149 .. _toolchains:
122 (PNaCl, pronounced "pinnacle"). Developers use the PNaCl toolchain
123 to produce a single, portable (**pexe**) module. At runtime, a translator
124 built into the browser translates the pexe into native code for the
125 relevant client architecture. Translation occurs before any code is executed.
126 150
127 The right side of the diagram shows how to use (non-portable) Native Client. 151 Toolchains
128 Developers use a nacl-gcc based toolchain to produce multiple 152 ----------
129 architecture-dependent (**nexe**) modules, which are packaged into an 153
130 application. At runtime, the browser decides which nexe to load based 154 A Native Client toolchain consists of a compiler, a linker, an assembler and
131 on the architecture of the client machine. 155 other tools that are used to convert C/C++ source code into a module that is
156 loadable by a browser.
157
158 The Native Client SDK provides two toolchains:
159
160 * The left side of the diagram shows **Portable Native Client** (PNaCl,
161 pronounced "pinnacle"). An LLVM based toolchain produces a single, portable
162 (**pexe**) module. At runtime, a translator built into the browser translates
163 the pexe into native code for the relevant client architecture. Translation
164 occurs before any code is executed.
165
166 * The right side of the diagram shows **(non-portable) Native Client**. A gcc
167 based toolchain produces multiple architecture-dependent (**nexe**) modules,
168 which are packaged into an application. At runtime the browser determines
169 which nexe to load based on the architecture of the client machine.
170
171 The PNaCl toolchain is recommended for most applications. The nacl-gcc
172 toolchain should only be used for applications that wont be distributed on the
173 open web.
174
175 .. _security:
132 176
133 Security 177 Security
134 -------- 178 --------
135 179
136 Since Native Client permits the execution of native code on client machines, 180 Since Native Client permits the execution of native code on client machines,
137 special security measures have to be implemented: 181 special security measures have to be implemented:
138 182
139 * The NaCl sandbox ensures that code accesses system resources only through 183 * The NaCl sandbox ensures that code accesses system resources only through
140 safe, whitelisted APIs, and operates within its limits without attempting to 184 safe, whitelisted APIs, and operates within its limits without attempting to
141 interfere with other code running either within the browser or outside it. 185 interfere with other code running either within the browser or outside it.
142 * The NaCl validator statically analyzes code prior to running it 186 * The NaCl validator statically analyzes code before running it to make sure it
143 to make sure it only uses code and data patterns that are permitted and safe. 187 only uses code and data patterns that are permitted and safe.
144 188
145 The above security measures are in addition to the existing sandbox in the 189 These security measures are in addition to the existing sandbox in the
146 Chrome browser---the Native Client module always executes in a process with 190 Chrome browser. The Native Client module always executes in a process with
147 restricted permissions. The only interaction between this process and the 191 restricted permissions. The only interaction between this process and the
148 outside world is through sanctioned browser interfaces. Because of the 192 outside world is through defined browser interfaces. Because of the
149 combination of the NaCl sandbox and the Chrome sandbox, we say that 193 combination of the NaCl sandbox and the Chrome sandbox, we say that
150 Native Client employs a double sandbox design. 194 Native Client employs a **double sandbox** design.
195
196 .. _portability:
151 197
152 Portability 198 Portability
153 ----------- 199 -----------
154 200
155 Portable Native Client (PNaCl, prounounced "pinnacle") employs state-of-the-art 201 Portable Native Client (PNaCl, prounounced "pinnacle") employs state-of-the-art
156 compiler technology to compile C/C++ source code to a portable bitcode 202 compiler technology to compile C/C++ source code to a portable bitcode
157 executable (**pexe**). PNaCl bitcode is an OS- and architecture-independent 203 executable (**pexe**). PNaCl bitcode is an OS- and architecture-independent
158 format that can be freely distributed on the web and :ref:`embedded in web 204 format that can be freely distributed on the web and :ref:`embedded in web
159 applications<link_nacl_in_web_apps>`. 205 applications<link_nacl_in_web_apps>`.
160 206
161 The PNaCl translator is a component embedded in the Chrome browser; its task is 207 The PNaCl translator is a component embedded in the Chrome browser; its task is
162 to run pexe modules. Internally, the translator compiles a pexe to a nexe 208 to run pexe modules. Internally, the translator compiles a pexe to a nexe
163 (a native executable for the client platform's architecture), and then executes 209 (described above), and then executes the nexe within the Native Client sandbox
164 the nexe within the Native Client sandbox as described above. It also uses 210 as described above. The translator uses intelligent caching to avoid
165 intelligent caching to avoid re-compiling the pexe if it was previously compiled 211 re-compiling the pexe if it was previously compiled on the client's browser.
166 on the client's browser.
167 212
168 Native Client also supports the execution of nexe modules directly in the 213 Native Client also supports the execution of nexe modules directly in the
169 browser. However, since nexes contain architecture-specific machine code, 214 browser. However, since nexes contain architecture-specific machine code, they
170 they are not allowed to be distributed on the open web---they can only be 215 are not allowed to be distributed on the open web. They can only be used as part
171 used as part of applications and extensions that are installed from the 216 of applications and extensions that are installed from the Chrome Web Store.
172 Chrome Web Store.
173 217
174 For more details on the difference between NaCl and PNaCl, see 218 For more details on the difference between NaCl and PNaCl, see
175 :doc:`NaCl and PNaCl <nacl-and-pnacl>`. 219 :doc:`NaCl and PNaCl <nacl-and-pnacl>`.
176 220
177 .. _toolchains:
178
179 Toolchains
180 ----------
181
182 A toolchain is a set of tools used to create an application from a set of
183 source files. In the case of Native Client, a toolchain consists of a compiler,
184 linker, assembler and other tools that are used to convert an
185 application written in C/C++ into a module that is loadable by the browser.
186
187 The Native Client SDK provides two toolchains:
188
189 * a **PNaCl toolchain** for generating portable NaCl modules (pexe files)
190 * a **gcc-based toolchain (nacl-gcc)** for generating non-portable NaCl modules
191 (nexe files)
192
193 The PNaCl toolchain is recommended for most applications. The nacl-gcc
194 toolchain should only be used for applications that will not be distributed
195 on the open web.
196
197 .. _link_nacl_in_web_apps: 221 .. _link_nacl_in_web_apps:
198 222
199 Native Client in a web application 223 Structure of a web application
200 ================================== 224 ==============================
201 225
202 .. _application_files: 226 .. _application_files:
203 227
204 A Native Client application consists of a set of files: 228 A Native Client application consists of a set of files:
205 229
206 * **HTML**, **CSS**, and **JavaScript** files, as in any modern web 230 * **HTML and CSS:** The HTML file tells the browser where to find the manifest
207 application. The JavaScript code is responsible for communicating with the 231 (nmf file) through the embed tag.
208 NaCl module. 232
209 * A **pexe** (portable NaCl) file. This module uses the :ref:`Pepper 233 .. naclcode::
210 <link_pepper>` API, which provides the bridge to JavaScript and 234
211 browser resources. 235 <embed name="mygame" src="mygame.nmf" type="application/x-pnacl" />
212 * A Native Client **manifest** file that specifies the pexe to load, along with
213 some loading options. This manifest file is embedded into the HTML page
214 through an ``<embed>`` tag, as shown in the figure below.
215 236
216 .. image:: /images/nacl-in-a-web-app.png 237 * **Manifest:** The manifest identifies the module to load and specifies
238 options. For example, "mygame.nmf" might look like this:
239
240 .. naclcode::
241
242 {...
243 ...
244 "url": "mygame.pexe",
245 }
246
247 * **pexe (portable NaCl file):** A compiled Native Client module. It uses the
248 :ref:`Pepper API <link_pepper>`, which provides a bridge to JavaScript and
249 other browser resources.
250
251 .. figure:: /images/nacl-in-a-web-app.png
252 :alt: Structure of a web application
253
254 Structure of a web application
217 255
218 For more details, see :doc:`Application Structure 256 For more details, see :doc:`Application Structure
219 <devguide/coding/application-structure>`. 257 <devguide/coding/application-structure>`.
220 258
221 .. _link_pepper: 259 .. _link_pepper:
222 260
223 Pepper Plugin API 261 Pepper plug-in API
224 ----------------- 262 ------------------
225 263
226 The Pepper Plugin API (PPAPI), called **Pepper** for convenience, is an 264 The Pepper plug-in API (PPAPI), called **Pepper** for convenience, is an
227 open-source, cross-platform C/C++ API for web browser plugins. From the point 265 open-source, cross-platform C/C++ API for web browser plug-ins. Pepper allows a
228 of view of Native Client, Pepper allows a C/C++ module to communicate with 266 C/C++ module to communicate with the hosting browser and to access system-level
229 the hosting browser and get access to system-level functions in a safe and 267 functions in a safe and portable way. One of the security constraints in Native
230 portable way. One of the security constraints in Native Client is that modules 268 Client is that modules cannot make OS-level calls. Pepper provides analogous
231 cannot make any OS-level calls directly. Pepper provides analogous APIs that 269 APIs that modules can use instead.
232 modules can target instead.
233 270
234 You can use the Pepper APIs to gain access to the full array of browser 271 You can use the Pepper APIs to gain access to the full array of browser
235 capabilities, including: 272 capabilities, including:
236 273
237 * :doc:`Talking to the JavaScript code in your application 274 * :doc:`Talking to the JavaScript code in your application
238 <devguide/coding/message-system>` from the C++ code in your NaCl module. 275 <devguide/coding/message-system>` from the C++ code in your NaCl module.
239 * :doc:`Doing file I/O <devguide/coding/file-io>`. 276 * :doc:`Doing file I/O <devguide/coding/file-io>`.
240 * :doc:`Playing audio <devguide/coding/audio>`. 277 * :doc:`Playing audio <devguide/coding/audio>`.
241 * :doc:`Rendering 3D graphics <devguide/coding/3D-graphics>`. 278 * :doc:`Rendering 3D graphics <devguide/coding/3D-graphics>`.
242 279
243 Pepper includes both a C API and a C++ API. The C++ API is a set of bindings 280 Pepper includes both a :doc:`C API </c-api>` and a :doc:`C++ API </cpp-api>`.
244 written on top of the C API. For additional information about Pepper, see 281 The C++ API is a set of bindings written on top of the C API. For additional
245 `Pepper Concepts <http://code.google.com/p/ppapi/wiki/Concepts>`_. 282 information about Pepper, see `Pepper Concepts
283 <http://code.google.com/p/ppapi/wiki/Concepts>`_.
284
285 .. _versioning:
246 286
247 Versioning 287 Versioning
248 ========== 288 ==========
249 289
250 Chrome is released on a six week cycle, and developer versions of Chrome are 290 Chrome is released on a six week cycle, and developer versions of Chrome are
251 pushed to the public beta channel three weeks before each release. As with any 291 pushed to the public beta channel three weeks before each release. As with any
252 software, each release of Chrome may include changes to Native Client and the 292 software, each release of Chrome may include changes to Native Client and the
253 Pepper interfaces that may require modification to existing applications. 293 Pepper interfaces that may require modification to existing applications.
254 However, modules compiled for one version of Pepper/Chrome should work with 294 However, modules compiled for one version of Pepper/Chrome should work with
255 subsequent versions of Pepper/Chrome. The SDK includes multiple versions of the 295 subsequent versions of Pepper/Chrome. The SDK includes multiple versions of the
256 Pepper APIs to help developers make adjustments to API changes and take 296 Pepper APIs to help you make adjustments to API changes and take
257 advantage of new features: `stable </native-client/pepper_stable>`_, `beta 297 advantage of new features: `stable </native-client/pepper_stable>`_, `beta
258 </native-client/pepper_beta>`_ and `dev </native-client/pepper_dev>`_. 298 </native-client/pepper_beta>`_ and `dev </native-client/pepper_dev>`_.
259 299
300 .. _where-to-start:
301
260 Where to start 302 Where to start
261 ============== 303 ==============
262 304
263 The :doc:`Quick Start <quick-start>` document provides links to downloads and 305 The :doc:`Quick Start <quick-start>` document provides links to downloads and
264 documentation that should help you get started with developing and distributing 306 documentation to help you get started with developing and distributing Native
265 Native Client applications. 307 Client applications.
OLDNEW
« native_client_sdk/src/doc/nacl-and-pnacl.rst ('K') | « native_client_sdk/src/doc/nacl-and-pnacl.rst ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698