Skip to content

Commit

Permalink
Bug 878395 - System Message API: a follow-up for bug 877627 to preven…
Browse files Browse the repository at this point in the history
…t wrong pages from handling the system messages. r=fabrice a=tef+
  • Loading branch information
airpingu committed Jun 1, 2013
1 parent 3b5f918 commit e1c1223
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
20 changes: 14 additions & 6 deletions dom/messages/SystemMessageInternal.js
Expand Up @@ -383,10 +383,12 @@ SystemMessageInternal.prototype = {
page.pendingMessages.length = 0;

// Send the array of pending messages.
aMessage.target.sendAsyncMessage("SystemMessageManager:GetPendingMessages:Return",
{ type: msg.type,
manifest: msg.manifest,
msgQueue: pendingMessages });
aMessage.target
.sendAsyncMessage("SystemMessageManager:GetPendingMessages:Return",
{ type: msg.type,
manifest: msg.manifest,
uri: msg.uri,
msgQueue: pendingMessages });
break;
}
case "SystemMessageManager:HasPendingMessages":
Expand Down Expand Up @@ -543,8 +545,9 @@ SystemMessageInternal.prototype = {
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.
// We only need to send the system message to the targets (processes)
// which contain the window page that matches the manifest/page URL of
// the destination of system message.
if (target.winCounts[aPageURI] === undefined) {
continue;
}
Expand All @@ -556,10 +559,15 @@ SystemMessageInternal.prototype = {
// we'll release the lock we acquired.
this._acquireCpuWakeLock(pageKey);

// Multiple windows can share the same target (process), the content
// window needs to check if the manifest/page URL is matched. Only
// *one* window should handle the system message.
let manager = target.target;
manager.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType,
msg: aMessage,
manifest: aManifestURI,
uri: aPageURI,
msgID: aMessageID });
}
}
Expand Down
14 changes: 11 additions & 3 deletions dom/messages/SystemMessageManager.js
Expand Up @@ -159,10 +159,18 @@ SystemMessageManager.prototype = {
// retrieve the pending system messages from the parent (i.e. after
// sending SystemMessageManager:GetPendingMessages).
receiveMessage: function sysMessMgr_receiveMessage(aMessage) {
debug("receiveMessage " + aMessage.name + " for [" + aMessage.data.type + "] " +
"with manifest = " + this._manifest + " and uri = " + this._uri);

let msg = aMessage.data;
debug("receiveMessage " + aMessage.name + " for [" + msg.type + "] " +
"with manifest = " + msg.manifest + " and uri = " + msg.uri);

// Multiple windows can share the same target (process), the content
// window needs to check if the manifest/page URL is matched. Only
// *one* window should handle the system message.
if (msg.manifest !== this._manifest || msg.uri !== this._uri) {
debug("This page shouldn't handle the messages because its " +
"manifest = " + this._manifest + " and uri = " + this._uri);
return;
}

if (aMessage.name == "SystemMessageManager:Message") {
// Send an acknowledgement to parent to clean up the pending message,
Expand Down

0 comments on commit e1c1223

Please sign in to comment.