diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-01-26 22:13:01 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-01-26 22:13:01 +0100 |
commit | 9d825eaaa0715ee5244a09bc3d1968aa1664d048 (patch) | |
tree | f75d9306339b65e15750489e9c383cdb51212aaf /background | |
parent | 42fe44050661ed59198fb166672bfdaa119d4333 (diff) | |
download | browser-extension-9d825eaaa0715ee5244a09bc3d1968aa1664d048.tar.gz browser-extension-9d825eaaa0715ee5244a09bc3d1968aa1664d048.zip |
add new root content script
Diffstat (limited to 'background')
-rw-r--r-- | background/patterns_query_manager.js | 16 | ||||
-rw-r--r-- | background/webrequest.js | 17 |
2 files changed, 17 insertions, 16 deletions
diff --git a/background/patterns_query_manager.js b/background/patterns_query_manager.js index 78cd0ef..3b74ee9 100644 --- a/background/patterns_query_manager.js +++ b/background/patterns_query_manager.js @@ -49,6 +49,9 @@ #FROM common/browser.js IMPORT browser #ENDIF +let default_allow = {}; +#EXPORT default_allow + let secret; const tree = pqt.make(); @@ -72,8 +75,9 @@ async function update_content_script() script_update_needed = false; const code = `\ -this.haketilo_secret = ${secret}; -this.haketilo_pattern_tree = ${JSON.stringify(tree)}; +this.haketilo_secret = ${JSON.stringify(secret)}; +this.haketilo_pattern_tree = ${JSON.stringify(tree)}; +this.haketilo_default_allow = ${JSON.stringify(default_allow.value)}; if (this.haketilo_content_script_main) haketilo_content_script_main();`; @@ -151,6 +155,14 @@ async function start(secret_) initial_mappings.forEach(m => register("mappings", m)); initial_blocking.forEach(b => register("blocking", b)); + const set_allow_val = ch => default_allow.value = (ch.new_val || {}).value; + const [setting_tracking, initial_settings] = + await haketilodb.track.settings(set_allow_val); + for (const setting of initial_settings) { + if (setting.name === "default_allow") + Object.assign(default_allow, setting); + } + #IF MOZILLA || MV3 script_update_needed = true; await update_content_script(); diff --git a/background/webrequest.js b/background/webrequest.js index 891cac3..bd091dc 100644 --- a/background/webrequest.js +++ b/background/webrequest.js @@ -50,22 +50,10 @@ #FROM common/misc.js IMPORT is_privileged_url, csp_header_regex #FROM common/policy.js IMPORT decide_policy -#FROM background/patterns_query_manager.js IMPORT tree +#FROM background/patterns_query_manager.js IMPORT tree, default_allow let secret; -let default_allow = false; - -async function track_default_allow() -{ - const set_val = ch => default_allow = (ch.new_val || {}).value; - const [tracking, settings] = await haketilodb.track.settings(set_val); - for (const setting of settings) { - if (setting.name === "default_allow") - default_allow = setting.value; - } -} - function on_headers_received(details) { const url = details.url; @@ -74,7 +62,8 @@ function on_headers_received(details) let headers = details.responseHeaders; - const policy = decide_policy(tree, details.url, !!default_allow, secret); + const policy = + decide_policy(tree, details.url, !!default_allow.value, secret); if (policy.allow) return; |