Project

General

Profile

« Previous | Next » 

Revision fbfddb02

Added by koszko over 1 year ago

add actual payload injection functionality to new content script

View differences:

content/content.js
48 48
#FROM common/policy.js            IMPORT decide_policy
49 49
#FROM content/policy_enforcing.js IMPORT enforce_blocking
50 50

  
51
let already_run = false, page_info;
51
let already_run = false, resolve_page_info,
52
    page_info_prom = new Promise(cb => resolve_page_info = cb);
52 53

  
53 54
function on_page_info_request([type], sender, respond_cb) {
54 55
    if (type !== "page_info")
55 56
	return;
56 57

  
57
    respond_cb(page_info);
58
    page_info_prom.then(respond_cb);
59

  
60
    return true;
58 61
}
59 62

  
60
globalThis.haketilo_content_script_main = function() {
63
globalThis.haketilo_content_script_main = async function() {
61 64
    if (already_run)
62 65
        return;
63 66

  
......
73 76
				 document.URL,
74 77
				 globalThis.haketilo_defualt_allow,
75 78
				 globalThis.haketilo_secret);
76
    page_info = Object.assign({url: document.URL}, policy);
79
    const page_info = Object.assign({url: document.URL}, policy);
77 80
    ["csp", "nonce"].forEach(prop => delete page_info[prop]);
78 81

  
79
    enforce_blocking(policy);
82
    if ("payload" in policy) {
83
	const msg = ["indexeddb_files", policy.payload.identifier];
84
	var scripts_prom = browser.runtime.sendMessage(msg);
85
    }
86

  
87
    await enforce_blocking(policy);
88

  
89
    if ("payload" in policy) {
90
	const script_response = await scripts_prom;
91

  
92
	if ("error" in script_response) {
93
	    resolve_page_info(Object.assign(page_info, script_response));
94
	    return;
95
	} else {
96
	    for (const script_contents of script_response) {
97
		const html_ns = "http://www.w3.org/1999/xhtml";
98
		const script = document.createElementNS(html_ns, "script");
99

  
100
		script.innerText = script_contents;
101
		script.setAttribute("nonce", policy.nonce);
102
		document.documentElement.append(script);
103
		script.remove();
104
	    }
105
	}
106
    }
107

  
108
    resolve_page_info(page_info);
80 109
}
81 110

  
82 111
function main() {

Also available in: Unified diff