package com.stoutner.privacybrowser.helpers;
import android.content.res.AssetManager;
-import android.net.Uri;
import com.stoutner.privacybrowser.activities.MainWebViewActivity;
// Initialize the header list.
List<String[]> headers = new ArrayList<>(); // 0.
- // Initialize the white lists.
+ // Initialize the whitelists.
List<String[]> mainWhiteList = new ArrayList<>(); // 1.
List<String[]> finalWhiteList = new ArrayList<>(); // 2.
List<String[]> domainWhiteList = new ArrayList<>(); // 3.
List<String[]> thirdPartyDomainWhiteList = new ArrayList<>(); // 7.
List<String[]> thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8.
- // Initialize the black lists
+ // Initialize the blacklists
List<String[]> mainBlackList = new ArrayList<>(); // 9.
List<String[]> initialBlackList = new ArrayList<>(); // 10.
List<String[]> finalBlackList = new ArrayList<>(); // 11.
// 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 positivies.
+
+ //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.
return combinedLists;
}
- public boolean isBlocked(String currentUrl, String resourceUrl, ArrayList<List<String[]>> blockList) {
+ public boolean isBlocked(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList<List<String[]>> 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.
}
// 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) {
}
// 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) {