Bug 816149 - When updating hosted apps with appcache, the update is automatically done [r=ferjm]

This commit is contained in:
Fabrice Desré 2012-12-03 11:38:09 -08:00
parent c0f807b818
commit 812a427150
2 changed files with 28 additions and 25 deletions

View File

@ -465,10 +465,20 @@ WebappsApplication.prototype = {
checkForUpdate: function() {
let request = this.createRequest();
cpmm.sendAsyncMessage("Webapps:CheckForUpdate",
{ manifestURL: this.manifestURL,
oid: this._id,
requestID: this.getRequestId(request) });
// We can't update apps that are not removable.
if (!this.removable) {
Services.tm.currentThread.dispatch({
run: function checkUpdateFail() {
Services.DOMRequest.fireError(request, "NOT_UPDATABLE");
}
}, Ci.nsIEventTarget.DISPATCH_NORMAL)
} else {
cpmm.sendAsyncMessage("Webapps:CheckForUpdate",
{ manifestURL: this.manifestURL,
oid: this._id,
requestID: this.getRequestId(request) });
}
return request;
},

View File

@ -805,6 +805,8 @@ this.DOMApplicationRegistry = {
} else {
// hosted app with no appcache, nothing to do, but we fire a
// downloaded event
debug("No appcache found, sending 'downloaded' for " + aManifestURL);
app.downloadAvailable = false;
DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
{ type: "downloaded",
manifestURL: aManifestURL,
@ -979,7 +981,7 @@ this.DOMApplicationRegistry = {
}
function updateHostedApp(aManifest) {
debug("updateHostedApp");
debug("updateHostedApp " + aData.manifestURL);
let id = this._appId(app.origin);
if (id in this._manifestCache) {
@ -1007,18 +1009,11 @@ this.DOMApplicationRegistry = {
let manifest = new ManifestHelper(aManifest, app.origin);
if (manifest.appcache_path) {
app.installState = "updating";
app.downloadAvailable = true;
app.downloading = true;
app.downloadsize = 0;
app.readyToApplyDownload = false;
} else {
app.installState = "installed";
app.downloadAvailable = false;
app.downloading = false;
app.readyToApplyDownload = false;
}
app.installState = "installed";
app.downloading = false;
app.downloadsize = 0;
app.readyToApplyDownload = false;
app.downloadAvailable = !!manifest.appcache_path;
app.name = aManifest.name;
app.csp = aManifest.csp || "";
@ -1028,13 +1023,12 @@ this.DOMApplicationRegistry = {
this.webapps[id] = app;
this._saveApps(function() {
aData.event = "downloadapplied";
aData.app = app;
aData.event = manifest.appcache_path ? "downloadavailable"
: "downloadapplied";
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
});
// Preload the appcache if needed.
this.startOfflineCacheDownload(manifest, app);
// Update the permissions for this app.
PermissionsInstaller.installPermissions({ manifest: aManifest,
origin: app.origin,
@ -1046,16 +1040,15 @@ this.DOMApplicationRegistry = {
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Ci.nsIXMLHttpRequest);
xhr.open("GET", aData.manifestURL, true);
xhr.responseType = "json";
if (app.etag) {
xhr.setRequestHeader("If-None-Match", app.etag);
}
xhr.addEventListener("load", (function() {
if (xhr.status == 200) {
let manifest;
try {
manifest = JSON.parse(xhr.responseText);
} catch(e) {
let manifest = xhr.response;
if (manifest == null) {
sendError("MANIFEST_PARSE_ERROR");
return;
}