1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
4 Copyright 2007, Google Inc.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14 3. Neither the name of Google Inc. nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 <title>LocalServer API
</title>
33 <link rel=
"stylesheet" type=
"text/css" href=
"gears.css" />
38 <h1>LocalServer API
</h1>
40 <div id=
"pagecontent">
42 <p>The LocalServer module allows a web application to cache and serve its HTTP
43 resources locally, without a network connection.
</p>
46 <li><a href=
"#overview">Overview
</a></li>
47 <li><a href=
"#example">Example
</a>
48 <li><a href=
"#classes">Classes
51 <li><a href=
"#LocalServer" >LocalServer
</a></li>
52 <li><a href=
"#ManagedResourceStore">ManagedResourceStore
</a></li>
53 <li><a href=
"#ResourceStore">ResourceStore
</a></li>
54 <li><a href=
"#FileSubmitter">FileSubmitter
</a></li>
57 <li><a href=
"#manifest_file">Manifest file
</a></li>
58 <li><a href=
"#required_cookie">Cookies and the LocalServer
</a></li>
59 <li><a href=
"#filesystem_location">Location of cached files
</a></li>
63 <h2 id=
"overview">Overview
</h2>
64 <p>The LocalServer module is a specialized URL cache that the web application controls.
65 Requests for URLs in the LocalServer's cache are intercepted and served
66 locally from the user's disk.
</p>
67 <h4>Resource stores
</h4>
68 <p>A
<em>resource store
</em> is a container of URLs. Using the LocalServer module,
69 applications can create any number of resource stores, and a resource store can contain any number of URLs.
</p>
70 <p>There are two types of resource stores:
</p>
72 <li><a href=
"#ResourceStore">ResourceStore
</a> - for capturing ad-hoc URLs using JavaScript.
73 The ResourceStore allows an application to capture user data files that need to be addressed with a URL,
74 such as a PDF file or an image.
</li>
75 <li><a href=
"#ManagedResourceStore">ManagedResourceStore
</a> - for capturing a related set of URLs that are
76 declared in a
<em>manifest file
</em>, and are updated automatically.
77 The ManagedResourceStore allows the set of resources needed to run a web application to be captured.
</li>
79 <p>For both types of stores, the set of URLs captured is explicitly controlled by the web application.
</p>
81 <h4>Updating of cached resources
</h4>
82 <p>A key difference between the two types of stores is how resources are updated. The contents of a ManagedResourceStore are automatically
83 updated whenever the version string in the store's manifest file changes. The ResourceStore's contents are never automatically
84 updated, and are only updated explicitly by the application.
</p>
85 <p>Google Gears automatically updates ManagedResourceStores according to these rules:
</p>
87 <li><code>checkForUpdate()
</code> is called each time a resource contained in a ManagedResourceStore is requested and served locally, but no more often than once every
10 seconds.
</li>
88 <li>If the manifest file's
<code>version
</code> value has changed, the automatic update process runs. For further details, see
<a href=
"#checkforupdate">checkForUpdate
</a>.
</li>
91 <h4>Local serving of cached resources
</h4>
92 <p>The LocalServer intercepts HTTP/HTTPS requests and serves them from the cache when all of these conditions are met:
</p>
94 <li>The URL is cached in a ResourceStore or ManagedResourceStore,
</li>
95 <li>The resource store's
<code>enabled
</code> attribute is set to true, and
</li>
96 <li>If the resource store has a
<code>requiredCookie
</code> attribute,
97 the request must have a cookie that matches. For further details read
<a href=
"#required_cookie">Cookies and the LocalServer
</a>.
</li>
99 <p>The LocalServer
<em>always
</em> serves a cached resource when the conditions are met, regardless of the network connection. The URLs contained in a store
100 are eligible for local serving without requiring the application to open the store.
</p>
101 <p>To disable local serving of stored resources and force URLs to be served using the regular network connection, the application can set
102 the store's
<code>enabled
</code> attribute to false.
</p>
107 <h2 id=
"example">Example
</h2>
109 <pre><code><script
type=
"text/javascript" src=
"<a href='tools.html#gears_init'>gears_init.js</a>"></script
>
110 <script
type=
"text/javascript">
111 var localServer = google.gears.factory.create('beta.localserver');
112 var store = localServer.createManagedStore('test-store');
113 store.manifestUrl = 'site-manifest.txt';
114 store.checkForUpdate();
115 </script
></code></pre>
117 <pre><code>// site-manifest.txt
119 "betaManifestVersion":
1,
120 "version":
"site_version_string",
122 {
"url":
"site.html" },
123 {
"url":
"gears_init.js" }
127 <h3 id=
"classes">Classes
</h3>
128 <pre><code><a href=
"#LocalServer" class=
"section">LocalServer class
</a>
129 boolean
<b>canServeLocally
</b>(string url)
130 ResourceStore
<b>createStore
</b>(string name, [string requiredCookie])
131 ResourceStore
<b>openStore
</b>(string name, [string requiredCookie])
132 void
<b>removeStore
</b>(string name, [string requiredCookie])
133 ManagedResourceStore
<b>createManagedStore
</b>(string name, [string requiredCookie])
134 ManagedResourceStore
<b>openManagedStore
</b>(string name, [string requiredCookie])
135 void
<b>removeManagedStore
</b>(string name, [string requiredCookie])
</code></pre>
138 <pre><code><a href=
"#ManagedResourceStore">ManagedResourceStore class
</a>
139 readonly attribute string
<b>name
</b>
140 readonly attribute string
<b>requiredCookie
</b>
141 readwrite attribute boolean
<b>enabled
</b>
142 readwrite attribute string
<b>manifestUrl
</b>
143 readonly attribute int
<b>lastUpdateCheckTime
</b>
144 readonly attribute int
<b>updateStatus
</b>
145 readonly attribute string
<b>lastErrorMessage
</b>
146 readonly attribute string
<b>currentVersion
</b>
147 event void
<b>oncomplete
</b>(Object details)
148 event void
<b>onerror
</b>(Error error)
149 event void
<b>onprogress
</b>(Object details)
150 void
<b>checkForUpdate
</b>()
</code></pre>
152 <pre><code><a href=
"#ResourceStore">ResourceStore class
</a>
153 readonly attribute string
<b>name
</b>
154 readonly attribute string
<b>requiredCookie
</b>
155 readwrite attribute boolean
<b>enabled
</b>
156 int
<b>capture
</b>(string urlOrUrlArray, completionCallback)
157 void
<b>abortCapture
</b>(int captureId)
158 void
<b>remove
</b>(string url)
159 void
<b>rename
</b>(string srcUrl, string destUrl)
160 void
<b>copy
</b>(string srcUrl, string destUrl)
161 boolean
<b>isCaptured
</b>(string url)
162 void
<b>captureFile
</b>(fileInputElement, url)
163 string
<b>getCapturedFileName
</b>(url)
164 string
<b>getHeader
</b>(string url, string name)
165 string
<b>getAllHeaders
</b>(string url)
166 FileSubmitter
<b>createFileSubmitter
</b>()
</code></pre>
168 <pre><code><a href=
"api_localserver.html#FileSubmitter">FileSubmitter class
</a>
169 void
<b>setFileInputElement
</b>(htmlElement el, string url)
</code></pre>
172 <!------------------------------------------------------------->
174 <!------------------------------------------------------------->
177 <a name=
"LocalServer"></a> </p>
178 <h2>LocalServer class
</h2>
181 <p>The LocalServer is a factory and container for the set of
182 ResourceStores and ManagedResourceStores your application creates and uses. Use resource stores to enable your JavaScript application to execute without a network connection.
</p>
184 <p>To create a LocalServer object, use the Gears Factory as follows:
</p>
186 <pre><code><script
type=
"text/javascript" src=
"<a href='tools.html#gears_init'>gears_init.js</a>"></script
>
187 <script
type=
"text/javascript">
188 var localServer = google.gears.factory.create('beta.localserver');
189 </script
></code></pre>
194 <th colspan=
"2"><div align=
"left"><code><strong>canServeLocally(string url)
</strong></code></div></th>
197 <td width=
"105">Return Value
</td>
198 <td width=
"579" >boolean
</td>
202 <td class=
"odd"><strong><code>url
</code></strong> - relative or absolute URL that is from the same origin as the current page
</td>
206 <td class=
"" >Throws an exception if the URL is not from the same origin
207 as the current page.
</td>
212 Returns true if a request for the URL can be satisfied from any of the resource stores available,
213 taking into account whether the containing store is enabled and if its requiredCookie matches.
214 Relative URLs are interpreted according to the current page location.
</td>
219 <th colspan=
"2"><div align=
"left"><code><strong>createStore(string name, [string requiredCookie])
</strong></code></div></th>
222 <td width=
"108">Return Value
</td>
223 <td width=
"579"><code>ResourceStore
</code></td>
227 <td><code>name
</code>
228 - string identifying the store.
<br />
229 <code>requiredCookie
</code> - optional.
<br />
230 The combination of name and requiredCookie (along with the domain) identify a unique store.
<br />
231 Expected cookie format is
"name=value
".
</td>
235 <td class=
"" >Throws a JavaScript exception if an errors occurs.
</td>
239 <td class=
"odd">Opens an existing ResourceStore or creates a new one if
240 no such store exists.
<br />
242 If a requiredCookie is given, creates a ResourceStore that requires the cookie to be present in the client in order to serve the contents from the store.
247 <th colspan=
"2"><div align=
"left"><code><strong>openStore(string name, [string requiredCookie])
</strong></code></div></th>
250 <td width=
"137">Return Value
</td>
251 <td width=
"546"><code>ResourceStore
</code><br />
252 <code>null
</code> - if no such store exists
</td>
256 <td><code>name
</code> - string identifying the store.
<br />
257 <code>requiredCookie
</code> - optional.
<br />
258 The combination of name and requiredCookie (along with the domain) identify a unique store.
<br />
259 Expected cookie format is
"name=value
".
</td>
263 <td class=
"" > Throws a JavaScript exception if an errors occurs.
</td>
267 <td class=
"odd">Opens an existing ResourceStore or returns null if no such store exists. If the store was originally created with a requiredCookie, the same value must be provided in order to open this ResourceStore.
272 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong> removeStore(string name, [string requiredCookie])
</strong></code></div></th>
275 <td width=
"113">Return Value
</td>
276 <td width=
"489" >void
</td>
280 <td><code>name
</code> - string identifying the store.
<br>
281 <code>requiredCookie
</code> - optional.
<br />
282 The combination of name and requiredCookie (along with the domain) identify a unique store.
<br />
283 Expected cookie format is
"name=value
".
</td>
287 <td class=
"" >Throws a JavaScript exception if an errors occurs.
</td>
291 <td class=
"odd">Removes a ResourceStore and deletes all of its contents.
</td>
296 <th colspan=
"2"><div align=
"left"><code><strong>createManagedStore(string name, [string requiredCookie])
</strong></code></div></th>
299 <td width=
"125">Return Value
</td>
300 <td width=
"562"><code>ManagedResourceStore
</code></td>
304 <td><code>name
</code> - string identifying the store.
<br />
305 <code>requiredCookie
</code> - optional.
<br />
306 The combination of name and requiredCookie (along with the domain) identify a unique store.
<br />
307 Expected cookie format is
"name=value
".
</td>
311 <td class=
"" >Throws a JavaScript exception if an errors occurs.
</td>
315 <td class=
"odd">Opens an existing ManagedResourceStore or creates a new one if
316 no such store exists.
</tr>
320 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>openManagedStore(string name, [string requiredCookie])
</strong></code></div></th>
323 <td width=
"113">Return Value
</td>
324 <td width=
"489"><code>ManagedResourceStore
</code></td>
328 <td><code>name
</code> - string identifying the store.
<br />
329 <code>requiredCookie
</code> - optional.
<br />
330 The combination of name and requiredCookie (along with the domain) identify a unique store.
<br />
331 Expected cookie format is
"name=value
".
</td>
335 <td class=
"" > Throws a JavaScript exception if an errors occurs.
</td>
339 <td class=
"odd">Opens an existing ManagedResourceStore or returns null if no such store exists.
</tr>
343 <th colspan=
"2"><div align=
"left"><code><strong> removeManagedStore(string name, [string requiredCookie])
</strong></code></div></th>
346 <td width=
"129">Return Value
</td>
347 <td width=
"558" >void
</td>
351 <td><code>name
</code> - string identifying the store.
<br>
352 <code>[requiredCookie]
</code></td>
356 <td class=
"" >Throws a JavaScript exception if an errors occurs.
</td>
360 <td class=
"odd">Removes a ManagedResourceStore and all of its contained URLs
361 from the local cache.
</td>
366 <!------------------------------------------------------------->
367 <!-- ManagedResourceStore -->
368 <!------------------------------------------------------------->
370 <a name=
"ManagedResourceStore"></a> </p>
373 <h2>ManagedResourceStore class
</h2>
376 <p>The ManagedResourceStore class is designed to cache a set of
377 inter-dependent resources. For example, it can cache the set of resources required
378 to bootstrap an application. The contents of a ManagedResourceStore are
379 determined by the URLs listed in a
<a href=
"#manifest_file">manifest file
</a>. When all resources listed
380 in the manifest have been captured, the LocalServer makes the set eligible
381 for use. Periodically, the LocalServer checks for an updated manifest file. If the manifest file has been updated, LocalServer automatically downloads the updated set of resources.
</p>
384 <p>A ManagedResourceStore is a container of cached URLs. Each distinct ManagedResourceStore is uniquely identified by these attributes:
</p>
387 <li><code>name
</code> - a string identifying the store.
<br>
388 <i>Currently the name must consist only of visible ASCII characters excluding the following:
</i>
389 <br><kbr>/ \ : * ?
" < > | ; , </kbr><br>
390 <i>Before finalization of the API we expect to remove this restriction.</i></li>
391 <li><code>requiredCookie</code> - a cookie of the format "name=value" or null </li>
392 <li><code>origin</code> - the scheme, domain, and port of the current page.</li>
396 <p> An application can have many <code>ManagedResourceStores</code>.</p>
397 <p>The ManagedResourceStores class requires a <em>manifest file</em> to define the URLs to store. The <a href="#manifest_file
">manifest file</a> is described in detail, below. </p>
402 <th width="158">Attribute</th>
404 <th >Description</th>
407 <td width="158"><strong>name</strong></td>
408 <td width="109" >readonly attribute string</td>
409 <td width="432" >The name of this managed resource store. </td>
412 <td><strong><a name="MRScookie
" id="MRScookie
"></a>requiredCookie</strong></td>
413 <td class="" >readonly attribute string </td>
414 <td class="" >The cookie requirements of the store.<br>
415 For further details see <a href="#required_cookie
">Cookies and the LocalServer</a>.
416 If empty, resources within this store are always served locally, provided the store is <code>enabled</code>.</td>
419 <td><strong>enabled</strong></td>
420 <td class="odd
">readwrite attribute boolean </td>
421 <td class="odd
">Enables local serving of URLs from this store when <code>enabled=true</code>. Disables local serving otherwise. </td>
424 <td><strong>manifestUrl</strong></td>
425 <td class="odd
">readwrite attribute string </td>
426 <td class="odd
">The location of the manifest file.</td>
429 <td><strong>lastUpdateCheckTime</strong></td>
430 <td class="odd
">readonly attribute int</td>
431 <td class="odd
">Time in second when the last update check
435 <td><strong>updateStatus</strong></td>
436 <td class="odd
">readonly attribute int</td>
438 Can be one of four values:
439 <table class="noborders
">
441 <td><strong>0</strong>
442 <td>Update OK. An update task is not running. The last update task to run succeeded.
444 <td><strong>1</strong>
445 <td>Update checking. Gears is checking for a new manifest file.
447 <td><strong>2</strong>
448 <td>Update downloading. Gears is found a new manifest and is downloading the new resources.
450 <td><strong>3</strong>
451 <td>Update failed. An update task is not running. The last update task to run failed, and the error message is in the <code>lastErrorMessage</code> property.
456 <td><strong> lastErrorMessage</strong> </td>
457 <td class="odd
">readonly attribute string</td>
458 <td class="odd
">When updateStatus is <strong>3</strong> (update failed), this property contains details about the error.</td>
461 <td><strong>currentVersion</strong></td>
462 <td class="odd
">readonly attribute string </td>
463 <td class="odd
">The version of the set of resources that is currently being served locally, or empty string if no version is
464 currently in use. This value reflects the <code>version</code> attribute from the manifest file only after all resources listed in the
465 manifest file have been cached locally.</td>
473 <th colspan="2"><code><strong>event void oncomplete(Object
474 details)</strong></code></th>
479 <code>details</code> An object containing information about the update.
480 Contains one property:
481 <br> • <code>String newVersion</code> - The new
482 version of the ManagedResourceStore if the version changed. Otherwise,
489 <p>This event is fired when a ManagedResourceStore completes an
490 update. Note that updates can be either started explicitly, by calling
491 <code>checkForUpdate()</code>, or implicitly, when resources are
492 served from the store.
493 <p>An update may or may not result in a new version of the store. If
494 a new version results, the <code>newVersion</code> property of the
495 <code>details</code> object will contain the store's new version string.
502 <th colspan="2"><code><strong>event void onerror(Error
503 error)</strong></code></th>
508 <code>error</code> Contains details about the error that occured.
509 Contains one property:
510 <br> • <code>String message</code> - The error
516 <td>This event is fired when a ManagedResourceStore update fails. Note
517 that update failure may occur normally when an application is running
518 offline, or if the server is down.</td>
524 <th colspan="2"><code><strong>event void onprogress(Object
525 details)</strong></code></th>
530 <code>details</code> Contains information about the progress of a
531 ManagedResourceStore update. Contains the following properties:
532 <br> • <code>Number filesComplete</code> - The number
533 of files that have been captured so far in the current update.
534 <br> • <code>Number filesTotal</code> - The total
535 number of files that need to be captured in the current update.
540 <td>This event is fired periodically during a ManagedResourceStore update.
541 The <code>filesTotal</code> property contains the total number of files
542 found in the manifest that need to be fetched. The
543 <code>filesComplete</code> property contains the number of files that have
544 been fetched so far. You can use this information to show progress
545 information to the user.</td>
549 <a name="checkforupdate
" id="checkforupdate
"></a>
553 <th colspan="2"><div align="left
"><code><strong>void checkForUpdate()</strong></code></div></th>
556 <td width="91">Return Value </td>
557 <td width="594" >void</td>
561 <td class="odd
"> </td>
565 <td class="" > </td>
568 <td >Description</td>
569 <td class="odd
"><p>Explicitly initiates an update task that runs asynchronously in the background, and returns immediately. <br />
570 <p>An update task first issues a conditional GET of the manifest file from <code>manifestUrl</code>.
571 If a response body is returned, the JSON data is parsed and the 'version' attribute is compared with
572 the <code>currentVersion</code> property of the store. If they are different, the update task proceeds
573 to GET each resource listed in the new manifest file. If the previous version contained a resource listed
574 in the new version, the update task will issue an IfModifiedSince conditional request. While an update
575 is in progress, resources from the previous version (if any) will continue to be served locally. After all
576 resources have been downloaded, the <code>currentVersion</code> property will be updated to indicate
577 that the new set of a resources are now being served locally and the previous version has been removed.
578 <p>An additional HTTP header is added when Gears is capturing URLs<br>
579 <code>X-Gears-Google: 1</code></p>
580 <p>If an update task is interrupted in the middle, processing will resume where it left off the next time
581 an update task for this store is initiated.</p>
582 <p>Note that the manifest file's version string is compared for equality against the current known version string, and if a <em>different</em> version is found, downloads it. No other types of comparisons are performed on the version string. </p>
583 <p>Update tasks are initiated automatically by Gears when resources stored in the ManagedResourceStore are requested and served. </p> </td>
593 <!------------------------------------------------------------->
594 <!-- ResourceStore -->
595 <!------------------------------------------------------------->
596 <a name="ResourceStore
"></a>
597 <h2>ResourceStore class </h2>
599 <p>A <code>ResourceStore</code> is a container of cached URLs.
600 Each distinct <code>ResourceStores</code> is uniquely identified by three attributes:
602 <li> <code>name</code> - a string name identifying the ResourceStore<br>
603 <i>Currently the name must consist only of visible ASCII characters excluding the following:</i>
604 <br><kbr>/ \ : * ? " < > | ; ,
</kbr><br>
605 <i>Before finalization of the API we expect to remove this restriction.
</i></li>
606 <li><code>requiredCookie
</code> - a cookie of the format
"name=value
" or null
</li>
607 <li><code>domain
</code> - the domain, protocol and port of the current page.
</li>
611 <p>There can be many
<code>ResourceStores
</code> in the system.
</p>
613 A
<code>ResourceStore
</code> is populated with URLs explicitly through the use of the JavaScript API
614 that this class provides.
</p>
619 <th width=
"123">Attribute
</th>
621 <th >Description
</th>
624 <td width=
"123"><strong>name
</strong></td>
625 <td width=
"126" >readonly attribute string
</td>
626 <td width=
"382" >The name of the store that you provided upon creating this object.
</td>
629 <td><strong>requiredCookie
</strong></td>
630 <td class=
"" >readonly attribute string
</td>
631 <td class=
"" >The cookie requirements of the store.
632 For further details see
<a href=
"#required_cookie">Cookies and the LocalServer
</a>.
<br>
633 If requiredCookie is empty, then resources within this store are always served locally, provided the store is
<code>enabled
</code>.
</td>
636 <td><strong>enabled
</strong></td>
637 <td class=
"odd">readwrite attribute boolean
</td>
638 <td class=
"odd">Enables local serving of URLs from this store when
<code>enabled=true
</code>. Disables local serving otherwise.
</td>
645 <th colspan=
"2"><div align=
"left"><code> <strong>capture(urlOrUrlArray, callback)
</strong> </code></div></th>
648 <td width=
"113">Return Value
</td>
649 <td width=
"489" >int
</td>
653 <td class=
"odd"><code>urlOrUrlArray
</code><br />
655 <code>callback(string url, boolean success, int captureId)
</code></td>
659 <td class=
"" >Throws an exception if any of the URLs is not from the same
660 origin as the current page.
</td>
664 <td class=
"odd"><p>Initiates a capture task that runs asynchronously in the
665 background, and returns immediately. The return value is a
<code>captureId
</code> which
666 can be passed to
<code>abortCapture
</code> to cancel the task.
<br />
669 interpreted according to the current page's location. Upon completion of each URL the
<code>callback
</code> function is invoked.
670 <p>An additional HTTP header is added when Gears is capturing URLs
<br><code>X-Gears-Google:
1</code></td>
676 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong> abortCapture(int captureId)
</strong></code></div></th>
679 <td width=
"113">Return Value
</td>
680 <td width=
"489" >void
</td>
684 <td class=
"odd"><code>captureId
</code></td>
688 <td class=
"" > </td>
692 <td class=
"odd">Aborts a capture task.
</td>
697 <th colspan=
"2"><div align=
"left"><code> <strong> remove(string url)
</strong></code></div></th>
700 <td width=
"113">Return Value
</td>
701 <td width=
"489" >void
</td>
705 <td><code>url
</code></td>
709 <td class=
"" >Throws an exception if URL is not from the same
710 origin as the current page.
</td>
714 <td class=
"odd">Removes a cached URL from the store.
</td>
719 <th colspan=
"2"><div align=
"left"><code><strong>rename(string srcUrl, string destUrl)
</strong></code></div></th>
722 <td width=
"131">Return Value
</td>
723 <td width=
"508" >void
</td>
727 <td><code>srcUrl
</code> <br />
729 <code>destUrl
</code></td>
733 <td class=
"" >Throws an exception if the source or destination URL is not from the same
734 origin as the current page.
</td>
738 <td class=
"odd">Renames a URL that is cached in the resource store.
</td>
743 <th colspan=
"2"><div align=
"left"><code><strong>copy(string srcUrl, string destUrl)
</strong></code></div></th>
746 <td width=
"113">Return Value
</td>
747 <td width=
"489" >void
</td>
751 <td><code>srcUrl
</code> <br />
753 <code>destUrl
</code></td>
757 <td class=
"" >Throws an exception if the source or destination URL is not from the same
758 origin as the current page.
</td>
762 <td class=
"odd">Copies a cached URL.
</td>
767 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>isCaptured(string url)
</strong></code></div></th>
770 <td width=
"113">Return Value
</td>
771 <td width=
"489" >boolean
</td>
775 <td><code>url
</code></td>
779 <td class=
"" >Throws an exception if the URL is not from the same
780 origin as the current page.
</td>
784 <td class=
"odd">Returns true if the URL is cached in the store.
</td>
789 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>captureFile(HtmlElement fileInputElement, string url)
</strong></code></div></th>
792 <td width=
"113">Return Value
</td>
793 <td width=
"489" >void
</td>
797 <td><code>fileInputElement
</code><br/>
799 <code>url
</code></td>
803 <td class=
"" >Throws an exception if the URL is not from the same
804 origin as the current page or if the file cannot be read.
</td>
808 <td class=
"odd">Captures the contents of the file indicated by the
809 <code>fileInputElement
</code> into the store and associates
810 that content with the given URL. The
<code>fileInputElement
</code>
811 argument must be a reference to an
<code> <input type=file
></code>
817 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>getCapturedFileName(string url)
</strong></code></div></th>
820 <td width=
"113">Return Value
</td>
821 <td width=
"489" >string
</td>
825 <td><code>url
</code></td>
829 <td class=
"" >Throws an exception if the
<code>url
</code> is not from the same
830 origin as the current page.
</td>
834 <td class=
"odd">Returns the leaf file name associated with
<code>url
</code> that was previously captured by
835 calling
<code>captureFile
</code>. Note that if
<code>url
</code> was captured by a method other than calling
836 <code>captureFile
</code> then an empty string will be returned and no exception will be thrown.
</td>
841 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>getHeader(string url, string name)
</strong></code></div></th>
844 <td width=
"113">Return Value
</td>
845 <td width=
"489" >string
</td>
849 <td><code>url
</code><br/><br/>
850 <code>name
</code> name of the header you want to retrieve, e.g. 'Content-Length'.
</td>
854 <td class=
"" >Throws an exception if the
<code>url
</code> is not from the same
855 origin as the current page.
</td>
859 <td width=
"489">Returns a specific HTTP header associated with the captured URL.
</td>
864 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>getAllHeaders(string url)
</strong></code></div></th>
867 <td width=
"113">Return Value
</td>
868 <td width=
"489" >string
</td>
872 <td class=
"odd"><code>url
</code></td>
876 <td class=
"" >Throws an exception if the
<code>url
</code> is not from the same
877 origin as the current page.
</td>
881 <td width=
"489">Returns all HTTP headers associated with the captured
<code>url
</code>.
</td>
886 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>createFileSubmitter()
</strong></code></div></th>
889 <td width=
"113">Return Value
</td>
890 <td width=
"489"><code>FileSubmitter
</code></td>
894 <td width=
"489">Returns a
<code>FileSubmitter
</code> object, which is used to submit URLs that are contained in this store
895 in HTML form submissions.
</td>
900 <!------------------------------------------------------------->
901 <!-- FileSubmitter -->
902 <!------------------------------------------------------------->
903 <a name=
"FileSubmitter"></a>
904 <h2>FileSubmitter class
</h2>
905 <p>The
<code>FileSubmitter
</code> object facilitates the submission of local files, that
906 were previously captured using
<code>ResourceStore.captureFile
</code>, in
907 multipart/form-data encoded form submissions.
</p>
908 <p>To create a
<code>FileSubmitter
</code>, call
909 <code>ResourceStore.createFileSubmitter()
</code>. The returned object allows only
910 URLs contained in the originating resource store to be submitted.
</p>
915 <th colspan=
"2" width=
"100%"><div align=
"left"><code><strong>setFileInputElement(htmlElement, url)
</strong></code></div></th>
918 <td width=
"113">Return Value
</td>
919 <td width=
"489"><code>void
</code></td>
923 <td><code>htmlElement
</code><br/><br/>
924 <code>url
</code></td>
928 <td class=
"" >Throws an exception if the URL is not from the same
929 origin as the current page.
</td>
933 <td width=
"489"><p>Prepares the htmlElement to submit the file indicated by url. The htmlElement
934 must be contained in an html form. When the form is submitted the file will be
935 included as part of the resulting POST. The url is the captured resource's
936 key in the originating Store. Relative URLs are interpreted according to the
937 current page's location. The name attribute of htmlElement determines the
938 parameter name associated with the uploaded file.
</p>
939 <p>Due to differences between Firefox and Internet Explorer, this method's
940 behavior is browser specific.
</p>
942 <li> Firefox: The
<code>htmlElement
</code> must be a reference to an
<code> <input type=
"file
"></code>
944 <li> Internet Explorer: The
<code>htmlElement
</code> must NOT be a reference to an
<input
>
950 <pre><code><form
method=
"POST" enctype=
"multipart/form-data" /
>
951 <input
id=
"fileinput" type=
"file" name=
"formFieldName" /
>
952 <link
id=
"iefileinput" name=
"formFieldName" /
>
956 var fileSubmitter = store.createFileSubmitter();
957 var htmlElement = isIE ? document.getElementById(
"iefileinput")
958 : document.getElementById(
"fileinput");
959 fileSubmitter.setFileInputElement(htmlElement, urlOfStoredResource);
960 </script
></code></pre>
962 <!------------------------------------------------------------->
963 <!-- Manifest File Format -->
964 <!------------------------------------------------------------->
966 <a name=
"manifest_file" id=
"manifest_file"></a>
967 <h2>Manifest File
</h2>
968 <p>A manifest file lists all of the URLs to be captured by a ManagedResourceStore. It also contains the version for the manifest file format, the version of the contents of the manifest, and an optional redirection URL.
</p>
969 <p> Using the ManagedResourceStore requires that you create a manifest file.
</p>
970 <p>The manifest file and all the URLs listed in it must follow the
"same-origin policy
", which means that all the URLs must originate from the same URI scheme, host, and port. See
<a href=
"security.html">Gears and Security
</a> for more information.
</p>
971 <p>An application can have any number of manifest files and ManagedResourceStores. You specify which manifest file to use when you create an instance of ManagedResourceStore.
</p>
972 <p>The manifest file is written in
<a href=
"http://www.google.com/url?sa=D&q=http://www.json.org">JavaScript Object Notation
</a> (JSON) format.
</p>
973 <p><strong>Sample manifest file
</strong></p>
975 // version of the manifest file format
976 "betaManifestVersion
":
1,
978 // version of the set of resources described in this manifest file
979 "version
":
"my_version_string
",
982 // If the store specifies a requiredCookie, when a request would hit
983 // an entry contained in the manifest except the requiredCookie is
984 // not present, the local server responds with a redirect to this URL.
985 "redirectUrl
":
"login.html
",
987 // URLs to be cached (URLs are given relative to the manifest URL)
988 "entries
": [
989 {
"url
":
"main.html
",
"src
":
"main_offline.html
" },
990 {
"url
":
".
",
"redirect
":
"main.html
" },
991 {
"url
":
"main.js
" }
992 {
"url
":
"formHandler.html
",
"ignoreQuery
": true },
996 <h3>Contents of a manifest file
</h3>
997 <p>Manifest File JSON object: A single object contains the attribute-value pairs described below.
</p>
998 <p>Note: All URLs can be provided as relative to the manifest file, or as fully-qualifed URIs.
</p>
1001 <th width=
"186"><div align=
"center" >Attribute
</div></th>
1002 <th width=
"208"><div align=
"center" >Value
</div></th>
1003 <th width=
"336"><div align=
"center" >Notes
</div></th>
1006 <td width=
"186"><code>"betaManifestVersion
"</code></td>
1007 <td width=
"208"><code>1</code></td>
1008 <td width=
"336" >Required. Represents the version of the manifest file format itself. The manifest file is recognized only if this attribute and value appear and are correct.
</td>
1011 <td><code>"version
"</code></td>
1012 <td class=
"odd">string
<strong></td>
1013 <td class=
"odd">Required. Represents the version, which you determine, of the manifest file's contents. This version is usually your application's version.
1015 <li>Version string is any value determined by your application.
</li>
1016 <li>String is case sensitive.
</li>
1017 <li>Any change in the version string indicates to Gears that the manifest file has changed.
</li>
1021 <td><code>"redirectUrl
"</code></td>
1022 <td class=
"" >URL
</td>
1023 <td class=
"" >Optional. The redirect URL is returned from the localServer if a
"<a href=
"#MRScookie">requiredCookie
</a>" is not present for the URL requested.
</td>
1026 <td><code>"entries
"</code></td>
1027 <td width=
"208">An array of URL resources, in JavaScript object format. (See table below for details.)
</td>
1028 <td width=
"336">Lists the URLs of all the resources to be captured for this manifest file.
</td>
1032 <p>The
<code>"entries
"</code> attribute in the manifest file is an array of URL resources, in JavaScript object format. The resource objects' attribute-value pairs are described below.
</p>
1035 <th width=
"186"><div align=
"center" >Attribute
</div></th>
1036 <th width=
"179"><div align=
"center" >Value
</div></th>
1037 <th width=
"365"><div align=
"center" >Notes
</div></th>
1040 <td width=
"186"><code>"url
"</code></td>
1041 <td width=
"179" >URL
</td>
1042 <td width=
"365" >Required. A URL of a resource to be stored locally and served when
<code>"url
"</code> is requested locally.
<br />
1044 All URLs must follow the same-origin
<a href=
"security.html">security
</a> policy.
</td>
1047 <td><code>"src
"</code></td>
1048 <td class=
"odd">URL
<strong></td>
1049 <td class=
"odd">Optional.
1050 If
<code>"src
"</code> is present, the given URL is fetched and
1051 served when
<code>"url
"</code> is requested locally.
<br />
1053 The
<code>"src
"</code> and
<code>"redirect
"</code> are mutually
1057 <td><code>"redirect
"</code></td>
1058 <td class=
"" >URL
</td>
1059 <td class=
"" >Optional. If
<code>"redirect
"</code> is present, the
1060 local server responds with a
302 redirect to the given URL when
<code>"url
"</code> is
1061 requested locally.
<br />
1063 The
<code>"src
"</code> and
<code>"redirect
"</code> are mutually
1067 <td><code>"ignoreQuery
"</code></td>
1068 <td width=
"179">boolean (default is
<code>false
</code>)
</td>
1069 <td width=
"365">Optional. If the value is
<code>true
</code> the query string in the request URL is ignored when matching against this entry's URL.
<br />
1071 For example, a request for
<code>formHandler.html?name=value
</code> can match the entries for the full URL including the query, or just the
<code>formHandler.html
</code> portion of the URL.
<br />
1073 Note: An entry with an exact URL match takes precedence over a match found by ignoring the query string.
</td>
1077 <!------------------------------------------------------------->
1078 <!-- Cookies and the LocalServer -->
1079 <!------------------------------------------------------------->
1081 <a name=
"required_cookie"></a>
1082 <h2>Cookies and the LocalServer
</h2>
1083 <p>Both the
<code>ResourceStore
</code> and
<code>ManagedResourceStore
</code>
1084 support an optional
<code>requiredCookie
</code> attribute.
1085 This value causes LocalServer to examine cookies when
1086 deciding which resource to serve for a request. The attribute is used as follows:
</p>
1090 <th><div align=
"center" >requiredCookie
</div></th>
1091 <th width=
"100%"><div align=
"center" >Behavior
</div></th>
1094 <td><code>"foo=bar
"</code></td>
1095 <td>Serves the resource from the store if cookie
<code>foo
</code> is present in the request, and
1096 has the value
<code>bar
</code>.
1100 <td><code>"foo=;NONE;
"</code></td>
1101 <td class=
"odd">Serves the resource from the store if cookie
<code>foo
</code>
1102 is
<b>not
</b> present in the request.
1107 <!------------------------------------------------------------->
1108 <!-- File system location -->
1109 <!------------------------------------------------------------->
1111 <a name=
"filesystem_location"></a>
1112 <h2>Location of cached files
</h2>
1113 <p>The LocalServer stores files that your application captures in a location determined by the browser and platform.
</p>
1114 <p><strong>Windows Vista - Internet Explorer
</strong></p>
1115 <p> Location: {FOLDERID_LocalAppDataLow}\Google\Google Gears for Internet Explorer
<br />
1116 Example: C:\Users\Bob\AppData\LocalLow\Google\Google Gears for Internet Explorer
</p>
1117 <p><strong>Windows Vista - Firefox
</strong>- Files are stored in the user local profile directory.
</p>
1118 <p>Location: C:\Users\
<username
>\AppData\Local\Mozilla\Firefox\Profiles\{profile}.default\Google Gears for Firefox
<br />
1119 Example: C:\Users\Bob\AppData\Local\Mozilla\Firefox\Profiles\uelib44s.default\Google Gears for Firefox
</p>
1120 <p><strong>Windows XP - Internet Explorer
</strong>- Files are stored in the user local profile directory.
</p>
1121 <p> Location: C:\Documents and Settings\
<username
>\Local Settings\Application Data\Google\Google Gears for Internet Explorer
<br />
1122 Example: C:\Documents and Settings\Bob\Local Settings\Application Data\Google\Google Gears for Internet Explorer
</p>
1123 <p><strong> Windows XP - Firefox
</strong>- Files are stored in the user local profile directory.
</p>
1124 <p>Location: C:\Documents and Settings\
<username
>\Local Settings\Application Data\Mozilla\Firefox\Profiles\{profile}\Google Gears for Firefox
<br />
1125 Example: C:\Documents and Settings\Bob\Local Settings\Application Data\Mozilla\Firefox\Profiles\uelib44s.default\Google Gears for Firefox
</p>
1126 <p><strong>Mac OS/X - Firefox
</strong>- Files are stored in the user local profile directory.
</p>
1127 <p>Location: Users/
<username
>/Library/Caches/Firefox/Profiles/{profile}.default/Google Gears for Firefox
<br />
1128 Example: Users/Bob/Library/Caches/Firefox/Profiles/
08ywpi3q.default/Google Gears for Firefox
</p>
1129 <p><strong>Linux - Firefox
</strong>- Files are stored in the user home directory.
</p>
1130 <p>Location: ~
<em>bob
</em>/.mozilla/firefox/
<firefox's profile id
>/Google Gears for Firefox
<br />
1131 Example: ~bob/.mozilla/firefox/
08ywpi3q.default/Google Gears for Firefox
</p>