diff options
Diffstat (limited to 'content/page_actions.js')
-rw-r--r-- | content/page_actions.js | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/content/page_actions.js b/content/page_actions.js index aff56b8..8057541 100644 --- a/content/page_actions.js +++ b/content/page_actions.js @@ -11,13 +11,18 @@ * IMPORT browser * IMPORT report_script * IMPORT report_settings + * IMPORT report_content_type * IMPORTS_END */ -var port; -var loaded = false; -var scripts_awaiting = []; -var nonce; +let policy_received_callback; +/* Snapshot url and content type early; these can be changed by other code. */ +let url; +let is_html; +let port; +let loaded = false; +let scripts_awaiting = []; +let nonce; function handle_message(message) { @@ -31,11 +36,13 @@ function handle_message(message) scripts_awaiting.push(script_text); } } - if (action === "settings") + if (action === "settings") { report_settings(data); + policy_received_callback({url, allow: data[1].allow}); + } } -function document_loaded(event) +function document_ready(event) { loaded = true; @@ -47,6 +54,9 @@ function document_loaded(event) function add_script(script_text) { + if (!is_html) + return; + let script = document.createElement("script"); script.textContent = script_text; script.setAttribute("nonce", nonce); @@ -56,11 +66,18 @@ function add_script(script_text) report_script(script_text); } -function handle_page_actions(script_nonce) { - document.addEventListener("DOMContentLoaded", document_loaded); +function handle_page_actions(script_nonce, policy_received_cb, + doc_ready_promise) { + policy_received_callback = policy_received_cb; + url = document.URL; + is_html = /html/.test(document.contentType); + report_content_type(document.contentType); + + doc_ready_promise.then(document_ready); + port = browser.runtime.connect({name : CONNECTION_TYPE.PAGE_ACTIONS}); port.onMessage.addListener(handle_message); - port.postMessage({url: document.URL}); + port.postMessage({url}); nonce = script_nonce; } |