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
|
const INSTALL_TIME = 132333986000; // Match this to value in applications-data.js
function debug(msg) {
//dump('-*- webapp-manifest.js: ' + msg + '\n');
}
let webappsTargetDir = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsILocalFile);
webappsTargetDir.initWithPath(PROFILE_DIR);
// Create profile folder if doesn't exists
if (!webappsTargetDir.exists())
webappsTargetDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));
// Create webapps folder if doesn't exists
webappsTargetDir.append('webapps');
if (!webappsTargetDir.exists())
webappsTargetDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));
let manifests = {};
let id = 1;
function copyRec(source, target) {
let results = [];
let files = source.directoryEntries;
if (!target.exists())
target.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));
while (files.hasMoreElements()) {
let file = files.getNext().QueryInterface(Ci.nsILocalFile);
if (file.isDirectory()) {
let subFolder = target.clone();
subFolder.append(file.leafName);
copyRec(file, subFolder);
} else {
file.copyTo(target, file.leafName);
}
}
}
// Returns the nsIPrincipal compliant integer
// from the "type" property in manifests.
function getAppStatus(status) {
let appStatus = 1; // By default, apps are installed
switch (status) {
case "certified":
appStatus = 3;
break;
case "privileged":
appStatus = 2;
break;
case "web":
default:
appStatus = 1;
break;
}
return appStatus;
}
Gaia.webapps.forEach(function (webapp) {
// If BUILD_APP_NAME isn't `*`, we only accept one webapp
if (BUILD_APP_NAME != '*' && webapp.sourceDirectoryName != BUILD_APP_NAME)
return;
// Compute webapp folder name in profile
let webappTargetDirName = webapp.domain;
// Copy webapp's manifest to the profile
let webappTargetDir = webappsTargetDir.clone();
webappTargetDir.append(webappTargetDirName);
webapp.manifestFile.copyTo(webappTargetDir, 'manifest.webapp');
// Add webapp's entry to the webapps global manifest.
// appStatus == 3 means this is a certified app.
// appStatus == 2 means this is a privileged app.
// appStatus == 1 means this is an installed (unprivileged) app
let url = webapp.url;
manifests[webappTargetDirName] = {
origin: url,
installOrigin: url,
receipt: null,
installTime: INSTALL_TIME,
manifestURL: url + '/manifest.webapp',
appStatus: getAppStatus(webapp.manifest.type),
localId: id++
};
});
// Write webapps global manifest
let manifestFile = webappsTargetDir.clone();
manifestFile.append('webapps.json');
// stringify json with 2 spaces indentation
writeContent(manifestFile, JSON.stringify(manifests, null, 2) + '\n');
|