Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chromium/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"indent": ["error", 2, {"outerIIFEBody": 0}],
"no-unused-vars": "error",
"no-undef": "error",
"strict": ["error", "global"]
"strict": ["error", "global"],
"space-before-blocks": ["error"],
"brace-style": ["error"]
},
"globals": {
"exports": true,
Expand Down
29 changes: 15 additions & 14 deletions chromium/background-scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var showCounter = true;
var isExtensionEnabled = true;
let disabledList = new Set();

function initializeStoredGlobals(){
function initializeStoredGlobals() {
return new Promise(resolve => {
store.get({
httpNowhere: false,
Expand Down Expand Up @@ -301,11 +301,11 @@ let simpleHTTPNowhereRedirect = new Map();

const cancelUrl = chrome.runtime.getURL("/pages/cancel/index.html");

function redirectOnCancel(shouldCancel, originURL){
function redirectOnCancel(shouldCancel, originURL) {
return shouldCancel ? {redirectUrl: newCancelUrl(originURL)} : {cancel: false};
}

function newCancelUrl(originURL){
function newCancelUrl(originURL) {
return cancelUrl + "?originURL=" + encodeURI(originURL);
}

Expand Down Expand Up @@ -553,7 +553,9 @@ function sortSwitchPlanner(tab_id, rewritten) {
var score = activeCount * 100 + passiveCount;
asset_host_list.push([score, activeCount, passiveCount, asset_host]);
}
asset_host_list.sort(function(a,b){return a[0]-b[0];});
asset_host_list.sort(function(a,b) {
return a[0]-b[0];
});
return asset_host_list;
}

Expand Down Expand Up @@ -665,8 +667,7 @@ function onErrorOccurred(details) {
details.error.indexOf("Unable to communicate securely with peer: requested domain name does not match the server’s certificate.") == 0 ||
details.error.indexOf("Cannot communicate securely with peer: no common encryption algorithm(s).") == 0 ||
details.error.indexOf("SSL peer has no certificate for the requested DNS name.") == 0
))
{
)) {
let url = new URL(details.url);
if (url.protocol == "https:") {
url.protocol = "http:";
Expand Down Expand Up @@ -782,7 +783,7 @@ function enableSwitchPlannerFor(tabId) {
// Listen for connection from the DevTools panel so we can set up communication.
chrome.runtime.onConnect.addListener(function (port) {
if (port.name == "devtools-page") {
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
var tabId = message.tabId;

var disableOnCloseCallback = function() {
Expand Down Expand Up @@ -815,9 +816,9 @@ chrome.runtime.onConnect.addListener(function (port) {

// This is necessary for communication with the popup in Firefox Private
// Browsing Mode, see https://bugzilla.mozilla.org/show_bug.cgi?id=1329304
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {

function get_update_channels_generic(update_channels){
function get_update_channels_generic(update_channels) {
let last_updated_promises = [];
for(let update_channel of update_channels) {
last_updated_promises.push(new Promise(resolve => {
Expand Down Expand Up @@ -944,7 +945,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
return obj;
}, new Set());

if(update_channel_names.has(message.object)){
if(update_channel_names.has(message.object)) {
return sendResponse(false);
}

Expand Down Expand Up @@ -983,8 +984,8 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
store.get({update_channels: []}, item => {
let scope_changed = false;
item.update_channels = item.update_channels.map(update_channel => {
if(update_channel.name == message.object.name){
if(update_channel.scope != message.object.scope){
if(update_channel.name == message.object.name) {
if(update_channel.scope != message.object.scope) {
scope_changed = true;
}
update_channel = message.object;
Expand All @@ -1000,7 +1001,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
// necesssary to avoid a race condition, see #16673
update.loadUpdateChannelsKeys().then(() => {
update.resetTimer();
if(scope_changed){
if(scope_changed) {
initializeAllRules();
}
sendResponse(true);
Expand Down Expand Up @@ -1029,7 +1030,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
return true;
},
is_firefox: () => {
if(typeof(browser) != "undefined"){
if(typeof(browser) != "undefined") {
browser.runtime.getBrowserInfo().then(function(info) {
if (info.name == "Firefox") {
sendResponse(true);
Expand Down
14 changes: 7 additions & 7 deletions chromium/background-scripts/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const nullIterable = Object.create(null, {
const scopes = new Map();

/* Returns the scope object from the map for the given scope string */
function getScope(scope){
function getScope(scope) {
if (!scopes.has(scope)) {
scopes.set(scope, new RegExp(scope));
}
Expand Down Expand Up @@ -174,7 +174,7 @@ RuleSet.prototype = {
}

if(this_rules_length > 0) {
for(let x = 0; x < this.rules.length; x++){
for(let x = 0; x < this.rules.length; x++) {
if(this.rules[x].to != ruleset.rules[x].to) {
return false;
}
Expand Down Expand Up @@ -431,7 +431,7 @@ RuleSets.prototype = {
}
},

addStoredCustomRulesets: function(){
addStoredCustomRulesets: function() {
return new Promise(resolve => {
this.store.get({
legacy_custom_rulesets: [],
Expand All @@ -445,17 +445,17 @@ RuleSets.prototype = {
},

// Load in the legacy custom rulesets, if any
loadCustomRulesets: function(legacy_custom_rulesets){
for(let legacy_custom_ruleset of legacy_custom_rulesets){
loadCustomRulesets: function(legacy_custom_rulesets) {
for(let legacy_custom_ruleset of legacy_custom_rulesets) {
this.loadCustomRuleset(legacy_custom_ruleset);
}
},

loadCustomRuleset: function(ruleset_string){
loadCustomRuleset: function(ruleset_string) {
this.addFromXml((new DOMParser()).parseFromString(ruleset_string, 'text/xml'));
},

setRuleActiveState: async function(ruleset_name, active){
setRuleActiveState: async function(ruleset_name, active) {
if (active == undefined) {
delete this.ruleActiveStates[ruleset_name];
} else {
Expand Down
2 changes: 1 addition & 1 deletion chromium/background-scripts/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function initialize() {
return new Promise(resolve => {
if (chrome.storage.sync) {
chrome.storage.sync.set({"sync-set-test": true}, () => {
if(chrome.runtime.lastError){
if(chrome.runtime.lastError) {
setStorage(chrome.storage.local);
} else {
setStorage(chrome.storage.sync);
Expand Down
36 changes: 18 additions & 18 deletions chromium/background-scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function loadUpdateChannelsKeys() {
imported_keys = {};
combined_update_channels = [];

for(let update_channel of combined_update_channels_preflight){
for(let update_channel of combined_update_channels_preflight) {

try{
imported_keys[update_channel.name] = await window.crypto.subtle.importKey(
Expand Down Expand Up @@ -88,17 +88,17 @@ async function checkForNewRulesets(update_channel) {
if(timestamp_result.status == 200) {
let rulesets_timestamp = Number(await timestamp_result.text());

if((await store.local.get_promise('rulesets-timestamp: ' + update_channel.name, 0)) < rulesets_timestamp){
if((await store.local.get_promise('rulesets-timestamp: ' + update_channel.name, 0)) < rulesets_timestamp) {
return rulesets_timestamp;
}
}
return false;
}

// Retrieve the timestamp for when a stored ruleset bundle was published
async function getRulesetTimestamps(){
async function getRulesetTimestamps() {
let timestamp_promises = [];
for(let update_channel of combined_update_channels){
for(let update_channel of combined_update_channels) {
timestamp_promises.push(new Promise(async resolve => {
let timestamp = await store.local.get_promise('rulesets-stored-timestamp: ' + update_channel.name, 0);
resolve([update_channel.name, timestamp]);
Expand Down Expand Up @@ -135,7 +135,7 @@ async function getNewRulesets(rulesets_timestamp, update_channel) {
// Returns a promise which verifies that the rulesets have a valid EFF
// signature, and if so, stores them and returns true.
// Otherwise, it throws an exception.
function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_channel){
function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_channel) {
return new Promise((resolve, reject) => {
window.crypto.subtle.verify(
{
Expand All @@ -154,7 +154,7 @@ function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_chan
const rulesets = new TextDecoder("utf-8").decode(rulesets_byte_array);
const rulesets_json = JSON.parse(rulesets);

if(rulesets_json.timestamp != rulesets_timestamp){
if(rulesets_json.timestamp != rulesets_timestamp) {
reject(update_channel.name + ': Downloaded ruleset had an incorrect timestamp. This may be an attempted downgrade attack. Aborting.');
} else {
await store.local.set_promise('rulesets: ' + update_channel.name, window.btoa(rulesets_gz));
Expand All @@ -170,13 +170,13 @@ function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_chan
}

// Unzip and apply the rulesets we have stored.
async function applyStoredRulesets(rulesets_obj){
async function applyStoredRulesets(rulesets_obj) {
let rulesets_promises = [];
for(let update_channel of combined_update_channels){
for(let update_channel of combined_update_channels) {
rulesets_promises.push(new Promise(resolve => {
const key = 'rulesets: ' + update_channel.name;
chrome.storage.local.get(key, root => {
if(root[key]){
if(root[key]) {
util.log(util.NOTE, update_channel.name + ': Applying stored rulesets.');

const rulesets_gz = window.atob(root[key]);
Expand All @@ -192,14 +192,14 @@ async function applyStoredRulesets(rulesets_obj){
}));
}

function isNotUndefined(subject){
function isNotUndefined(subject) {
return (typeof subject != 'undefined');
}

const channel_results = (await Promise.all(rulesets_promises)).filter(isNotUndefined);

if(channel_results.length > 0){
for(let channel_result of channel_results){
if(channel_results.length > 0) {
for(let channel_result of channel_results) {
rulesets_obj.addFromJson(channel_result.json.rulesets, channel_result.scope);
}
} else {
Expand All @@ -215,9 +215,9 @@ async function performCheck() {
store.local.set_promise('last-checked', current_timestamp);

let num_updates = 0;
for(let update_channel of combined_update_channels){
for(let update_channel of combined_update_channels) {
let new_rulesets_timestamp = await checkForNewRulesets(update_channel);
if(new_rulesets_timestamp){
if(new_rulesets_timestamp) {
util.log(util.NOTE, update_channel.name + ': A new ruleset bundle has been released. Downloading now.');
let new_rulesets = await getNewRulesets(new_rulesets_timestamp, update_channel);
try{
Expand All @@ -229,7 +229,7 @@ async function performCheck() {
}
}
}
if(num_updates > 0){
if(num_updates > 0) {
background_callback();
}
};
Expand All @@ -253,7 +253,7 @@ chrome.storage.onChanged.addListener(async function(changes, areaName) {
let initialCheck,
subsequentChecks;

async function createTimer(){
async function createTimer() {
const time_to_next_check = await timeToNextCheck();

initialCheck = setTimeout(() => {
Expand All @@ -262,7 +262,7 @@ async function createTimer(){
}, time_to_next_check * 1000);
}

function destroyTimer(){
function destroyTimer() {
if (initialCheck) {
clearTimeout(initialCheck);
}
Expand All @@ -271,7 +271,7 @@ function destroyTimer(){
}
}

async function initialize(store_param, cb){
async function initialize(store_param, cb) {
store = store_param;
background_callback = cb;

Expand Down
2 changes: 1 addition & 1 deletion chromium/background-scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function ArrayBufferToString(ab) {
let array = new Uint8Array(ab);
let string = "";

for (let byte of array){
for (let byte of array) {
string += String.fromCharCode(byte);
}

Expand Down
6 changes: 4 additions & 2 deletions chromium/pages/cancel/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
let observer;
document.addEventListener("DOMContentLoaded", () => {
const explainer = document.querySelector("[data-i18n=cancel_he_blocking_explainer]");
observer = new MutationObserver(() => {replaceLink(explainer)});
observer = new MutationObserver(() => {
replaceLink(explainer)
});
if (explainer.innerText.length > 0) {
replaceLink(explainer);
} else {
Expand All @@ -14,7 +16,7 @@ document.addEventListener("DOMContentLoaded", () => {
displayURL();
});

function replaceLink(explainer){
function replaceLink(explainer) {
observer.disconnect();
const linkText = chrome.i18n.getMessage("cancel_he_blocking_network");
const link = document.createElement("a");
Expand Down
4 changes: 3 additions & 1 deletion chromium/pages/debugging-rulesets/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ document.getElementById("save-button").addEventListener("click", e => {
e.preventDefault();
sendMessage("set_option", { debugging_rulesets: cm.getValue() }, () => {
savedTextElement.style.display = "block";
setTimeout(() => { savedTextElement.style.display = "none" }, 1000);
setTimeout(() => {
savedTextElement.style.display = "none"
}, 1000);

valueHasChanged = false;
document.title = savedTitle;
Expand Down
Loading