mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 777206 - SystemMessageInternal broadcasts information to all content processes [r=gwagner]
This commit is contained in:
parent
d82a273a26
commit
f73659a6b8
@ -25,7 +25,11 @@ try {
|
||||
kMaxPendingMessages = 5;
|
||||
}
|
||||
|
||||
function debug(aMsg) {
|
||||
const kMessages =["SystemMessageManager:GetPending",
|
||||
"SystemMessageManager:Register",
|
||||
"SystemMessageManager:Unregister"]
|
||||
|
||||
function debug(aMsg) {
|
||||
//dump("-- SystemMessageInternal " + Date.now() + " : " + aMsg + "\n");
|
||||
}
|
||||
|
||||
@ -35,16 +39,25 @@ function SystemMessageInternal() {
|
||||
// The set of pages registered by installed apps. We keep the
|
||||
// list of pending messages for each page here also.
|
||||
this._pages = [];
|
||||
this._listeners = {};
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
ppmm.addMessageListener("SystemMessageManager:GetPending", this);
|
||||
kMessages.forEach((function(aMsg) {
|
||||
ppmm.addMessageListener(aMsg, this);
|
||||
}).bind(this));
|
||||
}
|
||||
|
||||
SystemMessageInternal.prototype = {
|
||||
sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI) {
|
||||
debug("Broadcasting " + aType + " " + JSON.stringify(aMessage));
|
||||
ppmm.broadcastAsyncMessage("SystemMessageManager:Message" , { type: aType,
|
||||
msg: aMessage,
|
||||
manifest: aManifestURI.spec });
|
||||
if (this._listeners[aManifestURI.spec]) {
|
||||
this._listeners[aManifestURI.spec].forEach(function sendMsg(aListener) {
|
||||
aListener.sendAsyncMessage("SystemMessageManager:Message",
|
||||
{ type: aType,
|
||||
msg: aMessage,
|
||||
manifest: aManifestURI.spec })
|
||||
});
|
||||
}
|
||||
|
||||
this._pages.forEach(function sendMess_openPage(aPage) {
|
||||
if (aPage.type != aType ||
|
||||
aPage.manifest != aManifestURI.spec ||
|
||||
@ -61,10 +74,14 @@ SystemMessageInternal.prototype = {
|
||||
// Find pages that registered an handler for this type.
|
||||
this._pages.forEach(function(aPage) {
|
||||
if (aPage.type == aType) {
|
||||
ppmm.broadcastAsyncMessage("SystemMessageManager:Message" , { type: aType,
|
||||
msg: aMessage,
|
||||
manifest: aPage.manifest });
|
||||
|
||||
if (this._listeners[aPage.manifest]) {
|
||||
this._listeners[aPage.manifest].forEach(function sendMsg(aListener) {
|
||||
aListener.sendAsyncMessage("SystemMessageManager:Message",
|
||||
{ type: aType,
|
||||
msg: aMessage,
|
||||
manifest: aPage.manifest})
|
||||
});
|
||||
}
|
||||
this._processPage(aPage, aMessage);
|
||||
}
|
||||
}.bind(this))
|
||||
@ -82,37 +99,63 @@ SystemMessageInternal.prototype = {
|
||||
},
|
||||
|
||||
receiveMessage: function receiveMessage(aMessage) {
|
||||
debug("received SystemMessageManager:GetPending " + aMessage.json.type + " for " + aMessage.json.uri + " @ " + aMessage.json.manifest);
|
||||
// This is a sync call, use to return the pending message for a page.
|
||||
let msg = aMessage.json;
|
||||
debug(JSON.stringify(msg));
|
||||
switch(aMessage.name) {
|
||||
case "SystemMessageManager:Register":
|
||||
let manifest = msg.manifest;
|
||||
debug("Got Register from " + manifest);
|
||||
if (!this._listeners[manifest]) {
|
||||
this._listeners[manifest] = [];
|
||||
}
|
||||
this._listeners[manifest].push(aMessage.target);
|
||||
debug("listeners for " + manifest + " : " + this._listeners[manifest].length);
|
||||
break;
|
||||
case "SystemMessageManager:Unregister":
|
||||
debug("Got Unregister from " + aMessage.target);
|
||||
let mm = aMessage.target;
|
||||
for (let manifest in this._listeners) {
|
||||
let index = this._listeners[manifest].indexOf(mm);
|
||||
while (index != -1) {
|
||||
debug("Removing " + mm + " at index " + index);
|
||||
this._listeners[manifest].splice(index, 1);
|
||||
index = this._listeners[manifest].indexOf(mm);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "SystemMessageManager:GetPending":
|
||||
debug("received SystemMessageManager:GetPending " + aMessage.json.type +
|
||||
" for " + aMessage.json.uri + " @ " + aMessage.json.manifest);
|
||||
// This is a sync call, use to return the pending message for a page.
|
||||
debug(JSON.stringify(msg));
|
||||
// Find the right page.
|
||||
let page = null;
|
||||
this._pages.some(function(aPage) {
|
||||
if (aPage.uri == msg.uri &&
|
||||
aPage.type == msg.type &&
|
||||
aPage.manifest == msg.manifest) {
|
||||
page = aPage;
|
||||
}
|
||||
return page !== null;
|
||||
});
|
||||
if (!page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find the right page.
|
||||
let page = null;
|
||||
this._pages.some(function(aPage) {
|
||||
if (aPage.uri == msg.uri &&
|
||||
aPage.type == msg.type &&
|
||||
aPage.manifest == msg.manifest) {
|
||||
page = aPage;
|
||||
}
|
||||
return page !== null;
|
||||
});
|
||||
let pending = page.pending;
|
||||
// Clear the pending queue for this page.
|
||||
// This is ok since we'll store pending events in SystemMessageManager.js
|
||||
page.pending = [];
|
||||
|
||||
if (!page) {
|
||||
return null;
|
||||
return pending;
|
||||
break;
|
||||
}
|
||||
|
||||
let pending = page.pending;
|
||||
// Clear the pending queue for this page.
|
||||
// This is ok since we'll store pending events in SystemMessageManager.js
|
||||
page.pending = [];
|
||||
|
||||
return pending;
|
||||
},
|
||||
|
||||
observe: function observe(aSubject, aTopic, aData) {
|
||||
if (aTopic == "xpcom-shutdown") {
|
||||
ppmm.removeMessageListener("SystemMessageManager:GetPending", this);
|
||||
kMessages.forEach((function(aMsg) {
|
||||
ppmm.removeMessageListener(aMsg, this);
|
||||
}).bind(this));
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
ppmm = null;
|
||||
this._pages = null;
|
||||
|
@ -143,6 +143,7 @@ SystemMessageManager.prototype = {
|
||||
},
|
||||
|
||||
uninit: function sysMessMgr_uninit() {
|
||||
cpmm.sendAsyncMessage("SystemMessageManager:Unregister", { });
|
||||
this._handlers = null;
|
||||
this._pendings = null;
|
||||
},
|
||||
@ -177,6 +178,9 @@ SystemMessageManager.prototype = {
|
||||
.getService(Ci.nsIAppsService);
|
||||
this._manifest = appsService.getManifestURLByLocalId(principal.appId);
|
||||
this._window = aWindow;
|
||||
cpmm.sendAsyncMessage("SystemMessageManager:Register",
|
||||
{ manifest: this._manifest });
|
||||
debug("done");
|
||||
},
|
||||
|
||||
classID: Components.ID("{bc076ea0-609b-4d8f-83d7-5af7cbdc3bb2}"),
|
||||
|
Loading…
Reference in New Issue
Block a user