2 Copyright 2007, Google Inc.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 1. Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 3. Neither the name of Google Inc. nor the names of its contributors may be
13 used to endorse or promote products derived from this software without
14 specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 <title>Hello World ResourceStore
</title>
33 <link rel=
"stylesheet" type=
"text/css" href=
"sample.css">
37 <h1>Google Gears ResourceStore Demo
</h1>
38 <div id=
"view-source"> </div>
41 <input type=
"button" value=
"Create Store" onclick=
"createStore();">
42 <input type=
"button" value=
"Capture" onclick=
"capture();">
43 <input type=
"button" value=
"Uncapture" onclick=
"uncapture();">
44 <input type=
"button" value=
"Remove Store" onclick=
"removeStore();">
49 <p><b>This page demonstrates basic usage of ResourceStore.
</b>
53 <li>Press the 'CreateStore' button to create a resource store to contain captured resources.
54 <li>Press the 'Capture' button to capture this page.
56 <li>Unplug the network cable and verify that you can still access this page.
57 <li>Delete your browser cache and verify that you can still access this page.
59 <li>Press the 'Uncapture' button to remove the page from the ResourceStore. Verify
60 that you can no longer access the page offline.
61 <li>Press the 'RemoveStore' button to remove the resource store.
64 <!-- ====================================== -->
65 <!-- End HTML code. Begin JavaScript code. -->
67 <script type=
"text/javascript" src=
"../gears_init.js"></script>
68 <script type=
"text/javascript" src=
"sample.js"></script>
70 var STORE_NAME
= 'helloworld-store'
74 var filesToCapture
= [
84 if (!window
.google
|| !google
.gears
) {
85 addStatus('Google Gears is not installed', 'error');
91 google
.gears
.factory
.create('beta.localserver');
93 var buttons
= document
.forms
[0].elements
;
94 for (var i
= 0, el
; el
= buttons
[i
]; i
++) {
98 setError('Could not create local server: ' + ex
.message
);
102 store
= localServer
.openStore(STORE_NAME
);
106 function createStore() {
107 if (!checkProtocol()) return;
109 // If the store already exists, it will be opened
110 store
= localServer
.createStore(STORE_NAME
);
113 addStatus('Created the store');
118 setError('Please create a store for the captured resources');
123 addStatus('Capturing...');
125 // Capture this page and the js library we need to run offline.
126 store
.capture(filesToCapture
, captureCallback
);
129 function captureCallback(url
, success
, captureId
) {
130 addStatus(url
+ ' captured ' + (success
? 'succeeded' : 'failed'));
133 function uncapture() {
135 setError('Please create a store for the captured resources');
139 for (var i
= 0; i
< filesToCapture
.length
; i
++) {
140 store
.remove(filesToCapture
[i
]);
144 addStatus('Removed files from the store');
147 function removeStore() {
148 // We call openStore() to test for it's existence prior to removing it
149 if (localServer
.openStore(STORE_NAME
)) {
150 localServer
.removeStore(STORE_NAME
);
153 addStatus('Removed the store');
156 addStatus('The store does not exist', 'error');