diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-12-22 16:39:34 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-12-22 16:39:34 +0100 |
commit | b590eaa2f64ead3384eadc6fe58f6358aa1a0478 (patch) | |
tree | 8f1e9403c1a75246c2a9a0afc4ab30706ea7afbe /content | |
parent | b7378a9994724750198e0d165c575be8538334fb (diff) | |
download | browser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.tar.gz browser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.zip |
reworked build system; added missing license notices
Diffstat (limited to 'content')
-rw-r--r-- | content/activity_info_server.js | 34 | ||||
-rw-r--r-- | content/main.js | 29 | ||||
-rw-r--r-- | content/page_actions.js | 19 | ||||
-rw-r--r-- | content/repo_query.js | 30 |
4 files changed, 39 insertions, 73 deletions
diff --git a/content/activity_info_server.js b/content/activity_info_server.js index c1b9736..db8ff80 100644 --- a/content/activity_info_server.js +++ b/content/activity_info_server.js @@ -42,15 +42,10 @@ * proprietary program, I am not going to enforce this in court. */ -/* - * IMPORTS_START - * IMPORT listen_for_connection - * IMPORT CONNECTION_TYPE - * IMPORT repo_query - * IMPORT subscribe_repo_query_results - * IMPORT unsubscribe_repo_query_results - * IMPORTS_END - */ +#IMPORT common/connection_types.js AS CONNECTION_TYPE +#IMPORT content/repo_query.js + +#FROM common/message_server.js IMPORT listen_for_connection var activities = []; var ports = new Set(); @@ -73,6 +68,7 @@ function report_script(script_data) { report_activity("script", script_data); } +#EXPORT report_script function report_settings(settings) { @@ -80,11 +76,13 @@ function report_settings(settings) Object.assign(settings_clone, settings) report_activity("settings", settings_clone); } +#EXPORT report_settings function report_document_type(is_html) { report_activity("is_html", is_html); } +#EXPORT report_document_type function report_repo_query_action(update, port) { @@ -93,13 +91,13 @@ function report_repo_query_action(update, port) function trigger_repo_query(query_specifier) { - repo_query(...query_specifier); + repo_query.query(...query_specifier); } function handle_disconnect(port, report_action) { ports.delete(port) - unsubscribe_repo_query_results(report_action); + repo_query.unsubscribe_results(report_action); } function new_connection(port) @@ -112,7 +110,7 @@ function new_connection(port) port.postMessage(activity); const report_action = u => report_repo_query_action(u, port); - subscribe_repo_query_results(report_action); + repo_query.subscribe_results(report_action); /* * So far the only thing we expect to receive is repo query order. Once more @@ -123,16 +121,8 @@ function new_connection(port) port.onDisconnect.addListener(() => handle_disconnect(port, report_action)); } -function start_activity_info_server() +function start() { listen_for_connection(CONNECTION_TYPE.ACTIVITY_INFO, new_connection); } - -/* - * EXPORTS_START - * EXPORT start_activity_info_server - * EXPORT report_script - * EXPORT report_settings - * EXPORT report_document_type - * EXPORTS_END - */ +#EXPORT start diff --git a/content/main.js b/content/main.js index 5a798e0..9e98635 100644 --- a/content/main.js +++ b/content/main.js @@ -42,20 +42,12 @@ * proprietary program, I am not going to enforce this in court. */ -/* - * IMPORTS_START - * IMPORT handle_page_actions - * IMPORT gen_nonce - * IMPORT is_privileged_url - * IMPORT browser - * IMPORT is_chrome - * IMPORT is_mozilla - * IMPORT start_activity_info_server - * IMPORT make_csp_rule - * IMPORT csp_header_regex - * IMPORT report_settings - * IMPORTS_END - */ +#IMPORT content/activity_info_server.js + +#FROM content/page_actions.js IMPORT handle_page_actions +#FROM common/misc.js IMPORT gen_nonce, is_privileged_url, \ + make_csp_rule, csp_header_regex +#FROM common/browser.js IMPORT browser document.content_loaded = document.readyState === "complete"; const wait_loaded = e => e.content_loaded ? Promise.resolve() : @@ -234,12 +226,13 @@ function mozilla_initial_block(doc) */ async function sanitize_document(doc, policy) { +#IF MOZILLA /* * Blocking of scripts that are in the DOM from the beginning. Needed for * Mozilla. */ - if (is_mozilla) - mozilla_initial_block(doc); + mozilla_initial_block(doc); +#ENDIF /* * Ensure our CSP rules are employed from the beginning. This CSP injection @@ -338,7 +331,7 @@ if (!is_privileged_url(document.URL)) { console.debug("current policy", policy); - report_settings(policy); + activity_info_server.report_settings(policy); policy.nonce = gen_nonce(); @@ -350,5 +343,5 @@ if (!is_privileged_url(document.URL)) { handle_page_actions(policy, doc_ready); - start_activity_info_server(); + activity_info_server.start(); } diff --git a/content/page_actions.js b/content/page_actions.js index f26e247..b2cc5ce 100644 --- a/content/page_actions.js +++ b/content/page_actions.js @@ -41,14 +41,10 @@ * proprietary program, I am not going to enforce this in court. */ -/* - * IMPORTS_START - * IMPORT CONNECTION_TYPE - * IMPORT browser - * IMPORT report_script - * IMPORT report_document_type - * IMPORTS_END - */ +#IMPORT common/connection_types.js AS CONNECTION_TYPE + +#FROM common/browser.js IMPORT browser +#FROM content/activity_info_server.js IMPORT report_script, report_document_type let policy; /* Snapshot url and content type early; these can be changed by other code. */ @@ -114,9 +110,4 @@ function handle_page_actions(_policy, doc_ready_promise) { port.postMessage({payload: policy.payload}); } } - -/* - * EXPORTS_START - * EXPORT handle_page_actions - * EXPORTS_END - */ +#EXPORT handle_page_actions diff --git a/content/repo_query.js b/content/repo_query.js index 3201159..5dd503d 100644 --- a/content/repo_query.js +++ b/content/repo_query.js @@ -41,15 +41,12 @@ * proprietary program, I am not going to enforce this in court. */ -/* - * IMPORTS_START - * IMPORT make_ajax_request - * IMPORT observables - * IMPORT TYPE_PREFIX - * IMPORT parse_json_with_schema - * IMPORT matchers - * IMPORTS_END - */ +#IMPORT common/observables.js + +#FROM common/ajax.js IMPORT make_ajax_request +#FROM common/stored_types.js IMPORT TYPE_PREFIX +#FROM common/sanitize_JSON.js IMPORT parse_json_with_schema +#FROM common/misc.js IMPORT matchers const paths = { [TYPE_PREFIX.PAGE]: "/pattern", @@ -71,6 +68,7 @@ function repo_query(prefix, item, repo_urls) for (const repo_url of repo_urls) perform_query_against(key, repo_url, results); } +#EXPORT repo_query AS query const page_schema = { pattern: matchers.nonempty_string, @@ -127,22 +125,16 @@ async function perform_query_against(key, repo_url, results) observables.broadcast(observable, broadcast_msg); } -function subscribe_repo_query_results(cb) +function subscribe_results(cb) { observables.subscribe(observable, cb); for (const [key, results] of queried_items.entries()) cb({prefix: key[0], item: key.substring(1), results}); } +#EXPORT subscribe_results -function unsubscribe_repo_query_results(cb) +function unsubscribe_results(cb) { observables.unsubscribe(observable, cb); } - -/* - * EXPORTS_START - * EXPORT repo_query - * EXPORT subscribe_repo_query_results - * EXPORT unsubscribe_repo_query_results - * EXPORTS_END - */ +#EXPORT unsubscribe_results |