aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--background/policy_injector.js1
-rw-r--r--common/misc.js20
-rw-r--r--content/main.js1
3 files changed, 20 insertions, 2 deletions
diff --git a/background/policy_injector.js b/background/policy_injector.js
index 01da094..9a994f8 100644
--- a/background/policy_injector.js
+++ b/background/policy_injector.js
@@ -16,7 +16,6 @@
* IMPORT gen_unique
* IMPORT gen_nonce
* IMPORT is_privileged_url
- * IMPORT url_item
* IMPORT url_extract_target
* IMPORT sign_policy
* IMPORT get_query_best
diff --git a/common/misc.js b/common/misc.js
index a59ec14..6af2327 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -154,6 +154,25 @@ function sign_policy(policy, now, hours_offset) {
return gen_unique(time + policy);
}
+/* Parse a CSP header */
+function parse_csp(csp) {
+ let directive, directive_array;
+ let directives = {};
+ for (directive of csp.split(';')) {
+ directive = directive.trim;
+ if (directive === '')
+ continue;
+
+ directive_array = directive.split(/\s+/);
+ directive = directive_array.shift();
+ /* The "true" case should never occur; nevertheless... */
+ directives[directive] = directive in directives ?
+ directives[directive].concat(directive_array) :
+ directive_array;
+ }
+ return directives;
+}
+
/*
* EXPORTS_START
* EXPORT gen_nonce
@@ -165,5 +184,6 @@ function sign_policy(policy, now, hours_offset) {
* EXPORT nice_name
* EXPORT open_in_settings
* EXPORT is_privileged_url
+ * EXPORT parse_csp
* EXPORTS_END
*/
diff --git a/content/main.js b/content/main.js
index 8f8375e..9ed557c 100644
--- a/content/main.js
+++ b/content/main.js
@@ -9,7 +9,6 @@
/*
* IMPORTS_START
* IMPORT handle_page_actions
- * IMPORT url_item
* IMPORT url_extract_target
* IMPORT gen_unique
* IMPORT gen_nonce