summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/ExtensionChild.jsm
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-20 17:51:57 -0400
committerGitHub <noreply@github.com>2018-04-20 17:51:57 -0400
commit6896f6898546ce6bd9dd16901411cfb02528b699 (patch)
treeb0438c6a4b2571ea9570faf5109e4b30624c3111 /toolkit/components/webextensions/ExtensionChild.jsm
parent68c11d035c78211def675d16ad07bede2732cc1d (diff)
parent0b2e4f1afad41e638bce2c631c7bc895ba6c0c69 (diff)
downloadUXP-6896f6898546ce6bd9dd16901411cfb02528b699.tar
UXP-6896f6898546ce6bd9dd16901411cfb02528b699.tar.gz
UXP-6896f6898546ce6bd9dd16901411cfb02528b699.tar.lz
UXP-6896f6898546ce6bd9dd16901411cfb02528b699.tar.xz
UXP-6896f6898546ce6bd9dd16901411cfb02528b699.zip
Merge pull request #217 from janekptacijarabaci/webextensions_runtime_onMessageExternal-onConnectExternal_1
moebius#217: WebExtensions - Implemented "runtime.onMessageExternal"/"onConnectExternal"
Diffstat (limited to 'toolkit/components/webextensions/ExtensionChild.jsm')
-rw-r--r--toolkit/components/webextensions/ExtensionChild.jsm28
1 files changed, 23 insertions, 5 deletions
diff --git a/toolkit/components/webextensions/ExtensionChild.jsm b/toolkit/components/webextensions/ExtensionChild.jsm
index c953dd685..5dc4e2277 100644
--- a/toolkit/components/webextensions/ExtensionChild.jsm
+++ b/toolkit/components/webextensions/ExtensionChild.jsm
@@ -325,7 +325,7 @@ class Messenger {
return this.sendMessage(messageManager, msg, recipient, responseCallback);
}
- onMessage(name) {
+ _onMessage(name, filter) {
return new SingletonEventManager(this.context, name, callback => {
let listener = {
messageFilterPermissive: this.optionalFilter,
@@ -333,7 +333,8 @@ class Messenger {
filterMessage: (sender, recipient) => {
// Ignore the message if it was sent by this Messenger.
- return sender.contextId !== this.context.contextId;
+ return (sender.contextId !== this.context.contextId &&
+ filter(sender, recipient));
},
receiveMessage: ({target, data: message, sender, recipient}) => {
@@ -373,6 +374,14 @@ class Messenger {
}).api();
}
+ onMessage(name) {
+ return this._onMessage(name, sender => sender.id === this.sender.id);
+ }
+
+ onMessageExternal(name) {
+ return this._onMessage(name, sender => sender.id !== this.sender.id);
+ }
+
_connect(messageManager, port, recipient) {
let msg = {
name: port.name,
@@ -407,7 +416,7 @@ class Messenger {
return this._connect(messageManager, port, recipient);
}
- onConnect(name) {
+ _onConnect(name, filter) {
return new SingletonEventManager(this.context, name, callback => {
let listener = {
messageFilterPermissive: this.optionalFilter,
@@ -415,7 +424,8 @@ class Messenger {
filterMessage: (sender, recipient) => {
// Ignore the port if it was created by this Messenger.
- return sender.contextId !== this.context.contextId;
+ return (sender.contextId !== this.context.contextId &&
+ filter(sender, recipient));
},
receiveMessage: ({target, data: message, sender}) => {
@@ -438,6 +448,14 @@ class Messenger {
};
}).api();
}
+
+ onConnect(name) {
+ return this._onConnect(name, sender => sender.id === this.sender.id);
+ }
+
+ onConnectExternal(name) {
+ return this._onConnect(name, sender => sender.id !== this.sender.id);
+ }
}
var apiManager = new class extends SchemaAPIManager {
@@ -745,7 +763,7 @@ class ExtensionPageContextChild extends BaseContext {
// This is the MessageSender property passed to extension.
// It can be augmented by the "page-open" hook.
- let sender = {id: extension.uuid};
+ let sender = {id: extension.id};
if (viewType == "tab") {
sender.tabId = tabId;
this.tabId = tabId;