Bug 830294 - Can't launch an app after canceling its update r=ferjm
authorFabrice Desré <fabrice@mozilla.com>
Wed, 16 Jan 2013 16:55:50 -0800
changeset 119091 fdc7bbbc2eeab6305082e1981ece83701179378e
parent 119090 836eb526e5fe74ab70e5342789a5f2699b9e973c
child 119092 871089b35c46ff1b64536edca591faad3eb7f3e7
push id24189
push useremorley@mozilla.com
push dateThu, 17 Jan 2013 10:42:06 +0000
treeherdermozilla-central@712eca11a04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersferjm
bugs830294
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 830294 - Can't launch an app after canceling its update r=ferjm
dom/apps/src/Webapps.jsm
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -893,24 +893,31 @@ this.DOMApplicationRegistry = {
     debug("cancelDownload " + aManifestURL);
     let error = aError || "DOWNLOAD_CANCELED";
     let download = AppDownloadManager.get(aManifestURL);
     if (!download) {
       debug("Could not find a download for " + aManifestURL);
       return;
     }
 
+    let app = this.webapps[download.appId];
+
     if (download.cacheUpdate) {
       // Cancel hosted app download.
       try {
         download.cacheUpdate.cancel();
       } catch (e) { debug (e); }
     } else if (download.channel) {
       // Cancel packaged app download.
-      download.channel.cancel(Cr.NS_BINDING_ABORTED);
+      app.isCanceling = true;
+      try {
+        download.channel.cancel(Cr.NS_BINDING_ABORTED);
+      } catch(e) {
+        delete app.isCanceling;
+      }
     } else {
       return;
     }
 
     let app = this.webapps[download.appId];
     app.progress = 0;
     app.installState = download.previousState;
     app.downloading = false;
@@ -1212,35 +1219,35 @@ this.DOMApplicationRegistry = {
       app.name = manifest.name;
       app.csp = manifest.csp || "";
       app.updateTime = Date.now();
 
       // Update the registry.
       this.webapps[id] = app;
 
       this._saveApps(function() {
+        let reg = DOMApplicationRegistry;
         aData.app = app;
         app.manifest = aNewManifest || aOldManifest;
         if (!manifest.appcache_path) {
           aData.event = "downloadapplied";
-          DOMApplicationRegistry.broadcastMessage("Webapps:CheckForUpdate:Return:OK",
-                                                  aData);
+          reg.broadcastMessage("Webapps:CheckForUpdate:Return:OK", aData);
         } else {
           // Check if the appcache is updatable, and send "downloadavailable" or
           // "downloadapplied".
           let updateObserver = {
             observe: function(aSubject, aTopic, aObsData) {
               debug("updateHostedApp: updateSvc.checkForUpdate return for " +
                     app.manifestURL + " - event is " + aTopic);
               aData.event =
                 aTopic == "offline-cache-update-available" ? "downloadavailable"
                                                            : "downloadapplied";
               aData.app.downloadAvailable = (aData.event == "downloadavailable");
-              DOMApplicationRegistry.broadcastMessage("Webapps:CheckForUpdate:Return:OK",
-                                                      aData);
+              reg._saveApps();
+              reg.broadcastMessage("Webapps:CheckForUpdate:Return:OK", aData);
             }
           }
           debug("updateHostedApp: updateSvc.checkForUpdate for " +
                 manifest.fullAppcachePath());
           updateSvc.checkForUpdate(Services.io.newURI(manifest.fullAppcachePath(), null, null),
                                    app.localId, false, updateObserver);
         }
         delete app.manifest;
@@ -1813,17 +1820,18 @@ this.DOMApplicationRegistry = {
       let dir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
       try {
         dir.remove(true);
       } catch (e) { }
 
       // We avoid notifying the error to the DOM side if the app download
       // was cancelled via cancelDownload, which already sends its own
       // notification.
-      if (!app.downloading && !app.downloadAvailable && !app.downloadSize) {
+      if (app.isCanceling) {
+        delete app.isCanceling;
         return;
       }
 
       let download = AppDownloadManager.get(aApp.manifestURL);
       app.downloading = false;
       // If there were not enough storage to download the packaged app we
       // won't have a record of the download details, so we just set the
       // installState to 'pending'.