/
index.html
141 lines (126 loc) · 3.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
<head>
<title>app1</title>
<script src="https://myapps.mozillalabs.com/jsapi/include.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
.status {
border: 2px solid #000;
background-color: #ddd;
display: inline;
padding: 4px;
}
div {
margin-bottom: 1em;
}
pre {
border: 1px solid #999;
overflow: wrap;
width: 100%;
}
</style>
<script>
$(function () {
function setInstalled() {
var pending = navigator.mozApps.getSelf();
pending.onsuccess = function () {
if (this.result) {
$('#unknown').hide();
$('#uninstalled').hide();
$('#installed').show();
var result = {};
for (var i in this.result) {
if (i == '_window' || i == 'classID' || i == 'classInfo') {
continue;
}
result[i] = this.result[i];
try {
JSON.stringify(result[i]);
} catch (e) {
alert('Bad attribute: ' + i + ' typeof: ' + (typeof result[i]));
}
}
try {
$('#record').text(JSON.stringify(result, null, ' '));
} catch (e) {
$('#record').text('Error serializing record: ' + e);
}
} else {
$('#unknown').hide();
$('#installed').hide();
$('#uninstalled').show();
$('#record').text('');
}
};
pending.onerror = function () {
alert('Error in getSelf: ' + (this.error.name || this.error));
};
}
setInstalled();
function querystring(key) {
var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
var r=[], m;
while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
return r[0];
}
$('#install').click(function () {
var name = '/' + (querystring('manifest') || 'manifest.webapp');
var url = location.protocol + '//' + location.host + name;
console.log('Installing from', url);
var pending = navigator.mozApps.install(url);
$('#record').text('started installation: ' + url);
pending.onsuccess = function () {
#('#record').text('onsuccess called: ' + this.result');
setInstalled();
};
pending.onerror = function () {
$('#record').text("Error: " + this.error + "\n name: " + (this.error && this.error.name));
if (this.error == 'DENIED' || this.error.name == 'DENIED') {
return;
}
alert('Error in install: ' + (this.error.name || this.error));
};
});
$('#uninstall').click(function () {
var pending = navigator.mozApps.getSelf();
pending.onsuccess = function () {
var uninstall = this.result.uninstall();
uninstall.onsuccess = function () {
setInstalled();
};
uninstall.onerror = function () {
alert('Error in uninstall: ' + (this.error.name || this.error));
};
};
pending.onerror = function () {
alert('Error in getSelf: ' + (this.error.name || this.error));
};
});
});
</script>
</head>
<body>
<div>
Welcome to <code>app1</code>
</div>
<div>The manifest is located at <a
href="http://app1.ianbicking.org/manifest.webapp">http://app1.ianbicking.org/manifest.webapp</a>
</div>
<div>Installation status is:
<div id="unknown" class="status">Unknown</div>
<div id="installed" class="status" style="display: none">Installed</div>
<div id="uninstalled" class="status" style="display: none">Uninstalled</div>
</div>
<div>To install or reinstall:
<button type="button" id="install">Install</button>
<button type="button" id="uninstall">Uninstall</button>
</div>
<pre id="record"></pre>
<div>
Other versions:
<ol>
<li><a href="/">Normal version</a></li>
<li><a href="/?manifest=manifest_bad_installs_allowed_from.webapp">Blocked installs_allowed_from</a></li>
</ol>
</div>
</body>