Bug 1042882 - Add an explicit field to track application kind in the registry r=myk

This commit is contained in:
Fabrice Desré 2014-08-01 10:41:52 -07:00
parent e7e1275ed0
commit b20c117986
3 changed files with 59 additions and 27 deletions

View File

@ -100,6 +100,7 @@ function _setAppProperties(aObj, aApp) {
aObj.storeVersion = aApp.storeVersion || 0;
aObj.role = aApp.role || "";
aObj.redirects = aApp.redirects;
aObj.kind = aApp.kind;
}
this.AppsUtils = {

View File

@ -151,6 +151,11 @@ XPCOMUtils.defineLazyGetter(this, "updateSvc", function() {
const STORE_ID_PENDING_PREFIX = "#unknownID#";
this.DOMApplicationRegistry = {
// pseudo-constants for the different application kinds.
get kPackaged() "packaged",
get kHosted() "hosted",
get kHostedAppcache() "hosted-appcache",
// Path to the webapps.json file where we store the registry data.
appsFile: null,
webapps: { },
@ -245,16 +250,16 @@ this.DOMApplicationRegistry = {
}
// Default storeId to "" and storeVersion to 0
if (this.webapps[id].storeId === undefined) {
this.webapps[id].storeId = "";
if (app.storeId === undefined) {
app.storeId = "";
}
if (this.webapps[id].storeVersion === undefined) {
this.webapps[id].storeVersion = 0;
if (app.storeVersion === undefined) {
app.storeVersion = 0;
}
// Default role to "".
if (this.webapps[id].role === undefined) {
this.webapps[id].role = "";
if (app.role === undefined) {
app.role = "";
}
// At startup we can't be downloading, and the $TMP directory
@ -343,6 +348,13 @@ this.DOMApplicationRegistry = {
if (app.appStatus >= Ci.nsIPrincipal.APP_STATUS_PRIVILEGED) {
app.redirects = this.sanitizeRedirects(aResult.redirects);
}
if (app.origin.startsWith("app://")) {
app.kind = this.kPackaged;
} else {
// Hosted apps, can be appcached or not.
app.kind = aResult.manifest.appcache_path ? this.kHostedAppcache
: this.kHosted;
}
});
// Nothing else to do but notifying we're ready.
@ -971,6 +983,13 @@ this.DOMApplicationRegistry = {
if (app.appStatus >= Ci.nsIPrincipal.APP_STATUS_PRIVILEGED) {
app.redirects = this.sanitizeRedirects(manifest.redirects);
}
if (app.origin.startsWith("app://")) {
app.kind = this.kPackaged;
} else {
// Hosted apps, can be appcached or not.
app.kind = aResult.manifest.appcache_path ? this.kHostedAppcache
: this.kHosted;
}
this._registerSystemMessages(manifest, app);
this._registerInterAppConnections(manifest, app);
appsToRegister.push({ manifest: manifest, app: app });
@ -1647,7 +1666,7 @@ this.DOMApplicationRegistry = {
}),
startOfflineCacheDownload: function(aManifest, aApp, aProfileDir, aIsUpdate) {
if (!aManifest.appcache_path) {
if (aApp.kind !== this.kHostedAppcache) {
return;
}
@ -1755,8 +1774,7 @@ this.DOMApplicationRegistry = {
// If the app is packaged and its manifestURL has an app:// scheme,
// then we can't have an update.
if (app.origin.startsWith("app://") &&
app.manifestURL.startsWith("app://")) {
if (app.kind == this.kPackaged && app.manifestURL.startsWith("app://")) {
sendError("NOT_UPDATABLE");
return;
}
@ -1772,21 +1790,16 @@ this.DOMApplicationRegistry = {
#endif
if (onlyCheckAppCache) {
// Bail out for packaged apps.
if (app.origin.startsWith("app://")) {
// Bail out for packaged apps & hosted apps without appcache.
if (app.kind !== this.kHostedAppcache) {
sendError("NOT_UPDATABLE");
return;
}
// We need the manifest to check if we have an appcache.
// We need the manifest to get the appcache path.
this._readManifests([{ id: id }]).then((aResult) => {
let manifest = aResult[0].manifest;
if (!manifest.appcache_path) {
sendError("NOT_UPDATABLE");
return;
}
debug("Checking only appcache for " + aData.manifestURL);
let manifest = aResult[0].manifest;
// Check if the appcache is updatable, and send "downloadavailable" or
// "downloadapplied".
let updateObserver = {
@ -1825,7 +1838,7 @@ this.DOMApplicationRegistry = {
function onload(xhr, oldManifest) {
debug("Got http status=" + xhr.status + " for " + aData.manifestURL);
let oldHash = app.manifestHash;
let isPackage = app.origin.startsWith("app://");
let isPackage = app.kind == DOMApplicationRegistry.kPackaged;
if (xhr.status == 200) {
let manifest = xhr.response;
@ -2069,7 +2082,7 @@ this.DOMApplicationRegistry = {
this.webapps[aId] = aApp;
yield this._saveApps();
if (!manifest.appcache_path) {
if (aApp.kind !== this.kHostedAppcache) {
this.broadcastMessage("Webapps:UpdateState", {
app: aApp,
manifest: aApp.manifest,
@ -2431,23 +2444,26 @@ this.DOMApplicationRegistry = {
appObject.appStatus =
aNewApp.appStatus || Ci.nsIPrincipal.APP_STATUS_INSTALLED;
if (aLocaleManifest.appcache_path) {
if (appObject.kind == this.kHostedAppcache) {
appObject.installState = "pending";
appObject.downloadAvailable = true;
appObject.downloading = true;
appObject.downloadSize = 0;
appObject.readyToApplyDownload = false;
} else if (aLocaleManifest.package_path) {
} else if (appObject.kind == this.kPackaged) {
appObject.installState = "pending";
appObject.downloadAvailable = true;
appObject.downloading = true;
appObject.downloadSize = aLocaleManifest.size;
appObject.readyToApplyDownload = false;
} else {
} else if (appObject.kind == this.kHosted) {
appObject.installState = "installed";
appObject.downloadAvailable = false;
appObject.downloading = false;
appObject.readyToApplyDownload = false;
} else {
debug("Unknown app kind: " + appObject.kind);
throw Error("Unknown app kind: " + appObject.kind);
}
appObject.localId = aLocalId;
@ -2574,6 +2590,13 @@ this.DOMApplicationRegistry = {
let manifest =
new ManifestHelper(jsonManifest, app.origin, app.manifestURL);
// Set the application kind.
if (aData.isPackage) {
app.kind = this.kPackaged;
} else {
app.kind = manifest.appcache_path ? this.kHostedAppcache : this.kHosted;
}
let appObject = this._cloneApp(aData, app, manifest, jsonManifest, id, localId);
this.webapps[id] = appObject;
@ -2604,13 +2627,13 @@ this.DOMApplicationRegistry = {
let dontNeedNetwork = false;
if (manifest.appcache_path) {
if (appObject.kind == this.kHostedAppcache) {
this.queuedDownload[app.manifestURL] = {
manifest: manifest,
app: appObject,
profileDir: aProfileDir
}
} else if (manifest.package_path) {
} else if (appObject.kind == this.kPackaged) {
// If it is a local app then it must been installed from a local file
// instead of web.
// In that case, we would already have the manifest, not just the update
@ -2621,7 +2644,7 @@ this.DOMApplicationRegistry = {
if (aData.app.localInstallPath) {
dontNeedNetwork = true;
jsonManifest.package_path = "file://" + aData.app.localInstallPath;
}
}
#endif
// origin for install apps is meaningless here, since it's app:// and this

View File

@ -256,6 +256,13 @@ WebappsActor.prototype = {
reg._saveApps().then(() => {
aApp.manifest = manifest;
// We need the manifest to set the app kind for hosted apps,
// because of appcache.
if (aApp.kind == undefined) {
aApp.kind = manifest.appcache_path ? reg.kHostedAppcache
: reg.kHosted;
}
// Needed to evict manifest cache on content side
// (has to be dispatched first, otherwise other messages like
// Install:Return:OK are going to use old manifest version)
@ -284,7 +291,7 @@ WebappsActor.prototype = {
// We can't have appcache for packaged apps.
if (!aApp.origin.startsWith("app://")) {
reg.startOfflineCacheDownload(
new ManifestHelper(manifest, aApp.origin, aApp.manifestURL));
new ManifestHelper(manifest, aApp.origin, aApp.manifestURL), aApp);
}
});
// Cleanup by removing the temporary directory.
@ -532,6 +539,7 @@ WebappsActor.prototype = {
manifestURL: manifestURL,
appStatus: appType,
receipts: aReceipts,
kind: DOMApplicationRegistry.kPackaged,
}
self._registerApp(deferred, app, id, aDir);