diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-11-18 18:47:35 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-11-18 18:47:35 +0900 |
commit | 63b93ce1ca16e93563453e5caba451886fa3c01d (patch) | |
tree | bf31b6519fe10f0150ecc8c6da55c7576e9677c0 /src/background/infrastructures/content-message-listener.js | |
parent | 822033613061696e89725beb97265aad2bdffaa7 (diff) |
Use webextension message to console
Diffstat (limited to 'src/background/infrastructures/content-message-listener.js')
-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; + } } |