Bug 962790 - ensure registryReady before calling DOMApplicationRegistry methods; r=wesj
authorMyk Melez <myk@mozilla.org>
Fri, 24 Jan 2014 21:05:07 -0800
changeset 181234 a85a91d17061a58f24d75490d5f117fa67119522
parent 181233 14de085ae57f5e4a82e8151a8d8b9730a8a3b25e
child 181235 d3382f9254a819a7cc847d792bfbceea3c79f941
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs962790
milestone29.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 962790 - ensure registryReady before calling DOMApplicationRegistry methods; r=wesj
mobile/android/modules/WebappManager.jsm
--- a/mobile/android/modules/WebappManager.jsm
+++ b/mobile/android/modules/WebappManager.jsm
@@ -114,28 +114,30 @@ this.WebappManager = {
     // which has already happened) and because nsCacheService shuts down
     // when we trigger the native install dialog and doesn't re-init itself
     // afterward (TODO: file bug about this behavior).
     if ("appcache_path" in aData.app.manifest) {
       dump("deleting appcache_path from manifest: " + aData.app.manifest.appcache_path);
       delete aData.app.manifest.appcache_path;
     }
 
-    DOMApplicationRegistry.confirmInstall(aData, file, (function(aManifest) {
-      let localeManifest = new ManifestHelper(aManifest, aData.app.origin);
+    DOMApplicationRegistry.registryReady.then(() => {
+      DOMApplicationRegistry.confirmInstall(aData, file, (function(aManifest) {
+        let localeManifest = new ManifestHelper(aManifest, aData.app.origin);
 
-      // aData.app.origin may now point to the app: url that hosts this app.
-      sendMessageToJava({
-        type: "WebApps:PostInstall",
-        apkPackageName: aData.app.apkPackageName,
-        origin: aData.app.origin,
-      });
+        // aData.app.origin may now point to the app: url that hosts this app.
+        sendMessageToJava({
+          type: "WebApps:PostInstall",
+          apkPackageName: aData.app.apkPackageName,
+          origin: aData.app.origin,
+        });
 
-      this.writeDefaultPrefs(file, localeManifest);
-    }).bind(this));
+        this.writeDefaultPrefs(file, localeManifest);
+      }).bind(this));
+    });
   },
 
   launch: function({ manifestURL, origin }) {
     dump("launchWebapp: " + manifestURL);
 
     sendMessageToJava({
       type: "WebApps:Open",
       manifestURL: manifestURL,
@@ -182,49 +184,54 @@ this.WebappManager = {
     // Thus, we should take the APK as the source of truth.
     message.app.manifestURL = aData.manifestUrl;
     message.app.manifest = aData.manifest;
     message.app.apkPackageName = aData.apkPackageName;
     message.profilePath = aData.profilePath;
     message.autoInstall = true;
     message.mm = mm;
 
-    switch (aData.type) { // can be hosted or packaged.
-      case "hosted":
-        DOMApplicationRegistry.doInstall(message, mm);
-        break;
+    DOMApplicationRegistry.registryReady.then(() => {
+      switch (aData.type) { // can be hosted or packaged.
+        case "hosted":
+          DOMApplicationRegistry.doInstall(message, mm);
+          break;
 
-      case "packaged":
-        message.isPackage = true;
-        DOMApplicationRegistry.doInstallPackage(message, mm);
-        break;
-    }
+        case "packaged":
+          message.isPackage = true;
+          DOMApplicationRegistry.doInstallPackage(message, mm);
+          break;
+      }
+    });
   },
 
   autoUninstall: function(aData) {
     let mm = {
       sendAsyncMessage: function (aMessageName, aData) {
         // TODO hook this back to Java to report errors.
         dump("autoUninstall sendAsyncMessage " + aMessageName + ": " + JSON.stringify(aData));
       }
     };
-    let installed = {};
-    DOMApplicationRegistry.doGetAll(installed, mm);
+
+    DOMApplicationRegistry.registryReady.then(() => {
+      let installed = {};
+      DOMApplicationRegistry.doGetAll(installed, mm);
 
-    for (let app in installed.apps) {
-      if (aData.apkPackageNames.indexOf(installed.apps[app].apkPackageName) > -1) {
-        let appToRemove = installed.apps[app];
-        dump("should remove: " + appToRemove.name);
-        DOMApplicationRegistry.uninstall(appToRemove.manifestURL, function() {
-          dump(appToRemove.name + " uninstalled");
-        }, function() {
-          dump(appToRemove.name + " did not uninstall");
-        });
+      for (let app in installed.apps) {
+        if (aData.apkPackageNames.indexOf(installed.apps[app].apkPackageName) > -1) {
+          let appToRemove = installed.apps[app];
+          dump("should remove: " + appToRemove.name);
+          DOMApplicationRegistry.uninstall(appToRemove.manifestURL, function() {
+            dump(appToRemove.name + " uninstalled");
+          }, function() {
+            dump(appToRemove.name + " did not uninstall");
+          });
+        }
       }
-    }
+    });
   },
 
   writeDefaultPrefs: function(aProfile, aManifest) {
       // build any app specific default prefs
       let prefs = [];
       if (aManifest.orientation) {
         prefs.push({name:"app.orientation.default", value: aManifest.orientation.join(",") });
       }