Bug 1175605 - Do not access DOMApplicationRegistry properties before it is ready. r=myk
authorEugen Sawin <esawin@mozilla.com>
Thu, 18 Jun 2015 22:09:49 +0200
changeset 280400 3c6b38653a58aa3527f2066d0ed585c29f319afc
parent 280399 4b0fb77f77a43835b83f07afee72574d06b6998a
child 280401 69d63551c4dd6f48ff0fa9b9ebd102ed859904ec
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs1175605
milestone41.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 1175605 - Do not access DOMApplicationRegistry properties before it is ready. r=myk
mobile/android/chrome/content/browser.js
mobile/android/modules/WebappManager.jsm
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -300,18 +300,20 @@ XPCOMUtils.defineLazyModuleGetter(
       this.ppmm.removeMessageListener(msgName, this);
     });
   },
   {
     receiveMessage: function() {
       // This is called only once when we receive a message for the first time.
       // With this, we trigger the import of Webapps.jsm and forward the message
       // to the real registry.
-      return DOMApplicationRegistry.receiveMessage.apply(
-          DOMApplicationRegistry, arguments);
+      DOMApplicationRegistry.registryReady.then(() => {
+        DOMApplicationRegistry.receiveMessage.apply(
+            DOMApplicationRegistry, arguments);
+      });
     }
   }
 );
 
 XPCOMUtils.defineLazyModuleGetter(this, "Log",
   "resource://gre/modules/AndroidLog.jsm", "AndroidLog");
 
 // Define the "dump" function as a binding of the Log.d function so it specifies
--- a/mobile/android/modules/WebappManager.jsm
+++ b/mobile/android/modules/WebappManager.jsm
@@ -261,26 +261,16 @@ this.WebappManager = {
       DOMApplicationRegistry.uninstall(aData.manifestURL);
     }
 
   }),
 
   autoInstall: function(aData) {
     debug("autoInstall " + aData.manifestURL);
 
-    // If the app is already installed, update the existing installation.
-    // We should be able to use DOMApplicationRegistry.getAppByManifestURL,
-    // but it returns a mozIApplication, while _autoUpdate needs the original
-    // object from DOMApplicationRegistry.webapps in order to modify it.
-    for (let [ , app] in Iterator(DOMApplicationRegistry.webapps)) {
-      if (app.manifestURL == aData.manifestURL) {
-        return this._autoUpdate(aData, app);
-      }
-    }
-
     let mm = {
       sendAsyncMessage: function (aMessageName, aData) {
         // TODO hook this back to Java to report errors.
         debug("sendAsyncMessage " + aMessageName + ": " + JSON.stringify(aData));
       }
     };
 
     let origin = Services.io.newURI(aData.manifestURL, null, null).prePath;
@@ -305,16 +295,26 @@ this.WebappManager = {
     message.app.manifestURL = aData.manifestURL;
     message.app.manifest = aData.manifest;
     message.app.apkPackageName = aData.apkPackageName;
     message.profilePath = aData.profilePath;
     message.mm = mm;
     message.apkInstall = true;
 
     DOMApplicationRegistry.registryReady.then(() => {
+      // If the app is already installed, update the existing installation.
+      // We should be able to use DOMApplicationRegistry.getAppByManifestURL,
+      // but it returns a mozIApplication, while _autoUpdate needs the original
+      // object from DOMApplicationRegistry.webapps in order to modify it.
+      for (let [ , app] in Iterator(DOMApplicationRegistry.webapps)) {
+        if (app.manifestURL == aData.manifestURL) {
+          return this._autoUpdate(aData, app);
+        }
+      }
+
       switch (aData.type) { // can be hosted or packaged.
         case "hosted":
           DOMApplicationRegistry.doInstall(message, mm);
           break;
 
         case "packaged":
           message.isPackage = true;
           DOMApplicationRegistry.doInstallPackage(message, mm);