Skip to content
Snippets Groups Projects
Commit 6ba7e978 authored by Fabrice Desré's avatar Fabrice Desré
Browse files

Bug 809947 - Implement app.checkForUpdate for hosted apps [r=ferjm]

parent 4bede739
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,11 @@ XPCOMUtils.defineLazyGetter(this, "msgmgr", function() {
.getService(Ci.nsISystemMessagesInternal);
});
XPCOMUtils.defineLazyGetter(this, "updateSvc", function() {
return Cc["@mozilla.org/offlinecacheupdate-service;1"]
.getService(Ci.nsIOfflineCacheUpdateService);
});
#ifdef MOZ_WIDGET_GONK
const DIRECTORY_NAME = "webappsDir";
#elifdef ANDROID
......@@ -931,8 +936,6 @@ this.DOMApplicationRegistry = {
// if the manifest has an appcache_path property, use it to populate the appcache
if (aManifest.appcache_path) {
let appcacheURI = Services.io.newURI(aManifest.fullAppcachePath(), null, null);
let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"]
.getService(Ci.nsIOfflineCacheUpdateService);
let docURI = Services.io.newURI(aManifest.fullLaunchPath(), null, null);
// We determine the app's 'installState' according to its previous
// state. Cancelled download should remain as 'pending'. Successfully
......@@ -943,8 +946,9 @@ this.DOMApplicationRegistry = {
// We set the 'downloading' flag right before starting the app
// download/update.
aApp.downloading = true;
let cacheUpdate = aProfileDir ? updateService.scheduleCustomProfileUpdate(appcacheURI, docURI, aProfileDir)
: updateService.scheduleAppUpdate(appcacheURI, docURI, aApp.localId, false);
let cacheUpdate = aProfileDir
? updateSvc.scheduleCustomProfileUpdate(appcacheURI, docURI, aProfileDir)
: updateSvc.scheduleAppUpdate(appcacheURI, docURI, aApp.localId, false);
cacheUpdate.addObserver(new AppcacheObserver(aApp), false);
if (aOfflineCacheObserver) {
cacheUpdate.addObserver(aOfflineCacheObserver, false);
......@@ -1038,9 +1042,23 @@ this.DOMApplicationRegistry = {
this._saveApps(function() {
aData.app = app;
aData.event = manifest.appcache_path ? "downloadavailable"
: "downloadapplied";
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
if (!manifest.appcache_path) {
aData.event = "downloadapplied";
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
} else {
// Check if the appcache is updatable, and send "downloadavailable" or
// "downloadapplied".
let updateObserver = {
observe: function(aSubject, aTopic, aData) {
aData.event =
aTopic == "offline-cache-update-available" ? "downloadavailable"
: "downloadapplied";
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
}
}
updateSvc.checkForUpdate(Services.io.newURI(aData.manifestURL, null, null),
app.localId, false, updateObserver);
}
});
// Update the permissions for this app.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment