Bug 792846 - SystemMessageInternal.js fails if one of the message receiver is closed. r=vingtetun

This commit is contained in:
Gregor Wagner 2012-09-26 11:06:25 -07:00
parent 4cab7b262f
commit 8f327a8d66
2 changed files with 49 additions and 16 deletions

View File

@ -497,10 +497,20 @@ let DOMApplicationRegistry = {
if (!(aMsgName in this.children)) {
return;
}
this.children[aMsgName].forEach(function _doBroadcast(aMsgMgr) {
aMsgMgr.sendAsyncMessage(aMsgName, aContent);
});
let i;
for (i = this.children[aMsgName].length - 1; i >= 0; i -= 1) {
let msgMgr = this.children[aMsgName][i];
try {
msgMgr.sendAsyncMessage(aMsgName, aContent);
} catch (e) {
// Remove once 777508 lands.
let index;
if ((index = this.children[aMsgName].indexOf(msgMgr)) != -1) {
this.children[aMsgName].splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
},
_getAppDir: function(aId) {

View File

@ -50,12 +50,24 @@ SystemMessageInternal.prototype = {
sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI) {
debug("Broadcasting " + aType + " " + JSON.stringify(aMessage));
if (this._listeners[aManifestURI.spec]) {
this._listeners[aManifestURI.spec].forEach(function sendMsg(aListener) {
aListener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aManifestURI.spec })
});
let i;
let listener;
for (i = this._listeners[aManifestURI.spec].length - 1; i >= 0; i -= 1) {
listener = this._listeners[aManifestURI.spec][i];
try {
listener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aManifestURI.spec })
} catch (e) {
// Remove once 777508 lands.
let index;
if ((index = this._listeners[aManifestURI.spec].indexOf(listener)) != -1) {
this._listeners[aManifestURI.spec].splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
}
this._pages.forEach(function sendMess_openPage(aPage) {
@ -75,12 +87,23 @@ SystemMessageInternal.prototype = {
this._pages.forEach(function(aPage) {
if (aPage.type == aType) {
if (this._listeners[aPage.manifest]) {
this._listeners[aPage.manifest].forEach(function sendMsg(aListener) {
aListener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aPage.manifest})
});
let i;
for (i = this._listeners[aPage.manifest].length - 1; i >= 0; i -= 1) {
let listener = this._listeners[aPage.manifest][i];
try {
listener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aPage.manifest})
} catch (e) {
// Remove once 777508 lands.
let index;
if ((index = this._listeners[aPage.manifest].indexOf(listener)) != -1) {
this._listeners[aPage.manifest].splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
}
this._processPage(aPage, aMessage);
}