2 * Copyright © 2018-2019 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.helpers;
22 import android.content.res.AssetManager;
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.regex.Pattern;
31 public class BlockListHelper {
32 // Describe the schema of the string array in each entry of the resource requests array list.
33 public final static int REQUEST_DISPOSITION = 0;
34 public final static int REQUEST_URL = 1;
35 public final static int REQUEST_BLOCKLIST = 2;
36 public final static int REQUEST_SUBLIST = 3;
37 public final static int REQUEST_BLOCKLIST_ENTRIES = 4;
38 public final static int REQUEST_BLOCKLIST_ORIGINAL_ENTRY = 5;
40 // The request disposition options.
41 public final static String REQUEST_DEFAULT = "0";
42 public final static String REQUEST_ALLOWED = "1";
43 public final static String REQUEST_THIRD_PARTY = "2";
44 public final static String REQUEST_BLOCKED = "3";
47 public final static String MAIN_WHITELIST = "1";
48 public final static String FINAL_WHITELIST = "2";
49 public final static String DOMAIN_WHITELIST = "3";
50 public final static String DOMAIN_INITIAL_WHITELIST = "4";
51 public final static String DOMAIN_FINAL_WHITELIST = "5";
52 public final static String THIRD_PARTY_WHITELIST = "6";
53 public final static String THIRD_PARTY_DOMAIN_WHITELIST = "7";
54 public final static String THIRD_PARTY_DOMAIN_INITIAL_WHITELIST = "8";
57 public final static String MAIN_BLACKLIST = "9";
58 public final static String INITIAL_BLACKLIST = "10";
59 public final static String FINAL_BLACKLIST = "11";
60 public final static String DOMAIN_BLACKLIST = "12";
61 public final static String DOMAIN_INITIAL_BLACKLIST = "13";
62 public final static String DOMAIN_FINAL_BLACKLIST = "14";
63 public final static String DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "15";
64 public final static String THIRD_PARTY_BLACKLIST = "16";
65 public final static String THIRD_PARTY_INITIAL_BLACKLIST = "17";
66 public final static String THIRD_PARTY_DOMAIN_BLACKLIST = "18";
67 public final static String THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST = "19";
68 public final static String THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST = "20";
69 public final static String THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "21";
70 public final static String REGULAR_EXPRESSION_BLACKLIST = "22";
72 public ArrayList<List<String[]>> parseBlockList(AssetManager assets, String blockListName) {
73 // Initialize the header list.
74 List<String[]> headers = new ArrayList<>(); // 0.
76 // Initialize the whitelists.
77 List<String[]> mainWhiteList = new ArrayList<>(); // 1.
78 List<String[]> finalWhiteList = new ArrayList<>(); // 2.
79 List<String[]> domainWhiteList = new ArrayList<>(); // 3.
80 List<String[]> domainInitialWhiteList = new ArrayList<>(); // 4.
81 List<String[]> domainFinalWhiteList = new ArrayList<>(); // 5.
82 List<String[]> thirdPartyWhiteList = new ArrayList<>(); // 6.
83 List<String[]> thirdPartyDomainWhiteList = new ArrayList<>(); // 7.
84 List<String[]> thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8.
86 // Initialize the blacklists
87 List<String[]> mainBlackList = new ArrayList<>(); // 9.
88 List<String[]> initialBlackList = new ArrayList<>(); // 10.
89 List<String[]> finalBlackList = new ArrayList<>(); // 11.
90 List<String[]> domainBlackList = new ArrayList<>(); // 12.
91 List<String[]> domainInitialBlackList = new ArrayList<>(); // 13.
92 List<String[]> domainFinalBlackList = new ArrayList<>(); // 14.
93 List<String[]> domainRegularExpressionBlackList = new ArrayList<>(); // 15.
94 List<String[]> thirdPartyBlackList = new ArrayList<>(); // 16.
95 List<String[]> thirdPartyInitialBlackList = new ArrayList<>(); // 17.
96 List<String[]> thirdPartyDomainBlackList = new ArrayList<>(); // 18.
97 List<String[]> thirdPartyDomainInitialBlackList = new ArrayList<>(); // 19.
98 List<String[]> regularExpressionBlackList = new ArrayList<>(); // 20.
99 List<String[]> thirdPartyRegularExpressionBlackList = new ArrayList<>(); // 21.
100 List<String[]> thirdPartyDomainRegularExpressionBlackList = new ArrayList<>(); // 22.
103 // Populate the block lists. The `try` is required by `InputStreamReader`.
105 // Load the block list into a `BufferedReader`.
106 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assets.open(blockListName)));
108 // Create a string for storing the block list entries.
109 String blockListEntry;
111 // Parse the block list.
112 while ((blockListEntry = bufferedReader.readLine()) != null) {
113 // Store the original block list entry.
114 String originalBlockListEntry = blockListEntry;
116 // Remove any `^` from the block list entry. Privacy Browser does not process them in the interest of efficiency.
117 blockListEntry = blockListEntry.replace("^", "");
119 //noinspection StatementWithEmptyBody
120 if (blockListEntry.contains("##") || blockListEntry.contains("#?#") || blockListEntry.contains("#@#") || blockListEntry.startsWith("[")) {
121 // Entries that contain `##`, `#?#`, and `#@#` are for hiding elements in the main page's HTML. Entries that start with `[` describe the AdBlock compatibility level.
122 // Do nothing. Privacy Browser does not currently use these entries.
124 //Log.i("BlockLists", "Not added: " + blockListEntry);
125 } else //noinspection StatementWithEmptyBody
126 if (blockListEntry.contains("$csp=script-src")) { // Ignore entries that contain `$csp=script-src`.
127 // 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.
129 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
130 } else //noinspection StatementWithEmptyBody
131 if (blockListEntry.contains("$websocket") || blockListEntry.contains("$third-party,websocket") || blockListEntry.contains("$script,websocket")) { // Ignore entries with `websocket`.
132 // Do nothing. Privacy Browser does not differentiate between websocket requests and other requests and these entries cause a lot of false positives.
134 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
135 } else if (blockListEntry.startsWith("!")) { // Comment entries.
136 if (blockListEntry.startsWith("! Version:")) {
137 // Get the list version number.
138 String[] listVersion = {blockListEntry.substring(11)};
140 // Store the list version in the headers list.
141 headers.add(listVersion);
144 if (blockListEntry.startsWith("! Title:")) {
145 // Get the list title.
146 String[] listTitle = {blockListEntry.substring(9)};
148 // Store the list title in the headers list.
149 headers.add(listTitle);
152 //Log.i("BlockLists", "Not added: " + blockListEntry);
153 } else if (blockListEntry.startsWith("@@")) { // Entries that begin with `@@` are whitelists.
155 blockListEntry = blockListEntry.substring(2);
157 // Strip out any initial `||`. Privacy Browser doesn't differentiate items that only match against the end of the domain name.
158 if (blockListEntry.startsWith("||")) {
159 blockListEntry = blockListEntry.substring(2);
162 if (blockListEntry.contains("$")) { // Filter entries.
163 //noinspection StatementWithEmptyBody
164 if (blockListEntry.contains("~third-party")) { // Ignore entries that contain `~third-party`.
167 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
168 } else if (blockListEntry.contains("third-party")) { // Third-party white list entries.
169 if (blockListEntry.contains("domain=")) { // Third-party domain white list entries.
171 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
172 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
173 String domains = filters.substring(filters.indexOf("domain=") + 7);
175 //noinspection StatementWithEmptyBody
176 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
179 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
180 } else if (blockListEntry.startsWith("|")) { // Third-party domain initial white list entries.
181 // Strip out the initial `|`.
182 entry = entry.substring(1);
184 //noinspection StatementWithEmptyBody
185 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
186 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
188 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
189 } else { // Process third-party domain initial white list entries.
190 // Process each domain.
192 // Create a string to keep track of the current domain.
195 if (domains.contains("|")) { // There is more than one domain in the list.
196 // Get the first domain from the list.
197 domain = domains.substring(0, domains.indexOf("|"));
199 // Remove the first domain from the list.
200 domains = domains.substring(domains.indexOf("|") + 1);
201 } else { // There is only one domain in the list.
205 if (entry.contains("*")) { // Process a third-party domain initial white list double entry.
206 // Get the index of the wildcard.
207 int wildcardIndex = entry.indexOf("*");
209 // Split the entry into components.
210 String firstEntry = entry.substring(0, wildcardIndex);
211 String secondEntry = entry.substring(wildcardIndex + 1);
213 // Create an entry string array.
214 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
216 // Add the entry to the white list.
217 thirdPartyDomainInitialWhiteList.add(domainDoubleEntry);
219 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + firstEntry + " , " + secondEntry +
220 // " - " + originalBlockListEntry);
221 } else { // Process a third-party domain initial white list single entry.
222 // Create a domain entry string array.
223 String[] domainEntry = {domain, entry, originalBlockListEntry};
225 // Add the entry to the third party domain initial white list.
226 thirdPartyDomainInitialWhiteList.add(domainEntry);
228 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
230 } while (domains.contains("|"));
232 } else { // Third-party domain entries.
233 // Process each domain.
235 // Create a string to keep track of the current domain.
238 if (domains.contains("|")) { // three is more than one domain in the list.
239 // Get the first domain from the list.
240 domain = domains.substring(0, domains.indexOf("|"));
242 // Remove the first domain from the list.
243 domains = domains.substring(domains.indexOf("|") + 1);
244 } else { // There is only one domain in the list.
248 // Remove any trailing `*` from the entry.
249 if (entry.endsWith("*")) {
250 entry = entry.substring(0, entry.length() - 1);
253 if (entry.contains("*")) { // Process a third-party domain double entry.
254 // Get the index of the wildcard.
255 int wildcardIndex = entry.indexOf("*");
257 // Split the entry into components.
258 String firstEntry = entry.substring(0, wildcardIndex);
259 String secondEntry = entry.substring(wildcardIndex + 1);
261 // Create an entry string array.
262 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
264 // Add the entry to the white list.
265 thirdPartyDomainWhiteList.add(domainDoubleEntry);
267 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
268 // originalBlockListEntry);
269 } else { // Process a third-party domain single entry.
270 // Create an entry string array.
271 String[] domainEntry = {domain, entry, originalBlockListEntry};
273 // Add the entry to the white list.
274 thirdPartyDomainWhiteList.add(domainEntry);
276 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
278 } while (domains.contains("|"));
280 } else { // Process third-party white list entries.
282 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
284 if (entry.contains("*")) { // There are two or more entries.
285 // Get the index of the wildcard.
286 int wildcardIndex = entry.indexOf("*");
288 // Split the entry into components.
289 String firstEntry = entry.substring(0, wildcardIndex);
290 String secondEntry = entry.substring(wildcardIndex + 1);
292 if (secondEntry.contains("*")) { // There are three or more entries.
293 // Get the index of the wildcard.
294 int secondWildcardIndex = secondEntry.indexOf("*");
296 // Split the entry into components.
297 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
298 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
300 if (thirdEntry.contains("*")) { // There are four or more entries.
301 // Get the index of the wildcard.
302 int thirdWildcardIndex = thirdEntry.indexOf("*");
304 // Split the entry into components.
305 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
306 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
308 if (fourthEntry.contains("*")) { // Process a third-party white list quintuple entry.
309 // Get the index of the wildcard.
310 int fourthWildcardIndex = fourthEntry.indexOf("*");
312 // Split the entry into components.
313 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
314 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
316 // Create an entry string array.
317 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
319 // Add the entry to the white list.
320 thirdPartyWhiteList.add(quintupleEntry);
322 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
323 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
324 } else { // Process a third-party white list quadruple entry.
325 // Create an entry string array.
326 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
328 // Add the entry to the white list.
329 thirdPartyWhiteList.add(quadrupleEntry);
331 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
332 // fourthEntry + " - " + originalBlockListEntry);
334 } else { // Process a third-party white list triple entry.
335 // Create an entry string array.
336 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
338 // Add the entry to the white list.
339 thirdPartyWhiteList.add(tripleEntry);
341 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
342 // originalBlockListEntry);
344 } else { // Process a third-party white list double entry.
345 // Create an entry string array.
346 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
348 // Add the entry to the white list.
349 thirdPartyWhiteList.add(doubleEntry);
351 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
353 } else { // Process a third-party white list single entry.
354 // Create an entry string array.
355 String[] singleEntry = {entry, originalBlockListEntry};
357 // Add the entry to the white list.
358 thirdPartyWhiteList.add(singleEntry);
360 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + entry + " - " + originalBlockListEntry);
363 } else if (blockListEntry.contains("domain=")) { // Process domain white list entries.
365 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
366 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
367 String domains = filters.substring(filters.indexOf("domain=") + 7);
369 if (entry.startsWith("|")) { // Initial domain white list entries.
370 // Strip the initial `|`.
371 entry = entry.substring(1);
373 //noinspection StatementWithEmptyBody
374 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
375 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
377 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
378 } else { // Initial domain white list entry.
379 // Process each domain.
381 // Create a string to keep track of the current domain.
384 if (domains.contains("|")) { // There is more than one domain in the list.
385 // Get the first domain from the list.
386 domain = domains.substring(0, domains.indexOf("|"));
388 // Remove the first domain from the list.
389 domains = domains.substring(domains.indexOf("|") + 1);
390 } else { // There is only one domain in the list.
394 if (entry.contains("*")) { // There are two or more entries.
395 // Get the index of the wildcard.
396 int wildcardIndex = entry.indexOf("*");
398 // Split the entry into components.
399 String firstEntry = entry.substring(0, wildcardIndex);
400 String secondEntry = entry.substring(wildcardIndex + 1);
402 if (secondEntry.contains("*")) { // Process a domain initial triple entry.
403 // Get the index of the wildcard.
404 int secondWildcardIndex = secondEntry.indexOf("*");
406 // Split the entry into components.
407 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
408 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
410 // Create an entry string array.
411 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
413 // Add the entry to the white list.
414 domainInitialWhiteList.add(domainTripleEntry);
416 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
417 // thirdEntry + " - " + originalBlockListEntry);
418 } else { // Process a domain initial double entry.
419 // Create an entry string array.
420 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
422 // Add the entry to the white list.
423 domainInitialWhiteList.add(domainDoubleEntry);
425 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
426 // originalBlockListEntry);
428 } else { // Process a domain initial single entry.
429 // Create an entry string array.
430 String[] domainEntry = {domain, entry, originalBlockListEntry};
432 // Add the entry to the white list.
433 domainInitialWhiteList.add(domainEntry);
435 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + entry + " - " + originalBlockListEntry);
437 } while (domains.contains("|"));
439 } else if (entry.endsWith("|")) { // Final domain white list entries.
440 // Strip the `|` from the end of the entry.
441 entry = entry.substring(0, entry.length() - 1);
443 // Process each domain.
445 // Create a string to keep track of the current domain.
448 if (domains.contains("|")) { // There is more than one domain in the list.
449 // Get the first domain from the list.
450 domain = domains.substring(0, domains.indexOf("|"));
452 // Remove the first domain from the list.
453 domains = domains.substring(domains.indexOf("|") + 1);
454 } else { // There is only one domain in the list.
458 if (entry.contains("*")) { // Process a domain final white list double entry.
459 // Get the index of the wildcard.
460 int wildcardIndex = entry.indexOf("*");
462 // Split the entry into components.
463 String firstEntry = entry.substring(0, wildcardIndex);
464 String secondEntry = entry.substring(wildcardIndex + 1);
466 // Create an entry string array.
467 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
469 // Add the entry to the white list.
470 domainFinalWhiteList.add(domainDoubleEntry);
472 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
473 // originalBlockListEntry);
474 } else { // Process a domain final white list single entry.
475 // create an entry string array.
476 String[] domainEntry = {domain, entry, originalBlockListEntry};
478 // Add the entry to the white list.
479 domainFinalWhiteList.add(domainEntry);
481 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
483 } while (domains.contains("|"));
485 } else { // Standard domain white list entries with filters.
486 //noinspection StatementWithEmptyBody
487 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
490 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
492 // Process each domain.
494 // Create a string to keep track of the current domain.
497 if (domains.contains("|")) { // There is more than one domain in the list.
498 // Get the first domain from the list.
499 domain = domains.substring(0, domains.indexOf("|"));
501 // Remove the first domain from the list.
502 domains = domains.substring(domains.indexOf("|") + 1);
503 } else { // There is only one domain in the list.
507 if (entry.contains("*")) { // There are two or more entries.
508 // Get the index of the wildcard.
509 int wildcardIndex = entry.indexOf("*");
511 // Split the entry into components.
512 String firstEntry = entry.substring(0, wildcardIndex);
513 String secondEntry = entry.substring(wildcardIndex + 1);
515 if (secondEntry.contains("*")) { // There are three or more entries.
516 // Get the index of the wildcard.
517 int secondWildcardIndex = secondEntry.indexOf("*");
519 // Split the entry into components.
520 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
521 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
523 if (thirdEntry.contains("*")) { // Process a domain white list quadruple entry.
524 // Get the index of the wildcard.
525 int thirdWildcardIndex = thirdEntry.indexOf("*");
527 // Split the entry into components.
528 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
529 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
531 // Create an entry string array.
532 String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
534 // Add the entry to the white list.
535 domainWhiteList.add(domainQuadrupleEntry);
537 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
538 // realThirdEntry + " , " + fourthEntry + " - " + originalBlockListEntry);
539 } else { // Process a domain white list triple entry.
540 // Create an entry string array.
541 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
543 // Add the entry to the white list.
544 domainWhiteList.add(domainTripleEntry);
546 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
547 // thirdEntry + " - " + originalBlockListEntry);
549 } else { // Process a domain white list double entry.
550 // Create an entry string array.
551 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
553 // Add the entry to the white list.
554 domainWhiteList.add(domainDoubleEntry);
556 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
557 // originalBlockListEntry);
559 } else { // Process a domain white list single entry.
560 // Create an entry string array.
561 String[] domainEntry = {domain, entry, originalBlockListEntry};
563 // Add the entry to the white list.
564 domainWhiteList.add(domainEntry);
566 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + entry + " - " + originalBlockListEntry);
568 } while (domains.contains("|"));
571 } // Ignore all other filter entries.
572 } else if (blockListEntry.endsWith("|")) { // Final white list entries.
573 // Remove the final `|` from the entry.
574 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
576 if (entry.contains("*")) { // Process a final white list double entry
577 // Get the index of the wildcard.
578 int wildcardIndex = entry.indexOf("*");
580 // split the entry into components.
581 String firstEntry = entry.substring(0, wildcardIndex);
582 String secondEntry = entry.substring(wildcardIndex + 1);
584 // Create an entry string array.
585 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
587 // Add the entry to the white list.
588 finalWhiteList.add(doubleEntry);
590 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
591 } else { // Process a final white list single entry.
592 // Create an entry string array.
593 String[] singleEntry = {entry, originalBlockListEntry};
595 // Add the entry to the white list.
596 finalWhiteList.add(singleEntry);
598 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + entry + " - " + originalBlockListEntry);
600 } else { // Main white list entries.
601 if (blockListEntry.contains("*")) { // There are two or more entries.
602 // Get the index of the wildcard.
603 int wildcardIndex = blockListEntry.indexOf("*");
605 // Split the entry into components.
606 String firstEntry = blockListEntry.substring(0, wildcardIndex);
607 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
609 if (secondEntry.contains("*")) { // Process a main white list triple entry.
610 // Get the index of the wildcard.
611 int secondWildcardIndex = secondEntry.indexOf("*");
613 // Split the entry into components.
614 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
615 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
617 // Create an entry string array.
618 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
620 // Add the entry to the white list.
621 mainWhiteList.add(tripleEntry);
623 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
624 } else { // Process a main white list double entry.
625 // Create an entry string array.
626 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
628 // Add the entry to the white list.
629 mainWhiteList.add(doubleEntry);
631 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
633 } else { // Process a main white list single entry.
634 // Create an entry string array.
635 String[] singleEntry = {blockListEntry, originalBlockListEntry};
637 // Add the entry to the white list.
638 mainWhiteList.add(singleEntry);
640 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - " + originalBlockListEntry);
643 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
644 // Strip out the final "|"
645 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
647 // Strip out any initial `||`. They are redundant in this case because the block list entry is being matched against the end of the URL.
648 if (entry.startsWith("||")) {
649 entry = entry.substring(2);
652 if (entry.contains("*")) { // Process a final black list double entry.
653 // Get the index of the wildcard.
654 int wildcardIndex = entry.indexOf("*");
656 // Split the entry into components.
657 String firstEntry = entry.substring(0, wildcardIndex);
658 String secondEntry = entry.substring(wildcardIndex + 1);
660 // Create an entry string array.
661 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
663 // Add the entry to the black list.
664 finalBlackList.add(doubleEntry);
666 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
667 } else { // Process a final black list single entry.
668 // create an entry string array.
669 String[] singleEntry = {entry, originalBlockListEntry};
671 // Add the entry to the black list.
672 finalBlackList.add(singleEntry);
674 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
676 } else if (blockListEntry.contains("$")) { // Entries with filter options.
677 // Strip out any initial `||`. These will be treated like any other entry.
678 if (blockListEntry.startsWith("||")) {
679 blockListEntry = blockListEntry.substring(2);
682 if (blockListEntry.contains("third-party")) { // Third-party entries.
683 //noinspection StatementWithEmptyBody
684 if (blockListEntry.contains("~third-party")) { // Third-party filter white list entries.
685 // Do not process these white list entries. They are designed to combine with block filters that Privacy Browser doesn't use, like `subdocument` and `xmlhttprequest`.
687 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
688 } else if (blockListEntry.contains("domain=")) { // Third-party domain entries.
689 if (blockListEntry.startsWith("|")) { // Third-party domain initial entries.
690 // Strip the initial `|`.
691 blockListEntry = blockListEntry.substring(1);
694 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
695 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
696 String domains = filters.substring(filters.indexOf("domain=") + 7);
698 //noinspection StatementWithEmptyBody
699 if (entry.equals("http:") || entry.equals("https:") || entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
700 // Do nothing. These entries will almost entirely disable the website.
701 // Often the original entry blocks filter options like `$script`, which Privacy Browser does not differentiate.
703 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
704 } else { // Third-party domain initial entries.
705 // Process each domain.
707 // Create a string to keep track of the current domain.
710 if (domains.contains("|")) { // There is more than one domain in the list.
711 // Get the first domain from the list.
712 domain = domains.substring(0, domains.indexOf("|"));
714 // Remove the first domain from the list.
715 domains = domains.substring(domains.indexOf("|") + 1);
716 } else { // There is only one domain in the list.
720 if (entry.contains("*")) { // Three are two or more entries.
721 // Get the index of the wildcard.
722 int wildcardIndex = entry.indexOf("*");
724 // Split the entry into components.
725 String firstEntry = entry.substring(0, wildcardIndex);
726 String secondEntry = entry.substring(wildcardIndex + 1);
728 if (secondEntry.contains("*")) { // Process a third-party domain initial black list triple entry.
729 // Get the index of the wildcard.
730 int secondWildcardIndex = secondEntry.indexOf("*");
732 // Split the entry into components.
733 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
734 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
736 // Create an entry string array.
737 String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
739 // Add the entry to the black list.
740 thirdPartyDomainInitialBlackList.add(tripleDomainEntry);
742 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry +
743 // " , " + thirdEntry + " - " + originalBlockListEntry);
744 } else { // Process a third-party domain initial black list double entry.
745 // Create an entry string array.
746 String[] doubleDomainEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
748 // Add the entry to the black list.
749 thirdPartyDomainInitialBlackList.add(doubleDomainEntry);
751 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + secondEntry +
752 // " - " + originalBlockListEntry);
754 } else { // Process a third-party domain initial black list single entry.
755 // Create an entry string array.
756 String[] singleEntry = {domain, entry, originalBlockListEntry};
758 // Add the entry to the black list.
759 thirdPartyDomainInitialBlackList.add(singleEntry);
761 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
763 } while (domains.contains("|"));
765 } else if (blockListEntry.contains("\\")) { // Process a third-party domain black list regular expression.
766 // Parse the entry. At least one regular expression in this entry contains `$`, so the parser uses `/$`.
767 String entry = blockListEntry.substring(0, blockListEntry.indexOf("/$") + 1);
768 String filters = blockListEntry.substring(blockListEntry.indexOf("/$") + 2);
769 String domains = filters.substring(filters.indexOf("domain=") + 7);
771 // Process each domain.
773 // Create a string to keep track of the current domain.
776 if (domains.contains("|")) { // There is more than one domain in the list.
777 // Get the first domain from the list.
778 domain = domains.substring(0, domains.indexOf("|"));
780 // Remove the first domain from the list.
781 domains = domains.substring(domains.indexOf("|") + 1);
782 } else { // There is only one domain in the list.
786 // Create an entry string array.
787 String[] domainEntry = {domain, entry, originalBlockListEntry};
789 // Add the entry to the black list.
790 thirdPartyDomainRegularExpressionBlackList.add(domainEntry);
792 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
793 } while (domains.contains("|"));
794 } else { // Third-party domain entries.
796 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
797 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
798 String domains = filters.substring(filters.indexOf("domain=") + 7);
800 // Strip any trailing "*" from the entry.
801 if (entry.endsWith("*")) {
802 entry = entry.substring(0, entry.length() - 1);
805 // Track if any third-party white list filters are applied.
806 boolean whiteListDomain = false;
808 // Process each domain.
810 // Create a string to keep track of the current domain.
813 if (domains.contains("|")) { // There is more than one domain in the list.
814 // Get the first domain from the list.
815 domain = domains.substring(0, domains.indexOf("|"));
817 // Remove the first domain from the list.
818 domains = domains.substring(domains.indexOf("|") + 1);
819 } else { // The is only one domain in the list.
823 // Differentiate between block list domains and white list domains.
824 if (domain.startsWith("~")) { // White list third-party domain entry.
825 // Strip the initial `~`.
826 domain = domain.substring(1);
828 // Set the white list domain flag.
829 whiteListDomain = true;
831 if (entry.contains("*")) { // Process a third-party domain white list double entry.
832 // Get the index of the wildcard.
833 int wildcardIndex = entry.indexOf("*");
835 // Split the entry into components.
836 String firstEntry = entry.substring(0, wildcardIndex);
837 String secondEntry = entry.substring(wildcardIndex + 1);
839 // Create an entry string array.
840 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
842 // Add the entry to the white list.
843 thirdPartyDomainWhiteList.add(domainDoubleEntry);
845 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
846 // originalBlockListEntry);
847 } else { // Process a third-party domain white list single entry.
848 // Create an entry string array.
849 String[] domainEntry = {domain, entry, originalBlockListEntry};
851 // Add the entry to the white list.
852 thirdPartyDomainWhiteList.add(domainEntry);
854 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
856 } else { // Third-party domain black list entries.
857 if (entry.contains("*")) { // Process a third-party domain black list double entry.
858 // Get the index of the wildcard.
859 int wildcardIndex = entry.indexOf("*");
861 // Split the entry into components.
862 String firstEntry = entry.substring(0, wildcardIndex);
863 String secondEntry = entry.substring(wildcardIndex + 1);
865 // Create an entry string array.
866 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
868 // Add the entry to the black list
869 thirdPartyDomainBlackList.add(domainDoubleEntry);
871 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
872 // originalBlockListEntry);
873 } else { // Process a third-party domain black list single entry.
874 // Create an entry string array.
875 String[] domainEntry = {domain, entry, originalBlockListEntry};
877 // Add the entry to the black list.
878 thirdPartyDomainBlackList.add(domainEntry);
880 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain block list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
883 } while (domains.contains("|"));
885 // Add a third-party black list entry if a white list domain was processed.
886 if (whiteListDomain) {
887 if (entry.contains("*")) { // Process a third-party black list double entry.
888 // Get the index of the wildcard.
889 int wildcardIndex = entry.indexOf("*");
891 // Split the entry into components.
892 String firstEntry = entry.substring(0, wildcardIndex);
893 String secondEntry = entry.substring(wildcardIndex + 1);
895 // Create an entry string array.
896 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
898 // Add the entry to the black list.
899 thirdPartyBlackList.add(doubleEntry);
901 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
902 } else { // Process a third-party black list single entry.
903 // Create an entry string array.
904 String[] singleEntry = {entry, originalBlockListEntry};
906 // Add an entry to the black list.
907 thirdPartyBlackList.add(singleEntry);
909 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + entry + " - " + originalBlockListEntry);
913 } else if (blockListEntry.startsWith("|")) { // Third-party initial black list entries.
914 // Strip the initial `|`.
915 blockListEntry = blockListEntry.substring(1);
918 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
920 if (entry.contains("*")) { // Process a third-party initial black list double entry.
921 // Get the index of the wildcard.
922 int wildcardIndex = entry.indexOf("*");
924 // Split the entry into components.
925 String firstEntry = entry.substring(0, wildcardIndex);
926 String secondEntry = entry.substring(wildcardIndex + 1);
928 // Create an entry string array.
929 String[] thirdPartyDoubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
931 // Add the entry to the black list.
932 thirdPartyInitialBlackList.add(thirdPartyDoubleEntry);
934 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
935 } else { // Process a third-party initial black list single entry.
936 // Create an entry string array.
937 String[] singleEntry = {entry, originalBlockListEntry};
939 // Add the entry to the black list.
940 thirdPartyInitialBlackList.add(singleEntry);
942 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + entry + " - " + originalBlockListEntry);
944 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
945 // Prepare a string to hold the entry.
949 if (blockListEntry.contains("$/$")) { // The first `$` is part of the regular expression.
950 entry = blockListEntry.substring(0, blockListEntry.indexOf("$/$") + 2);
951 } else { // The only `$` indicates the filter options.
952 entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
955 // Create an entry string array.
956 String[] singleEntry = {entry, originalBlockListEntry};
958 // Add the entry to the black list.
959 thirdPartyRegularExpressionBlackList.add(singleEntry);
961 //Log.i("BlockLists", headers.get(1)[0] + " third-party regular expression black list added: " + entry + " - " + originalBlockListEntry);
962 } else if (blockListEntry.contains("*")) { // Third-party and regular expression black list entries.
964 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
966 if (entry.endsWith("*")) { // Process a third-party black list single entry.
967 // Strip the final `*`.
968 entry = entry.substring(0, entry.length() - 1);
970 // Create an entry string array.
971 String[] singleEntry = {entry, originalBlockListEntry};
973 // Add the entry to the black list.
974 thirdPartyBlackList.add(singleEntry);
976 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
977 } else { // There are two or more entries.
978 // Get the index of the wildcard.
979 int wildcardIndex = entry.indexOf("*");
981 // Split the entry into components.
982 String firstEntry = entry.substring(0, wildcardIndex);
983 String secondEntry = entry.substring(wildcardIndex + 1);
985 if (secondEntry.contains("*")) { // There are three or more entries.
986 // Get the index of the wildcard.
987 int secondWildcardIndex = secondEntry.indexOf("*");
989 // Split the entry into components.
990 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
991 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
993 if (thirdEntry.contains("*")) { // Process a third-party black list quadruple entry.
994 // Get the index of the wildcard.
995 int thirdWildcardIndex = thirdEntry.indexOf("*");
997 // Split the entry into components.
998 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
999 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
1001 // Create an entry string array.
1002 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
1004 // Add the entry to the black list.
1005 thirdPartyBlackList.add(quadrupleEntry);
1007 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1008 // fourthEntry + " - " + originalBlockListEntry);
1009 } else { // Process a third-party black list triple entry.
1010 // Create an entry string array.
1011 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1013 // Add the entry to the black list.
1014 thirdPartyBlackList.add(tripleEntry);
1016 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1017 // originalBlockListEntry);
1019 } else { // Process a third-party black list double entry.
1020 // Create an entry string array.
1021 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1023 // Add the entry to the black list.
1024 thirdPartyBlackList.add(doubleEntry);
1026 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1029 } else { // Process a third party black list single entry.
1031 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1033 // Create an entry string array.
1034 String[] singleEntry = {entry, originalBlockListEntry};
1036 // Add the entry to the black list.
1037 thirdPartyBlackList.add(singleEntry);
1039 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
1041 } else if (blockListEntry.substring(blockListEntry.indexOf("$")).contains("domain=")) { // Domain entries.
1042 if (blockListEntry.contains("~")) { // Domain white list entries.
1043 // Separate the filters.
1044 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1045 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1046 String domains = filters.substring(filters.indexOf("domain=") + 7);
1048 // Strip any final `*` from the entry. They are redundant.
1049 if (entry.endsWith("*")) {
1050 entry = entry.substring(0, entry.length() - 1);
1053 // Process each domain.
1055 // Create a string to keep track of the current domain.
1058 if (domains.contains("|")) { // There is more than one domain in the list.
1059 // Get the first domain from the list.
1060 domain = domains.substring(0, domains.indexOf("|"));
1062 // Remove the first domain from the list.
1063 domains = domains.substring(domains.indexOf("|") + 1);
1064 } else { // There is only one domain in the list.
1068 // Strip the initial `~`.
1069 domain = domain.substring(1);
1071 if (entry.contains("*")) { // There are two or more entries.
1072 // Get the index of the wildcard.
1073 int wildcardIndex = entry.indexOf("*");
1075 // Split the entry into components.
1076 String firstEntry = entry.substring(0, wildcardIndex);
1077 String secondEntry = entry.substring(wildcardIndex + 1);
1079 if (secondEntry.contains("*")) { // Process a domain white list triple entry.
1080 // Get the index of the wildcard.
1081 int secondWildcardIndex = secondEntry.indexOf("*");
1083 // Split the entry into components.
1084 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1085 String thirdEntry = secondEntry.substring((secondWildcardIndex + 1));
1087 // Create an entry string array.
1088 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1090 // Add the entry to the white list.
1091 domainWhiteList.add(domainTripleEntry);
1093 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1094 // " - " + originalBlockListEntry);
1095 } else { // Process a domain white list double entry.
1096 // Create an entry string array.
1097 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1099 // Add the entry to the white list.
1100 domainWhiteList.add(domainDoubleEntry);
1102 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1104 } else { // Process a domain white list single entry.
1105 // Create an entry string array.
1106 String[] domainEntry = {domain, entry, originalBlockListEntry};
1108 // Add the entry to the white list.
1109 domainWhiteList.add(domainEntry);
1111 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1113 } while (domains.contains("|"));
1114 } else { // Domain black list entries.
1115 // Separate the filters.
1116 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1117 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1118 String domains = filters.substring(filters.indexOf("domain=") + 7);
1120 // Only process the item if the entry is not null. For example, some lines begin with `$websocket`, which create a null entry.
1121 if (!entry.equals("")) {
1122 // Process each domain.
1124 // Create a string to keep track of the current domain.
1127 if (domains.contains("|")) { // There is more than one domain in the list.
1128 // Get the first domain from the list.
1129 domain = domains.substring(0, domains.indexOf("|"));
1131 // Remove the first domain from the list.
1132 domains = domains.substring(domains.indexOf("|") + 1);
1133 } else { // There is only one domain in the list.
1137 if (entry.startsWith("|")) { // Domain initial black list entries.
1138 // Remove the initial `|`;
1139 String entryBase = entry.substring(1);
1141 //noinspection StatementWithEmptyBody
1142 if (entryBase.equals("http://") || entryBase.equals("https://")) {
1143 // Do nothing. These entries will entirely block the website.
1144 // Often the original entry blocks `$script` but Privacy Browser does not currently differentiate between scripts and other entries.
1146 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
1147 } else { // Process a domain initial black list entry
1148 // Create an entry string array.
1149 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1151 // Add the entry to the black list.
1152 domainInitialBlackList.add(domainEntry);
1154 //Log.i("BlockLists", headers.get(1)[0] + " domain initial black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1156 } else if (entry.endsWith("|")) { // Domain final black list entries.
1157 // Remove the final `|`.
1158 String entryBase = entry.substring(0, entry.length() - 1);
1160 if (entryBase.contains("*")) { // Process a domain final black list double entry.
1161 // Get the index of the wildcard.
1162 int wildcardIndex = entry.indexOf("*");
1164 // Split the entry into components.
1165 String firstEntry = entryBase.substring(0, wildcardIndex);
1166 String secondEntry = entryBase.substring(wildcardIndex + 1);
1168 // Create an entry string array.
1169 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1171 // Add the entry to the black list.
1172 domainFinalBlackList.add(domainDoubleEntry);
1174 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1175 // originalBlockListEntry);
1176 } else { // Process a domain final black list single entry.
1177 // Create an entry string array.
1178 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1180 // Add the entry to the black list.
1181 domainFinalBlackList.add(domainEntry);
1183 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1185 } else if (entry.contains("\\")) { // Process a domain regular expression black list entry.
1186 // Create an entry string array.
1187 String[] domainEntry = {domain, entry, originalBlockListEntry};
1189 // Add the entry to the black list.
1190 domainRegularExpressionBlackList.add(domainEntry);
1192 //Log.i("BlockLists", headers.get(1)[0] + " domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1193 } else if (entry.contains("*")) { // There are two or more entries.
1194 // Get the index of the wildcard.
1195 int wildcardIndex = entry.indexOf("*");
1197 // Split the entry into components.
1198 String firstEntry = entry.substring(0, wildcardIndex);
1199 String secondEntry = entry.substring(wildcardIndex + 1);
1201 if (secondEntry.contains("*")) { // Process a domain black list triple entry.
1202 // Get the index of the wildcard.
1203 int secondWildcardIndex = secondEntry.indexOf("*");
1205 // Split the entry into components.
1206 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1207 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1209 // Create an entry string array.
1210 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1212 // Add the entry to the black list.
1213 domainBlackList.add(domainTripleEntry);
1215 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1216 // " - " + originalBlockListEntry);
1217 } else { // Process a domain black list double entry.
1218 // Create an entry string array.
1219 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1221 // Add the entry to the black list.
1222 domainBlackList.add(domainDoubleEntry);
1224 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1225 // originalBlockListEntry);
1227 } else { // Process a domain black list single entry.
1228 // Create an entry string array.
1229 String[] domainEntry = {domain, entry, originalBlockListEntry};
1231 // Add the entry to the black list.
1232 domainBlackList.add(domainEntry);
1234 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1236 } while (domains.contains("|"));
1239 } else if (blockListEntry.contains("~")) { // White list entries. Privacy Browser does not differentiate against these filter options, so they are just generally white listed.
1240 // Remove the filter options.
1241 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1243 // Strip any trailing `*`.
1244 if (blockListEntry.endsWith("*")) {
1245 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1248 if (blockListEntry.contains("*")) { // Process a white list double entry.
1249 // Get the index of the wildcard.
1250 int wildcardIndex = blockListEntry.indexOf("*");
1252 // Split the entry into components.
1253 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1254 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1256 // Create an entry string array.
1257 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1259 // Add the entry to the white list.
1260 mainWhiteList.add(doubleEntry);
1262 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1263 } else { // Process a white list single entry.
1264 // Create an entry string array.
1265 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1267 // Add the entry to the white list.
1268 mainWhiteList.add(singleEntry);
1270 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - + " + originalBlockListEntry);
1272 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
1273 // Remove the filter options.
1274 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1276 // Create an entry string array.
1277 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1279 // Add the entry to the black list.
1280 regularExpressionBlackList.add(singleEntry);
1282 //Log.i("BlockLists", headers.get(1)[0] + " regular expression black list added: " + blockListEntry + " - " + originalBlockListEntry);
1283 } else { // Black list entries.
1284 // Remove the filter options.
1285 if (!blockListEntry.contains("$file")) { // EasyPrivacy contains an entry with `$file` that does not have filter options.
1286 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1289 // Strip any trailing `*`. These are redundant.
1290 if (blockListEntry.endsWith("*")) {
1291 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1294 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1295 // Strip the initial `|`.
1296 String entry = blockListEntry.substring(1);
1298 if (entry.contains("*")) { // Process an initial black list double entry.
1299 // Get the index of the wildcard.
1300 int wildcardIndex = entry.indexOf("*");
1302 // Split the entry into components.
1303 String firstEntry = entry.substring(0, wildcardIndex);
1304 String secondEntry = entry.substring(wildcardIndex + 1);
1306 // Create an entry string array.
1307 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1309 // Add the entry to the black list.
1310 initialBlackList.add(doubleEntry);
1312 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1313 } else { // Process an initial black list single entry.
1314 // Create an entry string array.
1315 String[] singleEntry = {entry, originalBlockListEntry};
1317 // Add the entry to the black list.
1318 initialBlackList.add(singleEntry);
1320 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1322 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1323 // Ignore entries with `object` filters. They can block entire websites and don't have any meaning in the context of Privacy Browser.
1324 if (!originalBlockListEntry.contains("$object")) {
1325 // Strip the final `|`.
1326 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1328 if (entry.contains("*")) { // There are two or more entries.
1329 // Get the index of the wildcard.
1330 int wildcardIndex = entry.indexOf("*");
1332 // Split the entry into components.
1333 String firstEntry = entry.substring(0, wildcardIndex);
1334 String secondEntry = entry.substring(wildcardIndex + 1);
1336 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1337 // Get the index of the wildcard.
1338 int secondWildcardIndex = secondEntry.indexOf("*");
1340 // Split the entry into components.
1341 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1342 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1344 // Create an entry string array.
1345 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1347 // Add the entry to the black list.
1348 finalBlackList.add(tripleEntry);
1350 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1351 // originalBlockListEntry);
1352 } else { // Process a final black list double entry.
1353 // Create an entry string array.
1354 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1356 // Add the entry to the black list.
1357 finalBlackList.add(doubleEntry);
1359 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1361 } else { // Process a final black list single entry.
1362 // Create an entry sting array.
1363 String[] singleEntry = {entry, originalBlockListEntry};
1365 // Add the entry to the black list.
1366 finalBlackList.add(singleEntry);
1368 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1371 } else if (blockListEntry.contains("*")) { // There are two or more entries.
1372 // Get the index of the wildcard.
1373 int wildcardIndex = blockListEntry.indexOf("*");
1375 // Split the entry into components.
1376 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1377 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1379 if (secondEntry.contains("*")) { // Process a main black list triple entry.
1380 // Get the index of the wildcard.
1381 int secondWildcardIndex = secondEntry.indexOf("*");
1383 // Split the entry into components.
1384 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1385 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1387 // Create an entry string array.
1388 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1390 // Add the entry to the black list.
1391 mainBlackList.add(tripleEntry);
1393 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1394 } else { // Process a main black list double entry.
1395 // Create an entry string array.
1396 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1398 // Add the entry to the black list.
1399 mainBlackList.add(doubleEntry);
1401 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1403 } else { // Process a main black list single entry.
1404 // Create an entry string array.
1405 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1407 // Add the entry to the black list.
1408 mainBlackList.add(singleEntry);
1410 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1413 } else { // Main black list entries
1414 // Strip out any initial `||`. These will be treated like any other entry.
1415 if (blockListEntry.startsWith("||")) {
1416 blockListEntry = blockListEntry.substring(2);
1419 // Strip out any initial `*`.
1420 if (blockListEntry.startsWith("*")) {
1421 blockListEntry = blockListEntry.substring(1);
1424 // Strip out any trailing `*`.
1425 if (blockListEntry.endsWith("*")) {
1426 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1429 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1430 // Strip the initial `|`.
1431 String entry = blockListEntry.substring(1);
1433 if (entry.contains("*")) { // Process an initial black list double entry.
1434 // Get the index of the wildcard.
1435 int wildcardIndex = entry.indexOf("*");
1437 // Split the entry into components.
1438 String firstEntry = entry.substring(0, wildcardIndex);
1439 String secondEntry = entry.substring(wildcardIndex + 1);
1441 // Create an entry string array.
1442 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1444 // Add the entry to the black list.
1445 initialBlackList.add(doubleEntry);
1447 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1448 } else { // Process an initial black list single entry.
1449 // Create an entry string array.
1450 String[] singleEntry = {entry, originalBlockListEntry};
1452 // Add the entry to the black list.
1453 initialBlackList.add(singleEntry);
1455 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1457 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1458 // Strip the final `|`.
1459 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1461 if (entry.contains("*")) { // There are two or more entries.
1462 // Get the index of the wildcard.
1463 int wildcardIndex = entry.indexOf("*");
1465 // Split the entry into components.
1466 String firstEntry = entry.substring(0, wildcardIndex);
1467 String secondEntry = entry.substring(wildcardIndex + 1);
1469 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1470 // Get the index of the wildcard.
1471 int secondWildcardIndex = secondEntry.indexOf("*");
1473 // Split the entry into components.
1474 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1475 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1477 // Create an entry string array.
1478 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1480 // Add the entry to the black list.
1481 finalBlackList.add(tripleEntry);
1483 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1484 // originalBlockListEntry);
1485 } else { // Process a final black list double entry.
1486 // Create an entry string array.
1487 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1489 // Add the entry to the black list.
1490 finalBlackList.add(doubleEntry);
1492 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1494 } else { // Process a final black list single entry.
1495 // Create an entry string array.
1496 String[] singleEntry = {entry, originalBlockListEntry};
1498 // Add the entry to the black list.
1499 finalBlackList.add(singleEntry);
1501 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1503 } else { // Main black list entries.
1504 if (blockListEntry.contains("*")) { // There are two or more entries.
1505 // Get the index of the wildcard.
1506 int wildcardIndex = blockListEntry.indexOf("*");
1508 // Split the entry into components.
1509 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1510 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1512 if (secondEntry.contains("*")) { // There are three or more entries.
1513 // Get the index of the wildcard.
1514 int secondWildcardIndex = secondEntry.indexOf("*");
1516 // Split the entry into components.
1517 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1518 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1520 if (thirdEntry.contains("*")) { // There are four or more entries.
1521 // Get the index of the wildcard.
1522 int thirdWildcardIndex = thirdEntry.indexOf("*");
1524 // Split the entry into components.
1525 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
1526 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
1528 if (fourthEntry.contains("*")) { // Process a main black list quintuple entry.
1529 // Get the index of the wildcard.
1530 int fourthWildcardIndex = fourthEntry.indexOf("*");
1532 // Split the entry into components.
1533 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
1534 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
1536 // Create an entry string array.
1537 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
1539 // Add the entry to the black list.
1540 mainBlackList.add(quintupleEntry);
1542 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1543 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
1544 } else { // Process a main black list quadruple entry.
1545 // Create an entry string array.
1546 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
1548 // Add the entry to the black list.
1549 mainBlackList.add(quadrupleEntry);
1551 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1552 // fourthEntry + " - " + originalBlockListEntry);
1554 } else { // Process a main black list triple entry.
1555 // Create an entry string array.
1556 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1558 // Add the entry to the black list.
1559 mainBlackList.add(tripleEntry);
1561 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1563 } else { // Process a main black list double entry.
1564 // Create an entry string array.
1565 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1567 // Add the entry to the black list.
1568 mainBlackList.add(doubleEntry);
1570 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1572 } else { // Process a main black list single entry.
1573 // Create an entry string array.
1574 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1576 // Add the entry to the black list.
1577 mainBlackList.add(singleEntry);
1579 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1584 // Close `bufferedReader`.
1585 bufferedReader.close();
1586 } catch (IOException e) {
1587 // The asset exists, so the `IOException` will never be thrown.
1590 // Initialize the combined list.
1591 ArrayList<List<String[]>> combinedLists = new ArrayList<>();
1593 // Add the headers (0).
1594 combinedLists.add(headers); // 0.
1596 // Add the white lists (1-8).
1597 combinedLists.add(mainWhiteList); // 1.
1598 combinedLists.add(finalWhiteList); // 2.
1599 combinedLists.add(domainWhiteList); // 3.
1600 combinedLists.add(domainInitialWhiteList); // 4.
1601 combinedLists.add(domainFinalWhiteList); // 5.
1602 combinedLists.add(thirdPartyWhiteList); // 6.
1603 combinedLists.add(thirdPartyDomainWhiteList); // 7.
1604 combinedLists.add(thirdPartyDomainInitialWhiteList); // 8.
1606 // Add the black lists (9-22).
1607 combinedLists.add(mainBlackList); // 9.
1608 combinedLists.add(initialBlackList); // 10.
1609 combinedLists.add(finalBlackList); // 11.
1610 combinedLists.add(domainBlackList); // 12.
1611 combinedLists.add(domainInitialBlackList); // 13.
1612 combinedLists.add(domainFinalBlackList); // 14.
1613 combinedLists.add(domainRegularExpressionBlackList); // 15.
1614 combinedLists.add(thirdPartyBlackList); // 16.
1615 combinedLists.add(thirdPartyInitialBlackList); // 17.
1616 combinedLists.add(thirdPartyDomainBlackList); // 18.
1617 combinedLists.add(thirdPartyDomainInitialBlackList); // 19.
1618 combinedLists.add(thirdPartyRegularExpressionBlackList); // 20.
1619 combinedLists.add(thirdPartyDomainRegularExpressionBlackList); // 21.
1620 combinedLists.add(regularExpressionBlackList); // 22.
1622 return combinedLists;
1625 public String[] checkBlocklist(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList<List<String[]>> blockList) {
1626 // Get the blocklist name.
1627 String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0];
1629 // Assert that currentDomain != null only if this is a third party request. Apparently, lint can't tell that this isn't redundant.
1630 //noinspection RedundantIfStatement
1631 if (isThirdPartyRequest) {
1632 assert currentDomain != null;
1635 // Process the white lists.
1637 for (String[] whiteListEntry : blockList.get(Integer.valueOf(MAIN_WHITELIST))) {
1638 switch (whiteListEntry.length) {
1639 case 2: // There is one entry.
1640 if (resourceUrl.contains(whiteListEntry[0])) {
1641 // Return a whitelist match request allowed.
1642 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0], whiteListEntry[1]};
1646 case 3: // There are two entries.
1647 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1648 // Return a whitelist match request allowed.
1649 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1653 case 4: // There are three entries.
1654 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1655 // Return a whitelist match request allowed.
1656 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1662 // Final white list.
1663 for (String[] whiteListEntry : blockList.get(Integer.valueOf(FINAL_WHITELIST))) {
1664 if (whiteListEntry.length == 2) { // There is one entry.
1665 if (resourceUrl.contains(whiteListEntry[0])) {
1666 // Return a whitelist match request allowed.
1667 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0], whiteListEntry[1]};
1669 } else { // There are two entries.
1670 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1671 // Return a whitelist match request allowed.
1672 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1677 // Only check the domain lists if the current domain is not null (like `about:blank`).
1678 if (currentDomain != null) {
1679 // Domain white list.
1680 for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_WHITELIST))) {
1681 switch (whiteListEntry.length) {
1682 case 3: // There is one entry.
1683 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1684 // Return a whitelist match request allowed.
1685 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1689 case 4: // There are two entries.
1690 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1691 // Return a whitelist match request allowed.
1692 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1697 case 5: // There are three entries.
1698 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1699 // Return a whitelist match request allowed.
1700 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" +
1701 whiteListEntry[3], whiteListEntry[4]};
1705 case 6: // There are four entries.
1706 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1707 resourceUrl.contains(whiteListEntry[4])) {
1708 // Return a whitelist match request allowed.
1709 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" +
1710 whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]};
1716 // Domain initial white list.
1717 for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_WHITELIST))) {
1718 switch (whiteListEntry.length) {
1719 case 3: // There is one entry.
1720 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1721 // Return a whitelist match request allowed.
1722 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1726 case 4: // There are two entries.
1727 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1728 // Return a whitelist match request allowed.
1729 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1734 case 5: // There are three entries.
1735 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) {
1736 // Return a whitelist match request allowed.
1737 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" +
1738 whiteListEntry[3], whiteListEntry[4]};
1744 // Domain final white list.
1745 for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_WHITELIST))) {
1746 switch (whiteListEntry.length) {
1747 case 3: // There is one entry;
1748 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) {
1749 // Return a whitelist match request allowed.
1750 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1754 case 4: // There are two entries;
1755 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) {
1756 // Return a whitelist match request allowed.
1757 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1765 // Only check the third-party white lists if this is a third-party request.
1766 if (isThirdPartyRequest) {
1767 // Third-party white list.
1768 for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_WHITELIST))) {
1769 switch (whiteListEntry.length) {
1770 case 2: // There is one entry
1771 if (resourceUrl.contains(whiteListEntry[0])) {
1772 // Return a whitelist match request allowed.
1773 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0], whiteListEntry[1]};
1777 case 3: // There are two entries.
1778 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1779 // Return a whitelist match request allowed.
1780 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1784 case 4: // There are three entries.
1785 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1786 // Return a whitelist match request allowed.
1787 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1792 case 5: // There are four entries.
1793 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1794 // Return a whitelist match request allowed.
1795 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" +
1796 whiteListEntry[3], whiteListEntry[4]};
1800 case 6: // There are five entries.
1801 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1802 resourceUrl.contains(whiteListEntry[4])) {
1803 // Return a whitelist match request allowed.
1804 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" +
1805 whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]};
1811 // Third-party domain white list.
1812 for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_WHITELIST))) {
1813 if (whiteListEntry.length == 3) { // There is one entry.
1814 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1815 // Return a whitelist match request allowed.
1816 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1818 } else { // There are two entries.
1819 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1820 // Return a whitelist match request allowed.
1821 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1827 // Third-party domain initial white list.
1828 for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_WHITELIST))) {
1829 if (whiteListEntry.length == 3) { // There is one entry.
1830 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1831 // Return a whitelist match request allowed.
1832 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1834 } else { // There are two entries.
1835 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1836 // Return a whitelist match request allowed.
1837 return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2],
1844 // Process the black lists.
1846 for (String[] blackListEntry : blockList.get(Integer.valueOf(MAIN_BLACKLIST))) {
1847 switch (blackListEntry.length) {
1848 case 2: // There is one entry.
1849 if (resourceUrl.contains(blackListEntry[0])) {
1850 // Return a blacklist match request blocked.
1851 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0], blackListEntry[1]};
1855 case 3: // There are two entries.
1856 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1857 // Return a blacklist match request blocked.
1858 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1862 case 4: // There are three entries.
1863 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
1864 // Return a blacklist match request blocked.
1865 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]};
1869 case 5: // There are four entries.
1870 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
1871 // Return a blacklist match request blocked.
1872 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" +
1873 blackListEntry[3], blackListEntry[4]};
1877 case 6: // There are five entries.
1878 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) &&
1879 resourceUrl.contains(blackListEntry[4])) {
1880 // Return a blacklist match request blocked.
1881 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" +
1882 blackListEntry[3] + "\n" + blackListEntry[4], blackListEntry[5]};
1888 // Initial black list.
1889 for (String[] blackListEntry : blockList.get(Integer.valueOf(INITIAL_BLACKLIST))) {
1890 if (blackListEntry.length == 2) { // There is one entry.
1891 if (resourceUrl.startsWith(blackListEntry[0])) {
1892 // Return a blacklist match request blocked.
1893 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]};
1895 } else { // There are two entries
1896 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1897 // Return a blacklist match request blocked.
1898 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1903 // Final black list.
1904 for (String[] blackListEntry : blockList.get(Integer.valueOf(FINAL_BLACKLIST))) {
1905 switch (blackListEntry.length) {
1906 case 2: // There is one entry.
1907 if (resourceUrl.endsWith(blackListEntry[0])) {
1908 // Return a blacklist match request blocked.
1909 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0], blackListEntry[1]};
1913 case 3: // There are two entries.
1914 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
1915 // Return a blacklist match request blocked.
1916 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1920 case 4: // There are three entries.
1921 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
1922 // Return a blacklist match request blocked.
1923 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]};
1929 // Only check the domain lists if the current domain is not null (like `about:blank`).
1930 if (currentDomain != null) {
1931 // Domain black list.
1932 for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_BLACKLIST))) {
1933 switch (blackListEntry.length) {
1934 case 3: // There is one entry.
1935 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1936 // Return a blacklist match request blocked.
1937 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1941 case 4: // There are two entries.
1942 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
1943 // Return a blacklist match request blocked.
1944 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2],
1949 case 5: // There are three entries.
1950 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
1951 // Return a blacklist match request blocked.
1952 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" +
1953 blackListEntry[3], blackListEntry[4]};
1959 // Domain initial black list.
1960 for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_BLACKLIST))) {
1961 // Store the entry in the resource request log.
1962 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
1963 // Return a blacklist match request blocked.
1964 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1968 // Domain final black list.
1969 for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_BLACKLIST))) {
1970 switch (blackListEntry.length) {
1971 case 3: // There is one entry.
1972 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
1973 // Return a blacklist match request blocked.
1974 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1978 case 4: // There are two entries.
1979 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
1980 // Return a blacklist match request blocked.
1981 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2],
1988 // Domain regular expression black list.
1989 for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
1990 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
1991 // Return a blacklist match request blocked.
1992 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
1997 // Only check the third-party black lists if this is a third-party request.
1998 if (isThirdPartyRequest) {
1999 // Third-party black list.
2000 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_BLACKLIST))) {
2001 switch (blackListEntry.length) {
2002 case 2: // There is one entry.
2003 if (resourceUrl.contains(blackListEntry[0])) {
2004 // Return a blacklist match request blocked.
2005 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0], blackListEntry[1]};
2009 case 3: // There are two entries.
2010 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2011 // Return a blacklist match request blocked.
2012 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
2016 case 4: // There are three entries.
2017 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2018 // Return a blacklist match request blocked.
2019 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2],
2024 case 5: // There are four entries.
2025 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2026 // Return a blacklist match request blocked.
2027 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" +
2028 blackListEntry[3], blackListEntry[4]};
2034 // Third-party initial black list.
2035 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_INITIAL_BLACKLIST))) {
2036 if (blackListEntry.length == 2) { // There is one entry.
2037 if (resourceUrl.startsWith(blackListEntry[0])) {
2038 // Return a blacklist match request blocked.
2039 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]};
2041 } else { // There are two entries.
2042 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2043 // Return a blacklist match request blocked.
2044 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
2049 // Third-party domain black list.
2050 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_BLACKLIST))) {
2051 if (blackListEntry.length == 3) { // There is one entry.
2052 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2053 // Return a blacklist match request blocked.
2054 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
2056 } else { // There are two entries.
2057 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2058 // Return a blacklist match request blocked.
2059 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2],
2065 // Third-party domain initial black list.
2066 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST))) {
2067 switch (blackListEntry.length) {
2068 case 3: // There is one entry.
2069 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2070 // Return a blacklist match request blocked.
2071 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
2075 case 4: // There are two entries.
2076 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2077 // Return a blacklist match request blocked.
2078 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" +
2079 blackListEntry[2], blackListEntry[3]};
2083 case 5: // There are three entries.
2084 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2085 // Return a blacklist match request blocked.
2086 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" +
2087 blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]};
2093 // Third-party regular expression black list.
2094 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST))) {
2095 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2096 // Return a blacklist match request blocked.
2097 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]};
2101 // Third-party domain regular expression black list.
2102 for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) {
2103 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2104 // Return a blacklist match request blocked.
2105 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]};
2110 // Regular expression black list.
2111 for (String[] blackListEntry : blockList.get(Integer.valueOf(REGULAR_EXPRESSION_BLACKLIST))) {
2112 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2113 // Return a blacklist match request blocked.
2114 return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]};
2118 // Return a no match request default.
2119 return new String[] {REQUEST_DEFAULT};