/*
- * Copyright © 2018-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2018-2019,2021-2022 Soren Stoutner <soren@stoutner.com>.
*
- * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
*
- * Privacy Browser is free software: you can redistribute it and/or modify
+ * Privacy Browser Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * Privacy Browser is distributed in the hope that it will be useful,
+ * Privacy Browser Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
+ * along with Privacy Browser Android. If not, see <http://www.gnu.org/licenses/>.
*/
package com.stoutner.privacybrowser.helpers;
// Process the white lists.
// Main white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(MAIN_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(MAIN_WHITELIST))) {
switch (whitelistEntry.length) {
case 2: // There is one entry.
if (resourceUrl.contains(whitelistEntry[0])) {
}
// Final white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(FINAL_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(FINAL_WHITELIST))) {
if (whitelistEntry.length == 2) { // There is one entry.
if (resourceUrl.contains(whitelistEntry[0])) {
// Return a whitelist match request allowed.
// 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(Integer.valueOf(DOMAIN_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(DOMAIN_WHITELIST))) {
switch (whitelistEntry.length) {
case 3: // There is one entry.
if (currentDomain.endsWith(whitelistEntry[0]) && resourceUrl.contains(whitelistEntry[1])) {
}
// Domain initial white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(DOMAIN_INITIAL_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(DOMAIN_INITIAL_WHITELIST))) {
switch (whitelistEntry.length) {
case 3: // There is one entry.
if (currentDomain.endsWith(whitelistEntry[0]) && resourceUrl.startsWith(whitelistEntry[1])) {
}
// Domain final white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(DOMAIN_FINAL_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(DOMAIN_FINAL_WHITELIST))) {
switch (whitelistEntry.length) {
case 3: // There is one entry;
if (currentDomain.endsWith(whitelistEntry[0]) && resourceUrl.endsWith(whitelistEntry[1])) {
// Only check the third-party white lists if this is a third-party request.
if (isThirdPartyRequest) {
// Third-party white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_WHITELIST))) {
switch (whitelistEntry.length) {
case 2: // There is one entry
if (resourceUrl.contains(whitelistEntry[0])) {
}
// Third-party domain white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_DOMAIN_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_DOMAIN_WHITELIST))) {
if (whitelistEntry.length == 3) { // There is one entry.
if (currentDomain.endsWith(whitelistEntry[0]) && resourceUrl.contains(whitelistEntry[1])) {
// Return a whitelist match request allowed.
}
// Third-party domain initial white list.
- for (String[] whitelistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_WHITELIST))) {
+ for (String[] whitelistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_DOMAIN_INITIAL_WHITELIST))) {
if (whitelistEntry.length == 3) { // There is one entry.
if (currentDomain.endsWith(whitelistEntry[0]) && resourceUrl.startsWith(whitelistEntry[1])) {
// Return a whitelist match request allowed.
// Process the black lists.
// Main black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(MAIN_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(MAIN_BLACKLIST))) {
switch (blacklistEntry.length) {
case 2: // There is one entry.
if (resourceUrl.contains(blacklistEntry[0])) {
}
// Initial black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(INITIAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(INITIAL_BLACKLIST))) {
if (blacklistEntry.length == 2) { // There is one entry.
if (resourceUrl.startsWith(blacklistEntry[0])) {
// Return a blacklist match request blocked.
}
// Final black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(FINAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(FINAL_BLACKLIST))) {
switch (blacklistEntry.length) {
case 2: // There is one entry.
if (resourceUrl.endsWith(blacklistEntry[0])) {
// 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(Integer.valueOf(DOMAIN_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(DOMAIN_BLACKLIST))) {
switch (blacklistEntry.length) {
case 3: // There is one entry.
if (currentDomain.endsWith(blacklistEntry[0]) && resourceUrl.contains(blacklistEntry[1])) {
}
// Domain initial black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(DOMAIN_INITIAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(DOMAIN_INITIAL_BLACKLIST))) {
// Store the entry in the resource request log.
if (currentDomain.endsWith(blacklistEntry[0]) && resourceUrl.startsWith(blacklistEntry[1])) {
// Return a blacklist match request blocked.
}
// Domain final black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(DOMAIN_FINAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(DOMAIN_FINAL_BLACKLIST))) {
switch (blacklistEntry.length) {
case 3: // There is one entry.
if (currentDomain.endsWith(blacklistEntry[0]) && resourceUrl.endsWith(blacklistEntry[1])) {
}
// Domain regular expression black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
if (currentDomain.endsWith(blacklistEntry[0]) && Pattern.matches(blacklistEntry[1], resourceUrl)) {
// 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 (isThirdPartyRequest) {
// Third-party black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_BLACKLIST))) {
switch (blacklistEntry.length) {
case 2: // There is one entry.
if (resourceUrl.contains(blacklistEntry[0])) {
}
// Third-party initial black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_INITIAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_INITIAL_BLACKLIST))) {
if (blacklistEntry.length == 2) { // There is one entry.
if (resourceUrl.startsWith(blacklistEntry[0])) {
// Return a blacklist match request blocked.
}
// Third-party domain black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_DOMAIN_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_DOMAIN_BLACKLIST))) {
if (blacklistEntry.length == 3) { // There is one entry.
if (currentDomain.endsWith(blacklistEntry[0]) && resourceUrl.contains(blacklistEntry[1])) {
// Return a blacklist match request blocked.
}
// Third-party domain initial black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST))) {
switch (blacklistEntry.length) {
case 3: // There is one entry.
if (currentDomain.endsWith(blacklistEntry[0]) && resourceUrl.startsWith(blacklistEntry[1])) {
}
// Third-party regular expression black list.
- for (String[] blacklistEntry : blocklist.get(Integer.valueOf(THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST))) {
if (Pattern.matches(blacklistEntry[0], resourceUrl)) {
// 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(Integer.valueOf(THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
if (currentDomain.endsWith(blacklistEntry[0]) && Pattern.matches(blacklistEntry[1], resourceUrl)) {
// 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(Integer.valueOf(REGULAR_EXPRESSION_BLACKLIST))) {
+ for (String[] blacklistEntry : blocklist.get(Integer.parseInt(REGULAR_EXPRESSION_BLACKLIST))) {
if (Pattern.matches(blacklistEntry[0], resourceUrl)) {
// Return a blacklist match request blocked.
return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, REGULAR_EXPRESSION_BLACKLIST, blacklistEntry[0], blacklistEntry[1]};