X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FBlockListHelper.java;h=619537a989e3c71afd71ebeb90bf70e9e90f833c;hp=55ad050a4c56c37ad39e97aa0de5f8a9b12f128b;hb=69b0fea4c49422f5e3c377994c4cf249bdc5a434;hpb=012e5595c82d6e8d0b8a46f1ef18a02a56341182 diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java index 55ad050a..619537a9 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java @@ -36,7 +36,7 @@ public class BlockListHelper { // Initialize the header list. List headers = new ArrayList<>(); // 0. - // Initialize the white lists. + // Initialize the whitelists. List mainWhiteList = new ArrayList<>(); // 1. List finalWhiteList = new ArrayList<>(); // 2. List domainWhiteList = new ArrayList<>(); // 3. @@ -46,7 +46,7 @@ public class BlockListHelper { List thirdPartyDomainWhiteList = new ArrayList<>(); // 7. List thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8. - // Initialize the black lists + // Initialize the blacklists List mainBlackList = new ArrayList<>(); // 9. List initialBlackList = new ArrayList<>(); // 10. List finalBlackList = new ArrayList<>(); // 11. @@ -85,6 +85,11 @@ public class BlockListHelper { // Do nothing. Privacy Browser does not currently use these entries. //Log.i("BlockLists", "Not added: " + blockListEntry); + } else //noinspection StatementWithEmptyBody + if (blockListEntry.contains("$csp=script-src")) { // Ignore entries that contain `$csp=script-src`. + // Do nothing. It is uncertain what this directive is even supposed to mean, and it is blocking entire websites like androidcentral.com. https://redmine.stoutner.com/issues/306. + + //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry); } else if (blockListEntry.startsWith("!")) { // Comment entries. if (blockListEntry.startsWith("! Version:")) { // Get the list version number. @@ -1575,24 +1580,14 @@ public class BlockListHelper { return combinedLists; } - public boolean isBlocked(String currentUrl, String resourceUrl, ArrayList> blockList) { + public boolean isBlocked(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList> blockList) { // Get the block list name. String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0]; - // Get the current domain. - Uri currentUri = Uri.parse(currentUrl); - String currentDomain = currentUri.getHost(); - - // Get the resource domain. - Uri resourceUri = Uri.parse(resourceUrl); - String resourceDomain = resourceUri.getHost(); - - // Initialize the third-party request tracker. - boolean thirdPartyRequest = false; - - // If one of the domains is `about:blank` it will throw a null object reference on the string comparison. - if ((currentDomain != null) && (resourceDomain != null)) { - thirdPartyRequest = !resourceDomain.equals(currentDomain); + // Assert that currentDomain != null only if this is a third party request. Apparently, lint can't tell that this isn't redundant. + //noinspection RedundantIfStatement + if (isThirdPartyRequest) { + assert currentDomain != null; } // Process the white lists. @@ -1781,7 +1776,7 @@ public class BlockListHelper { } // Only check the third-party white lists if this is a third-party request. - if (thirdPartyRequest) { + if (isThirdPartyRequest) { // Third-party white list. for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_WHITELIST)) { switch (whiteListEntry.length) { @@ -2110,7 +2105,7 @@ public class BlockListHelper { } // Only check the third-party black lists if this is a third-party request. - if (thirdPartyRequest) { + if (isThirdPartyRequest) { // Third-party black list. for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_BLACKLIST)) { switch (blackListEntry.length) {