/
include.html
109 lines (105 loc) · 3.38 KB
/
include.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
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<html>
<body>
This page contains javascript that can be included in an iframe and
upon recieving commands over postMessage will attempt to invoke privileged
repository management APIs.
</body>
<script src="../urlmatch.js"></script>
<script src="../jshelper.js"></script>
<!-- finally, define our handlers that'll be invoked over jschannel by the parent -->
<script>
window.addEventListener('message', doSomething);
var installed = false;
function doSomething(event) {
if(event.data == "getSelf") {
var origin = getOrigin(appURL);
mozAppscb(navigator.mozApps.getSelf(),
[{ status: "== \"success\"",
installOrigin: "== " + "chrome://mochitests".quote(),
origin: "== " + origin.quote(),
manifestURL: "== " + appURL.quote()
}],
check,
next);
}
else if(event.data == "uninstall") {
var pending = navigator.mozApps.getSelf();
pending.onsuccess = function () {
var result = pending.result.uninstall();
result.onsuccess = function() {
check(true, "app has been uninstalled by the domain");
next();
};
result.onerror = function() {
check(false, "app uninstall failed");
next();
};
};
pending.onerror = function() {
check(false, "app uninstall failed through getSelf");
next();
};
}
else if(event.data == "install") {
debug('type of check = ' + typeof check);
install(appURL, check, next);
installed = true;
}
else if(event.data == "getInstalled") {
if(installed == true) {
getInstalled([appURL], check, next);
}
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: "== \"success\""}],
check,
next);
}
else if(event.data == "mgmt.getAll") {
var hostname = window.location.hostname;
debug(hostname);
if (hostname != "http://example.com") {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"error\"",
name: "== \"DENIED\""
}],
check,
next
);
} else {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"success\""}],
check,
next
);
}
}
else if(event.data == "mgmt.event_error") {
var hostname = window.location.hostname;
debug(hostname);
if (hostname != "http://example.com") {
try {
navigator.mozApps.mgmt.addEventListener("install", function (ev) {check(ev.application.origin);});
} catch (e) {
check(!e.message, e.message);
}
try {
navigator.mozApps.mgmt.removeEventListener("install", function (ev) {check(!ev.application.origin);});
} catch (e) {
check(!e.message, e.message);
}
finally {
next();
}
} else {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"success\""}],
check,
next
);
}
}
}
</script>
</html>