aboutsummaryrefslogtreecommitdiff
path: root/background
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-09-02 18:35:49 +0200
committerWojtek Kosior <koszko@koszko.org>2021-09-02 18:35:49 +0200
commit6247f163d3ca89d5570450ac7ac8fd18f73bb74b (patch)
treee3d4817ae475e1f3553d3a50a77792fc5c3c25a0 /background
parent4b59dced912fb9b50ff041c67f0f72cbbad56b6c (diff)
downloadbrowser-extension-6247f163d3ca89d5570450ac7ac8fd18f73bb74b.tar.gz
browser-extension-6247f163d3ca89d5570450ac7ac8fd18f73bb74b.zip
enable toggling of global script blocking policy\n\nThis commit also introduces `light_storage' module which is later going to replace the storage code we use right now.\nAlso included is a hack to properly display scrollbars under Mozilla (needs testing on newer Mozilla browsers).
Diffstat (limited to 'background')
-rw-r--r--background/main.js6
-rw-r--r--background/page_actions_server.js11
2 files changed, 12 insertions, 5 deletions
diff --git a/background/main.js b/background/main.js
index 5d6e680..b1c252a 100644
--- a/background/main.js
+++ b/background/main.js
@@ -9,6 +9,7 @@
* IMPORTS_START
* IMPORT TYPE_PREFIX
* IMPORT get_storage
+ * IMPORT light_storage
* IMPORT start_storage_server
* IMPORT start_page_actions_server
* IMPORT browser
@@ -50,6 +51,7 @@ browser.runtime.onInstalled.addListener(init_ext);
let storage;
+let policy_observable = {};
function on_headers_received(details)
{
@@ -58,7 +60,7 @@ function on_headers_received(details)
return;
const [pattern, settings] = query_best(storage, details.url);
- const allow = !!(settings && settings.allow);
+ const allow = !!(settings ? settings.allow : policy_observable.value);
const nonce = gen_nonce();
const policy = {allow, url, nonce};
@@ -114,6 +116,8 @@ async function start_webRequest_operations()
{urls: ["<all_urls>"], types: all_types},
extra_opts.concat("requestHeaders")
);
+
+ policy_observable = await light_storage.observe_var("default_allow");
}
start_webRequest_operations();
diff --git a/background/page_actions_server.js b/background/page_actions_server.js
index 58a0073..b0db5f5 100644
--- a/background/page_actions_server.js
+++ b/background/page_actions_server.js
@@ -8,6 +8,7 @@
/*
* IMPORTS_START
* IMPORT get_storage
+ * IMPORT light_storage
* IMPORT TYPE_PREFIX
* IMPORT CONNECTION_TYPE
* IMPORT browser
@@ -20,17 +21,17 @@
var storage;
var handler;
+let policy_observable;
function send_actions(url, port)
{
- const [pattern, settings] = query_best(storage, url);
+ let [pattern, settings] = query_best(storage, url);
+ if (!settings)
+ settings = {allow: policy_observable && policy_observable.value};
const repos = storage.get_all(TYPE_PREFIX.REPO);
port.postMessage(["settings", [pattern, settings, repos]]);
- if (settings === undefined)
- return;
-
let components = settings.components;
let processed_bags = new Set();
@@ -127,6 +128,8 @@ async function start_page_actions_server()
storage = await get_storage();
listen_for_connection(CONNECTION_TYPE.PAGE_ACTIONS, new_connection);
+
+ policy_observable = await light_storage.observe_var("default_allow");
}
/*