Bug 887118 - Cannot update an preinstalled packaged app (signed or otherwise) to a signed packaged app. r=ferjm

This commit is contained in:
Antonio M. Amaya 2013-06-26 14:18:34 +02:00
parent a392d9e690
commit 604b8e6a46

View File

@ -79,6 +79,13 @@ XPCOMUtils.defineLazyGetter(this, "updateSvc", function() {
const DIRECTORY_NAME = WEBAPP_RUNTIME ? "WebappRegD" : "ProfD";
#endif
// We'll use this to identify privileged apps that have been preinstalled
// For those apps we'll set
// STORE_ID_PENDING_PREFIX + installOrigin
// as the storeID. This ensures it's unique and can't be set from a legit
// store even by error.
const STORE_ID_PENDING_PREFIX = "#unknownID#";
this.DOMApplicationRegistry = {
appsFile: null,
webapps: { },
@ -346,6 +353,11 @@ this.DOMApplicationRegistry = {
app.origin = "app://" + aId;
// Do this for all preinstalled apps... we can't know at this
// point if the updates will be signed or not and it doesn't
// hurt to have it always.
app.storeId = STORE_ID_PENDING_PREFIX + app.installOrigin;
// Extract the manifest.webapp file from application.zip.
let zipFile = baseDir.clone();
zipFile.append("application.zip");
@ -2253,7 +2265,8 @@ this.DOMApplicationRegistry = {
function checkForStoreIdMatch(aStoreId, aStoreVersion) {
// Things to check:
// 1. if it's a update:
// a. We should already have this storeId
// a. We should already have this storeId, or the original storeId must start
// with STORE_ID_PENDING_PREFIX
// b. The manifestURL for the stored app should be the same one we're
// updating
// c. And finally the version of the update should be higher than the one
@ -2267,14 +2280,17 @@ this.DOMApplicationRegistry = {
let appId = self.getAppLocalIdByStoreId(aStoreId);
let isInstalled = appId != Ci.nsIScriptSecurityManager.NO_APP_ID;
if (aIsUpdate) {
if (!isInstalled || (app.localId !== appId)) {
// If we don't have the storeId on track already, this
// cannot be an update
let isDifferent = app.localId !== appId;
let isPending = app.storeId.indexOf(STORE_ID_PENDING_PREFIX) == 0;
if ((!isInstalled && !isPending) || (isInstalled && isDifferent)) {
throw "WRONG_APP_STORE_ID";
}
if (app.storeVersion >= aStoreVersion) {
if (!isPending && (app.storeVersion >= aStoreVersion)) {
throw "APP_STORE_VERSION_ROLLBACK";
}
} else if (isInstalled) {
throw "WRONG_APP_STORE_ID";
}