Bug 1051114 - 400 MozInterAppMessagePort registered on frame message manager r=bent
--- 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]);