diff options
author | gorhill <rhill@raymondhill.net> | 2015-06-26 15:45:54 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-06-26 15:45:54 -0400 |
commit | 7d2855180c5560ebc1d850261edc5a2f5bdf3b0c (patch) | |
tree | 594357fdb9d32485f746fab72d2bc519c6399d57 /platform | |
parent | 631443768f2359e6fdb0bc6a3e457a0951e0a9e9 (diff) | |
download | uBlock-7d2855180c5560ebc1d850261edc5a2f5bdf3b0c.zip uBlock-7d2855180c5560ebc1d850261edc5a2f5bdf3b0c.tar.gz uBlock-7d2855180c5560ebc1d850261edc5a2f5bdf3b0c.tar.bz2 |
some refactoring of new DOM inspector code
Diffstat (limited to 'platform')
-rw-r--r-- | platform/chromium/vapi-background.js | 25 | ||||
-rw-r--r-- | platform/firefox/vapi-background.js | 26 |
2 files changed, 44 insertions, 7 deletions
diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 8e67b3d..ed66264 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -603,7 +603,7 @@ vAPI.messaging.onPortMessage = function(request, port) { return; } - console.error('µBlock> messaging > unknown request: %o', request); + console.error('uBlock> messaging > unknown request: %o', request); // Unhandled: // Need to callback anyways in case caller expected an answer, or @@ -661,9 +661,26 @@ vAPI.messaging.broadcast = function(message) { /******************************************************************************/ -vAPI.messaging.send = function(tabId, channelName, message) { +// "Auxiliary process": any process other than main process. +// +// Main process to auxiliary processes messaging. The approach is that of +// smoke-signal messaging, so emitters have to be ready to deal with no +// response at all (i.e. use timeout where needed). +// +// Mandatory: +// - receiverTabId: Which tab to send the message. +// No target tab id means sends to all tabs. +// - receiverChannel: Which channel to send the message. +// +// Optional: +// - senderTabId: From which tab the message originates. +// - senderChannel: From which channel the message originates. +// These optional fields are useful for the target, and may be used +// to send back a response to the sender. + +vAPI.messaging.post = function(message) { var port; - var chromiumTabId = toChromiumTabId(tabId); + var chromiumTabId = toChromiumTabId(message.receiverTabId); for ( var portName in this.ports ) { if ( this.ports.hasOwnProperty(portName) === false ) { continue; @@ -673,7 +690,7 @@ vAPI.messaging.send = function(tabId, channelName, message) { continue; } port.postMessage({ - channelName: channelName, + channelName: message.receiverChannel, msg: message }); if ( chromiumTabId !== 0 ) { diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index f7a4d72..67bda4f 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1239,10 +1239,30 @@ vAPI.messaging.setup = function(defaultHandler) { /******************************************************************************/ -vAPI.messaging.send = function(tabId, channelName, message) { - var ffTabId = tabId || ''; +// "Auxiliary process": any process other than main process. +// +// Main process to auxiliary processes messaging. The approach is that of +// smoke-signal messaging, so emitters have to be ready to deal with no +// response at all (i.e. use timeout where needed). +// +// Mandatory: +// - receiverTabId: Which tab to send the message. +// No target tab id means sends to all tabs. +// - receiverChannel: Which channel to send the message. +// +// Optional: +// - senderTabId: From which tab the message originates. +// - senderChannel: From which channel the message originates. +// These optional fields are useful for the target, and may be used +// to send back a response to the sender. + +vAPI.messaging.post = function(message) { + var ffTabId = message.receiverTabId || ''; var targetId = location.host + ':broadcast'; - var payload = JSON.stringify({ channelName: channelName, msg: message }); + var payload = JSON.stringify({ + channelName: message.receiverChannel, + msg: message + }); if ( ffTabId === '' ) { this.globalMessageManager.broadcastAsyncMessage(targetId, payload); |