2011-11-28 20:13:26 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Fabrice Desré <fabrice@mozilla.com>
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
let EXPORTED_SYMBOLS = ["DOMApplicationRegistry", "DOMApplicationManifest"];
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2011-12-06 04:22:01 +00:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
return NetUtil;
|
|
|
|
});
|
|
|
|
|
|
|
|
let DOMApplicationRegistry = {
|
|
|
|
appsFile: null,
|
|
|
|
webapps: { },
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this.mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
|
|
|
|
let messages = ["Webapps:Install", "Webapps:Uninstall",
|
2011-12-15 17:20:57 +00:00
|
|
|
"Webapps:Enumerate", "Webapps:EnumerateAll", "Webapps:Launch"];
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
messages.forEach((function(msgName) {
|
|
|
|
this.mm.addMessageListener(msgName, this);
|
|
|
|
}).bind(this));
|
|
|
|
|
2011-12-06 04:22:01 +00:00
|
|
|
let appsDir = FileUtils.getDir("ProfD", ["webapps"], true, true);
|
|
|
|
this.appsFile = FileUtils.getFile("ProfD", ["webapps", "webapps.json"], true);
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
if (!this.appsFile.exists())
|
|
|
|
return;
|
2011-12-06 04:22:01 +00:00
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._loadJSONAsync(this.appsFile, (function(aData) { this.webapps = aData; }).bind(this));
|
2011-12-15 17:20:57 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
let hosts = Services.prefs.getCharPref("dom.mozApps.whitelist")
|
|
|
|
hosts.split(",").forEach(function(aHost) {
|
|
|
|
Services.perms.add(Services.io.newURI(aHost, null, null), "webapps-manage",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
});
|
|
|
|
} catch(e) { }
|
2011-12-05 23:26:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_loadJSONAsync: function(aFile, aCallback) {
|
2011-11-28 20:13:26 +00:00
|
|
|
try {
|
2011-12-05 23:26:18 +00:00
|
|
|
let channel = NetUtil.newChannel(aFile);
|
2011-11-28 20:13:26 +00:00
|
|
|
channel.contentType = "application/json";
|
|
|
|
NetUtil.asyncFetch(channel, function(aStream, aResult) {
|
|
|
|
if (!Components.isSuccessCode(aResult)) {
|
2011-12-05 23:26:18 +00:00
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not read from json file " + aFile.path);
|
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read json file into a string
|
|
|
|
let data = null;
|
|
|
|
try {
|
2011-12-05 23:26:18 +00:00
|
|
|
data = JSON.parse(NetUtil.readInputStreamToString(aStream, aStream.available()) || "");
|
2011-11-28 20:13:26 +00:00
|
|
|
aStream.close();
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(data);
|
2011-11-28 20:13:26 +00:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not parse JSON: " + ex);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not read from " + aFile.path + " : " + ex);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let msg = aMessage.json;
|
|
|
|
let from = Services.io.newURI(msg.from, null, null);
|
|
|
|
let perm = Services.perms.testExactPermission(from, "webapps-manage");
|
|
|
|
|
|
|
|
//only pages with perm set and chrome or about pages can uninstall, enumerate all set oninstall an onuninstall
|
|
|
|
let hasPrivileges = perm == Ci.nsIPermissionManager.ALLOW_ACTION || from.schemeIs("chrome") || from.schemeIs("about");
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Webapps:Install":
|
|
|
|
// always ask for UI to install
|
|
|
|
Services.obs.notifyObservers(this, "webapps-ask-install", JSON.stringify(msg));
|
|
|
|
break;
|
|
|
|
case "Webapps:Uninstall":
|
|
|
|
if (hasPrivileges)
|
|
|
|
this.uninstall(msg);
|
|
|
|
break;
|
|
|
|
case "Webapps:Launch":
|
|
|
|
Services.obs.notifyObservers(this, "webapps-launch", JSON.stringify(msg));
|
|
|
|
break;
|
|
|
|
case "Webapps:Enumerate":
|
2011-12-15 17:20:57 +00:00
|
|
|
this.enumerate(msg);
|
|
|
|
break;
|
|
|
|
case "Webapps:EnumerateAll":
|
|
|
|
this.enumerateAll(msg);
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_writeFile: function ss_writeFile(aFile, aData, aCallbak) {
|
|
|
|
// Initialize the file output stream.
|
2011-12-06 04:22:01 +00:00
|
|
|
let ostream = FileUtils.openSafeFileOutputStream(aFile);
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
// Obtain a converter to convert our data to a UTF-8 encoded input stream.
|
|
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
|
|
converter.charset = "UTF-8";
|
|
|
|
|
|
|
|
// Asynchronously copy the data to the file.
|
|
|
|
let istream = converter.convertToInputStream(aData);
|
|
|
|
NetUtil.asyncCopy(istream, ostream, function(rc) {
|
|
|
|
if (aCallbak)
|
|
|
|
aCallbak();
|
|
|
|
});
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
// clones a app object, without the manifest
|
|
|
|
_cloneAppObject: function(aApp) {
|
|
|
|
let clone = {
|
|
|
|
installOrigin: aApp.installOrigin,
|
|
|
|
origin: aApp.origin,
|
|
|
|
receipt: aApp.receipt,
|
|
|
|
installTime: aApp.installTime
|
|
|
|
};
|
|
|
|
return clone;
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
denyInstall: function(aData) {
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
|
|
|
confirmInstall: function(aData, aFromSync) {
|
2011-11-28 20:13:26 +00:00
|
|
|
let app = aData.app;
|
2011-12-08 13:32:54 +00:00
|
|
|
let id = app.syncId || this._appId(app.origin);
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
// install an application again is considered as an update
|
|
|
|
if (id) {
|
2011-12-06 04:22:01 +00:00
|
|
|
let dir = FileUtils.getDir("ProfD", ["webapps", id], true, true);
|
2011-11-28 20:13:26 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
|
|
|
id = uuidGenerator.generateUUID().toString();
|
|
|
|
}
|
|
|
|
|
2011-12-06 04:22:01 +00:00
|
|
|
let dir = FileUtils.getDir("ProfD", ["webapps", id], true, true);
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
let manFile = dir.clone();
|
|
|
|
manFile.append("manifest.json");
|
|
|
|
this._writeFile(manFile, JSON.stringify(app.manifest));
|
|
|
|
|
|
|
|
this.webapps[id] = this._cloneAppObject(app);
|
|
|
|
delete this.webapps[id].manifest;
|
|
|
|
this.webapps[id].installTime = (new Date()).getTime()
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
|
|
|
|
if (!aFromSync)
|
|
|
|
this._saveApps((function() {
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Install:Return:OK", aData);
|
|
|
|
Services.obs.notifyObservers(this, "webapps-sync-install", id);
|
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
_appId: function(aURI) {
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (this.webapps[id].origin == aURI)
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
_saveApps: function(aCallback) {
|
|
|
|
this._writeFile(this.appsFile, JSON.stringify(this.webapps), function() {
|
|
|
|
if (aCallback)
|
|
|
|
aCallback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously reads a list of manifests
|
|
|
|
*/
|
|
|
|
_readManifests: function(aData, aFinalCallback, aIndex) {
|
2011-12-15 17:20:57 +00:00
|
|
|
if (!aData.length) {
|
|
|
|
aFinalCallback(aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
let index = aIndex || 0;
|
|
|
|
let id = aData[index].id;
|
2011-12-06 04:22:01 +00:00
|
|
|
let file = FileUtils.getFile("ProfD", ["webapps", id, "manifest.json"], true);
|
2011-12-05 23:26:18 +00:00
|
|
|
this._loadJSONAsync(file, (function(aJSON) {
|
|
|
|
aData[index].manifest = aJSON;
|
|
|
|
if (index == aData.length - 1)
|
|
|
|
aFinalCallback(aData);
|
|
|
|
else
|
|
|
|
this._readManifests(aData, aFinalCallback, index + 1);
|
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
uninstall: function(aData) {
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
let app = this.webapps[id];
|
|
|
|
if (app.origin == aData.origin) {
|
|
|
|
delete this.webapps[id];
|
2011-12-06 04:22:01 +00:00
|
|
|
let dir = FileUtils.getDir("ProfD", ["webapps", id], true, true);
|
2011-11-28 20:13:26 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2011-12-08 13:32:54 +00:00
|
|
|
this._saveApps((function() {
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Uninstall:Return:OK", aData);
|
|
|
|
Services.obs.notifyObservers(this, "webapps-sync-uninstall", id);
|
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
enumerate: function(aData) {
|
|
|
|
aData.apps = [];
|
2011-12-05 23:26:18 +00:00
|
|
|
let tmp = [];
|
2011-12-15 17:20:57 +00:00
|
|
|
let selfId;
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
let id = this._appId(aData.origin);
|
|
|
|
// if it's an app, add itself to the result
|
|
|
|
if (id) {
|
|
|
|
let app = this._cloneAppObject(this.webapps[id]);
|
|
|
|
aData.apps.push(app);
|
2011-12-05 23:26:18 +00:00
|
|
|
tmp.push({ id: id });
|
2011-12-15 17:20:57 +00:00
|
|
|
selfId = id;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if it's a store.
|
|
|
|
let isStore = false;
|
|
|
|
for (id in this.webapps) {
|
2011-12-15 17:20:57 +00:00
|
|
|
let app = this.webapps[id];
|
2011-11-28 20:13:26 +00:00
|
|
|
if (app.installOrigin == aData.origin) {
|
|
|
|
isStore = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add all the apps from this store
|
|
|
|
if (isStore) {
|
|
|
|
for (id in this.webapps) {
|
2011-12-15 17:20:57 +00:00
|
|
|
if (id == selfId)
|
|
|
|
continue;
|
2011-11-28 20:13:26 +00:00
|
|
|
let app = this._cloneAppObject(this.webapps[id]);
|
|
|
|
if (app.installOrigin == aData.origin) {
|
|
|
|
aData.apps.push(app);
|
2011-12-05 23:26:18 +00:00
|
|
|
tmp.push({ id: id });
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Enumerate:Return:OK", aData);
|
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
denyEnumerate: function(aData) {
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Enumerate:Return:KO", aData);
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerateAll: function(aData) {
|
|
|
|
aData.apps = [];
|
2011-12-05 23:26:18 +00:00
|
|
|
let tmp = [];
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
for (id in this.webapps) {
|
|
|
|
let app = this._cloneAppObject(this.webapps[id]);
|
|
|
|
aData.apps.push(app);
|
2011-12-05 23:26:18 +00:00
|
|
|
tmp.push({ id: id });
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Enumerate:Return:OK", aData);
|
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
getManifestFor: function(aOrigin, aCallback) {
|
|
|
|
if (!aCallback)
|
|
|
|
return;
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
let id = this._appId(aOrigin);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (!id) {
|
|
|
|
aCallback(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._readManifests([{ id: id }], function(aResult) {
|
|
|
|
aCallback(aResult[0].manifest);
|
|
|
|
});
|
2011-12-08 13:32:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/** added to support the sync engine */
|
|
|
|
|
|
|
|
getAppById: function(aId) {
|
|
|
|
if (!this.webapps[aId])
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let app = this._cloneAppObject(this.webapps[aId]);
|
|
|
|
return app;
|
|
|
|
},
|
|
|
|
|
|
|
|
itemExists: function(aId) {
|
|
|
|
return !!this.webapps[aId];
|
|
|
|
},
|
|
|
|
|
|
|
|
updateApps: function(aRecords, aCallback) {
|
|
|
|
for (let i = 0; i < aRecords.length; i++) {
|
|
|
|
let record = aRecords[i];
|
|
|
|
if (record.deleted) {
|
|
|
|
if (!this.webapps[record.id])
|
|
|
|
continue;
|
|
|
|
let origin = this.webapps[record.id].origin;
|
|
|
|
delete this.webapps[record.id];
|
|
|
|
let dir = FileUtils.getDir("ProfD", ["webapps", record.id], true, true);
|
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Uninstall:Return:OK", { origin: origin });
|
|
|
|
} else {
|
|
|
|
if (!!this.webapps[record.id]) {
|
|
|
|
this.webapps[record.id] = record.value;
|
|
|
|
delete this.webapps[record.id].manifest;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let data = { app: record.value };
|
|
|
|
this.confirmInstall(data, true);
|
|
|
|
this.mm.sendAsyncMessage("Webapps:Install:Return:OK", data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._saveApps(aCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* May be removed once sync API change
|
|
|
|
*/
|
|
|
|
getAllIDs: function() {
|
|
|
|
let apps = {};
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
// only sync http and https apps
|
|
|
|
if (this.webapps[id].origin.indexOf("http") == 0)
|
|
|
|
apps[id] = true;
|
|
|
|
}
|
|
|
|
return apps;
|
|
|
|
},
|
|
|
|
|
|
|
|
wipe: function(aCallback) {
|
|
|
|
let ids = this.getAllIDs();
|
|
|
|
for (let id in ids) {
|
|
|
|
delete this.webapps[id];
|
|
|
|
let dir = FileUtils.getDir("ProfD", ["webapps", id], true, true);
|
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._saveApps(aCallback);
|
|
|
|
}
|
2011-11-28 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper object to access manifest information with locale support
|
|
|
|
*/
|
|
|
|
DOMApplicationManifest = function(aManifest, aOrigin) {
|
|
|
|
this._origin = Services.io.newURI(aOrigin, null, null);
|
|
|
|
this._manifest = aManifest;
|
|
|
|
let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry)
|
|
|
|
.QueryInterface(Ci.nsIToolkitChromeRegistry);
|
|
|
|
let locale = chrome.getSelectedLocale("browser").toLowerCase();
|
|
|
|
this._localeRoot = this._manifest;
|
|
|
|
|
|
|
|
if (this._manifest.locales && this._manifest.locales[locale]) {
|
|
|
|
this._localeRoot = this._manifest.locales[locale];
|
|
|
|
}
|
|
|
|
else if (this._manifest.locales) {
|
|
|
|
// try with the language part of the locale ("en" for en-GB) only
|
|
|
|
let lang = locale.split('-')[0];
|
|
|
|
if (land != locale && this._manifest.locales[lang])
|
|
|
|
this._localeRoot = this._manifest.locales[lang];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMApplicationManifest.prototype = {
|
|
|
|
_localeProp: function(aProp) {
|
|
|
|
if (this._localeRoot[aProp] != undefined)
|
|
|
|
return this._localeRoot[aProp];
|
|
|
|
return this._manifest[aProp];
|
|
|
|
},
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return this._localeProp("name");
|
|
|
|
},
|
|
|
|
|
|
|
|
get description() {
|
|
|
|
return this._localeProp("description");
|
|
|
|
},
|
|
|
|
|
|
|
|
get version() {
|
|
|
|
return this._localeProp("version");
|
|
|
|
},
|
|
|
|
|
|
|
|
get launch_path() {
|
|
|
|
return this._localeProp("launch_path");
|
|
|
|
},
|
|
|
|
|
|
|
|
get developer() {
|
|
|
|
return this._localeProp("developer");
|
|
|
|
},
|
|
|
|
|
|
|
|
get icons() {
|
|
|
|
return this._localeProp("icons");
|
|
|
|
},
|
|
|
|
|
|
|
|
iconURLForSize: function(aSize) {
|
|
|
|
let icons = this._localeProp("icons");
|
|
|
|
if (!icons)
|
|
|
|
return null;
|
|
|
|
let dist = 100000;
|
|
|
|
let icon = null;
|
|
|
|
for (let size in icons) {
|
|
|
|
let iSize = parseInt(size);
|
|
|
|
if (Math.abs(iSize - aSize) < dist) {
|
|
|
|
icon = this._origin.resolve(icons[size]);
|
|
|
|
dist = Math.abs(iSize - aSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
},
|
|
|
|
|
|
|
|
fullLaunchPath: function() {
|
|
|
|
let launchPath = this._localeProp("launch_path");
|
|
|
|
return this._origin.resolve(launchPath ? launchPath : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMApplicationRegistry.init();
|