Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isWhitelisted(url, parentUrl, type)
{
// Ignore fragment identifier
var index = url.indexOf("#");
if (index >= 0)
url = url.substring(0, index);
var result = defaultMatcher.matchesAny(url, type || "DOCUMENT", extractHostFromURL(parentUrl || url), false);
return (result instanceof WhitelistFilter ? result : null);
}
if (sender.tab)
{
tabId = sender.tab.id;
frameId = getFrameId(tabId, request.documentUrl);
}
if (isFrameWhitelisted(tabId, frameId, "DOCUMENT"))
{
sendResponse(false);
break;
}
var requestHost = extractHostFromURL(request.url);
var documentHost = extractHostFromURL(request.documentUrl);
var thirdParty = isThirdParty(requestHost, documentHost);
var filter = defaultMatcher.matchesAny(request.url, request.type, documentHost, thirdParty);
if (filter instanceof BlockingFilter)
{
var collapse = filter.collapse;
if (collapse == null)
collapse = (localStorage.hidePlaceholders != "false");
sendResponse(collapse);
}
else
sendResponse(false);
break;
case "get-domain-enabled-state":
// Returns whether this domain is in the exclusion list.
// The page action popup asks us this.
if(sender.tab)
{
sendResponse({enabled: !isWhitelisted(sender.tab.url)});
}
}
sendResponse(selectors);
break;
case "should-collapse":
if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT"))
{
sendResponse(false);
break;
}
var requestHost = extractHostFromURL(msg.url);
var documentHost = extractHostFromFrame(sender.frame);
var thirdParty = isThirdParty(requestHost, documentHost);
var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHost, thirdParty);
if (filter instanceof BlockingFilter)
{
var collapse = filter.collapse;
if (collapse == null)
collapse = Prefs.hidePlaceholders;
sendResponse(collapse);
}
else
sendResponse(false);
break;
case "get-domain-enabled-state":
// Returns whether this domain is in the exclusion list.
// The browser action popup asks us this.
if(sender.page)
{
sendResponse({enabled: !isWhitelisted(sender.page.url)});
return response(true, false);
else
nogeneric = true;
}
}
let match = null;
let wndLocation = frames[0].location;
let docDomain = getHostname(wndLocation);
let [sitekey, sitekeyFrame] = getSitekey(frames);
let thirdParty = isThirdParty(location, docDomain);
let collapse = false;
if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentType))
{
match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty, sitekey, nogeneric);
if (match instanceof BlockingFilter && !this.nonVisualTypes.has(contentType))
collapse = (match.collapse != null ? match.collapse : !Prefs.fastcollapse);
}
addHit(null, contentType, docDomain, thirdParty, location, match);
return response(!match || match instanceof WhitelistFilter, collapse);
},
let [sitekey, sitekeyFrame] = getSitekey(frames);
let nogenericHit = null;
let typeMap = RegExpFilter.typeMap.DOCUMENT;
if (isElemHide)
typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE;
let genericType = (isElemHide ? "GENERICHIDE" : "GENERICBLOCK");
for (let i = 0; i < frames.length; i++)
{
let frame = frames[i];
let wndLocation = frame.location;
let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].location;
let parentDocDomain = getHostname(parentWndLocation);
let match = defaultMatcher.matchesAny(wndLocation, typeMap, parentDocDomain, false, sitekey);
if (match instanceof WhitelistFilter)
{
let whitelistType = (match.contentType & RegExpFilter.typeMap.DOCUMENT) ? "DOCUMENT" : "ELEMHIDE";
return [i, whitelistType, parentDocDomain, false, wndLocation, match];
}
if (!nogenericHit)
{
match = defaultMatcher.matchesAny(wndLocation,
RegExpFilter.typeMap[genericType], parentDocDomain, false, sitekey);
if (match instanceof WhitelistFilter)
nogenericHit = [i, genericType, parentDocDomain, false, wndLocation, match];
}
if (frame == sitekeyFrame)
[sitekey, sitekeyFrame] = getSitekey(frames.slice(i + 1));
function checkPotentialPopup(tabId, popup)
{
let urlObj = new URL(popup.url || "about:blank");
let urlString = stringifyURL(urlObj);
let documentHost = extractHostFromFrame(popup.sourceFrame);
let thirdParty = isThirdParty(urlObj, documentHost);
let specificOnly = !!checkWhitelisted(
popup.sourcePage, popup.sourceFrame,
RegExpFilter.typeMap.GENERICBLOCK
);
let filter = defaultMatcher.matchesAny(
urlString, RegExpFilter.typeMap.POPUP,
documentHost, thirdParty, null, specificOnly
);
if (filter instanceof BlockingFilter)
chrome.tabs.remove(tabId);
logRequest(
popup.sourcePage, urlString, "POPUP",
documentHost, thirdParty, null,
specificOnly, filter
);
}
{
let frame = frames[i];
let wndLocation = frame.location;
let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].location;
let parentDocDomain = getHostname(parentWndLocation);
let match = defaultMatcher.matchesAny(wndLocation, typeMap, parentDocDomain, false, sitekey);
if (match instanceof WhitelistFilter)
{
let whitelistType = (match.contentType & RegExpFilter.typeMap.DOCUMENT) ? "DOCUMENT" : "ELEMHIDE";
return [i, whitelistType, parentDocDomain, false, wndLocation, match];
}
if (!nogenericHit)
{
match = defaultMatcher.matchesAny(wndLocation,
RegExpFilter.typeMap[genericType], parentDocDomain, false, sitekey);
if (match instanceof WhitelistFilter)
nogenericHit = [i, genericType, parentDocDomain, false, wndLocation, match];
}
if (frame == sitekeyFrame)
[sitekey, sitekeyFrame] = getSitekey(frames.slice(i + 1));
}
return nogenericHit;
},