<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
	"use strict";
	
	const settings = require("./settings");
	const {preIntercept: intercept} = require("./intercept.js");
	const {ask} = require("./askForPermission.js");
	const lists = require("./lists.js");
	const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
	const getWrapped = require("sdk/getWrapped");
	
	const logging = require("./logging");
	const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = logging;
	setLogPrefix("frame script");
	
	// Variable to "unload" the script
	var enabled = true;
	
	message("starting", location.href);
	
	function check(message){
		if (enabled){
			return originalCheck(message);
		}
		else {
			return {type: [], mode: "allow"};
		}
	}
	function checkStack(stack){
		if (enabled){
			return originalCheckStack(stack);
		}
		else {
			return true;
		}
	}
	function askWrapper(data){
		return ask(data, {
			_: browser.i18n.getMessage,
			prefs
		});
	}
	
	message("open port to background script");
	var port = browser.runtime.connect();
	if (window === window.top){
		message("Is top level window -> tab had navigation -> clear page action");
		port.postMessage({"canvasBlocker-clear-page-action": true});
	}
	var tabId;
	port.onMessage.addListener(function(data){
		message("Got data from port", data);
		if (data.hasOwnProperty("tabId")){
			notice("my tab id is", data.tabId);
			tabId = data.tabId;
		}
		const persistentRndName = "persistent" + (browser.extension.inIncognitoContext? "Incognito": "") + "Rnd";
		if (data.hasOwnProperty(persistentRndName)){
			const persistentRndValue = data[persistentRndName];
			notice("got persistent random data", persistentRndValue);
			const {persistent: persistentRnd} = require("./randomSupplies.js");
			Object.keys(persistentRndValue).forEach(function(domain){
				verbose("random data for", domain, persistentRndValue[domain]);
				persistentRnd.setDomainRnd(domain, persistentRndValue[domain]);
			});
		}
	});
	var notifications = [];
	var notificationCounter = {};
	function notify(data){
		if (!settings.ignoredAPIs[data.api]){
			if (settings.storeNotificationData){
				notifications.push(data);
			}
			notificationCounter[data.messageId] = (notificationCounter[data.messageId] || 0) + 1;
			port.postMessage({"canvasBlocker-notify": data});
		}
	}
	
	function prefs(...args){
		return settings.get(...args);
	}
	
	
	var interceptedWindows = new WeakMap();
	function interceptWindow(window){
		try {
			var href = window.location.href;
		}
		catch (e){
			// we are unable to read the location due to SOP
			// therefore we also can not intercept anything.
			warning("NOT intercepting window due to SOP", window);
			return false;
		}
		
		if (!enabled || interceptedWindows.get(getWrapped(window))){<commit_msg>Send only necessary notifications to main process<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
	"use strict";
	
	const settings = require("./settings");
	const {preIntercept: intercept} = require("./intercept.js");
	const {ask} = require("./askForPermission.js");
	const lists = require("./lists.js");
	const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
	const getWrapped = require("sdk/getWrapped");
	
	const logging = require("./logging");
	const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = logging;
	setLogPrefix("frame script");
	
	// Variable to "unload" the script
	var enabled = true;
	
	message("starting", location.href);
	
	function check(message){
		if (enabled){
			return originalCheck(message);
		}
		else {
			return {type: [], mode: "allow"};
		}
	}
	function checkStack(stack){
		if (enabled){
			return originalCheckStack(stack);
		}
		else {
			return true;
		}
	}
	function askWrapper(data){
		return ask(data, {
			_: browser.i18n.getMessage,
			prefs
		});
	}
	
	message("open port to background script");
	var port = browser.runtime.connect();
	if (window === window.top){
		message("Is top level window -> tab had navigation -> clear page action");
		port.postMessage({"canvasBlocker-clear-page-action": true});
	}
	var tabId;
	port.onMessage.addListener(function(data){
		message("Got data from port", data);
		if (data.hasOwnProperty("tabId")){
			notice("my tab id is", data.tabId);
			tabId = data.tabId;
		}
		const persistentRndName = "persistent" + (browser.extension.inIncognitoContext? "Incognito": "") + "Rnd";
		if (data.hasOwnProperty(persistentRndName)){
			const persistentRndValue = data[persistentRndName];
			notice("got persistent random data", persistentRndValue);
			const {persistent: persistentRnd} = require("./randomSupplies.js");
			Object.keys(persistentRndValue).forEach(function(domain){
				verbose("random data for", domain, persistentRndValue[domain]);
				persistentRnd.setDomainRnd(domain, persistentRndValue[domain]);
			});
		}
	});
	var notifications = [];
	var notificationCounter = {};
	var sentAPIs = {};
	function notify(data){
		if (!settings.ignoredAPIs[data.api]){
			if (settings.storeNotificationData){
				notifications.push(data);
			}
			notificationCounter[data.messageId] = (notificationCounter[data.messageId] || 0) + 1;
			if (!sentAPIs[data.api]){
				sentAPIs[data.api] = true;
				port.postMessage({"canvasBlocker-notify": data});
			}
		}
	}
	
	function prefs(...args){
		return settings.get(...args);
	}
	
	
	var interceptedWindows = new WeakMap();
	function interceptWindow(window){
		try {
			var href = window.location.href;
		}
		catch (e){
			// we are unable to read the location due to SOP
			// therefore we also can not intercept anything.
			warning("NOT intercepting window due to SOP", window);
			return false;
		}
		
		if (!enabled || interceptedWindows.get(getWrapped(window))){
{'fraction_non_alphanumeric': 0.14460784313725492, 'fraction_numerical': 0.00261437908496732, 'mean_word_length': 4.245072836332477, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1618638', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1873, 'n_words': 491}