aboutsummaryrefslogtreecommitdiff
path: root/background
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-12-22 16:39:34 +0100
committerWojtek Kosior <koszko@koszko.org>2021-12-22 16:39:34 +0100
commitb590eaa2f64ead3384eadc6fe58f6358aa1a0478 (patch)
tree8f1e9403c1a75246c2a9a0afc4ab30706ea7afbe /background
parentb7378a9994724750198e0d165c575be8538334fb (diff)
downloadbrowser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.tar.gz
browser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.zip
reworked build system; added missing license notices
Diffstat (limited to 'background')
-rw-r--r--background/broadcast_broker.js24
-rw-r--r--background/main.js50
-rw-r--r--background/page_actions_server.js30
-rw-r--r--background/policy_injector.js20
-rw-r--r--background/storage.js28
-rw-r--r--background/storage_server.js22
-rw-r--r--background/stream_filter.js17
7 files changed, 71 insertions, 120 deletions
diff --git a/background/broadcast_broker.js b/background/broadcast_broker.js
index 7af8769..9847d7e 100644
--- a/background/broadcast_broker.js
+++ b/background/broadcast_broker.js
@@ -42,12 +42,9 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT listen_for_connection
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/message_server.js IMPORT listen_for_connection
let next_id = 1;
@@ -55,7 +52,7 @@ const listeners_by_channel = new Map();
function new_broadcast_listener(port)
{
- listener_ctx = {port, id: ++next_id, channels: new Set()};
+ const listener_ctx = {port, id: ++next_id, channels: new Set()};
port.onMessage.addListener(msg => listener_command(msg, listener_ctx));
port.onDisconnect.addListener(msg => listener_remove(msg, listener_ctx));
}
@@ -102,7 +99,7 @@ function remove_broadcast_listener(listener_ctx)
function new_broadcast_sender(port)
{
- sender_ctx = {prepared_broadcasts: new Set()};
+ const sender_ctx = {prepared_broadcasts: new Set()};
port.onMessage.addListener(msg => sender_command(msg, sender_ctx));
port.onDisconnect.addListener(msg => flush(sender_ctx));
}
@@ -125,7 +122,7 @@ function sender_command(msg, sender_ctx)
function prepare(sender_ctx, channel_name, value, timeout)
{
- broadcast_data = [channel_name, value];
+ const broadcast_data = [channel_name, value];
sender_ctx.prepared_broadcasts.add(broadcast_data);
if (timeout === 0)
@@ -170,15 +167,10 @@ function remove_broadcast_sender(sender_ctx)
sender_ctx.prepared_broadcasts.forEach(nv => broadcast(...nv));
}
-function start_broadcast_broker()
+function start()
{
listen_for_connection(CONNECTION_TYPE.BROADCAST_SEND, new_broadcast_sender);
listen_for_connection(CONNECTION_TYPE.BROADCAST_LISTEN,
new_broadcast_listener);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_broadcast_broker
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/main.js b/background/main.js
index 2809334..cff0786 100644
--- a/background/main.js
+++ b/background/main.js
@@ -42,26 +42,25 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT initial_data
- * IMPORT TYPE_PREFIX
- * IMPORT get_storage
- * IMPORT light_storage
- * IMPORT start_storage_server
- * IMPORT start_page_actions_server
- * IMPORT browser
- * IMPORT is_privileged_url
- * IMPORT query_best
- * IMPORT inject_csp_headers
- * IMPORT apply_stream_filter
- * IMPORT is_chrome
- * IMPORT is_mozilla
- * IMPORTS_END
- */
+#IMPORT common/storage_light.js AS light_storage
+
+#IMPORT background/storage_server.js
+#IMPORT background/page_actions_server.js
+#IMPORT background/stream_filter.js
+
+#FROM common/browser.js IMPORT browser
+#FROM common/stored_types.js IMPORT TYPE_PREFIX
+#FROM background/storage.js IMPORT get_storage
+#FROM common/misc.js IMPORT is_privileged_url
+#FROM common/settings_query.js IMPORT query_best
+#FROM background/policy_injector.js IMPORT inject_csp_headers
+
+const initial_data = (
+#INCLUDE_VERBATIM default_settings.json
+);
-start_storage_server();
-start_page_actions_server();
+storage_server.start();
+page_actions_server.start();
async function init_ext(install_details)
{
@@ -131,7 +130,7 @@ function sanitize_web_page(details)
if (!skip) {
/* Check for API availability. */
if (browser.webRequest.filterResponseData)
- headers = apply_stream_filter(details, headers, policy);
+ headers = stream_filter.apply(details, headers, policy);
}
return {responseHeaders: headers};
@@ -192,9 +191,11 @@ async function start_webRequest_operations()
{
storage = await get_storage();
+#IF CHROMIUM
+ const extra_opts = ["blocking", "extraHeaders"];
+#ELSE
const extra_opts = ["blocking"];
- if (is_chrome)
- extra_opts.push("extraHeaders");
+#ENDIF
browser.webRequest.onHeadersReceived.addListener(
sanitize_web_page,
@@ -214,6 +215,7 @@ async function start_webRequest_operations()
start_webRequest_operations();
+#IF MOZILLA
const code = `\
console.warn("Hi, I'm Mr Dynamic!");
@@ -232,5 +234,5 @@ async function test_dynamic_content_scripts()
});
}
-if (is_mozilla)
- test_dynamic_content_scripts();
+test_dynamic_content_scripts();
+#ENDIF
diff --git a/background/page_actions_server.js b/background/page_actions_server.js
index bb4c34f..578d1b1 100644
--- a/background/page_actions_server.js
+++ b/background/page_actions_server.js
@@ -41,18 +41,15 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT get_storage
- * IMPORT light_storage
- * IMPORT TYPE_PREFIX
- * IMPORT CONNECTION_TYPE
- * IMPORT browser
- * IMPORT listen_for_connection
- * IMPORT sha256
- * IMPORT make_ajax_request
- * IMPORTS_END
- */
+#IMPORT common/storage_light.js AS light_storage
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/browser.js IMPORT browser
+#FROM common/message_server.js IMPORT listen_for_connection
+#FROM background/storage.js IMPORT get_storage
+#FROM common/stored_types.js IMPORT TYPE_PREFIX
+#FROM common/sha256.js IMPORT sha256
+#FROM common/ajax.js IMPORT make_ajax_request
var storage;
var handler;
@@ -143,15 +140,10 @@ function new_connection(port)
port.onMessage.addListener(handler[0]);
}
-async function start_page_actions_server()
+async function start()
{
storage = await get_storage();
listen_for_connection(CONNECTION_TYPE.PAGE_ACTIONS, new_connection);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_page_actions_server
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/policy_injector.js b/background/policy_injector.js
index 787f1f0..2544e8e 100644
--- a/background/policy_injector.js
+++ b/background/policy_injector.js
@@ -43,14 +43,12 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT make_csp_rule
- * IMPORT csp_header_regex
- * Re-enable the import below once nonce stuff here is ready
- * !mport gen_nonce
- * IMPORTS_END
- */
+#FROM common/misc.js IMPORT make_csp_rule, csp_header_regex
+
+/* Re-enable the import below once nonce stuff here is ready */
+#IF NEVER
+#FROM common/misc.js IMPORT gen_nonce
+#ENDIF
function inject_csp_headers(headers, policy)
{
@@ -76,8 +74,4 @@ function inject_csp_headers(headers, policy)
return headers;
}
-/*
- * EXPORTS_START
- * EXPORT inject_csp_headers
- * EXPORTS_END
- */
+#EXPORT inject_csp_headers
diff --git a/background/storage.js b/background/storage.js
index d57c701..2a93b87 100644
--- a/background/storage.js
+++ b/background/storage.js
@@ -41,19 +41,13 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT raw_storage
- * IMPORT TYPE_NAME
- * IMPORT list_prefixes
- * IMPORT make_lock
- * IMPORT lock
- * IMPORT unlock
- * IMPORT make_once
- * IMPORT browser
- * IMPORT observables
- * IMPORTS_END
- */
+#IMPORT common/storage_raw.js AS raw_storage
+#IMPORT common/observables.js
+
+#FROM common/stored_types.js IMPORT list_prefixes, TYPE_NAME
+#FROM common/lock.js IMPORT lock, unlock, make_lock
+#FROM common/once.js IMPORT make_once
+#FROM common/browser.js IMPORT browser
var exports = {};
@@ -362,10 +356,4 @@ exports.clear = async function ()
unlock(list.lock);
}
-const get_storage = make_once(init);
-
-/*
- * EXPORTS_START
- * EXPORT get_storage
- * EXPORTS_END
- */
+#EXPORT make_once(init) AS get_storage
diff --git a/background/storage_server.js b/background/storage_server.js
index 9355f86..2d13690 100644
--- a/background/storage_server.js
+++ b/background/storage_server.js
@@ -41,14 +41,11 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT listen_for_connection
- * IMPORT get_storage
- * IMPORT list_prefixes
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/message_server.js IMPORT listen_for_connection
+#FROM background/storage.js IMPORT get_storage
+#FROM common/stored_types.js IMPORT list_prefixes
var storage;
@@ -89,15 +86,10 @@ function new_connection(port)
remove_storage_listener(handle_change));
}
-async function start_storage_server()
+async function start()
{
storage = await get_storage();
listen_for_connection(CONNECTION_TYPE.REMOTE_STORAGE, new_connection);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_storage_server
- * EXPORTS_END
- */
+#EXPORT start
diff --git a/background/stream_filter.js b/background/stream_filter.js
index 9d8e1e5..925a39d 100644
--- a/background/stream_filter.js
+++ b/background/stream_filter.js
@@ -29,12 +29,8 @@
* in LibreJS.
*/
-/*
- * IMPORTS_START
- * IMPORT browser
- * IMPORT csp_header_regex
- * IMPORTS_END
- */
+#FROM common/browser.js IMPORT browser
+#FROM common/misc.js IMPORT csp_header_regex
function validate_encoding(charset)
{
@@ -204,7 +200,7 @@ function filter_data(properties, event)
properties.filter.disconnect();
}
-function apply_stream_filter(details, headers, policy)
+function apply(details, headers, policy)
{
if (!policy.payload)
return headers;
@@ -224,9 +220,4 @@ function apply_stream_filter(details, headers, policy)
*/
return headers;
}
-
-/*
- * EXPORTS_START
- * EXPORT apply_stream_filter
- * EXPORTS_END
- */
+#EXPORT apply