diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-20 17:39:09 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-20 17:39:09 +0200 |
commit | 0b2e4f1afad41e638bce2c631c7bc895ba6c0c69 (patch) | |
tree | 0fdada34ddfa883d7e36142d0aa2084d1f343b35 /toolkit/components/webextensions/ExtensionChild.jsm | |
parent | 20a3f8c006445b176fa8559f6529c2cf3cb75b0d (diff) | |
download | UXP-0b2e4f1afad41e638bce2c631c7bc895ba6c0c69.tar UXP-0b2e4f1afad41e638bce2c631c7bc895ba6c0c69.tar.gz UXP-0b2e4f1afad41e638bce2c631c7bc895ba6c0c69.tar.lz UXP-0b2e4f1afad41e638bce2c631c7bc895ba6c0c69.tar.xz UXP-0b2e4f1afad41e638bce2c631c7bc895ba6c0c69.zip |
moebius#217: WebExtensions - Implemented "runtime.onMessageExternal"/"onConnectExternal"
https://github.com/MoonchildProductions/moebius/pull/217
Diffstat (limited to 'toolkit/components/webextensions/ExtensionChild.jsm')
-rw-r--r-- | toolkit/components/webextensions/ExtensionChild.jsm | 28 |
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; |