diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index a87d4f5f40a5..55087ae1e896 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -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.