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') {
let allowlistRecord = requestAnalyzer.allowlistedDomains[value];
let allowlistRecord = requestAnalyzer.allowlistedDomains[value] || requestAnalyzer.allowlistedDomains[helpers.getWildcard(value)];
sendResponse({'value': Boolean(allowlistRecord)});
return MessageResponse.SYNCHRONOUS;

View File

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

View File

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

View File

@ -126,6 +126,17 @@ helpers.extractDomainFromUrl = function (url, normalize) {
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) {
let pathSegments, filename;

View File

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