Bug 1051114 - 400 MozInterAppMessagePort registered on frame message manager r=bent
authorFabrice Desré <fabrice@mozilla.com>
Mon, 11 Aug 2014 10:37:09 -0700
changeset 213337 7f32109287e960466e70a5f856947c4fdfc4b926
parent 213336 332a663642b009a63bc77934c95660a74cd44a2a
child 213338 a213dabb5c5e1c5d6b78982e89b282414bd13e39
push id6741
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:57:58 +0000
treeherdermozilla-aurora@aed50d3edf33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1051114
milestone34.0a1
Bug 1051114 - 400 MozInterAppMessagePort registered on frame message manager r=bent
dom/apps/src/InterAppCommService.jsm
dom/apps/src/InterAppMessagePort.js
--- a/dom/apps/src/InterAppCommService.jsm
+++ b/dom/apps/src/InterAppCommService.jsm
@@ -799,16 +799,23 @@ this.InterAppCommService = {
 
     if (DEBUG) debug("Unregistering message ports based on this target.");
     let messagePortIDs = [];
     for (let messagePortID in this._messagePortPairs) {
       let pair = this._messagePortPairs[messagePortID];
       if (pair.publisher.target === aTarget ||
           pair.subscriber.target === aTarget) {
         messagePortIDs.push(messagePortID);
+        // Send a shutdown message to the part of the pair that is still alive.
+        let actor = pair.publisher.target === aTarget ? pair.subscriber
+                                                       : pair.publisher;
+        actor.target.sendAsyncMessage("InterAppMessagePort:Shutdown",
+          { manifestURL: actor.manifestURL,
+            pageURL: actor.pageURL,
+            messagePortID: messagePortID });
       }
     }
     messagePortIDs.forEach(function(aMessagePortID) {
       delete this._messagePortPairs[aMessagePortID];
     }, this);
   },
 
   _postMessage: function(aMessage) {
--- a/dom/apps/src/InterAppMessagePort.js
+++ b/dom/apps/src/InterAppMessagePort.js
@@ -25,17 +25,18 @@ function debug(aMsg) {
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 XPCOMUtils.defineLazyServiceGetter(this, "appsService",
                                    "@mozilla.org/AppsService;1",
                                    "nsIAppsService");
 
-const kMessages = ["InterAppMessagePort:OnMessage"];
+const kMessages = ["InterAppMessagePort:OnMessage",
+                   "InterAppMessagePort:Shutdown"];
 
 function InterAppMessagePort() {
   if (DEBUG) debug("InterAppMessagePort()");
 };
 
 InterAppMessagePort.prototype = {
   __proto__: DOMRequestIpcHelper.prototype,
 
@@ -144,16 +145,18 @@ InterAppMessagePort.prototype = {
     this._closed = true;
     this._messageQueue.length = 0;
 
     // When this method called on a local port that is entangled with another
     // port, must cause the user agent to disentangle the coupling ports.
     cpmm.sendAsyncMessage("InterAppMessagePort:Unregister",
                           { messagePortID: this._messagePortID,
                             manifestURL: this._manifestURL });
+
+    this.removeMessageListeners(kMessages);
   },
 
   get onmessage() {
     if (DEBUG) debug("Getting onmessage handler.");
 
     return this.__DOM_IMPL__.getEventHandler("onmessage");
   },
 
@@ -188,17 +191,18 @@ InterAppMessagePort.prototype = {
 
   receiveMessage: function(aMessage) {
     if (DEBUG) debug("receiveMessage: name: " + aMessage.name);
 
     let message = aMessage.json;
     if (message.manifestURL != this._manifestURL ||
         message.pageURL != this._pageURL ||
         message.messagePortID != this._messagePortID) {
-      if (DEBUG) debug("The message doesn't belong to this page. Returning.");
+      if (DEBUG) debug("The message doesn't belong to this page. Returning. " +
+                       uneval(message));
       return;
     }
 
     switch (aMessage.name) {
       case "InterAppMessagePort:OnMessage":
         if (this._closed) {
           if (DEBUG) debug("close() has been called. Drop the message.");
           return;
@@ -208,16 +212,19 @@ InterAppMessagePort.prototype = {
           if (DEBUG) debug("Not yet called start(). Queue up the message.");
           this._messageQueue.push(message.message);
           return;
         }
 
         this._dispatchMessage(message.message);
         break;
 
+      case "InterAppMessagePort:Shutdown":
+        this.close();
+        break;
       default:
         if (DEBUG) debug("Error! Shouldn't fall into this case.");
         break;
     }
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([InterAppMessagePort]);