Bug 797574 - PermissionsInstaller.jsm broken for package apps [r=gwagner] [a=blocking-basecamp]
authorFabrice Desré <fabrice@mozilla.com>
Wed, 10 Oct 2012 14:29:07 -0700
changeset 115997 f0f25ebd2ea7f0c28b033175dcbcd70ae9e585fe
parent 115996 8df80d7202e88109ca180474f5e2601a69e1af44
child 115998 dd84a391861266036285dd8c108b5b293e8695e6
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner, blocking-basecamp
bugs797574
milestone18.0a2
Bug 797574 - PermissionsInstaller.jsm broken for package apps [r=gwagner] [a=blocking-basecamp]
dom/apps/src/PermissionsInstaller.jsm
dom/apps/src/Webapps.jsm
--- a/dom/apps/src/PermissionsInstaller.jsm
+++ b/dom/apps/src/PermissionsInstaller.jsm
@@ -409,17 +409,16 @@ let PermissionsInstaller = {
    * @param string aValue
    *        The permission value.
    * @param object aApp
    *        The just-installed app configuration.
             The properties used are manifestURL, origin and manifest.
    * @returns void
    **/
   _setPermission: function setPermission(aPerm, aValue, aApp) {
-    dump("XxXxX setting " + aPerm + " to " + aValue + "\n");
     if (aPerm != "storage") {
       PermSettings.set(aPerm, aValue, aApp.manifestURL, aApp.origin, false);
       return;
     }
 
     ["indexedDB-unlimited", "offline-app", "pin-app"].forEach(
       function(aName) {
         PermSettings.set(aName, aValue, aApp.manifestURL, aApp.origin, false);
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -703,24 +703,29 @@ let DOMApplicationRegistry = {
     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) {
+    this.getManifestFor(app.origin, (function(aData) {
       app.readyToApplyDownload = false;
       this.broadcastMessage("Webapps:PackageEvent",
                             { type: "applied",
                               manifestURL: aApp.manifestURL,
                               app: app,
                               manifest: aData });
-    });
+      // Update the permissions for this app.
+      PermissionsInstaller.installPermissions({ manifest: aData,
+                                                origin: app.origin,
+                                                manifestURL: aApp.manifestURL },
+                                              true);
+    }).bind(this));
   },
 
   startOfflineCacheDownload: function startOfflineCacheDownload(aManifest, aApp,
                                                                 aProfileDir,
                                                                 aOfflineCacheObserver) {
     // 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);
@@ -806,16 +811,22 @@ let DOMApplicationRegistry = {
       this.webapps[id] = app;
 
       this._saveApps((function() {
         // XXX Should we fire notifications ?
       }).bind(this));
 
       // Preload the appcache if needed.
       this.startOfflineCacheDownload(manifest, app);
+
+      // Update the permissions for this app.
+      PermissionsInstaller.installPermissions({ manifest: aManifest,
+                                                origin: app.origin,
+                                                manifestURL: aData.manifestURL },
+                                              true);
     }
 
     // First, we download the manifest.
     let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
                 .createInstance(Ci.nsIXMLHttpRequest);
     xhr.open("GET", aData.manifestURL, true);
     if (aData.etag) {
       xhr.setRequestHeader("If-None-Match", aData.etag);
@@ -946,19 +957,23 @@ let DOMApplicationRegistry = {
       appObject.downloading = false;
       appObject.readyToApplyDownload = false;
     }
 
     appObject.name = manifest.name;
 
     this.webapps[id] = appObject;
 
-    PermissionsInstaller.installPermissions(aData.app, isReinstall, (function() {
-      this.uninstall(aData, aData.mm);
-    }).bind(this));
+    // For package apps, the permissions are not in the mini-manifest, so
+    // don't update the permissions yet.
+    if (!aData.isPackage) {
+      PermissionsInstaller.installPermissions(aData.app, isReinstall, (function() {
+        this.uninstall(aData, aData.mm);
+      }).bind(this));
+    }
 
     ["installState", "downloadAvailable",
      "downloading", "downloadSize", "readyToApplyDownload"].forEach(function(aProp) {
       aData.app[aProp] = appObject[aProp];
      });
 
     if (!aFromSync)
       this._saveApps((function() {
@@ -996,16 +1011,21 @@ let DOMApplicationRegistry = {
         DOMApplicationRegistry._writeFile(manFile,
                                           JSON.stringify(aManifest),
                                           function() { });
         // Set state and fire events.
         app.installState = "installed";
         app.downloading = false;
         app.downloadavailable = false;
         DOMApplicationRegistry._saveApps(function() {
+          // Update the permissions for this app.
+          PermissionsInstaller.installPermissions({ manifest: aManifest,
+                                                    origin: appObject.origin,
+                                                    manifestURL: appObject.manifestURL },
+                                                  true);
           debug("About to fire Webapps:PackageEvent");
           DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
                                                   { type: "installed",
                                                     manifestURL: appObject.manifestURL,
                                                     app: app,
                                                     manifest: aManifest });
         });
       });