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
|
'use strict';
const PREFERRED_ICON_SIZE = 60;
const GAIA_CORE_APP_SRCDIR = 'apps';
const GAIA_EXTERNAL_APP_SRCDIR = 'external-apps';
const INSTALL_TIME = 132333986000; // Match this to value in webapp-manifests.js
// Initial Homescreen icon descriptors.
// c.f. the corresponding implementation in the Homescreen app.
function bestMatchingIcon(preferred_size, manifest, origin) {
var icons = manifest.icons;
if (!icons) {
return undefined;
}
var preferredSize = Number.MAX_VALUE;
var max = 0;
for (var size in icons) {
size = parseInt(size, 10);
if (size > max)
max = size;
if (size >= PREFERRED_ICON_SIZE && size < preferredSize)
preferredSize = size;
}
// If there is an icon matching the preferred size, we return the result,
// if there isn't, we will return the maximum available size.
if (preferredSize === Number.MAX_VALUE)
preferredSize = max;
var url = icons[preferredSize];
if (!url) {
return undefined;
}
// If the icon path is not an absolute URL, prepend the app's origin.
if (url.indexOf('data:') == 0 ||
url.indexOf('app://') == 0 ||
url.indexOf('http://') == 0 ||
url.indexOf('https://') == 0)
return url;
return origin + url;
}
function iconDescriptor(directory, app_name, entry_point) {
let origin = gaiaOriginURL(app_name);
let manifestURL = gaiaManifestURL(app_name);
// For external/3rd party apps that don't use the Gaia domain, we have an
// 'origin' file that specifies the URL.
let dir = getFile(GAIA_DIR, directory, app_name);
let originFile = dir.clone();
originFile.append("origin");
if (originFile.exists()) {
origin = getFileContent(originFile).replace(/^\s+|\s+$/, '');
if (origin.slice(-1) == "/") {
manifestURL = origin + "manifest.webapp";
} else {
manifestURL = origin + "/manifest.webapp";
}
}
let manifestFile = dir.clone();
manifestFile.append("manifest.webapp");
let manifest = getJSON(manifestFile);
if (entry_point &&
manifest.entry_points &&
manifest.entry_points[entry_point]) {
manifest = manifest.entry_points[entry_point];
}
let icon = bestMatchingIcon(PREFERRED_ICON_SIZE, manifest, origin);
//TODO set localizedName once we know the default locale
return {
manifestURL: manifestURL,
entry_point: entry_point,
updateTime: INSTALL_TIME,
name: manifest.name,
icon: icon
};
}
|