Bug 788125 - System messages don't work with different entry points if the app is not already open [r=vingtetun]
authorFabrice Desré <fabrice@mozilla.com>
Thu, 13 Sep 2012 11:47:34 -0700
changeset 106993 e169364def658a76c21c50b7c49f11a59b21464b
parent 106989 0ec10e895d42536076c6d3825f9c101559249cfe
child 106994 81bcdc9521510f23a0b5a3d6ffb898cda592b4c4
push id14807
push userfdesre@mozilla.com
push dateThu, 13 Sep 2012 18:48:49 +0000
treeherdermozilla-inbound@81bcdc952151 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs788125
milestone18.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 788125 - System messages don't work with different entry points if the app is not already open [r=vingtetun]
dom/apps/src/Webapps.jsm
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -126,36 +126,73 @@ let DOMApplicationRegistry = {
       } else {
         // The directory we're trying to load from doesn't exist.
         this.dirsToLoad--;
       }
     }).bind(this));
   },
 
 #ifdef MOZ_SYS_MSG
-  _registerSystemMessages: function(aManifest, aApp) {
-    if (aManifest.messages && Array.isArray(aManifest.messages) &&
-        aManifest.messages.length > 0) {
-      let manifest = new DOMApplicationManifest(aManifest, aApp.origin);
-      let launchPath = Services.io.newURI(manifest.fullLaunchPath(), null, null);
-      let manifestURL = Services.io.newURI(aApp.manifestURL, null, null);
-      aManifest.messages.forEach(function registerPages(aMessage) {
-        msgmgr.registerPage(aMessage, launchPath, manifestURL);
-      });
+
+  // aEntryPoint is either the entry_point name or the null, in which case we
+  // use the root of the manifest.
+  _registerSystemMessagesForEntryPoint: function(aManifest, aApp, aEntryPoint) {
+    let root = aManifest;
+    if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
+      root = aManifest.entry_points[aEntryPoint];
     }
-  },
 
-  _registerActivities: function(aManifest, aApp) {
-    if (!aManifest.activities) {
+    if (!root.messages || !Array.isArray(root.messages) ||
+        root.messages.length == 0) {
       return;
     }
 
     let manifest = new DOMApplicationManifest(aManifest, aApp.origin);
-    for (let activity in aManifest.activities) {
-      let description = aManifest.activities[activity];
+    let launchPath = Services.io.newURI(manifest.fullLaunchPath(aEntryPoint), null, null);
+    let manifestURL = Services.io.newURI(aApp.manifestURL, null, null);
+    root.messages.forEach(function registerPages(aMessage) {
+      let href = launchPath;
+      let messageName;
+      if (typeof(aMessage) === "object" && Object.keys(aMessage).length === 1) {
+        messageName = Object.keys(aMessage)[0];
+        href = Services.io.newURI(manifest.resolveFromOrigin(aMessage[messageName]), null, null);
+      } else {
+        messageName = aMessage;
+      }
+      msgmgr.registerPage(messageName, href, manifestURL);
+    });
+  },
+
+  _registerSystemMessages: function(aManifest, aApp) {
+    this._registerSystemMessagesForEntryPoint(aManifest, aApp, null);
+
+    if (!aManifest.entry_points) {
+      return;
+    }
+
+    for (let entryPoint in aManifest.entry_points) {
+      this._registerSystemMessagesForEntryPoint(aManifest, aApp, entryPoint);
+    }
+  },
+
+  // aEntryPoint is either the entry_point name or the null, in which case we
+  // use the root of the manifest.
+  _registerActivitiesForEntryPoint: function(aManifest, aApp, aEntryPoint) {
+    let root = aManifest;
+    if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
+      root = aManifest.entry_points[aEntryPoint];
+    }
+
+    if (!root.activities) {
+      return;
+    }
+
+    let manifest = new DOMApplicationManifest(aManifest, aApp.origin);
+    for (let activity in root.activities) {
+      let description = root.activities[activity];
       if (!description.href) {
         description.href = manifest.launch_path;
       }
       description.href = manifest.resolveFromOrigin(description.href);
       let json = {
         "manifest": aApp.manifestURL,
         "name": activity,
         "title": manifest.name,
@@ -166,31 +203,60 @@ let DOMApplicationRegistry = {
 
       let launchPath =
         Services.io.newURI(manifest.resolveFromOrigin(description.href), null, null);
       let manifestURL = Services.io.newURI(aApp.manifestURL, null, null);
       msgmgr.registerPage("activity", launchPath, manifestURL);
     }
   },
 
-  _unregisterActivities: function(aManifest, aApp) {
-    if (!aManifest.activities) {
+  _registerActivities: function(aManifest, aApp) {
+    this._registerActivitiesForEntryPoint(aManifest, aApp, null);
+
+    if (!aManifest.entry_points) {
       return;
     }
 
-    for (let activity in aManifest.activities) {
-      let description = aManifest.activities[activity];
+    for (let entryPoint in aManifest.entry_points) {
+      this._registerActivitiesForEntryPoint(aManifest, aApp, entryPoint);
+    }
+  },
+
+  _unregisterActivitiesForEntryPoint: function(aManifest, aApp, aEntryPoint) {
+    let root = aManifest;
+    if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
+      root = aManifest.entry_points[aEntryPoint];
+    }
+
+    if (!root.activities) {
+      return;
+    }
+
+    for (let activity in root.activities) {
+      let description = root.activities[activity];
       let json = {
         "manifest": aApp.manifestURL,
         "name": activity
       }
       cpmm.sendAsyncMessage("Activities:Unregister", json);
     }
   },
 
+  _unregisterActivities: function(aManifest, aApp) {
+    this._unregisterActivitiesForEntryPoint(aManifest, aApp, null);
+
+    if (!aManifest.entry_points) {
+      return;
+    }
+
+    for (let entryPoint in aManifest.entry_points) {
+      this._unregisterActivitiesForEntryPoint(aManifest, aApp, entryPoint);
+    }
+  },
+
   _processManifestForIds: function(aIds) {
     this._readManifests(aIds, (function registerManifests(aResults) {
       aResults.forEach(function registerManifest(aResult) {
         let app = this.webapps[aResult.id];
         let manifest = aResult.manifest;
         app.name = manifest.name;
         this._registerSystemMessages(manifest, app);
         this._registerActivities(manifest, app);
@@ -395,17 +461,18 @@ let DOMApplicationRegistry = {
         ppmm.broadcastAsyncMessage("Webapps:Install:Return:OK", aData);
         Services.obs.notifyObservers(this, "webapps-sync-install", appNote);
         this.children.forEach(function(aMsgMgr) {
           aMsgMgr.sendAsyncMessage("Webapps:AddApp", { id: id, app: appObject });
         });
       }).bind(this));
 
 #ifdef MOZ_SYS_MSG
-    this._registerSystemMessages(id, app);
+    this._registerSystemMessages(app.manifest, app);
+    this._registerActivities(app.manifest, app);
 #endif
 
     // if the manifest has an appcache_path property, use it to populate the appcache
     if (manifest.appcache_path) {
       let appcacheURI = Services.io.newURI(manifest.fullAppcachePath(), null, null);
       let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"]
                             .getService(Ci.nsIOfflineCacheUpdateService);
       let docURI = Services.io.newURI(manifest.fullLaunchPath(), null, null);