Bug 877627 - [Contacts][Dialer] Dialer doesn't show on screen when launching from contacts. r=fabrice,shianyow a=tef+
authorGene Lian <clian@mozilla.com>
Fri, 31 May 2013 22:34:33 +0800
changeset 119048 c1cf9c63bc4bb2b156e15c1bd1ae609ceac08373
parent 119047 be5c2ee11d02ff6abdf6db5d1fe5e6b1f6f83376
child 119049 bb73520e9dce3d253b92397c09d11298dacbc4f6
push id211
push userclian@mozilla.com
push dateFri, 31 May 2013 14:35:43 +0000
reviewersfabrice, shianyow, tef
bugs877627
milestone18.0
Bug 877627 - [Contacts][Dialer] Dialer doesn't show on screen when launching from contacts. r=fabrice,shianyow a=tef+
dom/messages/SystemMessageInternal.js
dom/messages/SystemMessageManager.js
--- a/dom/messages/SystemMessageInternal.js
+++ b/dom/messages/SystemMessageInternal.js
@@ -238,34 +238,50 @@ SystemMessageInternal.prototype = {
       let target = aTargets[index];
       if (target.target === aTarget) {
         return index;
       }
     }
     return -1;
   },
 
-  _removeTargetFromListener: function _removeTargetFromListener(aTarget, aManifest, aRemoveListener) {
+  _isEmptyObject: function _isEmptyObject(aObj) {
+    for (let name in aObj) {
+      return false;
+    }
+    return true;
+  },
+
+  _removeTargetFromListener: function _removeTargetFromListener(aTarget,
+                                                                aManifest,
+                                                                aRemoveListener,
+                                                                aUri) {
     let targets = this._listeners[aManifest];
     if (!targets) {
       return false;
     }
 
     let index = this._findTargetIndex(targets, aTarget);
     if (index === -1) {
       return false;
     }
 
     if (aRemoveListener) {
       debug("remove the listener for " + aManifest);
       delete this._listeners[aManifest];
       return true;
     }
 
-    if (--targets[index].winCount === 0) {
+    let target = targets[index];
+    if (aUri && target.winCounts[aUri] !== undefined &&
+        --target.winCounts[aUri] === 0) {
+      delete target.winCounts[aUri];
+    }
+
+    if (this._isEmptyObject(target.winCounts)) {
       if (targets.length === 1) {
         // If it's the only one, get rid of this manifest entirely.
         debug("remove the listener for " + aManifest);
         delete this._listeners[aManifest];
       } else {
         // If more than one left, remove this one and leave the rest.
         targets.splice(index, 1);
       }
@@ -292,47 +308,55 @@ SystemMessageInternal.prototype = {
 
     switch(aMessage.name) {
       case "SystemMessageManager:AskReadyToRegister":
         return true;
         break;
       case "SystemMessageManager:Register":
       {
         debug("Got Register from " + msg.uri + " @ " + msg.manifest);
+        let uri = msg.uri;
         let targets, index;
         if (!(targets = this._listeners[msg.manifest])) {
+          let winCounts = {};
+          winCounts[uri] = 1;
           this._listeners[msg.manifest] = [{ target: aMessage.target,
-                                             uri: msg.uri,
-                                             winCount: 1 }];
+                                             winCounts: winCounts }];
         } else if ((index = this._findTargetIndex(targets, aMessage.target)) === -1) {
+          let winCounts = {};
+          winCounts[uri] = 1;
           targets.push({ target: aMessage.target,
-                         uri: msg.uri,
-                         winCount: 1 });
+                         winCounts: winCounts });
         } else {
-          targets[index].winCount++;
+          let winCounts = targets[index].winCounts;
+          if (winCounts[uri] === undefined) {
+            winCounts[uri] = 1;
+          } else {
+            winCounts[uri]++;
+          }
         }
 
         debug("listeners for " + msg.manifest + " innerWinID " + msg.innerWindowID);
         break;
       }
       case "child-process-shutdown":
       {
         debug("Got child-process-shutdown from " + aMessage.target);
         for (let manifest in this._listeners) {
           // See if any processes in this manifest have this target.
-          if (this._removeTargetFromListener(aMessage.target, manifest, true)) {
+          if (this._removeTargetFromListener(aMessage.target, manifest, true, null)) {
             break;
           }
         }
         break;
       }
       case "SystemMessageManager:Unregister":
       {
         debug("Got Unregister from " + aMessage.target + "innerWinID " + msg.innerWindowID);
-        this._removeTargetFromListener(aMessage.target, msg.manifest, false);
+        this._removeTargetFromListener(aMessage.target, msg.manifest, false, msg.uri);
         break;
       }
       case "SystemMessageManager:GetPendingMessages":
       {
         debug("received SystemMessageManager:GetPendingMessages " + msg.type +
           " for " + msg.uri + " @ " + msg.manifest);
 
         // This is a sync call used to return the pending messages for a page.
@@ -516,17 +540,17 @@ SystemMessageInternal.prototype = {
                                            uri: aPageURI })
 
     let targets = this._listeners[aManifestURI];
     if (targets) {
       for (let index = 0; index < targets.length; ++index) {
         let target = targets[index];
         // We only need to send the system message to the targets which match
         // the manifest URL and page URL of the destination of system message.
-        if (target.uri != aPageURI) {
+        if (target.winCounts[aPageURI] === undefined) {
           continue;
         }
 
         appPageIsRunning = true;
         // We need to acquire a CPU wake lock for that page and expect that
         // we'll receive a "SystemMessageManager:HandleMessagesDone" message
         // when the page finishes handling the system message. At that point,
         // we'll release the lock we acquired.
--- a/dom/messages/SystemMessageManager.js
+++ b/dom/messages/SystemMessageManager.js
@@ -139,16 +139,17 @@ SystemMessageManager.prototype = {
     if (this._isInBrowserElement) {
       debug("the app loaded in the browser doesn't need to unregister " +
             "the manifest for listening to the system messages");
       return;
     }
 
     cpmm.sendAsyncMessage("SystemMessageManager:Unregister",
                           { manifest: this._manifest,
+                            uri: this._uri,
                             innerWindowID: this.innerWindowID });
   },
 
   // Possible messages:
   //
   //   - SystemMessageManager:Message
   //     This one will only be received when the child process is alive when
   //     the message is initially sent.