aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures/content-message-listener.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-12-08 10:48:25 +0900
committerGitHub <noreply@github.com>2018-12-08 10:48:25 +0900
commit9c34b961c68588d95cc942465dae55388e861ffa (patch)
tree697d1cf6ac625aacc4d3685ee37b7a051257f9ec /src/background/infrastructures/content-message-listener.js
parent97787c773f0d1b5e80beb438246b5a693dbd08aa (diff)
parent80de2149ad592c97158f1adb72b352dab3e0858e (diff)
Merge pull request #507 from ueokande/window-postmessage
Window postmessage
Diffstat (limited to 'src/background/infrastructures/content-message-listener.js')
-rw-r--r--src/background/infrastructures/content-message-listener.js22
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;
+ }
}