• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{{+bindTo:partials.standard_nacl_article}}
2
3<section id="distributing-your-application">
4<span id="distributing"></span><h1 id="distributing-your-application"><span id="distributing"></span>Distributing Your Application</h1>
5<div class="contents local" id="contents" style="display: none">
6<ul class="small-gap">
7<li><a class="reference internal" href="#portable-native-client" id="id1">Portable Native Client</a></li>
8<li><p class="first"><a class="reference internal" href="#non-portable-native-client" id="id2">Non-portable Native Client</a></p>
9<ul class="small-gap">
10<li><a class="reference internal" href="#packaged-application" id="id3">Packaged application</a></li>
11<li><a class="reference internal" href="#extension" id="id4">Extension</a></li>
12<li><a class="reference internal" href="#hosted-application" id="id5">Hosted application</a></li>
13<li><a class="reference internal" href="#registering-native-client-modules-to-handle-mime-types" id="id6">Registering Native Client modules to handle MIME types</a></li>
14</ul>
15</li>
16</ul>
17
18</div><p>This document describes how to distribute Portable Native Client applications
19on the web, and Native Client applications through the
20<a class="reference external" href="/webstore">Chrome Web Store</a> (CWS).</p>
21<h2 id="portable-native-client">Portable Native Client</h2>
22<p>Portable Native Client is enabled by default for web pages, so no separate
23distribution step is requred. Making PNaCl a part of your web application is as
24simple as embedding a manifest file that points to a <strong>pexe</strong>. See the
25<a class="reference internal" href="/native-client/overview.html"><em>technical overview</em></a> for more details.</p>
26<img alt="/native-client/images/nacl-in-a-web-app.png" src="/native-client/images/nacl-in-a-web-app.png" />
27<p>The only constraint for distributing PNaCl modules with a web application is
28abiding by the <a class="reference external" href="http://en.wikipedia.org/wiki/Same_origin_policy">Same-origin policy</a>. The PNaCl manifest and
29<strong>pexe</strong> must either be served from the same domain with the HTML, or the <a class="reference external" href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing">CORS
30mechanism</a> should
31be used to safely host them on a different domain.</p>
32<h2 id="non-portable-native-client">Non-portable Native Client</h2>
33<p>NaCl modules are only allowed for applications distributed through the <a class="reference external" href="https://chrome.google.com/webstore/category/apps">Chrome
34Web Store (CWS)</a>
35The CWS requirement is in place to prevent the proliferation of Native Client
36executables (<strong>nexe</strong>s) compiled for specific architecures (e.g., x86-32,
37x86-64, or ARM).</p>
38<p>In general, the considerations and guidelines for distributing applications
39through the Chrome Web Store apply to applications that contain NaCl modules as
40well. Here are a few pointers to relevant documentation:</p>
41<ul class="small-gap">
42<li><a class="reference external" href="/webstore">CWS Overview</a></li>
43<li><a class="reference external" href="/webstore/choosing">Choosing an App Type</a></li>
44<li><a class="reference external" href="/apps/about_apps">Getting started with packaged apps</a></li>
45<li><a class="reference external" href="https://developers.google.com/chrome/apps/docs/developers_guide">Hosted apps</a></li>
46<li><a class="reference external" href="/extensions">Chrome extensions</a></li>
47</ul>
48<p>In this document, we&#8217;ll focus only on distribution issues specific to
49applications that contain NaCl modules.</p>
50<h3 id="packaged-application"><span id="distributing-packaged"></span>Packaged application</h3>
51<p>A packaged application is a special zip file (with a .crx extension) hosted in
52the Chrome Web Store. This file contains all of the application parts: A Chrome
53Web Store manifest file (manifest.json), an icon, and all of the regular Native
54Client application files. Refer to
55<a class="reference external" href="/apps/about_apps">Packaged Apps</a>
56for more information about creating a packaged application.</p>
57<h4 id="reducing-the-size-of-the-user-download-package">Reducing the size of the user download package</h4>
58<aside class="note">
59<strong>Tip:</strong>
60Packaging an app in a multi-platform zip file can significantly reduce the
61download and storage requirements for the app.
62</aside>
63<p>As described above, to upload a packaged app to the CWS you have to create a zip
64file with all the resources that your app needs, including .nexe files for
65multiple architectures (x86-64, x86-32, and ARM). Prior to Chrome 28, when users
66installed your app they had to download a .crx file from the CWS with all the
67included .nexe files.</p>
68<p>Starting with Chrome 28, the Chrome Web Store includes a feature called
69<strong>multi-platform zip files.</strong> This feature lets you structure your application
70directory and zip file in a way that reduces the size of the user download
71package.  Here&#8217;s how this feature works:</p>
72<ul class="small-gap">
73<li>You still include all the .nexe files in the zip file that you upload to
74the CWS, but you designate specific .nexe files (and other files if
75appropriate) for specific architectures.</li>
76<li>The Chrome Web Store re-packages your app, so that users only download
77the files that they need for their specific architecture.</li>
78</ul>
79<p>Here is how to use this feature:</p>
80<ol class="arabic">
81<li><p class="first">Create a directory called <code>_platform_specific</code>.
82Put this directory at the same level where your CWS manifest file,
83<code>manifest.json</code>, is located.</p>
84</li>
85<li><p class="first">Create a subdirectory for each specific architecture that you support,
86and add the files for each architecture in the relevant subdirectory.</p>
87<p>Here is a sample app directory structure:</p>
88<pre>
89|-- my_app_directory/
90|       |-- manifest.json
91|       |-- my_app.html
92|       |-- my_module.nmf
93|       +-- css/
94|       +-- images/
95|       +-- scripts/
96|       |-- _platform_specific/
97|       |       |-- x86-64/
98|       |       |       |-- my_module_x86_64.nexe
99|       |       |-- x86-32/
100|       |       |       |-- my_module_x86_32.nexe
101|       |       |-- arm/
102|       |       |       |-- my_module_arm.nexe
103|       |       |-- all/
104|       |       |       |-- my_module_x86_64.nexe
105|       |       |       |-- my_module_x86_64.nexe
106|       |       |       |-- my_module_x86_32.nexe
107</pre>
108<p>Please note a few important points about the app directory structure:</p>
109<ul class="small-gap">
110<li><p class="first">The architecture-specific subdirectories:</p>
111<ul class="small-gap">
112<li><p class="first">can have arbitrary names;</p>
113</li>
114<li><p class="first">must be directly under the <code>_platform_specific</code> directory; and</p>
115</li>
116<li><p class="first">must be listed in the CWS manifest file (see step 3 below).</p>
117</li>
118</ul>
119</li>
120<li><p class="first">You can include a fallback subdirectory that provides a download package
121with all the architecture-specific files.  (In the example above this
122is the <code>all/</code> subdirectory.) This folder is used if the user has an
123earlier version of Chrome (prior to Chrome 28) that does not support
124multi-platform zip files.</p>
125</li>
126<li><p class="first">You cannot include any files directly in the folder
127<code>_platform_specific</code>.  All architecture-specific files
128must be under one of the architecture-specific subdirectories.</p>
129</li>
130<li><p class="first">Files that are not under the <code>_platform_specific</code> directory are
131included in all download packages.  (In the example above, that
132includes <code>my_app.html</code>, <code>my_module.nmf</code>,
133and the <code>css/</code>, <code>images/</code>, and <code>scripts/</code> directories.)</p>
134</li>
135</ul>
136</li>
137<li><p class="first">Modify the CWS manifest file, <code>manifest.json</code>, so that it specifies which
138subdirectory under <code>_platform_specific</code> corresponds to which architecture.</p>
139<p>The CWS manifest file must include a new name/value pair, where the name
140is <code>platforms</code> and the value is an array.  The array has an object for
141each Native Client architecture with two name/value pairs:</p>
142<table border="1" class="docutils">
143<colgroup>
144</colgroup>
145<thead valign="bottom">
146<tr class="row-odd"><th class="head"><p class="first last">Name</p>
147</th>
148<th class="head"><p class="first last">Value</p>
149</th>
150</tr>
151</thead>
152<tbody valign="top">
153<tr class="row-even"><td><p class="first last"><code>nacl_arch</code></p>
154</td>
155<td><p class="first last"><code>x86-64</code>, <code>x86-32</code>, or <code>arm</code></p>
156</td>
157</tr>
158<tr class="row-odd"><td><p class="first last"><code>sub_package_path</code></p>
159</td>
160<td><p class="first last">the path of the directory (starting
161with <code>_platform_specific</code>) that
162contains the files for the designated
163NaCl architecture</p>
164</td>
165</tr>
166</tbody>
167</table>
168<p>Here is a sample <code>manifest.json</code> file:</p>
169<pre>
170{
171  &quot;name&quot;: &quot;My Reminder App&quot;,
172  &quot;description&quot;: &quot;A reminder app that syncs across Chrome browsers.&quot;,
173  &quot;manifest_version&quot;: 2,
174  &quot;minimum_chrome_version&quot;: &quot;28&quot;,
175  &quot;offline_enabled&quot;: true,
176  &quot;version&quot;: &quot;0.3&quot;,
177  &quot;permissions&quot;: [
178    {&quot;fileSystem&quot;: [&quot;write&quot;]},
179    &quot;alarms&quot;,
180    &quot;storage&quot;
181  ],
182  &quot;app&quot;: {
183    &quot;background&quot;: {
184      &quot;scripts&quot;: [&quot;scripts/background.js&quot;]
185    }
186  },
187  &quot;icons&quot;: {
188    &quot;16&quot;: &quot;images/icon-16x16.png&quot;,
189    &quot;128&quot;: &quot;images/icon-128x128.png&quot;
190  },
191  &quot;platforms&quot;: [
192    {
193      &quot;nacl_arch&quot;: &quot;x86-64&quot;,
194      &quot;sub_package_path&quot;: &quot;_platform_specific/x86-64/&quot;
195    },
196    {
197      &quot;nacl_arch&quot;: &quot;x86-32&quot;,
198      &quot;sub_package_path&quot;: &quot;_platform_specific/x86-32/&quot;
199    },
200    {
201      &quot;nacl_arch&quot;: &quot;arm&quot;,
202      &quot;sub_package_path&quot;: &quot;_platform_specific/arm/&quot;
203    },
204    {
205      &quot;sub_package_path&quot;: &quot;_platform_specific/all/&quot;
206    }
207  ]
208}
209</pre>
210<p>Note the last entry in the CWS manifest file above, which specifies a
211<code>sub_package_path</code> without a corresponding <code>nacl_arch</code>. This entry
212identifies the fallback directory, which is included in the download
213package if the user architecture does not match any of the listed NaCl
214architectures, or if the user is using an older version of Chrome that
215does not support multi-platform zip files.</p>
216</li>
217<li><p class="first">Modify your application as necessary so that it uses the files for the
218correct user architecture.</p>
219<p>To reference architecture-specific files, use the JavaScript API
220<a class="reference external" href="/extensions/runtime.html#method-getPlatformInfo">chrome.runtime.getPlatformInfo()</a>.
221As an example, if you have architecture-specific files in the directories
222<code>x86-64</code>, <code>x86-32</code>, and <code>arm</code>, you can use the following JavaScript
223code to create a path for the files:</p>
224<pre class="prettyprint">
225function getPath(name) {
226  return '_platform_specific/' +
227    chrome.runtime.getPlatformInfo().nacl_arch +
228    '/' + name;
229}
230</pre>
231</li>
232<li><p class="first">Test your app, create a zip file, and upload the app to the CWS as before.</p>
233</li>
234</ol>
235<h4 id="additional-considerations-for-a-packaged-application"><span id="additional-considerations-packaged"></span>Additional considerations for a packaged application</h4>
236<ul class="small-gap">
237<li>In the description of your application in the CWS, make sure to mention that
238your application is a Native Client application that only works with the
239Chrome browser. Also make sure to identify the minimum version of Chrome
240that your application requires.</li>
241<li><p class="first">Hosted and packaged applications have a &#8220;launch&#8221; parameter in the CWS
242manifest. This parameter is present only in apps (not extensions), and it
243tells Google Chrome what to show when a user starts an installed app. For
244example:</p>
245<pre>
246&quot;launch&quot;: {
247  &quot;web_url&quot;: &quot;http://mail.google.com/mail/&quot;
248}
249</pre>
250</li>
251<li>If you want to write local data using the Pepper
252<a class="reference external" href="/native-client/peppercpp/classpp_1_1_file_i_o">FileIO</a>
253API, you must set the &#8216;unlimitedStorage&#8217; permission in your Chrome Web
254Store manifest file, just as you would for a JavaScript application that
255uses the HTML5 File API.</li>
256<li>For packaged applications, you can only use in-app purchases.</li>
257<li>You can place your application in the Google Web Store with access only to
258certain people for testing. See <a class="reference external" href="/webstore/publish">Publishing to test accounts</a> for more information.</li>
259</ul>
260<h3 id="extension">Extension</h3>
261<p>The NaCl-specific notes for a <a class="reference internal" href="#distributing-packaged"><em>package application</em></a>
262apply to extensions as well.</p>
263<h3 id="hosted-application">Hosted application</h3>
264<p>The .html file, .nmf file (Native Client manifest file), and .nexe files must
265be served from the same domain, and the Chrome Web Store manifest file must
266specify the correct, verified domain. Other files can be served from the same
267or another domain.</p>
268<p>In addition, see <a class="reference internal" href="#additional-considerations-packaged"><em>Additional considerations for a packaged application</em></a>.</p>
269<h3 id="registering-native-client-modules-to-handle-mime-types">Registering Native Client modules to handle MIME types</h3>
270<p>If you want Chrome to use a Native Client module to display a particular type
271of content, you can associate the MIME type of that content with the Native
272Client module. Use the <code>nacl_modules</code> attribute in the Chrome Web Store
273manifest file to register a Native Client module as the handler for one or more
274specific MIME types. For example, the bold code in the snippet below registers
275a Native Client module as the content handler for the OpenOffice spreadsheet
276MIME type:</p>
277<pre>
278{
279   &quot;name&quot;: &quot;My Native Client Spreadsheet Viewer&quot;,
280   &quot;version&quot;: &quot;0.1&quot;,
281   &quot;description&quot;: &quot;Open spreadsheets right in your browser.&quot;,
282   &quot;nacl_modules&quot;: [{
283      &quot;path&quot;: &quot;SpreadsheetViewer.nmf&quot;,
284      &quot;mime_type&quot;: &quot;application/vnd.oasis.opendocument.spreadsheet&quot;
285   }]
286}
287</pre>
288<p>The value of &#8220;path&#8221; is the location of a Native Client manifest file (.nmf)
289within the application directory. For more information on Native Client
290manifest files, see <a class="reference internal" href="/native-client/devguide/coding/application-structure.html#manifest-file"><em>Manifest Files</em></a>.</p>
291<p>The value of &#8220;mime_type&#8221; is a specific MIME type that you want the Native
292Client module to handle. Each MIME type can be associated with only one .nmf
293file, but a single .nmf file might handle multiple MIME types. The following
294example shows an extension with two .nmf files that handle three MIME types.</p>
295<pre>
296{
297   &quot;name&quot;: &quot;My Native Client Spreadsheet and Document Viewer&quot;,
298   &quot;version&quot;: &quot;0.1&quot;,
299   &quot;description&quot;: &quot;Open spreadsheets and documents right in your browser.&quot;,
300   &quot;nacl_modules&quot;: [{
301     &quot;path&quot;: &quot;SpreadsheetViewer.nmf&quot;,
302     &quot;mime_type&quot;: &quot;application/vnd.oasis.opendocument.spreadsheet&quot;
303   },
304   {
305      &quot;path&quot;: &quot;SpreadsheetViewer.nmf&quot;,
306      &quot;mime_type&quot;: &quot;application/vnd.oasis.opendocument.spreadsheet-template&quot;
307   },
308   {
309      &quot;path&quot;: &quot;DocumentViewer.nmf&quot;,
310      &quot;mime_type&quot;: &quot;application/vnd.oasis.opendocument.text&quot;
311   }]
312}
313</pre>
314<p>The <code>nacl_modules</code> attribute is optional&#8212;specify this attribute only if
315you want Chrome to use a Native Client module to display a particular type of
316content.</p>
317</section>
318
319{{/partials.standard_nacl_article}}
320