Bug 820630 - Allow preinstalled packaged apps to specify the etag of the update manifest and package file [r=ferjm]

This commit is contained in:
Fabrice Desré 2012-12-21 10:28:58 -08:00
Родитель f6455eb9eb
Коммит a7a7ab4ca9
2 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -48,6 +48,7 @@ this.AppsUtils = {
lastUpdateCheck: aApp.lastUpdateCheck,
updateTime: aApp.updateTime,
etag: aApp.etag,
packageEtag: aApp.packageEtag,
installerAppId: aApp.installerAppId || Ci.nsIScriptSecurityManager.NO_APP_ID,
installerIsBrowser: !!aApp.installerIsBrowser
};

Просмотреть файл

@ -1742,6 +1742,7 @@ this.DOMApplicationRegistry = {
manifestURL: aApp.manifestURL,
error: aError,
app: app });
self._saveApps();
AppDownloadManager.remove(aApp.manifestURL);
}
@ -1750,6 +1751,10 @@ this.DOMApplicationRegistry = {
let requestChannel = NetUtil.newChannel(aManifest.fullPackagePath())
.QueryInterface(Ci.nsIHttpChannel);
if (app.packageEtag) {
requestChannel.setRequestHeader("If-None-Match", app.packageEtag);
}
AppDownloadManager.add(aApp.manifestURL,
{
channel: requestChannel,
@ -1828,6 +1833,31 @@ this.DOMApplicationRegistry = {
bufferedOutputStream.close();
outputStream.close();
if (requestChannel.responseStatus == 304) {
// The package's Etag has not changed.
// We send a "applied" event right away.
app.downloading = false;
app.downloadAvailable = false;
app.downloadSize = 0;
app.installState = "installed";
app.readyToApplyDownload = false;
self.broadcastMessage("Webapps:PackageEvent", {
type: "applied",
manifestURL: aApp.manifestURL,
app: app });
// Save the updated registry, and cleanup the tmp directory.
self._saveApps();
let file = FileUtils.getFile("TmpD", ["webapps", id], false);
if (file && file.exists()) {
file.remove(true);
}
return;
}
// Save the new Etag for the package.
app.packageEtag = requestChannel.getResponseHeader("Etag");
debug("Package etag=" + app.packageEtag);
if (!Components.isSuccessCode(aStatusCode)) {
cleanup("NETWORK_ERROR");
return;