aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-07-20 11:19:37 +0200
committerWojtek Kosior <koszko@koszko.org>2021-07-20 11:19:37 +0200
commit9e26b71e8e6d2dd1c08d29972c96d3114b1bd24a (patch)
treef4ab2ee9cfd31a28e533df2f9773cf0378d487b0 /common
parent0c7c1ebddab49e1e0b1ad4cc4c8fcdeedd220946 (diff)
downloadbrowser-extension-9e26b71e8e6d2dd1c08d29972c96d3114b1bd24a.tar.gz
browser-extension-9e26b71e8e6d2dd1c08d29972c96d3114b1bd24a.zip
fix page info server bugs
Diffstat (limited to 'common')
-rw-r--r--common/message_server.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/message_server.js b/common/message_server.js
new file mode 100644
index 0000000..a541a04
--- /dev/null
+++ b/common/message_server.js
@@ -0,0 +1,37 @@
+/**
+ * Myext message server
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+/*
+ * IMPORTS_START
+ * IMPORT browser
+ * IMPORTS_END
+ */
+
+var listeners = {};
+
+/* magic should be one of the constants from /common/connection_types.js */
+
+function listen_for_connection(magic, cb)
+{
+ listeners[magic] = cb;
+}
+
+function raw_listen(port)
+{
+ if (listeners[port.name] === undefined)
+ return;
+
+ listeners[port.name](port);
+}
+
+browser.runtime.onConnect.addListener(raw_listen);
+
+/*
+ * EXPORTS_START
+ * EXPORT listen_for_connection
+ * EXPORTS_END
+ */