diff options
Diffstat (limited to 'src/background/infrastructures')
-rw-r--r-- | src/background/infrastructures/content-message-listener.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/background/infrastructures/content-message-listener.js b/src/background/infrastructures/content-message-listener.js index beb52fe..aae07c0 100644 --- a/src/background/infrastructures/content-message-listener.js +++ b/src/background/infrastructures/content-message-listener.js @@ -16,6 +16,8 @@ export default class ContentMessageListener { this.linkController = new LinkController(); this.backgroundOperationController = new OperationController(); this.markController = new MarkController(); + + this.consolePorts = {}; } run() { @@ -38,6 +40,7 @@ export default class ContentMessageListener { }); } }); + browser.runtime.onConnect.addListener(this.onConnected.bind(this)); } onMessage(message, sender) { @@ -65,6 +68,8 @@ export default class ContentMessageListener { return this.onMarkSetGlobal(message.key, message.x, message.y); case messages.MARK_JUMP_GLOBAL: return this.onMarkJumpGlobal(message.key); + case messages.CONSOLE_FRAME_MESSAGE: + return this.onConsoleFrameMessage(sender.tab.id, message.message); } } @@ -116,4 +121,21 @@ export default class ContentMessageListener { onMarkJumpGlobal(key) { return this.markController.jumpGlobal(key); } + + onConsoleFrameMessage(tabId, message) { + let port = this.consolePorts[tabId]; + if (!port) { + return; + } + port.postMessage(message); + } + + onConnected(port) { + if (port.name !== 'vimvixen-console') { + return; + } + + let id = port.sender.tab.id; + this.consolePorts[id] = port; + } } |