Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ window.__firefox__.execute(function($) {
return originalFetch.apply(this, arguments)
}

const url = new URL(urlString, window.location.href)
const url = new $.URL(urlString, window.location.href)
return sendMessage(url).then(blocked => {
if (blocked) {
return Promise.reject(new TypeError('Load failed'))
return Promise.reject(new $.TypeError('Load failed'))
} else {
return originalFetch.apply(this, arguments)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ window.__firefox__.execute(function($) {
try {
// We do this in a try/catch block to not fail the request in case we can't
// create a URL
resourceURL = new URL(this[localURLProp], window.location.href)
resourceURL = new $.URL(this[localURLProp], window.location.href)
} catch (error) {
// Ignore this error and proceed like a regular request
return originalSend.apply(this, arguments)
Expand All @@ -110,10 +110,10 @@ window.__firefox__.execute(function($) {
Object.defineProperties(this, {
readyState: { value: 4 }
})
this.dispatchEvent(patchProgressEvent(new ProgressEvent('loadstart')))
this.dispatchEvent(new Event('readystatechange'))
this.dispatchEvent(patchProgressEvent(new ProgressEvent('error')))
this.dispatchEvent(patchProgressEvent(new ProgressEvent('loadend')))
this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('loadstart')))
this.dispatchEvent(new $.Event('readystatechange'))
this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('error')))
this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('loadend')))
} else {
originalSend.apply(this, arguments)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ window.__firefox__.execute(function($) {

let resourceURL = null;
try {
resourceURL = new URL(urlString, document.location.href);
resourceURL = new $.URL(urlString, document.location.href);

// First party urls or invalid URLs are not blocked
if (document.location.host === resourceURL.host) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ window.__firefox__.execute(function($) {

const targetHref = canonicalLinkElm.getAttribute('href');
try {
const destUrl = new URL(targetHref);
const destUrl = new $.URL(targetHref);
W.clearInterval(intervalId);

if (W.location.href == destUrl.href || !(destUrl.protocol === 'http:' || destUrl.protocol === 'https:')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,28 @@ window.__firefox__.execute(function($) {
const classIdWithoutHtmlOrBody = '[id]:not(html):not(body),[class]:not(html):not(body)'

const CC = {
allSelectors: new Set(),
pendingSelectors: { ids: new Set(), classes: new Set() },
alwaysHiddenSelectors: new Set(),
hiddenSelectors: new Set(),
unhiddenSelectors: new Set(),
allSelectors: new $.Set(),
pendingSelectors: { ids: new $.Set(), classes: new $.Set() },
alwaysHiddenSelectors: new $.Set(),
hiddenSelectors: new $.Set(),
unhiddenSelectors: new $.Set(),
allStyleRules: [],
runQueues: [
// All new selectors go in this first run queue
new Set(),
new $.Set(),
// Third party matches go in the second and third queues.
new Set(),
new $.Set(),
// This is the final run queue.
// It's only evaluated for 1p content one more time.
new Set()
new $.Set()
],
// URLS
pendingOrigins: new Set(),
pendingOrigins: new $.Set(),
// A map of origin strings and their isFirstParty results
urlFirstParty: new Map(),
alreadyKnownFirstPartySubtrees: new WeakSet()
urlFirstParty: new $.Map(),
alreadyKnownFirstPartySubtrees: new $.WeakSet(),
// A list all the selectors that need to be removed from the stylesheet
selectorsToRemove: []
}

/**
Expand All @@ -97,7 +99,7 @@ window.__firefox__.execute(function($) {
}

const origins = Array.from(CC.pendingOrigins)
CC.pendingOrigins = new Set()
CC.pendingOrigins = new $.Set()
const results = await getPartiness(origins)

for (const origin of origins) {
Expand Down Expand Up @@ -129,8 +131,8 @@ window.__firefox__.execute(function($) {

const ids = Array.from(CC.pendingSelectors.ids)
const classes = Array.from(CC.pendingSelectors.classes)
CC.pendingSelectors.ids = new Set()
CC.pendingSelectors.classes = new Set()
CC.pendingSelectors.ids = new $.Set()
CC.pendingSelectors.classes = new $.Set()

let hasChanges = false
const results = await sendSelectors(ids, classes)
Expand Down Expand Up @@ -322,7 +324,7 @@ window.__firefox__.execute(function($) {
selectorsPollingIntervalId = undefined
}

const observer = new MutationObserver(onMutations)
const observer = new $.MutationObserver(onMutations)

const observerConfig = {
subtree: true,
Expand Down Expand Up @@ -388,7 +390,7 @@ window.__firefox__.execute(function($) {
*/
const extractOriginFromURLString = (urlString) => {
try {
const url = new URL(urlString, window.location.toString())
const url = new $.URL(urlString, window.location.toString())
return url.origin
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -847,7 +849,7 @@ window.__firefox__.execute(function($) {
* @returns A list of unhidden selectors
*/
const unhideSelectorsMatchingElementsAndTheirParents = (nodes) => {
const selectorsUnHidden = new Set()
const selectorsUnHidden = new $.Set()

for (const nodeRef of nodes) {
const node = nodeRef.deref()
Expand Down Expand Up @@ -881,15 +883,15 @@ window.__firefox__.execute(function($) {
switch (mutation.attributeName) {
case 'src':
if (extractOriginIfNeeded(changedElm)) {
elementsWithURLs.push(new WeakRef(changedElm))
elementsWithURLs.push(new $.WeakRef(changedElm))
}
break
}
} else if (mutation.addedNodes.length > 0) {
for (const node of mutation.addedNodes) {
if (!isElement(node)) { continue }
if (extractOriginIfNeeded(node)) {
elementsWithURLs.push(new WeakRef(node))
elementsWithURLs.push(new $.WeakRef(node))
}
}
}
Expand All @@ -914,7 +916,7 @@ window.__firefox__.execute(function($) {
selectorsPollingIntervalId = undefined
}

const observer = new MutationObserver(onURLMutations)
const observer = new $.MutationObserver(onURLMutations)

const observerConfig = {
subtree: true,
Expand All @@ -936,7 +938,7 @@ window.__firefox__.execute(function($) {

elmWithClassOrId.forEach((node) => {
if (extractOriginIfNeeded(node)) {
possibleAdChildNodes.push(new WeakRef(node))
possibleAdChildNodes.push(new $.WeakRef(node))
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ if (!window.__firefox__) {
return value;
};

/// Secure URL object
$.URL = window.URL;
/// Secure Event object
$.Event = window.Event;
/// Secure ProgressEvent object
$.ProgressEvent = window.ProgressEvent;
/// Secure MutationObserver object
$.MutationObserver = window.MutationObserver;
/// Secure Map object
$.Map = window.Map;
/// Secure Set object
$.Set = window.Set;
/// Secure TypeError object
$.TypeError = window.TypeError;
/// Secure WeakRef object
$.WeakRef = window.WeakRef;
/// Secure WeakMap object
$.WeakMap = window.WeakMap;
/// Secure WeakSet object
$.WeakSet = window.WeakSet;

/*
* Freeze an object and its prototype
*/
Expand Down