Fixed: UI integration (#233)

This commit is contained in:
nobody 2021-01-17 09:52:49 +01:00
parent 784dc29316
commit f4be2cbf43
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
5 changed files with 30 additions and 16 deletions

View File

@ -42,8 +42,7 @@ messenger._handleMessageReceived = function (message, sender, sendResponse) {
} }
if (topic === 'domain:fetch-is-allowlisted') { if (topic === 'domain:fetch-is-allowlisted') {
let allowlistRecord = requestAnalyzer.allowlistedDomains[value] || requestAnalyzer.allowlistedDomains[helpers.getWildcard(value)];
let allowlistRecord = requestAnalyzer.allowlistedDomains[value];
sendResponse({'value': Boolean(allowlistRecord)}); sendResponse({'value': Boolean(allowlistRecord)});
return MessageResponse.SYNCHRONOUS; return MessageResponse.SYNCHRONOUS;

View File

@ -29,7 +29,7 @@ var requestAnalyzer = {};
*/ */
requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) { requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
let initiatorDomain, isAllowlisted, sDomain; let initiatorDomain, isAllowlisted, wildcard;
initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true); initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
@ -37,15 +37,8 @@ requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
initiatorDomain = Address.EXAMPLE; initiatorDomain = Address.EXAMPLE;
} }
wildcard = helpers.getWildcard(initiatorDomain);
sDomain = initiatorDomain.split("."); isAllowlisted = requestAnalyzer.allowlistedDomains[initiatorDomain] || requestAnalyzer.allowlistedDomains[wildcard];
if (sDomain.length <= 2) {
isAllowlisted = requestAnalyzer.allowlistedDomains[initiatorDomain];
} else {
sDomain[0] = '*';
sDomain = sDomain.join().replace(/,/g, '.');
isAllowlisted = requestAnalyzer.allowlistedDomains[sDomain];
}
if (isAllowlisted) { if (isAllowlisted) {
return false; return false;

View File

@ -91,8 +91,16 @@ stateManager.removeDomainFromAllowlist = function (domain) {
return new Promise((resolve) => { return new Promise((resolve) => {
let allowlistedDomains = requestAnalyzer.allowlistedDomains; let allowlistedDomains, wildcard;
delete allowlistedDomains[domain];
allowlistedDomains = requestAnalyzer.allowlistedDomains;
wildcard = helpers.getWildcard(domain);
if (allowlistedDomains[domain]) {
delete allowlistedDomains[domain];
} else {
delete allowlistedDomains[wildcard];
}
storageManager.type.set({allowlistedDomains}, resolve); storageManager.type.set({allowlistedDomains}, resolve);
}); });
@ -239,7 +247,6 @@ stateManager._removeIconBadgeFromTab = function (tab) {
}; };
stateManager._domainIsListed = function (domain, listname) { stateManager._domainIsListed = function (domain, listname) {
if (domain !== null) { if (domain !== null) {
let allowlistRecord, isAllowlisted; let allowlistRecord, isAllowlisted;
@ -248,7 +255,7 @@ stateManager._domainIsListed = function (domain, listname) {
allowlistRecord = requestAnalyzer.domainsManipulateDOM[domain]; allowlistRecord = requestAnalyzer.domainsManipulateDOM[domain];
isAllowlisted = Boolean(allowlistRecord); isAllowlisted = Boolean(allowlistRecord);
} else { } else {
allowlistRecord = requestAnalyzer.allowlistedDomains[domain]; allowlistRecord = requestAnalyzer.allowlistedDomains[domain] || requestAnalyzer.allowlistedDomains[helpers.getWildcard(domain)];
isAllowlisted = Boolean(allowlistRecord); isAllowlisted = Boolean(allowlistRecord);
} }

View File

@ -126,6 +126,17 @@ helpers.extractDomainFromUrl = function (url, normalize) {
return extractedDomain; return extractedDomain;
}; };
helpers.getWildcard = function(initiatorDomain) {
let domain = initiatorDomain.split(".");
if (domain.length > 2) {
domain[0] = '*';
domain = domain.join().replace(/,/g, '.');
return domain;
}
};
helpers.extractFilenameFromPath = function (path) { helpers.extractFilenameFromPath = function (path) {
let pathSegments, filename; let pathSegments, filename;

View File

@ -187,6 +187,10 @@ popup._determineDomainAllowlistStatus = function () {
value: popup._domain, value: popup._domain,
}; };
if (popup._domain === null) {
return;
}
chrome.runtime.sendMessage(message, function (response) { chrome.runtime.sendMessage(message, function (response) {
popup._domainIsAllowlisted = response.value; popup._domainIsAllowlisted = response.value;
resolve(); resolve();