aboutsummaryrefslogtreecommitdiff
path: root/common/misc.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/misc.js')
-rw-r--r--common/misc.js43
1 files changed, 10 insertions, 33 deletions
diff --git a/common/misc.js b/common/misc.js
index 4d4b346..dc4a598 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -42,21 +42,8 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT browser
- * IMPORT TYPE_NAME
- * IMPORT TYPE_PREFIX
- * IMPORTS_END
- */
-
-/* Generate a random base64-encoded 128-bit sequence */
-function gen_nonce()
-{
- let randomData = new Uint8Array(16);
- crypto.getRandomValues(randomData);
- return btoa(String.fromCharCode.apply(null, randomData));
-}
+#FROM common/browser.js IMPORT browser
+#FROM common/stored_types.js IMPORT TYPE_NAME, TYPE_PREFIX
/*
* generating unique, per-site value that can be computed synchronously
@@ -78,6 +65,7 @@ function gen_nonce(length=16)
crypto.getRandomValues(randomData);
return Uint8toHex(randomData);
}
+#EXPORT gen_nonce
/* CSP rule that blocks scripts according to policy's needs. */
function make_csp_rule(policy)
@@ -88,19 +76,18 @@ function make_csp_rule(policy)
rule += ` script-src ${script_src}; script-src-elem ${script_src};`;
return rule;
}
+#EXPORT make_csp_rule
/* Check if some HTTP header might define CSP rules. */
const csp_header_regex =
/^\s*(content-security-policy|x-webkit-csp|x-content-security-policy)/i;
+#EXPORT csp_header_regex
/*
* Print item together with type, e.g.
* nice_name("s", "hello") → "hello (script)"
*/
-function nice_name(prefix, name)
-{
- return `${name} (${TYPE_NAME[prefix]})`;
-}
+#EXPORT (prefix, name) => `${name} (${TYPE_NAME[prefix]})` AS nice_name
/* Open settings tab with given item's editing already on. */
function open_in_settings(prefix, name)
@@ -109,6 +96,7 @@ function open_in_settings(prefix, name)
const url = browser.runtime.getURL("html/options.html#" + prefix + name);
window.open(url, "_blank");
}
+#EXPORT open_in_settings
/*
* Check if url corresponds to a browser's special page (or a directory index in
@@ -116,7 +104,7 @@ function open_in_settings(prefix, name)
*/
const privileged_reg =
/^(chrome(-extension)?|moz-extension):\/\/|^about:|^file:\/\/.*\/$/;
-const is_privileged_url = url => privileged_reg.test(url);
+#EXPORT url => privileged_reg.test(url) AS is_privileged_url
/* Parse a CSP header */
function parse_csp(csp) {
@@ -148,6 +136,7 @@ const matchers = {
nonempty_string_matcher
]
};
+#EXPORT matchers
/*
* Facilitates checking if there aren't any keys in object. This does *NOT*
@@ -159,16 +148,4 @@ function is_object_empty(object)
return false;
return true;
}
-
-/*
- * EXPORTS_START
- * EXPORT gen_nonce
- * EXPORT make_csp_rule
- * EXPORT csp_header_regex
- * EXPORT nice_name
- * EXPORT open_in_settings
- * EXPORT is_privileged_url
- * EXPORT matchers
- * EXPORT is_object_empty
- * EXPORTS_END
- */
+#EXPORT is_object_empty