Back out eae519534b01 (bug 772364), 4935822abf87 (bug 795164) and ddee22deae16 (bug 793082) for orange on a CLOSED TREE
authorPhil Ringnalda <philringnalda@gmail.com>
Sat, 29 Sep 2012 13:20:09 -0700
changeset 108645 25041824911b6ccdfcdd427c90860c4a359a99a5
parent 108644 eae519534b01a97f75ccd08b4bd87bd66d943a95
child 108646 72e03ee74f40c90f4d646000b0983ec3f3724efb
push id15612
push userphilringnalda@gmail.com
push dateSat, 29 Sep 2012 20:20:43 +0000
treeherdermozilla-inbound@25041824911b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs772364, 795164, 793082
milestone18.0a1
backs outeae519534b01a97f75ccd08b4bd87bd66d943a95
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
Back out eae519534b01 (bug 772364), 4935822abf87 (bug 795164) and ddee22deae16 (bug 793082) for orange on a CLOSED TREE
b2g/chrome/content/shell.js
dom/apps/src/Webapps.js
dom/apps/src/Webapps.jsm
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -182,17 +182,16 @@ var shell = {
     SettingsListener.observe("debug.fps.enabled", false, function(value) {
       Services.prefs.setBoolPref("layers.acceleration.draw-fps", value);
     });
     SettingsListener.observe("debug.paint-flashing.enabled", false, function(value) {
       Services.prefs.setBoolPref("nglayout.debug.paint_flashing", value);
     });
 
     this.contentBrowser.src = homeURL;
-    this.isHomeLoaded = false;
 
     ppmm.addMessageListener("content-handler", this);
   },
 
   stop: function shell_stop() {
     window.removeEventListener('keydown', this, true);
     window.removeEventListener('keypress', this, true);
     window.removeEventListener('keyup', this, true);
@@ -308,27 +307,16 @@ var shell = {
 
         let chromeWindow = window.QueryInterface(Ci.nsIDOMChromeWindow);
         chromeWindow.browserDOMWindow = new nsBrowserAccess();
 
         Cu.import('resource://gre/modules/Webapps.jsm');
         DOMApplicationRegistry.allAppsLaunchable = true;
 
         this.sendEvent(window, 'ContentStart');
-
-        content.addEventListener('load', function shell_homeLoaded() {
-          content.removeEventListener('load', shell_homeLoaded);
-          shell.isHomeLoaded = true;
-
-          if ('pendingChromeEvents' in shell) {
-            shell.pendingChromeEvents.forEach((shell.sendChromeEvent).bind(shell));
-          }
-          delete shell.pendingChromeEvents;
-        });
-
         break;
       case 'MozApplicationManifest':
         try {
           if (!Services.prefs.getBoolPref('browser.cache.offline.enable'))
             return;
 
           let contentWindow = evt.originalTarget.defaultView;
           let documentElement = contentWindow.document.documentElement;
@@ -364,25 +352,16 @@ var shell = {
 
   sendEvent: function shell_sendEvent(content, type, details) {
     let event = content.document.createEvent('CustomEvent');
     event.initCustomEvent(type, true, true, details ? details : {});
     content.dispatchEvent(event);
   },
 
   sendChromeEvent: function shell_sendChromeEvent(details) {
-    if (!this.isHomeLoaded) {
-      if (!('pendingChromeEvents' in this)) {
-        this.pendingChromeEvents = [];
-      }
-
-      this.pendingChromeEvents.push(details);
-      return;
-    }
-
     this.sendEvent(getContentWindow(), "mozChromeEvent",
                    ObjectWrapper.wrap(details, getContentWindow()));
   },
 
   sendSystemMessage: function shell_sendSystemMessage(msg) {
     let origin = Services.io.newURI(msg.manifest, null, null).prePath;
     this.sendChromeEvent({
       type: 'open-app',
--- a/dom/apps/src/Webapps.js
+++ b/dom/apps/src/Webapps.js
@@ -433,18 +433,17 @@ WebappsApplication.prototype = {
     return this._ondownloadapplied;
   },
 
   get downloadError() {
     return createDOMError(this._downloadError);
   },
 
   download: function() {
-    cpmm.sendAsyncMessage("Webapps:Download",
-                          { manifestURL: this.manifestURL });
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
 
   cancelDownload: function() {
     cpmm.sendAsyncMessage("Webapps:CancelDownload",
                           { manifestURL: this.manifestURL });
   },
 
   checkForUpdate: function() {
@@ -534,19 +533,16 @@ WebappsApplication.prototype = {
         }
         break;
         case "Webapps:CheckForUpdate:Return:OK":
           for (let prop in msg.app) {
             this[prop] = msg.app[prop];
             if (msg.event == "downloadapplied") {
               Services.DOMRequest.fireSuccess(req, this.manifestURL);
               this._fireEvent("downloadapplied", this._ondownloadapplied);
-            } else if (msg.event == "downloadavailable") {
-              Services.DOMRequest.fireSuccess(req, this.manifestURL);
-              this._fireEvent("downloadavailable", this._ondownloadavailable);
             }
           }
           break;
         case "Webapps:CheckForUpdate:Return:KO":
           Services.DOMRequest.fireError(req, msg.error);
           break;
         case "Webapps:PackageEvent":
           if (msg.manifestURL != this.manifestURL)
@@ -578,28 +574,16 @@ WebappsApplication.prototype = {
               this.downloadAvailable = app.downloadAvailable;
               this.downloading = app.downloading;
               this.readyToApplyDownload = app.readyToApplyDownload;
               this.downloadSize = app.downloadSize || 0;
               this.installState = app.installState;
               this._downloadError = msg.error;
               this._fireEvent("downloaderror", this._ondownloaderror);
               break;
-            case "downloaded":
-              app = msg.app;
-              this.downloading = app.downloading;
-              this.downloadavailable = app.downloadavailable;
-              this.readyToApplyDownload = app.readyToApplyDownload;
-              this._fireEvent("downloaded", this._ondownloaded);
-              break;
-            case "applied":
-              app = msg.app;
-              this.readyToApplyDownload = app.readyToApplyDownload;
-              this._fireEvent("downloadapplied", this._ondownloadapplied);
-              break;
           }
           break;
     }
   },
 
   classID: Components.ID("{723ed303-7757-4fb0-b261-4f78b1f6bd22}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.mozIDOMApplication]),
@@ -649,22 +633,17 @@ WebappsApplicationMgmt.prototype = {
   uninit: function() {
     this._oninstall = null;
     this._onuninstall = null;
     cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
                           ["Webapps:Install:Return:OK", "Webapps:Uninstall:Return:OK"]);
   },
 
   applyDownload: function(aApp) {
-    if (!aApp.readyToApplyDownload) {
-      return;
-    }
-
-    cpmm.sendAsyncMessage("Webapps::ApplyDownload",
-                          { manifestURL: aApp.manifestURL });
+    return Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
 
   getAll: function() {
     let request = this.createRequest();
     cpmm.sendAsyncMessage("Webapps:GetAll", { oid: this._id,
                                               requestID: this.getRequestId(request),
                                               hasPrivileges: this.hasPrivileges });
     return request;
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -155,18 +155,17 @@ let DOMApplicationRegistry = {
   init: function() {
     this.messages = ["Webapps:Install", "Webapps:Uninstall",
                      "Webapps:GetSelf", "Webapps:IsInstalled",
                      "Webapps:GetInstalled", "Webapps:GetNotInstalled",
                      "Webapps:Launch", "Webapps:GetAll",
                      "Webapps:InstallPackage", "Webapps:GetBasePath",
                      "Webapps:GetList", "Webapps:RegisterForMessages",
                      "Webapps:UnregisterForMessages",
-                     "Webapps:CancelDownload", "Webapps:CheckForUpdate",
-                     "Webapps::Download", "Webapps::ApplyDownload"];
+                     "Webapps:CancelDownload", "Webapps:CheckForUpdate"];
 
     this.frameMessages = ["Webapps:ClearBrowserData"];
 
     this.messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     cpmm.addMessageListener("Activities:Register:OK", this);
@@ -503,19 +502,17 @@ let DOMApplicationRegistry = {
     }
   },
 
   addMessageListener: function(aMsgNames, aMm) {
     aMsgNames.forEach(function (aMsgName) {
       if (!(aMsgName in this.children)) {
         this.children[aMsgName] = [];
       }
-      if (this.children[aMsgName].indexOf(aMm) === -1) {
-        this.children[aMsgName].push(aMm);
-      }
+      this.children[aMsgName].push(aMm);
     }, this);
   },
 
   removeMessageListener: function(aMsgNames, aMm) {
     aMsgNames.forEach(function (aMsgName) {
       if (!(aMsgName in this.children)) {
         return;
       }
@@ -576,28 +573,22 @@ let DOMApplicationRegistry = {
         this.addMessageListener(msg, mm);
         break;
       case "Webapps:UnregisterForMessages":
         this.removeMessageListener(msg, mm);
         break;
       case "Webapps:GetList":
         this.addMessageListener(["Webapps:AddApp", "Webapps:RemoveApp"], mm);
         return this.webapps;
-      case "Webapps:Download":
-        this.startDownload(msg.manifestURL);
-        break;
       case "Webapps:CancelDownload":
-        this.cancelDownload(msg.manifestURL);
+        this.cancelDowload(msg.manifestURL);
         break;
       case "Webapps:CheckForUpdate":
         this.checkForUpdate(msg, mm);
         break;
-      case "Webapps::ApplyDownload":
-        this.ApplyDownload(msg.manifestURL);
-        break;
       case "Activities:Register:OK":
         this.activitiesRegistered++;
         if (this.allActivitiesSent &&
             this.activitiesRegistered === this.activitiesToRegister) {
           this.onInitDone();
         }
         break;
     }
@@ -662,121 +653,40 @@ let DOMApplicationRegistry = {
     if (app.installState == "pending") {
       aMm.sendAsyncMessage("Webapps:Launch:Return:KO", aData);
       return;
     }
 
     Services.obs.notifyObservers(aMm, "webapps-launch", JSON.stringify(aData));
   },
 
-  cancelDownload: function cancelDownload(aManifestURL) {
-    // We can't cancel appcache downloads for now.
+  cancelDownload: function cancelDowload(aManifestURL) {
+    // We can't cancel appcache dowloads for now.
     if (!this.downloads[aManifestURL]) {
       return;
     }
     // This is a HTTP channel.
     let download = this.downloads[aManifestURL]
     download.channel.cancel(Cr.NS_BINDING_ABORTED);
-    let app = this.webapps[download.appId];
+    let app = this.webapps[dowload.appId];
 
     app.progress = 0;
     app.installState = app.previousState;
-    app.downloading = false;
-    app.downloadavailable = false;
+    app.dowloading = false;
+    app.dowloadavailable = false;
     app.downloadSize = 0;
     this._saveApps((function() {
       this.broadcastMessage("Webapps:PackageEvent",
                              { type: "canceled",
                                manifestURL:  aApp.manifestURL,
                                app: app,
                                error: "DOWNLOAD_CANCELED" });
     }).bind(this));
   },
 
-  startDownload: function cancelDownload(aManifestURL) {
-    let app = this.getAppByManifestURL(manifestURL);
-    if (!app) {
-      return;
-    }
-
-    let id = this._appIdForManifestURL(manifestURL);
-
-    // We need to get the update manifest here, not the webapp manifest.
-    let file = FileUtils.getFile(DIRECTORY_NAME,
-                                 ["webapps", id, "update.webapp"], true);
-
-    this._loadJSONAsync(file, (function(aJSON) {
-      if (!aJSON) {
-        return;
-      }
-
-      let manifest = new DOMApplicationManifest(aJSON, app.origin);
-      this.downloadPackage(manifest, { manifestURL: aManifestURL,
-                                       origin: app.origin }, true,
-        function(aId, aManifest) {
-          // Success! Keep the zip in of TmpD, we'll move it out when
-          // applyDownload() will be called.
-          let tmpDir = FileUtils.getDir("TmpD", ["webapps", aId], true, true);
-
-          // Save the manifest in TmpD also
-          let manFile = tmpDir.clone();
-          manFile.append("manifest.webapp");
-          DOMApplicationRegistry._writeFile(manFile,
-                                            JSON.stringify(aManifest),
-                                            function() { });
-          // Set state and fire events.
-          app.downloading = false;
-          app.downloadavailable = false;
-          app.readyToApplyDownload = true;
-          DOMApplicationRegistry._saveApps(function() {
-            debug("About to fire Webapps:PackageEvent");
-            DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
-                                                    { type: "downloaded",
-                                                      manifestURL: manifestURL,
-                                                      app: app,
-                                                      manifest: aManifest });
-          });
-        });
-    }).bind(this));
-  },
-
-  applyDownload: function applyDownload(aManifestURL) {
-    let app = this.getAppByManifestURL(manifestURL);
-    if (!app || (app && !app.readyToApplyDownload)) {
-      return;
-    }
-
-    let id = this._appIdForManifestURL(aApp.manifestURL);
-
-    // Move the application.zip and manifest.webapp files out of TmpD
-    let tmpDir = FileUtils.getDir("TmpD", ["webapps", aId], true, true);
-    let manFile = tmpDir.clone();
-    manFile.append("manifest.webapp");
-    let appFile = tmpDir.clone();
-    appFile.append("application.zip");
-
-    let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
-    appFile.moveTo(dir, "application.zip");
-    manFile.moveTo(dir, "manifest.webapp");
-
-    try {
-      tmpDir.remove(true);
-    } catch(e) { }
-
-    // Get the manifest, and set properties.
-    this.getManifestFor(app.origin, function(aData) {
-      app.readyToApplyDownload = false;
-      this.broadcastMessage("Webapps:PackageEvent",
-                            { type: "applied",
-                              manifestURL: aApp.manifestURL,
-                              app: app,
-                              manifest: aData });
-    });
-  },
-
   startOfflineCacheDownload: function startOfflineCacheDownload(aManifest, aApp, aProfileDir) {
     // 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);
       let cacheUpdate = aProfileDir ? updateService.scheduleCustomProfileUpdate(appcacheURI, docURI, aProfileDir)
@@ -899,29 +809,16 @@ let DOMApplicationRegistry = {
 
     function sendError(aError) {
       aData.error = aError;
       aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:KO", aData);
     }
 
     function updatePackagedApp(aManifest) {
       debug("updatePackagedApp");
-      let manifest = new DOMApplicationManifest(aManifest, app.manifestURL);
-      // A package is available: set downloadAvailable to fire the matching
-      // event.
-      app.downloadAvailable = true;
-      app.downloadSize = manifest.size;
-      aData.event = "downloadavailable";
-      aData.app = {
-        downloadAvailable: true,
-        downloadSize: manifest.size
-      }
-      DOMApplicationRegistry._saveApps(function() {
-        aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
-      });
     }
 
     function updateHostedApp(aManifest) {
       debug("updateHostedApp");
       let id = this._appId(app.origin);
 
 #ifdef MOZ_SYS_MSG
       // Update the Web Activities
@@ -983,17 +880,17 @@ let DOMApplicationRegistry = {
           sendError("MANIFEST_PARSE_ERROR");
           return;
         }
         if (!AppsUtils.checkManifest(manifest, installOrigin)) {
           sendError("INVALID_MANIFEST");
         } else {
           app.etag = xhr.getResponseHeader("Etag");
           app.lastCheckedUpdate = Date.now();
-          if (manifest.package_path) {
+          if (package_path in manifest) {
             updatePackagedApp(manifest);
           } else {
             updateHostedApp(manifest);
           }
         }
         this._saveApps();
       } else if (xhr.status == 304) {
         // The manifest has not changed. We just update lastCheckedUpdate.
@@ -1120,49 +1017,17 @@ let DOMApplicationRegistry = {
     if (!aData.isPackage) {
       this._registerSystemMessages(app.manifest, app);
       this._registerActivities(app.manifest, app);
     }
 #endif
 
     this.startOfflineCacheDownload(manifest, appObject, aProfileDir);
     if (manifest.package_path) {
-      // origin for install apps is meaningless here, since it's app:// and this
-      // can't be used to resolve package paths.
-      manifest = new DOMApplicationManifest(jsonManifest, app.manifestURL);
-      this.downloadPackage(manifest, appObject, false, function(aId, aManifest) {
-        // Success! Move the zip out of TmpD.
-        let app = DOMApplicationRegistry.webapps[id];
-        let zipFile = FileUtils.getFile("TmpD", ["webapps", aId, "application.zip"], true);
-        let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", aId], true, true);
-        zipFile.moveTo(dir, "application.zip");
-        let tmpDir = FileUtils.getDir("TmpD", ["webapps", aId], true, true);
-        try {
-          tmpDir.remove(true);
-        } catch(e) { }
-
-        // Save the manifest
-        let manFile = dir.clone();
-        manFile.append("manifest.webapp");
-        DOMApplicationRegistry._writeFile(manFile,
-                                          JSON.stringify(aManifest),
-                                          function() { });
-        // Set state and fire events.
-        app.installState = "installed";
-        app.downloading = false;
-        app.downloadavailable = false;
-        DOMApplicationRegistry._saveApps(function() {
-          debug("About to fire Webapps:PackageEvent");
-          DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
-                                                  { type: "installed",
-                                                    manifestURL: appObject.manifestURL,
-                                                    app: app,
-                                                    manifest: aManifest });
-        });
-      });
+      this.downloadPackage(manifest, appObject);
     }
   },
 
   _nextLocalId: function() {
     let id = Services.prefs.getIntPref("dom.mozApps.maxLocalId") + 1;
     Services.prefs.setIntPref("dom.mozApps.maxLocalId", id);
     return id;
   },
@@ -1221,17 +1086,17 @@ let DOMApplicationRegistry = {
       aData[index].manifest = aJSON;
       if (index == aData.length - 1)
         aFinalCallback(aData);
       else
         this._readManifests(aData, aFinalCallback, index + 1);
     }).bind(this));
   },
 
-  downloadPackage: function(aManifest, aApp, aIsUpdate, aOnSuccess) {
+  downloadPackage: function(aManifest, aApp) {
     // Here are the steps when installing a package:
     // - create a temp directory where to store the app.
     // - download the zip in this directory.
     // - extract the manifest from the zip and check it.
     // - ask confirmation to the user.
     // - add the new app to the registry.
     // If we fail at any step, we backout the previous ones and return an error.
 
@@ -1277,17 +1142,17 @@ let DOMApplicationRegistry = {
 
     debug("About to download " + aManifest.fullPackagePath());
 
     let requestChannel = NetUtil.newChannel(aManifest.fullPackagePath())
                                 .QueryInterface(Ci.nsIHttpChannel);
     this.downloads[aApp.manifestURL] =
       { channel:requestChannel,
         appId: id,
-        previousState: aIsUpdate ? "installed" : "pending"
+        previousState: "pending"
       };
     requestChannel.notificationCallbacks = {
       QueryInterface: function notifQI(aIID) {
         if (aIID.equals(Ci.nsISupports)          ||
             aIID.equals(Ci.nsIProgressEventSink))
           return this;
 
         throw Cr.NS_ERROR_NO_INTERFACE;
@@ -1346,20 +1211,43 @@ let DOMApplicationRegistry = {
           if (!AppsUtils.checkManifest(manifest, aApp.installOrigin)) {
             throw "INVALID_MANIFEST";
           }
 
           if (!checkAppStatus(manifest)) {
             throw "INVALID_SECURITY_LEVEL";
           }
 
-          if (aOnSuccess) {
-            aOnSuccess(id, manifest);
-          }
-          delete DOMApplicationRegistry.downloads[aApp.manifestURL];
+          // Success! Move the zip out of TmpD.
+          let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
+          zipFile.moveTo(dir, "application.zip");
+          let tmpDir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
+          try {
+            tmpDir.remove(true);
+          } catch(e) { }
+
+          // Save the manifest
+          let manFile = dir.clone();
+          manFile.append("manifest.webapp");
+          DOMApplicationRegistry._writeFile(manFile,
+                                            JSON.stringify(manifest),
+                                            function() { });
+          // Set state and fire events.
+          app.installState = "installed";
+          app.dowloading = false;
+          app.dowloadavailable = false;
+          DOMApplicationRegistry._saveApps(function() {
+            debug("About to fire Webapps:PackageEvent");
+            DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
+                                                    { type: "installed",
+                                                      manifestURL: aApp.manifestURL,
+                                                      app: app,
+                                                      manifest: manifest });
+            delete DOMApplicationRegistry.downloads[aApp.manifestURL]
+          });
         } catch (e) {
           // XXX we may need new error messages.
           cleanup(e);
         } finally {
           zipReader.close();
         }
       });
     });