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=3337a96ecbf7a8f04c81bf8a56688579c445ceae;hp=55ad050a4c56c37ad39e97aa0de5f8a9b12f128b;hb=8a72caf321663f9549997695af01d89db45fe7d1;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..3337a96e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Soren Stoutner . + * Copyright © 2018-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,9 +20,6 @@ package com.stoutner.privacybrowser.helpers; import android.content.res.AssetManager; -import android.net.Uri; - -import com.stoutner.privacybrowser.activities.MainWebViewActivity; import java.io.BufferedReader; import java.io.IOException; @@ -32,11 +29,51 @@ import java.util.List; import java.util.regex.Pattern; public class BlockListHelper { + // Describe the schema of the string array in each entry of the resource requests array list. + public final static int REQUEST_DISPOSITION = 0; + public final static int REQUEST_URL = 1; + public final static int REQUEST_BLOCKLIST = 2; + public final static int REQUEST_SUBLIST = 3; + public final static int REQUEST_BLOCKLIST_ENTRIES = 4; + public final static int REQUEST_BLOCKLIST_ORIGINAL_ENTRY = 5; + + // The request disposition options. + public final static String REQUEST_DEFAULT = "0"; + public final static String REQUEST_ALLOWED = "1"; + public final static String REQUEST_THIRD_PARTY = "2"; + public final static String REQUEST_BLOCKED = "3"; + + // The whitelists. + public final static String MAIN_WHITELIST = "1"; + public final static String FINAL_WHITELIST = "2"; + public final static String DOMAIN_WHITELIST = "3"; + public final static String DOMAIN_INITIAL_WHITELIST = "4"; + public final static String DOMAIN_FINAL_WHITELIST = "5"; + public final static String THIRD_PARTY_WHITELIST = "6"; + public final static String THIRD_PARTY_DOMAIN_WHITELIST = "7"; + public final static String THIRD_PARTY_DOMAIN_INITIAL_WHITELIST = "8"; + + // The blacklists. + public final static String MAIN_BLACKLIST = "9"; + public final static String INITIAL_BLACKLIST = "10"; + public final static String FINAL_BLACKLIST = "11"; + public final static String DOMAIN_BLACKLIST = "12"; + public final static String DOMAIN_INITIAL_BLACKLIST = "13"; + public final static String DOMAIN_FINAL_BLACKLIST = "14"; + public final static String DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "15"; + public final static String THIRD_PARTY_BLACKLIST = "16"; + public final static String THIRD_PARTY_INITIAL_BLACKLIST = "17"; + public final static String THIRD_PARTY_DOMAIN_BLACKLIST = "18"; + public final static String THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST = "19"; + public final static String THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST = "20"; + public final static String THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "21"; + public final static String REGULAR_EXPRESSION_BLACKLIST = "22"; + public ArrayList> parseBlockList(AssetManager assets, String blockListName) { // 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 +83,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 +122,16 @@ 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 //noinspection StatementWithEmptyBody + if (blockListEntry.contains("$websocket") || blockListEntry.contains("$third-party,websocket") || blockListEntry.contains("$script,websocket")) { // Ignore entries with `websocket`. + // Do nothing. Privacy Browser does not differentiate between websocket requests and other requests and these entries cause a lot of false positives. + + //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,85 +1622,54 @@ public class BlockListHelper { return combinedLists; } - public boolean isBlocked(String currentUrl, String resourceUrl, ArrayList> blockList) { - // Get the block list name. + public String[] checkBlocklist(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList> blockList) { + // Get the blocklist 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. // Main white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.MAIN_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(MAIN_WHITELIST))) { switch (whiteListEntry.length) { case 2: // There is one entry. if (resourceUrl.contains(whiteListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0], whiteListEntry[1]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } break; case 3: // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], - whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; case 4: // There are three entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; } break; } } // Final white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.FINAL_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(FINAL_WHITELIST))) { if (whiteListEntry.length == 2) { // There is one entry. if (resourceUrl.contains(whiteListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0], whiteListEntry[1]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } } else { // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } } @@ -1661,119 +1677,85 @@ public class BlockListHelper { // Only check the domain lists if the current domain is not null (like `about:blank`). if (currentDomain != null) { // Domain white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_WHITELIST))) { switch (whiteListEntry.length) { case 3: // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; case 4: // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; case 5: // There are three entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3], - whiteListEntry[4]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; case 6: // There are four entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) && resourceUrl.contains(whiteListEntry[4])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" + - whiteListEntry[4], whiteListEntry[5]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]}; } break; } } // Domain initial white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_WHITELIST))) { switch (whiteListEntry.length) { case 3: // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; case 4: // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; case 5: // There are three entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3], - whiteListEntry[4]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; } } // Domain final white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_WHITELIST))) { switch (whiteListEntry.length) { case 3: // There is one entry; if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; case 4: // There are two entries; if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; } @@ -1781,111 +1763,79 @@ 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)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_WHITELIST))) { switch (whiteListEntry.length) { case 2: // There is one entry if (resourceUrl.contains(whiteListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0], whiteListEntry[1]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } break; case 3: // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; case 4: // There are three entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; case 5: // There are four entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3], - whiteListEntry[4]}; - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; case 6: // There are five entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) && resourceUrl.contains(whiteListEntry[4])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" + - whiteListEntry[4], whiteListEntry[5]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]}; } break; } } // Third-party domain white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_WHITELIST))) { if (whiteListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } } } // Third-party domain initial white list. - for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_WHITELIST))) { if (whiteListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } } } @@ -1893,123 +1843,84 @@ public class BlockListHelper { // Process the black lists. // Main black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.MAIN_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(MAIN_BLACKLIST))) { switch (blackListEntry.length) { case 2: // There is one entry. if (resourceUrl.contains(blackListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}; } break; case 5: // There are four entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; case 6: // There are five entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) && resourceUrl.contains(blackListEntry[4])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3] + "\n" + - blackListEntry[4], blackListEntry[5]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3] + "\n" + blackListEntry[4], blackListEntry[5]}; } break; } } // Initial black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.INITIAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(INITIAL_BLACKLIST))) { if (blackListEntry.length == 2) { // There is one entry. if (resourceUrl.startsWith(blackListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } else { // There are two entries if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Final black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.FINAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(FINAL_BLACKLIST))) { switch (blackListEntry.length) { case 2: // There is one entry. if (resourceUrl.endsWith(blackListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}; } break; } @@ -2018,271 +1929,193 @@ public class BlockListHelper { // Only check the domain lists if the current domain is not null (like `about:blank`). if (currentDomain != null) { // Domain black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_BLACKLIST))) { switch (blackListEntry.length) { case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; case 5: // There are three entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], - blackListEntry[4]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; } } // Domain initial black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_BLACKLIST))) { // Store the entry in the resource request log. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) { - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], - blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } // Domain final black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_BLACKLIST))) { switch (blackListEntry.length) { case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; } } // Domain regular expression black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) { if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // 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)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_BLACKLIST))) { switch (blackListEntry.length) { case 2: // There is one entry. if (resourceUrl.contains(blackListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; case 5: // There are four entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], - blackListEntry[4]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; } } // Third-party initial black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_INITIAL_BLACKLIST))) { if (blackListEntry.length == 2) { // There is one entry. if (resourceUrl.startsWith(blackListEntry[0])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } else { // There are two entries. if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Third-party domain black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_BLACKLIST))) { if (blackListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } } } // Third-party domain initial black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST))) { switch (blackListEntry.length) { case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + + blackListEntry[2], blackListEntry[3]}; } break; case 5: // There are three entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], - blackListEntry[4]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]}; } break; } } // Third-party regular expression black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST))) { if (Pattern.matches(blackListEntry[0], resourceUrl)) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } // Third-party domain regular expression black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) { if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Regular expression black list. - for (String[] blackListEntry : blockList.get(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(REGULAR_EXPRESSION_BLACKLIST))) { if (Pattern.matches(blackListEntry[0], resourceUrl)) { - // Store the entry in the resource request log. - MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING, - String.valueOf(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]}); - - // blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } - // Not blocked. - return false; + // Return a no match request default. + return new String[] {REQUEST_DEFAULT}; } } \ No newline at end of file