Bug 908999 - Update Registered/Allowed Connections for Inter-App Communication API When App Gets Uninstalled. r=gene
authorSean Lin <selin@mozilla.com>
Fri, 20 Jun 2014 17:44:37 +0800
changeset 191108 c2c67da7f87193e0f2627435bda8e3f588eb23fc
parent 191107 ff5d3c1b985647271f4c3aab81e888644b257b74
child 191109 4ee025b24758f0a842bdd197595b38c0f54bd541
push id45477
push usercbook@mozilla.com
push dateFri, 27 Jun 2014 07:47:07 +0000
treeherdermozilla-inbound@4ee025b24758 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgene
bugs908999
milestone33.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 908999 - Update Registered/Allowed Connections for Inter-App Communication API When App Gets Uninstalled. r=gene
dom/apps/src/InterAppCommService.jsm
--- a/dom/apps/src/InterAppCommService.jsm
+++ b/dom/apps/src/InterAppCommService.jsm
@@ -47,16 +47,17 @@ const kMessages =["Webapps:Connect",
  * from and interacting with the content processes.
  *
  * [1] https://wiki.mozilla.org/WebAPI/Inter_App_Communication_Alt_proposal
  */
 
 this.InterAppCommService = {
   init: function() {
     Services.obs.addObserver(this, "xpcom-shutdown", false);
+    Services.obs.addObserver(this, "webapps-clear-data", false);
 
     kMessages.forEach(function(aMsg) {
       ppmm.addMessageListener(aMsg, this);
     }, this);
 
     // This matrix is used for saving the inter-app connection info registered in
     // the app manifest. The object literal is defined as below:
     //
@@ -927,18 +928,87 @@ this.InterAppCommService = {
         break;
     }
   },
 
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "xpcom-shutdown":
         Services.obs.removeObserver(this, "xpcom-shutdown");
+        Services.obs.removeObserver(this, "webapps-clear-data");
         kMessages.forEach(function(aMsg) {
           ppmm.removeMessageListener(aMsg, this);
         }, this);
         ppmm = null;
         break;
+      case "webapps-clear-data":
+        let params =
+          aSubject.QueryInterface(Ci.mozIApplicationClearPrivateDataParams);
+        if (!params) {
+          if (DEBUG) {
+            debug("Error updating registered/allowed connections for an " +
+                  "uninstalled app.");
+          }
+          return;
+        }
+
+        // Only update registered/allowed connections for apps.
+        if (params.browserOnly) {
+          if (DEBUG) {
+            debug("Only update registered/allowed connections for apps.");
+          }
+          return;
+        }
+
+        let manifestURL = appsService.getManifestURLByLocalId(params.appId);
+        if (!manifestURL) {
+          if (DEBUG) {
+            debug("Error updating registered/allowed connections for an " +
+                  "uninstalled app.");
+          }
+          return;
+        }
+
+        // Update registered connections.
+        for (let keyword in this._registeredConnections) {
+          let subAppManifestURLs = this._registeredConnections[keyword];
+          if (subAppManifestURLs[manifestURL]) {
+            delete subAppManifestURLs[manifestURL];
+            if (DEBUG) {
+              debug("Remove " + manifestURL + " from registered connections " +
+                    "due to app uninstallation.");
+            }
+          }
+        }
+
+        // Update allowed connections.
+        for (let keyword in this._allowedConnections) {
+          let allowedPubAppManifestURLs = this._allowedConnections[keyword];
+          if (allowedPubAppManifestURLs[manifestURL]) {
+            delete allowedPubAppManifestURLs[manifestURL];
+            if (DEBUG) {
+              debug("Remove " + manifestURL + " (as a pub app) from allowed " +
+                    "connections due to app uninstallation.");
+            }
+          }
+
+          for (let pubAppManifestURL in allowedPubAppManifestURLs) {
+            let subAppManifestURLs = allowedPubAppManifestURLs[pubAppManifestURL];
+            for (let i = subAppManifestURLs.length - 1; i >= 0; i--) {
+              if (subAppManifestURLs[i] === manifestURL) {
+                subAppManifestURLs.splice(i, 1);
+                if (DEBUG) {
+                  debug("Remove " + manifestURL + " (as a sub app to pub " +
+                        pubAppManifestURL + ") from allowed connections " +
+                        "due to app uninstallation.");
+                }
+              }
+            }
+          }
+        }
+        debug("Finish updating registered/allowed connections for an " +
+              "uninstalled app.");
+        break;
     }
   }
 };
 
 InterAppCommService.init();