Bug 967653 - [Inter-App Communication API] use appsService.getAppByManifestURL(aManifestURL).appStatus to get appStatus. r=fabrice a=v1.4+
authorGene Lian <clian@mozilla.com>
Thu, 17 Apr 2014 18:57:02 +0800
changeset 179701 8e54082157d0ff2abefdea7ee0ba1fe4b3a3ff4c
parent 179700 330186521ea26c1dc77c60060ff2686d8f5062c1
child 179702 3110a484f0afeafa94752cad4dbc2a0bdebef39d
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersfabrice, v1
bugs967653
milestone31.0a1
Bug 967653 - [Inter-App Communication API] use appsService.getAppByManifestURL(aManifestURL).appStatus to get appStatus. r=fabrice a=v1.4+
dom/apps/src/InterAppCommService.js
dom/apps/src/Webapps.js
dom/apps/src/Webapps.jsm
dom/interfaces/apps/nsIInterAppCommService.idl
--- a/dom/apps/src/InterAppCommService.js
+++ b/dom/apps/src/InterAppCommService.js
@@ -71,31 +71,28 @@ function InterAppCommService() {
   //
   // For example:
   //
   // {
   //   "foo": {
   //     "app://subApp1.gaiamobile.org/manifest.webapp": {
   //       pageURL: "app://subApp1.gaiamobile.org/handler.html",
   //       description: "blah blah",
-  //       appStatus: Ci.nsIPrincipal.APP_STATUS_CERTIFIED,
   //       rules: { ... }
   //     },
   //     "app://subApp2.gaiamobile.org/manifest.webapp": {
   //       pageURL: "app://subApp2.gaiamobile.org/handler.html",
   //       description: "blah blah",
-  //       appStatus: Ci.nsIPrincipal.APP_STATUS_PRIVILEGED,
   //       rules: { ... }
   //     }
   //   },
   //   "bar": {
   //     "app://subApp3.gaiamobile.org/manifest.webapp": {
   //       pageURL: "app://subApp3.gaiamobile.org/handler.html",
   //       description: "blah blah",
-  //       appStatus: Ci.nsIPrincipal.APP_STATUS_INSTALLED,
   //       rules: { ... }
   //     }
   //   }
   // }
   //
   // TODO Bug 908999 - Update registered connections when app gets uninstalled.
   this._registeredConnections = {};
 
@@ -209,38 +206,37 @@ function InterAppCommService() {
   //     }
   //   }
   // }
   this._messagePortPairs = {};
 }
 
 InterAppCommService.prototype = {
   registerConnection: function(aKeyword, aHandlerPageURI, aManifestURI,
-                               aDescription, aAppStatus, aRules) {
+                               aDescription, aRules) {
     let manifestURL = aManifestURI.spec;
     let pageURL = aHandlerPageURI.spec;
 
     if (DEBUG) {
       debug("registerConnection: aKeyword: " + aKeyword +
             " manifestURL: " + manifestURL + " pageURL: " + pageURL +
-            " aDescription: " + aDescription + " aAppStatus: " + aAppStatus +
+            " aDescription: " + aDescription +
             " aRules.minimumAccessLevel: " + aRules.minimumAccessLevel +
             " aRules.manifestURLs: " + aRules.manifestURLs +
             " aRules.installOrigins: " + aRules.installOrigins);
     }
 
     let subAppManifestURLs = this._registeredConnections[aKeyword];
     if (!subAppManifestURLs) {
       subAppManifestURLs = this._registeredConnections[aKeyword] = {};
     }
 
     subAppManifestURLs[manifestURL] = {
       pageURL: pageURL,
       description: aDescription,
-      appStatus: aAppStatus,
       rules: aRules,
       manifestURL: manifestURL
     };
   },
 
   _matchMinimumAccessLevel: function(aRules, aAppStatus) {
     if (!aRules || !aRules.minimumAccessLevel) {
       if (DEBUG) {
@@ -295,77 +291,76 @@ InterAppCommService.prototype = {
     if (DEBUG) {
       debug("rules.manifestURLs is not matched!" +
             " manifestURLs: " + manifestURLs +
             " aManifestURL : " + aManifestURL);
     }
     return false;
   },
 
-  _matchInstallOrigins: function(aRules, aManifestURL) {
+  _matchInstallOrigins: function(aRules, aInstallOrigin) {
     if (!aRules || !Array.isArray(aRules.installOrigins)) {
       if (DEBUG) {
         debug("rules.installOrigins is not available. No need to match.");
       }
       return true;
     }
 
-    let installOrigin =
-      appsService.getAppByManifestURL(aManifestURL).installOrigin;
-
     let installOrigins = aRules.installOrigins;
-    if (installOrigins.indexOf(installOrigin) != -1) {
+    if (installOrigins.indexOf(aInstallOrigin) != -1) {
       return true;
     }
 
     if (DEBUG) {
       debug("rules.installOrigins is not matched!" +
-            " aManifestURL: " + aManifestURL +
             " installOrigins: " + installOrigins +
-            " installOrigin : " + installOrigin);
+            " installOrigin : " + aInstallOrigin);
     }
     return false;
   },
 
-  _matchRules: function(aPubAppManifestURL, aPubAppStatus, aPubRules,
-                        aSubAppManifestURL, aSubAppStatus, aSubRules) {
+  _matchRules: function(aPubAppManifestURL, aPubRules,
+                        aSubAppManifestURL, aSubRules) {
+    let pubApp = appsService.getAppByManifestURL(aPubAppManifestURL);
+    let subApp = appsService.getAppByManifestURL(aSubAppManifestURL);
+
     // TODO Bug 907068 In the initiative step, we only expose this API to
     // certified apps to meet the time line. Eventually, we need to make
     // it available for the non-certified apps as well. For now, only the
     // certified apps can match the rules.
-    if (aPubAppStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED ||
-        aSubAppStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED) {
+    if (pubApp.appStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED ||
+        subApp.appStatus != Ci.nsIPrincipal.APP_STATUS_CERTIFIED) {
       if (DEBUG) {
         debug("Only certified apps are allowed to do connections.");
       }
       return false;
     }
 
     if (!aPubRules && !aSubRules) {
       if (DEBUG) {
         debug("No rules for publisher and subscriber. No need to match.");
       }
       return true;
     }
 
     // Check minimumAccessLevel.
-    if (!this._matchMinimumAccessLevel(aPubRules, aSubAppStatus) ||
-        !this._matchMinimumAccessLevel(aSubRules, aPubAppStatus)) {
+    if (!this._matchMinimumAccessLevel(aPubRules, subApp.appStatus) ||
+        !this._matchMinimumAccessLevel(aSubRules, pubApp.appStatus)) {
       return false;
     }
 
     // Check manifestURLs.
     if (!this._matchManifestURLs(aPubRules, aSubAppManifestURL) ||
         !this._matchManifestURLs(aSubRules, aPubAppManifestURL)) {
       return false;
     }
 
     // Check installOrigins.
-    if (!this._matchInstallOrigins(aPubRules, aSubAppManifestURL) ||
-        !this._matchInstallOrigins(aSubRules, aPubAppManifestURL)) {
+    if (!this._matchInstallOrigins(aPubRules, subApp.installOrigin) ||
+        !this._matchInstallOrigins(aSubRules, pubApp.installOrigin)) {
       return false;
     }
 
     // Check developers.
     // TODO Do we really want to check this? This one seems naive.
 
     if (DEBUG) debug("All rules are matched.");
     return true;
@@ -447,17 +442,16 @@ InterAppCommService.prototype = {
   },
 
   _connect: function(aMessage, aTarget) {
     let keyword = aMessage.keyword;
     let pubRules = aMessage.rules;
     let pubAppManifestURL = aMessage.manifestURL;
     let outerWindowID = aMessage.outerWindowID;
     let requestID = aMessage.requestID;
-    let pubAppStatus = aMessage.appStatus;
 
     let subAppManifestURLs = this._registeredConnections[keyword];
     if (!subAppManifestURLs) {
       if (DEBUG) {
         debug("No apps are subscribed for this connection. Returning.");
       }
       this._dispatchMessagePorts(keyword, pubAppManifestURL, [],
                                  aTarget, outerWindowID, requestID);
@@ -481,22 +475,21 @@ InterAppCommService.prototype = {
         if (DEBUG) {
           debug("Don't need to select again. Skipping: " + subAppManifestURL);
         }
         continue;
       }
 
       // Only rule-matched publishers/subscribers are allowed to connect.
       let subscribedInfo = subAppManifestURLs[subAppManifestURL];
-      let subAppStatus = subscribedInfo.appStatus;
       let subRules = subscribedInfo.rules;
 
       let matched =
-        this._matchRules(pubAppManifestURL, pubAppStatus, pubRules,
-                         subAppManifestURL, subAppStatus, subRules);
+        this._matchRules(pubAppManifestURL, pubRules,
+                         subAppManifestURL, subRules);
       if (!matched) {
         if (DEBUG) {
           debug("Rules are not matched. Skipping: " + subAppManifestURL);
         }
         continue;
       }
 
       appsToSelect.push({
--- a/dom/apps/src/Webapps.js
+++ b/dom/apps/src/Webapps.js
@@ -481,17 +481,16 @@ WebappsApplication.prototype = {
 
   connect: function(aKeyword, aRules) {
     return this.createPromise(function (aResolve, aReject) {
       cpmm.sendAsyncMessage("Webapps:Connect",
                             { keyword: aKeyword,
                               rules: aRules,
                               manifestURL: this.manifestURL,
                               outerWindowID: this._id,
-                              appStatus: this._appStatus,
                               requestID: this.getPromiseResolverId({
                                 resolve: aResolve,
                                 reject: aReject
                               })});
     }.bind(this));
   },
 
   getConnections: function() {
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -732,17 +732,16 @@ this.DOMApplicationRegistry = {
         msgmgr.registerPage("connection", handlerPageURI, manifestURI);
       }
 
       interAppCommService.
         registerConnection(keyword,
                            handlerPageURI,
                            manifestURI,
                            connection.description,
-                           AppsUtils.getAppManifestStatus(manifest),
                            connection.rules);
     }
   },
 
   _registerSystemMessages: function(aManifest, aApp) {
     this._registerSystemMessagesForEntryPoint(aManifest, aApp, null);
 
     if (!aManifest.entry_points) {
--- a/dom/interfaces/apps/nsIInterAppCommService.idl
+++ b/dom/interfaces/apps/nsIInterAppCommService.idl
@@ -11,30 +11,27 @@ interface nsIURI;
  *
  * This interface contains helpers for Inter-App Communication API [1] related
  * purposes. A singleton service of this interface will be instantiated during
  * the system boot-up, which plays the role of the central service receiving
  * messages from and interacting with the content processes.
  *
  * [1] https://wiki.mozilla.org/WebAPI/Inter_App_Communication_Alt_proposal
  */
-[scriptable, uuid(7fdd8b68-0b0a-11e3-9b4c-afbc236da250)]
+[scriptable, uuid(b3d711a4-c6a4-11e3-8fd3-738e7fbcb6d6)]
 interface nsIInterAppCommService : nsISupports
 {
   /*
    * Registration of a page that wants to be connected to other apps through
    * the Inter-App Communication API.
    *
    * @param keyword        The connection's keyword.
    * @param handlerPageURI The URI of the handler's page.
    * @param manifestURI    The webapp's manifest URI.
    * @param description    The connection's description.
-   * @param appStatus      The app status can be Ci.nsIPrincipal.APP_STATUS_[
-   *                       NOT_INSTALLED, INSTALLED, PRIVILEGED, CERTIFIED].
    * @param rules          The connection's rules.
    */
   void registerConnection(in DOMString      keyword,
                           in nsIURI         handlerPageURI,
                           in nsIURI         manifestURI,
                           in DOMString      description,
-                          in unsigned short appStatus,
                           in jsval          rules);
 };