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