- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / templates / articles / autoupdate.html
1 <h1>Autoupdating</h1>
2
3
4 <p>We want extensions and apps to be autoupdated for some of the same reasons as Google Chrome itself: to incorporate bug and security fixes, add new features or performance enhancements, and improve user interfaces.</p>
5
6 <p>If you publish using the <a href="https://chrome.google.com/webstore/developer/dashboard">Chrome Developer Dashboard</a>, you can <em>ignore this page</em>. You can use the dashboard to release updated versions to users, as well as to the Chrome Web Store.</p>
7
8 <p>If you want to host somewhere other than the store, keep reading.
9 You should also read <a href="hosting.html">Hosting</a> and
10 <a href="packaging.html">Packaging</a>.</p>
11
12
13 <h2 id="overview">Overview</h2>
14 <ul><li>A manifest may contain an "update_url" field, pointing to a location for doing update checks.</li>
15 <li>The content returned by an update check is an <em>update manifest</em> XML document listing the latest version of an extension.</li></ul>
16
17 <p>Every few hours, the browser checks whether any installed extensions or apps have an update URL. For each one, it makes a request to that URL looking for an update manifest XML file. If the update manifest mentions a version that is more recent than what's installed, the browser downloads and installs the new version. As with manual updates, the new <code>.crx</code> file must be signed with the same private key as the currently installed version.</p>
18
19
20 <h2 id="update_url">Update URL</h2>
21 <p>If you're hosting your own extension or app, you need to add the "update_url" field to your <a href="manifest.html"><code>manifest.json</code></a> file,
22 like this:</p>
23
24 <pre data-filename="manifest.json">
25 {
26   "name": "My extension",
27   ...
28   <b>"update_url": "http://myhost.com/mytestextension/updates.xml"</b>,
29   ...
30 }
31 </pre>
32
33 <h2 id="update_manifest">Update manifest</h2>
34 <p>The update manifest returned by the server should be an XML document that looks like this (highlights indicate parts you should modify):</p>
35
36 <pre data-filename="updates.xml">
37 &lt;?xml version='1.0' encoding='UTF-8'?&gt;
38 &lt;gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'&gt;
39   &lt;app appid='<b>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</b>'&gt;
40    &nbsp;&lt;updatecheck&nbsp;codebase='<b>http://myhost.com/mytestextension/mte_v2.crx</b>'&nbsp;version='<b>2.0</b>' /&gt;
41   &lt;/app&gt;
42 &lt;/gupdate&gt;
43 </pre>
44
45 <p>This XML format is borrowed from that used by Omaha, Google's update infrastructure. See <a href="http://code.google.com/p/omaha/">http://code.google.com/p/omaha/</a> for more details.
46 The extensions system uses the following attributes
47 for the <strong>&lt;app></strong>
48 and <strong>&lt;updatecheck></strong> elements of the update manifest:
49 </p>
50
51 <p><b>appid</b><br>
52 The extension or app ID, generated based on a hash of the public key,
53 as described in <a href="packaging.html">Packaging</a>. You can find the
54 ID of an extension or Chrome App by going to the Extensions page (<b>chrome://extensions</b>).
55 </p>
56 {{?is_apps}}
57 <p>
58 Hosted apps, however, are not listed on the Extensions page.  You can find the ID of any
59 app using the following steps:
60 </p>
61 {{/is_apps}}
62
63 {{?is_apps}}
64 <ul>
65   <li> Open the app. You can do this by clicking its icon on the New Tab page.</li>
66   <li> Open the JavaScript console.  You can do this by clicking the wrench icon
67        and choosing <b>Tools &gt; JavaScript Console</b>.</li>
68   <li> Enter the following expression into the JavaScript console: <code>chrome.app.getDetails().id</code>
69       <p>The console shows the app's ID as a quoted string.</p>
70   </li>
71 </ul>
72 {{/is_apps}}
73
74 <p><b>codebase</b><br>
75 A URL to the <code>.crx</code> file.</p>
76
77 <p><b>version</b><br>
78 Used by the client to determine whether it should download the <code>.crx</code> file specified by <code>codebase</code>. It should match the value of "version" in the <code>.crx</code> file's <code>manifest.json</code> file.</p>
79 <p>The update manifest XML file may contain information about multiple extensions by including multiple &lt;app&gt; elements.</p>
80
81
82 <h2 id="testing">Testing</h2>
83 <p>The default update check frequency is several hours,
84 but you can force an update using the Extensions page's
85 <b>Update extensions now</b> button.
86 </p>
87
88 <p>
89 Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:</p>
90 <pre>
91 chrome.exe <b>--extensions-update-frequency=45</b></pre>
92
93 <p>Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.</p>
94
95
96 <h2 id="request_parameters">Advanced usage: request parameters</h2>
97 <p>The basic autoupdate mechanism is designed to make the server-side work as easy as just dropping a static XML file onto any plain web server such as Apache, and updating that XML file as you release new versions of your extensions.</p>
98 <p>More advanced developers may wish to take advantage of the fact that we add on parameters to the request for the update manifest to indicate the extension ID and version. Then they can use the same update URL for all of their extensions, pointing to a URL running dynamic server-side code instead of a static XML file.</p>
99 <p>The format of the request parameters is:</p>
100 <p><code>&nbsp;&nbsp;?x=<em>&lt;extension_data&gt;</em></code></p>
101 <p>Where <code><em>&lt;extension_data&gt;</em></code> is a URL-encoded string of the format:</p>
102 <p><code>&nbsp;&nbsp;<em>id=&lt;id&gt;</em>&amp;v=<em>&lt;version&gt;</em></code></p>
103
104 <p>For example, say you have two extensions,
105 both of which point to the same update URL
106 (<code>http://test.com/extension_updates.php</code>):
107 </p>
108
109 <ul>
110 <li> Extension 1
111   <ul>
112     <li> ID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" </li>
113     <li> Version: "1.1"</li>
114   </ul>
115 <li> Extension 2
116   <ul>
117     <li> ID: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" </li>
118     <li> Version: "0.4"</li>
119   </ul>
120 </ul>
121
122
123 <p>The request to update each individual extension would be:</p>
124
125 <ul>
126   <li> <code>http://test.com/extension_updates.php?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%26v%3D1.1</code> </li>
127   <li> <code>http://test.com/extension_updates.php?x=id%3Dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb%26v%3D0.4</code> </li>
128 </ul>
129
130 <p>
131 Multiple extensions can be listed in a single request for each unique update URL.
132 For the above example, if a user has both of the extensions installed,
133 then the two requests are merged into a single request:</p>
134 <p><code>http://test.com/extension_updates.php?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%26v%3D1.1&amp;x=id%3Dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb%26v%3D0.4</code></p>
135
136 <p>If the number of installed extensions using the same update URL is large enough that a GET request URL is too long (over 2000 characters or so), the update check issues additional GET requests as necessary.</p>
137
138 <p class="note">
139 <b>Note:</b>
140 In the future, instead of issuing multiple GET requests,
141 a single POST request might be issued
142 with the request parameters in the POST body.
143 </p>
144
145 <h2 id="minimum_browser_version">Advanced usage: minimum browser version</h2>
146 <p>As we add more APIs to the extensions system, it's possible you will want to release an updated version of an extension or app that will work only with newer versions of the browser. While Google Chrome itself is autoupdated, it can take a few days before the majority of the user base has updated to any given new release. To ensure that a given update will apply only to Google Chrome versions at or higher than a specific version, you add the "prodversionmin" attribute to the &lt;app&gt; element in your update manifest. For example:</p>
147
148 <pre data-filename="updates.xml">
149 &lt;?xml version='1.0' encoding='UTF-8'?&gt;
150 &lt;gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'&gt;
151 &nbsp;&nbsp;&lt;app appid='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'&gt;
152 &nbsp;&nbsp; &nbsp;&lt;updatecheck&nbsp;codebase='http://myhost.com/mytestextension/mte_v2.crx'&nbsp;version='2.0' <b>prodversionmin='3.0.193.0'</b>/&gt;
153 &nbsp;&nbsp;&lt;/app&gt;
154 &lt;/gupdate&gt;
155 </pre>
156
157 <p>This would ensure that users would autoupdate to version 2 only if they are running Google Chrome 3.0.193.0 or greater.</p>