2 * Copyright © 2018 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 com.stoutner.privacybrowser.activities.MainWebViewActivity;
26 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.regex.Pattern;
33 public class BlockListHelper {
34 public ArrayList<List<String[]>> parseBlockList(AssetManager assets, String blockListName) {
35 // Initialize the header list.
36 List<String[]> headers = new ArrayList<>(); // 0.
38 // Initialize the whitelists.
39 List<String[]> mainWhiteList = new ArrayList<>(); // 1.
40 List<String[]> finalWhiteList = new ArrayList<>(); // 2.
41 List<String[]> domainWhiteList = new ArrayList<>(); // 3.
42 List<String[]> domainInitialWhiteList = new ArrayList<>(); // 4.
43 List<String[]> domainFinalWhiteList = new ArrayList<>(); // 5.
44 List<String[]> thirdPartyWhiteList = new ArrayList<>(); // 6.
45 List<String[]> thirdPartyDomainWhiteList = new ArrayList<>(); // 7.
46 List<String[]> thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8.
48 // Initialize the blacklists
49 List<String[]> mainBlackList = new ArrayList<>(); // 9.
50 List<String[]> initialBlackList = new ArrayList<>(); // 10.
51 List<String[]> finalBlackList = new ArrayList<>(); // 11.
52 List<String[]> domainBlackList = new ArrayList<>(); // 12.
53 List<String[]> domainInitialBlackList = new ArrayList<>(); // 13.
54 List<String[]> domainFinalBlackList = new ArrayList<>(); // 14.
55 List<String[]> domainRegularExpressionBlackList = new ArrayList<>(); // 15.
56 List<String[]> thirdPartyBlackList = new ArrayList<>(); // 16.
57 List<String[]> thirdPartyInitialBlackList = new ArrayList<>(); // 17.
58 List<String[]> thirdPartyDomainBlackList = new ArrayList<>(); // 18.
59 List<String[]> thirdPartyDomainInitialBlackList = new ArrayList<>(); // 19.
60 List<String[]> regularExpressionBlackList = new ArrayList<>(); // 20.
61 List<String[]> thirdPartyRegularExpressionBlackList = new ArrayList<>(); // 21.
62 List<String[]> thirdPartyDomainRegularExpressionBlackList = new ArrayList<>(); // 22.
65 // Populate the block lists. The `try` is required by `InputStreamReader`.
67 // Load the block list into a `BufferedReader`.
68 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assets.open(blockListName)));
70 // Create a string for storing the block list entries.
71 String blockListEntry;
73 // Parse the block list.
74 while ((blockListEntry = bufferedReader.readLine()) != null) {
75 // Store the original block list entry.
76 String originalBlockListEntry = blockListEntry;
78 // Remove any `^` from the block list entry. Privacy Browser does not process them in the interest of efficiency.
79 blockListEntry = blockListEntry.replace("^", "");
81 //noinspection StatementWithEmptyBody
82 if (blockListEntry.contains("##") || blockListEntry.contains("#?#") || blockListEntry.contains("#@#") || blockListEntry.startsWith("[")) {
83 // Entries that contain `##`, `#?#`, and `#@#` are for hiding elements in the main page's HTML. Entries that start with `[` describe the AdBlock compatibility level.
84 // Do nothing. Privacy Browser does not currently use these entries.
86 //Log.i("BlockLists", "Not added: " + blockListEntry);
87 } else //noinspection StatementWithEmptyBody
88 if (blockListEntry.contains("$csp=script-src")) { // Ignore entries that contain `$csp=script-src`.
89 // 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.
91 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
92 } else //noinspection StatementWithEmptyBody
93 if (blockListEntry.contains("$websocket") || blockListEntry.contains("$third-party,websocket") || blockListEntry.contains("$script,websocket")) { // Ignore entries with `websocket`.
94 // Do nothing. Privacy Browser does not differentiate between websocket requests and other requests and these entries cause a lot of false positivies.
96 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
97 } else if (blockListEntry.startsWith("!")) { // Comment entries.
98 if (blockListEntry.startsWith("! Version:")) {
99 // Get the list version number.
100 String[] listVersion = {blockListEntry.substring(11)};
102 // Store the list version in the headers list.
103 headers.add(listVersion);
106 if (blockListEntry.startsWith("! Title:")) {
107 // Get the list title.
108 String[] listTitle = {blockListEntry.substring(9)};
110 // Store the list title in the headers list.
111 headers.add(listTitle);
114 //Log.i("BlockLists", "Not added: " + blockListEntry);
115 } else if (blockListEntry.startsWith("@@")) { // Entries that begin with `@@` are whitelists.
117 blockListEntry = blockListEntry.substring(2);
119 // Strip out any initial `||`. Privacy Browser doesn't differentiate items that only match against the end of the domain name.
120 if (blockListEntry.startsWith("||")) {
121 blockListEntry = blockListEntry.substring(2);
124 if (blockListEntry.contains("$")) { // Filter entries.
125 //noinspection StatementWithEmptyBody
126 if (blockListEntry.contains("~third-party")) { // Ignore entries that contain `~third-party`.
129 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
130 } else if (blockListEntry.contains("third-party")) { // Third-party white list entries.
131 if (blockListEntry.contains("domain=")) { // Third-party domain white list entries.
133 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
134 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
135 String domains = filters.substring(filters.indexOf("domain=") + 7);
137 //noinspection StatementWithEmptyBody
138 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
141 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
142 } else if (blockListEntry.startsWith("|")) { // Third-party domain initial white list entries.
143 // Strip out the initial `|`.
144 entry = entry.substring(1);
146 //noinspection StatementWithEmptyBody
147 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
148 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
150 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
151 } else { // Process third-party domain initial white list entries.
152 // Process each domain.
154 // Create a string to keep track of the current domain.
157 if (domains.contains("|")) { // There is more than one domain in the list.
158 // Get the first domain from the list.
159 domain = domains.substring(0, domains.indexOf("|"));
161 // Remove the first domain from the list.
162 domains = domains.substring(domains.indexOf("|") + 1);
163 } else { // There is only one domain in the list.
167 if (entry.contains("*")) { // Process a third-party domain initial white list double entry.
168 // Get the index of the wildcard.
169 int wildcardIndex = entry.indexOf("*");
171 // Split the entry into components.
172 String firstEntry = entry.substring(0, wildcardIndex);
173 String secondEntry = entry.substring(wildcardIndex + 1);
175 // Create an entry string array.
176 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
178 // Add the entry to the white list.
179 thirdPartyDomainInitialWhiteList.add(domainDoubleEntry);
181 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + firstEntry + " , " + secondEntry +
182 // " - " + originalBlockListEntry);
183 } else { // Process a third-party domain initial white list single entry.
184 // Create a domain entry string array.
185 String[] domainEntry = {domain, entry, originalBlockListEntry};
187 // Add the entry to the third party domain initial white list.
188 thirdPartyDomainInitialWhiteList.add(domainEntry);
190 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
192 } while (domains.contains("|"));
194 } else { // Third-party domain entries.
195 // Process each domain.
197 // Create a string to keep track of the current domain.
200 if (domains.contains("|")) { // three is more than one domain in the list.
201 // Get the first domain from the list.
202 domain = domains.substring(0, domains.indexOf("|"));
204 // Remove the first domain from the list.
205 domains = domains.substring(domains.indexOf("|") + 1);
206 } else { // There is only one domain in the list.
210 // Remove any trailing `*` from the entry.
211 if (entry.endsWith("*")) {
212 entry = entry.substring(0, entry.length() - 1);
215 if (entry.contains("*")) { // Process a third-party domain double entry.
216 // Get the index of the wildcard.
217 int wildcardIndex = entry.indexOf("*");
219 // Split the entry into components.
220 String firstEntry = entry.substring(0, wildcardIndex);
221 String secondEntry = entry.substring(wildcardIndex + 1);
223 // Create an entry string array.
224 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
226 // Add the entry to the white list.
227 thirdPartyDomainWhiteList.add(domainDoubleEntry);
229 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
230 // originalBlockListEntry);
231 } else { // Process a third-party domain single entry.
232 // Create an entry string array.
233 String[] domainEntry = {domain, entry, originalBlockListEntry};
235 // Add the entry to the white list.
236 thirdPartyDomainWhiteList.add(domainEntry);
238 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
240 } while (domains.contains("|"));
242 } else { // Process third-party white list entries.
244 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
246 if (entry.contains("*")) { // There are two or more entries.
247 // Get the index of the wildcard.
248 int wildcardIndex = entry.indexOf("*");
250 // Split the entry into components.
251 String firstEntry = entry.substring(0, wildcardIndex);
252 String secondEntry = entry.substring(wildcardIndex + 1);
254 if (secondEntry.contains("*")) { // There are three or more entries.
255 // Get the index of the wildcard.
256 int secondWildcardIndex = secondEntry.indexOf("*");
258 // Split the entry into components.
259 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
260 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
262 if (thirdEntry.contains("*")) { // There are four or more entries.
263 // Get the index of the wildcard.
264 int thirdWildcardIndex = thirdEntry.indexOf("*");
266 // Split the entry into components.
267 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
268 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
270 if (fourthEntry.contains("*")) { // Process a third-party white list quintuple entry.
271 // Get the index of the wildcard.
272 int fourthWildcardIndex = fourthEntry.indexOf("*");
274 // Split the entry into components.
275 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
276 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
278 // Create an entry string array.
279 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
281 // Add the entry to the white list.
282 thirdPartyWhiteList.add(quintupleEntry);
284 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
285 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
286 } else { // Process a third-party white list quadruple entry.
287 // Create an entry string array.
288 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
290 // Add the entry to the white list.
291 thirdPartyWhiteList.add(quadrupleEntry);
293 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
294 // fourthEntry + " - " + originalBlockListEntry);
296 } else { // Process a third-party white list triple entry.
297 // Create an entry string array.
298 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
300 // Add the entry to the white list.
301 thirdPartyWhiteList.add(tripleEntry);
303 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
304 // originalBlockListEntry);
306 } else { // Process a third-party white list double entry.
307 // Create an entry string array.
308 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
310 // Add the entry to the white list.
311 thirdPartyWhiteList.add(doubleEntry);
313 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
315 } else { // Process a third-party white list single entry.
316 // Create an entry string array.
317 String[] singleEntry = {entry, originalBlockListEntry};
319 // Add the entry to the white list.
320 thirdPartyWhiteList.add(singleEntry);
322 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + entry + " - " + originalBlockListEntry);
325 } else if (blockListEntry.contains("domain=")) { // Process domain white list entries.
327 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
328 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
329 String domains = filters.substring(filters.indexOf("domain=") + 7);
331 if (entry.startsWith("|")) { // Initial domain white list entries.
332 // Strip the initial `|`.
333 entry = entry.substring(1);
335 //noinspection StatementWithEmptyBody
336 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
337 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
339 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
340 } else { // Initial domain white list entry.
341 // Process each domain.
343 // Create a string to keep track of the current domain.
346 if (domains.contains("|")) { // There is more than one domain in the list.
347 // Get the first domain from the list.
348 domain = domains.substring(0, domains.indexOf("|"));
350 // Remove the first domain from the list.
351 domains = domains.substring(domains.indexOf("|") + 1);
352 } else { // There is only one domain in the list.
356 if (entry.contains("*")) { // There are two or more entries.
357 // Get the index of the wildcard.
358 int wildcardIndex = entry.indexOf("*");
360 // Split the entry into components.
361 String firstEntry = entry.substring(0, wildcardIndex);
362 String secondEntry = entry.substring(wildcardIndex + 1);
364 if (secondEntry.contains("*")) { // Process a domain initial triple entry.
365 // Get the index of the wildcard.
366 int secondWildcardIndex = secondEntry.indexOf("*");
368 // Split the entry into components.
369 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
370 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
372 // Create an entry string array.
373 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
375 // Add the entry to the white list.
376 domainInitialWhiteList.add(domainTripleEntry);
378 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
379 // thirdEntry + " - " + originalBlockListEntry);
380 } else { // Process a domain initial double entry.
381 // Create an entry string array.
382 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
384 // Add the entry to the white list.
385 domainInitialWhiteList.add(domainDoubleEntry);
387 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
388 // originalBlockListEntry);
390 } else { // Process a domain initial single entry.
391 // Create an entry string array.
392 String[] domainEntry = {domain, entry, originalBlockListEntry};
394 // Add the entry to the white list.
395 domainInitialWhiteList.add(domainEntry);
397 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + entry + " - " + originalBlockListEntry);
399 } while (domains.contains("|"));
401 } else if (entry.endsWith("|")) { // Final domain white list entries.
402 // Strip the `|` from the end of the entry.
403 entry = entry.substring(0, entry.length() - 1);
405 // Process each domain.
407 // Create a string to keep track of the current domain.
410 if (domains.contains("|")) { // There is more than one domain in the list.
411 // Get the first domain from the list.
412 domain = domains.substring(0, domains.indexOf("|"));
414 // Remove the first domain from the list.
415 domains = domains.substring(domains.indexOf("|") + 1);
416 } else { // There is only one domain in the list.
420 if (entry.contains("*")) { // Process a domain final white list double entry.
421 // Get the index of the wildcard.
422 int wildcardIndex = entry.indexOf("*");
424 // Split the entry into components.
425 String firstEntry = entry.substring(0, wildcardIndex);
426 String secondEntry = entry.substring(wildcardIndex + 1);
428 // Create an entry string array.
429 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
431 // Add the entry to the white list.
432 domainFinalWhiteList.add(domainDoubleEntry);
434 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
435 // originalBlockListEntry);
436 } else { // Process a domain final white list single entry.
437 // create an entry string array.
438 String[] domainEntry = {domain, entry, originalBlockListEntry};
440 // Add the entry to the white list.
441 domainFinalWhiteList.add(domainEntry);
443 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
445 } while (domains.contains("|"));
447 } else { // Standard domain white list entries with filters.
448 //noinspection StatementWithEmptyBody
449 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
452 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
454 // Process each domain.
456 // Create a string to keep track of the current domain.
459 if (domains.contains("|")) { // There is more than one domain in the list.
460 // Get the first domain from the list.
461 domain = domains.substring(0, domains.indexOf("|"));
463 // Remove the first domain from the list.
464 domains = domains.substring(domains.indexOf("|") + 1);
465 } else { // There is only one domain in the list.
469 if (entry.contains("*")) { // There are two or more entries.
470 // Get the index of the wildcard.
471 int wildcardIndex = entry.indexOf("*");
473 // Split the entry into components.
474 String firstEntry = entry.substring(0, wildcardIndex);
475 String secondEntry = entry.substring(wildcardIndex + 1);
477 if (secondEntry.contains("*")) { // There are three or more entries.
478 // Get the index of the wildcard.
479 int secondWildcardIndex = secondEntry.indexOf("*");
481 // Split the entry into components.
482 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
483 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
485 if (thirdEntry.contains("*")) { // Process a domain white list quadruple entry.
486 // Get the index of the wildcard.
487 int thirdWildcardIndex = thirdEntry.indexOf("*");
489 // Split the entry into components.
490 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
491 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
493 // Create an entry string array.
494 String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
496 // Add the entry to the white list.
497 domainWhiteList.add(domainQuadrupleEntry);
499 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
500 // realThirdEntry + " , " + fourthEntry + " - " + originalBlockListEntry);
501 } else { // Process a domain white list triple entry.
502 // Create an entry string array.
503 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
505 // Add the entry to the white list.
506 domainWhiteList.add(domainTripleEntry);
508 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
509 // thirdEntry + " - " + originalBlockListEntry);
511 } else { // Process a domain white list double entry.
512 // Create an entry string array.
513 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
515 // Add the entry to the white list.
516 domainWhiteList.add(domainDoubleEntry);
518 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
519 // originalBlockListEntry);
521 } else { // Process a domain white list single entry.
522 // Create an entry string array.
523 String[] domainEntry = {domain, entry, originalBlockListEntry};
525 // Add the entry to the white list.
526 domainWhiteList.add(domainEntry);
528 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + entry + " - " + originalBlockListEntry);
530 } while (domains.contains("|"));
533 } // Ignore all other filter entries.
534 } else if (blockListEntry.endsWith("|")) { // Final white list entries.
535 // Remove the final `|` from the entry.
536 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
538 if (entry.contains("*")) { // Process a final white list double entry
539 // Get the index of the wildcard.
540 int wildcardIndex = entry.indexOf("*");
542 // split the entry into components.
543 String firstEntry = entry.substring(0, wildcardIndex);
544 String secondEntry = entry.substring(wildcardIndex + 1);
546 // Create an entry string array.
547 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
549 // Add the entry to the white list.
550 finalWhiteList.add(doubleEntry);
552 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
553 } else { // Process a final white list single entry.
554 // Create an entry string array.
555 String[] singleEntry = {entry, originalBlockListEntry};
557 // Add the entry to the white list.
558 finalWhiteList.add(singleEntry);
560 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + entry + " - " + originalBlockListEntry);
562 } else { // Main white list entries.
563 if (blockListEntry.contains("*")) { // There are two or more entries.
564 // Get the index of the wildcard.
565 int wildcardIndex = blockListEntry.indexOf("*");
567 // Split the entry into components.
568 String firstEntry = blockListEntry.substring(0, wildcardIndex);
569 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
571 if (secondEntry.contains("*")) { // Process a main white list triple entry.
572 // Get the index of the wildcard.
573 int secondWildcardIndex = secondEntry.indexOf("*");
575 // Split the entry into components.
576 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
577 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
579 // Create an entry string array.
580 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
582 // Add the entry to the white list.
583 mainWhiteList.add(tripleEntry);
585 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
586 } else { // Process a main white list double entry.
587 // Create an entry string array.
588 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
590 // Add the entry to the white list.
591 mainWhiteList.add(doubleEntry);
593 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
595 } else { // Process a main white list single entry.
596 // Create an entry string array.
597 String[] singleEntry = {blockListEntry, originalBlockListEntry};
599 // Add the entry to the white list.
600 mainWhiteList.add(singleEntry);
602 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - " + originalBlockListEntry);
605 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
606 // Strip out the final "|"
607 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
609 // Strip out any initial `||`. They are redundant in this case because the block list entry is being matched against the end of the URL.
610 if (entry.startsWith("||")) {
611 entry = entry.substring(2);
614 if (entry.contains("*")) { // Process a final black list double entry.
615 // Get the index of the wildcard.
616 int wildcardIndex = entry.indexOf("*");
618 // Split the entry into components.
619 String firstEntry = entry.substring(0, wildcardIndex);
620 String secondEntry = entry.substring(wildcardIndex + 1);
622 // Create an entry string array.
623 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
625 // Add the entry to the black list.
626 finalBlackList.add(doubleEntry);
628 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
629 } else { // Process a final black list single entry.
630 // create an entry string array.
631 String[] singleEntry = {entry, originalBlockListEntry};
633 // Add the entry to the black list.
634 finalBlackList.add(singleEntry);
636 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
638 } else if (blockListEntry.contains("$")) { // Entries with filter options.
639 // Strip out any initial `||`. These will be treated like any other entry.
640 if (blockListEntry.startsWith("||")) {
641 blockListEntry = blockListEntry.substring(2);
644 if (blockListEntry.contains("third-party")) { // Third-party entries.
645 //noinspection StatementWithEmptyBody
646 if (blockListEntry.contains("~third-party")) { // Third-party filter white list entries.
647 // 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`.
649 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
650 } else if (blockListEntry.contains("domain=")) { // Third-party domain entries.
651 if (blockListEntry.startsWith("|")) { // Third-party domain initial entries.
652 // Strip the initial `|`.
653 blockListEntry = blockListEntry.substring(1);
656 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
657 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
658 String domains = filters.substring(filters.indexOf("domain=") + 7);
660 //noinspection StatementWithEmptyBody
661 if (entry.equals("http:") || entry.equals("https:") || entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
662 // Do nothing. These entries will almost entirely disable the website.
663 // Often the original entry blocks filter options like `$script`, which Privacy Browser does not differentiate.
665 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
666 } else { // Third-party domain initial entries.
667 // Process each domain.
669 // Create a string to keep track of the current domain.
672 if (domains.contains("|")) { // There is more than one domain in the list.
673 // Get the first domain from the list.
674 domain = domains.substring(0, domains.indexOf("|"));
676 // Remove the first domain from the list.
677 domains = domains.substring(domains.indexOf("|") + 1);
678 } else { // There is only one domain in the list.
682 if (entry.contains("*")) { // Three are two or more entries.
683 // Get the index of the wildcard.
684 int wildcardIndex = entry.indexOf("*");
686 // Split the entry into components.
687 String firstEntry = entry.substring(0, wildcardIndex);
688 String secondEntry = entry.substring(wildcardIndex + 1);
690 if (secondEntry.contains("*")) { // Process a third-party domain initial black list triple entry.
691 // Get the index of the wildcard.
692 int secondWildcardIndex = secondEntry.indexOf("*");
694 // Split the entry into components.
695 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
696 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
698 // Create an entry string array.
699 String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
701 // Add the entry to the black list.
702 thirdPartyDomainInitialBlackList.add(tripleDomainEntry);
704 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry +
705 // " , " + thirdEntry + " - " + originalBlockListEntry);
706 } else { // Process a third-party domain initial black list double entry.
707 // Create an entry string array.
708 String[] doubleDomainEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
710 // Add the entry to the black list.
711 thirdPartyDomainInitialBlackList.add(doubleDomainEntry);
713 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + secondEntry +
714 // " - " + originalBlockListEntry);
716 } else { // Process a third-party domain initial black list single entry.
717 // Create an entry string array.
718 String[] singleEntry = {domain, entry, originalBlockListEntry};
720 // Add the entry to the black list.
721 thirdPartyDomainInitialBlackList.add(singleEntry);
723 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
725 } while (domains.contains("|"));
727 } else if (blockListEntry.contains("\\")) { // Process a third-party domain black list regular expression.
728 // Parse the entry. At least one regular expression in this entry contains `$`, so the parser uses `/$`.
729 String entry = blockListEntry.substring(0, blockListEntry.indexOf("/$") + 1);
730 String filters = blockListEntry.substring(blockListEntry.indexOf("/$") + 2);
731 String domains = filters.substring(filters.indexOf("domain=") + 7);
733 // Process each domain.
735 // Create a string to keep track of the current domain.
738 if (domains.contains("|")) { // There is more than one domain in the list.
739 // Get the first domain from the list.
740 domain = domains.substring(0, domains.indexOf("|"));
742 // Remove the first domain from the list.
743 domains = domains.substring(domains.indexOf("|") + 1);
744 } else { // There is only one domain in the list.
748 // Create an entry string array.
749 String[] domainEntry = {domain, entry, originalBlockListEntry};
751 // Add the entry to the black list.
752 thirdPartyDomainRegularExpressionBlackList.add(domainEntry);
754 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
755 } while (domains.contains("|"));
756 } else { // Third-party domain entries.
758 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
759 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
760 String domains = filters.substring(filters.indexOf("domain=") + 7);
762 // Strip any trailing "*" from the entry.
763 if (entry.endsWith("*")) {
764 entry = entry.substring(0, entry.length() - 1);
767 // Track if any third-party white list filters are applied.
768 boolean whiteListDomain = false;
770 // Process each domain.
772 // Create a string to keep track of the current domain.
775 if (domains.contains("|")) { // There is more than one domain in the list.
776 // Get the first domain from the list.
777 domain = domains.substring(0, domains.indexOf("|"));
779 // Remove the first domain from the list.
780 domains = domains.substring(domains.indexOf("|") + 1);
781 } else { // The is only one domain in the list.
785 // Differentiate between block list domains and white list domains.
786 if (domain.startsWith("~")) { // White list third-party domain entry.
787 // Strip the initial `~`.
788 domain = domain.substring(1);
790 // Set the white list domain flag.
791 whiteListDomain = true;
793 if (entry.contains("*")) { // Process a third-party domain white list double entry.
794 // Get the index of the wildcard.
795 int wildcardIndex = entry.indexOf("*");
797 // Split the entry into components.
798 String firstEntry = entry.substring(0, wildcardIndex);
799 String secondEntry = entry.substring(wildcardIndex + 1);
801 // Create an entry string array.
802 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
804 // Add the entry to the white list.
805 thirdPartyDomainWhiteList.add(domainDoubleEntry);
807 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
808 // originalBlockListEntry);
809 } else { // Process a third-party domain white list single entry.
810 // Create an entry string array.
811 String[] domainEntry = {domain, entry, originalBlockListEntry};
813 // Add the entry to the white list.
814 thirdPartyDomainWhiteList.add(domainEntry);
816 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
818 } else { // Third-party domain black list entries.
819 if (entry.contains("*")) { // Process a third-party domain black list double entry.
820 // Get the index of the wildcard.
821 int wildcardIndex = entry.indexOf("*");
823 // Split the entry into components.
824 String firstEntry = entry.substring(0, wildcardIndex);
825 String secondEntry = entry.substring(wildcardIndex + 1);
827 // Create an entry string array.
828 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
830 // Add the entry to the black list
831 thirdPartyDomainBlackList.add(domainDoubleEntry);
833 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
834 // originalBlockListEntry);
835 } else { // Process a third-party domain black list single entry.
836 // Create an entry string array.
837 String[] domainEntry = {domain, entry, originalBlockListEntry};
839 // Add the entry to the black list.
840 thirdPartyDomainBlackList.add(domainEntry);
842 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain block list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
845 } while (domains.contains("|"));
847 // Add a third-party black list entry if a white list domain was processed.
848 if (whiteListDomain) {
849 if (entry.contains("*")) { // Process a third-party black list double entry.
850 // Get the index of the wildcard.
851 int wildcardIndex = entry.indexOf("*");
853 // Split the entry into components.
854 String firstEntry = entry.substring(0, wildcardIndex);
855 String secondEntry = entry.substring(wildcardIndex + 1);
857 // Create an entry string array.
858 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
860 // Add the entry to the black list.
861 thirdPartyBlackList.add(doubleEntry);
863 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
864 } else { // Process a third-party black list single entry.
865 // Create an entry string array.
866 String[] singleEntry = {entry, originalBlockListEntry};
868 // Add an entry to the black list.
869 thirdPartyBlackList.add(singleEntry);
871 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + entry + " - " + originalBlockListEntry);
875 } else if (blockListEntry.startsWith("|")) { // Third-party initial black list entries.
876 // Strip the initial `|`.
877 blockListEntry = blockListEntry.substring(1);
880 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
882 if (entry.contains("*")) { // Process a third-party initial black list double entry.
883 // Get the index of the wildcard.
884 int wildcardIndex = entry.indexOf("*");
886 // Split the entry into components.
887 String firstEntry = entry.substring(0, wildcardIndex);
888 String secondEntry = entry.substring(wildcardIndex + 1);
890 // Create an entry string array.
891 String[] thirdPartyDoubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
893 // Add the entry to the black list.
894 thirdPartyInitialBlackList.add(thirdPartyDoubleEntry);
896 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
897 } else { // Process a third-party initial black list single entry.
898 // Create an entry string array.
899 String[] singleEntry = {entry, originalBlockListEntry};
901 // Add the entry to the black list.
902 thirdPartyInitialBlackList.add(singleEntry);
904 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + entry + " - " + originalBlockListEntry);
906 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
907 // Prepare a string to hold the entry.
911 if (blockListEntry.contains("$/$")) { // The first `$` is part of the regular expression.
912 entry = blockListEntry.substring(0, blockListEntry.indexOf("$/$") + 2);
913 } else { // The only `$` indicates the filter options.
914 entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
917 // Create an entry string array.
918 String[] singleEntry = {entry, originalBlockListEntry};
920 // Add the entry to the black list.
921 thirdPartyRegularExpressionBlackList.add(singleEntry);
923 //Log.i("BlockLists", headers.get(1)[0] + " third-party regular expression black list added: " + entry + " - " + originalBlockListEntry);
924 } else if (blockListEntry.contains("*")) { // Third-party and regular expression black list entries.
926 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
928 if (entry.endsWith("*")) { // Process a third-party black list single entry.
929 // Strip the final `*`.
930 entry = entry.substring(0, entry.length() - 1);
932 // Create an entry string array.
933 String[] singleEntry = {entry, originalBlockListEntry};
935 // Add the entry to the black list.
936 thirdPartyBlackList.add(singleEntry);
938 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
939 } else { // There are two or more entries.
940 // Get the index of the wildcard.
941 int wildcardIndex = entry.indexOf("*");
943 // Split the entry into components.
944 String firstEntry = entry.substring(0, wildcardIndex);
945 String secondEntry = entry.substring(wildcardIndex + 1);
947 if (secondEntry.contains("*")) { // There are three or more entries.
948 // Get the index of the wildcard.
949 int secondWildcardIndex = secondEntry.indexOf("*");
951 // Split the entry into components.
952 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
953 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
955 if (thirdEntry.contains("*")) { // Process a third-party black list quadruple entry.
956 // Get the index of the wildcard.
957 int thirdWildcardIndex = thirdEntry.indexOf("*");
959 // Split the entry into components.
960 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
961 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
963 // Create an entry string array.
964 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
966 // Add the entry to the black list.
967 thirdPartyBlackList.add(quadrupleEntry);
969 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
970 // fourthEntry + " - " + originalBlockListEntry);
971 } else { // Process a third-party black list triple entry.
972 // Create an entry string array.
973 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
975 // Add the entry to the black list.
976 thirdPartyBlackList.add(tripleEntry);
978 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
979 // originalBlockListEntry);
981 } else { // Process a third-party black list double entry.
982 // Create an entry string array.
983 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
985 // Add the entry to the black list.
986 thirdPartyBlackList.add(doubleEntry);
988 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
991 } else { // Process a third party black list single entry.
993 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
995 // Create an entry string array.
996 String[] singleEntry = {entry, originalBlockListEntry};
998 // Add the entry to the black list.
999 thirdPartyBlackList.add(singleEntry);
1001 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
1003 } else if (blockListEntry.substring(blockListEntry.indexOf("$")).contains("domain=")) { // Domain entries.
1004 if (blockListEntry.contains("~")) { // Domain white list entries.
1005 // Separate the filters.
1006 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1007 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1008 String domains = filters.substring(filters.indexOf("domain=") + 7);
1010 // Strip any final `*` from the entry. They are redundant.
1011 if (entry.endsWith("*")) {
1012 entry = entry.substring(0, entry.length() - 1);
1015 // Process each domain.
1017 // Create a string to keep track of the current domain.
1020 if (domains.contains("|")) { // There is more than one domain in the list.
1021 // Get the first domain from the list.
1022 domain = domains.substring(0, domains.indexOf("|"));
1024 // Remove the first domain from the list.
1025 domains = domains.substring(domains.indexOf("|") + 1);
1026 } else { // There is only one domain in the list.
1030 // Strip the initial `~`.
1031 domain = domain.substring(1);
1033 if (entry.contains("*")) { // There are two or more entries.
1034 // Get the index of the wildcard.
1035 int wildcardIndex = entry.indexOf("*");
1037 // Split the entry into components.
1038 String firstEntry = entry.substring(0, wildcardIndex);
1039 String secondEntry = entry.substring(wildcardIndex + 1);
1041 if (secondEntry.contains("*")) { // Process a domain white list triple entry.
1042 // Get the index of the wildcard.
1043 int secondWildcardIndex = secondEntry.indexOf("*");
1045 // Split the entry into components.
1046 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1047 String thirdEntry = secondEntry.substring((secondWildcardIndex + 1));
1049 // Create an entry string array.
1050 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1052 // Add the entry to the white list.
1053 domainWhiteList.add(domainTripleEntry);
1055 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1056 // " - " + originalBlockListEntry);
1057 } else { // Process a domain white list double entry.
1058 // Create an entry string array.
1059 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1061 // Add the entry to the white list.
1062 domainWhiteList.add(domainDoubleEntry);
1064 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1066 } else { // Process a domain white list single entry.
1067 // Create an entry string array.
1068 String[] domainEntry = {domain, entry, originalBlockListEntry};
1070 // Add the entry to the white list.
1071 domainWhiteList.add(domainEntry);
1073 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1075 } while (domains.contains("|"));
1076 } else { // Domain black list entries.
1077 // Separate the filters.
1078 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1079 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1080 String domains = filters.substring(filters.indexOf("domain=") + 7);
1082 // Only process the item if the entry is not null. For example, some lines begin with `$websocket`, which create a null entry.
1083 if (!entry.equals("")) {
1084 // Process each domain.
1086 // Create a string to keep track of the current domain.
1089 if (domains.contains("|")) { // There is more than one domain in the list.
1090 // Get the first domain from the list.
1091 domain = domains.substring(0, domains.indexOf("|"));
1093 // Remove the first domain from the list.
1094 domains = domains.substring(domains.indexOf("|") + 1);
1095 } else { // There is only one domain in the list.
1099 if (entry.startsWith("|")) { // Domain initial black list entries.
1100 // Remove the initial `|`;
1101 String entryBase = entry.substring(1);
1103 //noinspection StatementWithEmptyBody
1104 if (entryBase.equals("http://") || entryBase.equals("https://")) {
1105 // Do nothing. These entries will entirely block the website.
1106 // Often the original entry blocks `$script` but Privacy Browser does not currently differentiate between scripts and other entries.
1108 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
1109 } else { // Process a domain initial black list entry
1110 // Create an entry string array.
1111 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1113 // Add the entry to the black list.
1114 domainInitialBlackList.add(domainEntry);
1116 //Log.i("BlockLists", headers.get(1)[0] + " domain initial black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1118 } else if (entry.endsWith("|")) { // Domain final black list entries.
1119 // Remove the final `|`.
1120 String entryBase = entry.substring(0, entry.length() - 1);
1122 if (entryBase.contains("*")) { // Process a domain final black list double entry.
1123 // Get the index of the wildcard.
1124 int wildcardIndex = entry.indexOf("*");
1126 // Split the entry into components.
1127 String firstEntry = entryBase.substring(0, wildcardIndex);
1128 String secondEntry = entryBase.substring(wildcardIndex + 1);
1130 // Create an entry string array.
1131 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1133 // Add the entry to the black list.
1134 domainFinalBlackList.add(domainDoubleEntry);
1136 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1137 // originalBlockListEntry);
1138 } else { // Process a domain final black list single entry.
1139 // Create an entry string array.
1140 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1142 // Add the entry to the black list.
1143 domainFinalBlackList.add(domainEntry);
1145 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1147 } else if (entry.contains("\\")) { // Process a domain regular expression black list entry.
1148 // Create an entry string array.
1149 String[] domainEntry = {domain, entry, originalBlockListEntry};
1151 // Add the entry to the black list.
1152 domainRegularExpressionBlackList.add(domainEntry);
1154 //Log.i("BlockLists", headers.get(1)[0] + " domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1155 } else if (entry.contains("*")) { // There are two or more entries.
1156 // Get the index of the wildcard.
1157 int wildcardIndex = entry.indexOf("*");
1159 // Split the entry into components.
1160 String firstEntry = entry.substring(0, wildcardIndex);
1161 String secondEntry = entry.substring(wildcardIndex + 1);
1163 if (secondEntry.contains("*")) { // Process a domain black list triple entry.
1164 // Get the index of the wildcard.
1165 int secondWildcardIndex = secondEntry.indexOf("*");
1167 // Split the entry into components.
1168 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1169 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1171 // Create an entry string array.
1172 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1174 // Add the entry to the black list.
1175 domainBlackList.add(domainTripleEntry);
1177 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1178 // " - " + originalBlockListEntry);
1179 } else { // Process a domain black list double entry.
1180 // Create an entry string array.
1181 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1183 // Add the entry to the black list.
1184 domainBlackList.add(domainDoubleEntry);
1186 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1187 // originalBlockListEntry);
1189 } else { // Process a domain black list single entry.
1190 // Create an entry string array.
1191 String[] domainEntry = {domain, entry, originalBlockListEntry};
1193 // Add the entry to the black list.
1194 domainBlackList.add(domainEntry);
1196 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1198 } while (domains.contains("|"));
1201 } else if (blockListEntry.contains("~")) { // White list entries. Privacy Browser does not differentiate against these filter options, so they are just generally white listed.
1202 // Remove the filter options.
1203 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1205 // Strip any trailing `*`.
1206 if (blockListEntry.endsWith("*")) {
1207 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1210 if (blockListEntry.contains("*")) { // Process a white list double entry.
1211 // Get the index of the wildcard.
1212 int wildcardIndex = blockListEntry.indexOf("*");
1214 // Split the entry into components.
1215 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1216 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1218 // Create an entry string array.
1219 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1221 // Add the entry to the white list.
1222 mainWhiteList.add(doubleEntry);
1224 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1225 } else { // Process a white list single entry.
1226 // Create an entry string array.
1227 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1229 // Add the entry to the white list.
1230 mainWhiteList.add(singleEntry);
1232 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - + " + originalBlockListEntry);
1234 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
1235 // Remove the filter options.
1236 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1238 // Create an entry string array.
1239 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1241 // Add the entry to the black list.
1242 regularExpressionBlackList.add(singleEntry);
1244 //Log.i("BlockLists", headers.get(1)[0] + " regular expression black list added: " + blockListEntry + " - " + originalBlockListEntry);
1245 } else { // Black list entries.
1246 // Remove the filter options.
1247 if (!blockListEntry.contains("$file")) { // EasyPrivacy contains an entry with `$file` that does not have filter options.
1248 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1251 // Strip any trailing `*`. These are redundant.
1252 if (blockListEntry.endsWith("*")) {
1253 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1256 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1257 // Strip the initial `|`.
1258 String entry = blockListEntry.substring(1);
1260 if (entry.contains("*")) { // Process an initial black list double entry.
1261 // Get the index of the wildcard.
1262 int wildcardIndex = entry.indexOf("*");
1264 // Split the entry into components.
1265 String firstEntry = entry.substring(0, wildcardIndex);
1266 String secondEntry = entry.substring(wildcardIndex + 1);
1268 // Create an entry string array.
1269 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1271 // Add the entry to the black list.
1272 initialBlackList.add(doubleEntry);
1274 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1275 } else { // Process an initial black list single entry.
1276 // Create an entry string array.
1277 String[] singleEntry = {entry, originalBlockListEntry};
1279 // Add the entry to the black list.
1280 initialBlackList.add(singleEntry);
1282 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1284 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1285 // Ignore entries with `object` filters. They can block entire websites and don't have any meaning in the context of Privacy Browser.
1286 if (!originalBlockListEntry.contains("$object")) {
1287 // Strip the final `|`.
1288 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1290 if (entry.contains("*")) { // There are two or more entries.
1291 // Get the index of the wildcard.
1292 int wildcardIndex = entry.indexOf("*");
1294 // Split the entry into components.
1295 String firstEntry = entry.substring(0, wildcardIndex);
1296 String secondEntry = entry.substring(wildcardIndex + 1);
1298 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1299 // Get the index of the wildcard.
1300 int secondWildcardIndex = secondEntry.indexOf("*");
1302 // Split the entry into components.
1303 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1304 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1306 // Create an entry string array.
1307 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1309 // Add the entry to the black list.
1310 finalBlackList.add(tripleEntry);
1312 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1313 // originalBlockListEntry);
1314 } else { // Process a final black list double entry.
1315 // Create an entry string array.
1316 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1318 // Add the entry to the black list.
1319 finalBlackList.add(doubleEntry);
1321 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1323 } else { // Process a final black list single entry.
1324 // Create an entry sting array.
1325 String[] singleEntry = {entry, originalBlockListEntry};
1327 // Add the entry to the black list.
1328 finalBlackList.add(singleEntry);
1330 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1333 } else if (blockListEntry.contains("*")) { // There are two or more entries.
1334 // Get the index of the wildcard.
1335 int wildcardIndex = blockListEntry.indexOf("*");
1337 // Split the entry into components.
1338 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1339 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1341 if (secondEntry.contains("*")) { // Process a main black list triple entry.
1342 // Get the index of the wildcard.
1343 int secondWildcardIndex = secondEntry.indexOf("*");
1345 // Split the entry into components.
1346 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1347 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1349 // Create an entry string array.
1350 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1352 // Add the entry to the black list.
1353 mainBlackList.add(tripleEntry);
1355 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1356 } else { // Process a main black list double entry.
1357 // Create an entry string array.
1358 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1360 // Add the entry to the black list.
1361 mainBlackList.add(doubleEntry);
1363 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1365 } else { // Process a main black list single entry.
1366 // Create an entry string array.
1367 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1369 // Add the entry to the black list.
1370 mainBlackList.add(singleEntry);
1372 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1375 } else { // Main black list entries
1376 // Strip out any initial `||`. These will be treated like any other entry.
1377 if (blockListEntry.startsWith("||")) {
1378 blockListEntry = blockListEntry.substring(2);
1381 // Strip out any initial `*`.
1382 if (blockListEntry.startsWith("*")) {
1383 blockListEntry = blockListEntry.substring(1);
1386 // Strip out any trailing `*`.
1387 if (blockListEntry.endsWith("*")) {
1388 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1391 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1392 // Strip the initial `|`.
1393 String entry = blockListEntry.substring(1);
1395 if (entry.contains("*")) { // Process an initial black list double entry.
1396 // Get the index of the wildcard.
1397 int wildcardIndex = entry.indexOf("*");
1399 // Split the entry into components.
1400 String firstEntry = entry.substring(0, wildcardIndex);
1401 String secondEntry = entry.substring(wildcardIndex + 1);
1403 // Create an entry string array.
1404 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1406 // Add the entry to the black list.
1407 initialBlackList.add(doubleEntry);
1409 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1410 } else { // Process an initial black list single entry.
1411 // Create an entry string array.
1412 String[] singleEntry = {entry, originalBlockListEntry};
1414 // Add the entry to the black list.
1415 initialBlackList.add(singleEntry);
1417 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1419 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1420 // Strip the final `|`.
1421 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1423 if (entry.contains("*")) { // There are two or more entries.
1424 // Get the index of the wildcard.
1425 int wildcardIndex = entry.indexOf("*");
1427 // Split the entry into components.
1428 String firstEntry = entry.substring(0, wildcardIndex);
1429 String secondEntry = entry.substring(wildcardIndex + 1);
1431 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1432 // Get the index of the wildcard.
1433 int secondWildcardIndex = secondEntry.indexOf("*");
1435 // Split the entry into components.
1436 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1437 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1439 // Create an entry string array.
1440 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1442 // Add the entry to the black list.
1443 finalBlackList.add(tripleEntry);
1445 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1446 // originalBlockListEntry);
1447 } else { // Process a final black list double entry.
1448 // Create an entry string array.
1449 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1451 // Add the entry to the black list.
1452 finalBlackList.add(doubleEntry);
1454 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1456 } else { // Process a final black list single entry.
1457 // Create an entry string array.
1458 String[] singleEntry = {entry, originalBlockListEntry};
1460 // Add the entry to the black list.
1461 finalBlackList.add(singleEntry);
1463 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1465 } else { // Main black list entries.
1466 if (blockListEntry.contains("*")) { // There are two or more entries.
1467 // Get the index of the wildcard.
1468 int wildcardIndex = blockListEntry.indexOf("*");
1470 // Split the entry into components.
1471 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1472 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1474 if (secondEntry.contains("*")) { // There are three or more entries.
1475 // Get the index of the wildcard.
1476 int secondWildcardIndex = secondEntry.indexOf("*");
1478 // Split the entry into components.
1479 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1480 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1482 if (thirdEntry.contains("*")) { // There are four or more entries.
1483 // Get the index of the wildcard.
1484 int thirdWildcardIndex = thirdEntry.indexOf("*");
1486 // Split the entry into components.
1487 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
1488 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
1490 if (fourthEntry.contains("*")) { // Process a main black list quintuple entry.
1491 // Get the index of the wildcard.
1492 int fourthWildcardIndex = fourthEntry.indexOf("*");
1494 // Split the entry into components.
1495 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
1496 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
1498 // Create an entry string array.
1499 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
1501 // Add the entry to the black list.
1502 mainBlackList.add(quintupleEntry);
1504 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1505 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
1506 } else { // Process a main black list quadruple entry.
1507 // Create an entry string array.
1508 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
1510 // Add the entry to the black list.
1511 mainBlackList.add(quadrupleEntry);
1513 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1514 // fourthEntry + " - " + originalBlockListEntry);
1516 } else { // Process a main black list triple entry.
1517 // Create an entry string array.
1518 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1520 // Add the entry to the black list.
1521 mainBlackList.add(tripleEntry);
1523 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1525 } else { // Process a main black list double entry.
1526 // Create an entry string array.
1527 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1529 // Add the entry to the black list.
1530 mainBlackList.add(doubleEntry);
1532 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1534 } else { // Process a main black list single entry.
1535 // Create an entry string array.
1536 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1538 // Add the entry to the black list.
1539 mainBlackList.add(singleEntry);
1541 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1546 // Close `bufferedReader`.
1547 bufferedReader.close();
1548 } catch (IOException e) {
1549 // The asset exists, so the `IOException` will never be thrown.
1552 // Initialize the combined list.
1553 ArrayList<List<String[]>> combinedLists = new ArrayList<>();
1555 // Add the headers (0).
1556 combinedLists.add(headers); // 0.
1558 // Add the white lists (1-8).
1559 combinedLists.add(mainWhiteList); // 1.
1560 combinedLists.add(finalWhiteList); // 2.
1561 combinedLists.add(domainWhiteList); // 3.
1562 combinedLists.add(domainInitialWhiteList); // 4.
1563 combinedLists.add(domainFinalWhiteList); // 5.
1564 combinedLists.add(thirdPartyWhiteList); // 6.
1565 combinedLists.add(thirdPartyDomainWhiteList); // 7.
1566 combinedLists.add(thirdPartyDomainInitialWhiteList); // 8.
1568 // Add the black lists (9-22).
1569 combinedLists.add(mainBlackList); // 9.
1570 combinedLists.add(initialBlackList); // 10.
1571 combinedLists.add(finalBlackList); // 11.
1572 combinedLists.add(domainBlackList); // 12.
1573 combinedLists.add(domainInitialBlackList); // 13.
1574 combinedLists.add(domainFinalBlackList); // 14.
1575 combinedLists.add(domainRegularExpressionBlackList); // 15.
1576 combinedLists.add(thirdPartyBlackList); // 16.
1577 combinedLists.add(thirdPartyInitialBlackList); // 17.
1578 combinedLists.add(thirdPartyDomainBlackList); // 18.
1579 combinedLists.add(thirdPartyDomainInitialBlackList); // 19.
1580 combinedLists.add(thirdPartyRegularExpressionBlackList); // 20.
1581 combinedLists.add(thirdPartyDomainRegularExpressionBlackList); // 21.
1582 combinedLists.add(regularExpressionBlackList); // 22.
1584 return combinedLists;
1587 public boolean isBlocked(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList<List<String[]>> blockList) {
1588 // Get the block list name.
1589 String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0];
1591 // Assert that currentDomain != null only if this is a third party request. Apparently, lint can't tell that this isn't redundant.
1592 //noinspection RedundantIfStatement
1593 if (isThirdPartyRequest) {
1594 assert currentDomain != null;
1597 // Process the white lists.
1599 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.MAIN_WHITELIST)) {
1600 switch (whiteListEntry.length) {
1601 case 2: // There is one entry.
1602 if (resourceUrl.contains(whiteListEntry[0])) {
1603 // Store the entry in the resource request log.
1604 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1605 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1612 case 3: // There are two entries.
1613 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1614 // Store the entry in the resource request log.
1615 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1616 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1],
1624 case 4: // There are three entries.
1625 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1626 // Store the entry in the resource request log.
1627 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1628 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1637 // Final white list.
1638 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.FINAL_WHITELIST)) {
1639 if (whiteListEntry.length == 2) { // There is one entry.
1640 if (resourceUrl.contains(whiteListEntry[0])) {
1641 // Store the entry in the resource request log.
1642 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1643 String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1648 } else { // There are two entries.
1649 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1650 // Store the entry in the resource request log.
1651 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1652 String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1660 // Only check the domain lists if the current domain is not null (like `about:blank`).
1661 if (currentDomain != null) {
1662 // Domain white list.
1663 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_WHITELIST)) {
1664 switch (whiteListEntry.length) {
1665 case 3: // There is one entry.
1666 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1667 // Store the entry in the resource request log.
1668 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1669 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1676 case 4: // There are two entries.
1677 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1678 // Store the entry in the resource request log.
1679 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1680 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1687 case 5: // There are three entries.
1688 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1689 // Store the entry in the resource request log.
1690 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1691 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1699 case 6: // There are four entries.
1700 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1701 resourceUrl.contains(whiteListEntry[4])) {
1702 // Store the entry in the resource request log.
1703 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1704 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1705 whiteListEntry[4], whiteListEntry[5]};
1714 // Domain initial white list.
1715 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST)) {
1716 switch (whiteListEntry.length) {
1717 case 3: // There is one entry.
1718 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1719 // Store the entry in the resource request log.
1720 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1721 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1728 case 4: // There are two entries.
1729 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1730 // Store the entry in the resource request log.
1731 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1732 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1739 case 5: // There are three entries.
1740 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) {
1741 // Store the entry in the resource request log.
1742 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1743 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1753 // Domain final white list.
1754 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_WHITELIST)) {
1755 switch (whiteListEntry.length) {
1756 case 3: // There is one entry;
1757 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) {
1758 // Store the entry in the resource request log.
1759 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1760 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1767 case 4: // There are two entries;
1768 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) {
1769 // Store the entry in the resource request log.
1770 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1771 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1782 // Only check the third-party white lists if this is a third-party request.
1783 if (isThirdPartyRequest) {
1784 // Third-party white list.
1785 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_WHITELIST)) {
1786 switch (whiteListEntry.length) {
1787 case 2: // There is one entry
1788 if (resourceUrl.contains(whiteListEntry[0])) {
1789 // Store the entry in the resource request log.
1790 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1791 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1798 case 3: // There are two entries.
1799 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1800 // Store the entry in the resource request log.
1801 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1802 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1809 case 4: // There are three entries.
1810 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1811 // Store the entry in the resource request log.
1812 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1813 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1820 case 5: // There are four entries.
1821 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1822 // Store the entry in the resource request log.
1823 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1824 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1831 case 6: // There are five entries.
1832 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1833 resourceUrl.contains(whiteListEntry[4])) {
1834 // Store the entry in the resource request log.
1835 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1836 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1837 whiteListEntry[4], whiteListEntry[5]};
1846 // Third-party domain white list.
1847 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST)) {
1848 if (whiteListEntry.length == 3) { // There is one entry.
1849 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1850 // Store the entry in the resource request log.
1851 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1852 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1857 } else { // There are two entries.
1858 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1859 // Store the entry in the resource request log.
1860 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1861 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1869 // Third-party domain initial white list.
1870 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST)) {
1871 if (whiteListEntry.length == 3) { // There is one entry.
1872 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1873 // Store the entry in the resource request log.
1874 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1875 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1880 } else { // There are two entries.
1881 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1882 // Store the entry in the resource request log.
1883 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1884 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1893 // Process the black lists.
1895 for (String[] blackListEntry : blockList.get(MainWebViewActivity.MAIN_BLACKLIST)) {
1896 switch (blackListEntry.length) {
1897 case 2: // There is one entry.
1898 if (resourceUrl.contains(blackListEntry[0])) {
1899 // Store the entry in the resource request log.
1900 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1901 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1908 case 3: // There are two entries.
1909 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1910 // Store the entry in the resource request log.
1911 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1912 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1919 case 4: // There are three entries.
1920 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
1921 // Store the entry in the resource request log.
1922 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1923 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
1930 case 5: // There are four entries.
1931 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
1932 // Store the entry in the resource request log.
1933 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1934 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]});
1941 case 6: // There are five entries.
1942 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) &&
1943 resourceUrl.contains(blackListEntry[4])) {
1944 // Store the entry in the resource request log.
1945 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1946 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3] + "\n" +
1947 blackListEntry[4], blackListEntry[5]});
1956 // Initial black list.
1957 for (String[] blackListEntry : blockList.get(MainWebViewActivity.INITIAL_BLACKLIST)) {
1958 if (blackListEntry.length == 2) { // There is one entry.
1959 if (resourceUrl.startsWith(blackListEntry[0])) {
1960 // Store the entry in the resource request log.
1961 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1962 String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1967 } else { // There are two entries
1968 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1969 // Store the entry in the resource request log.
1970 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1971 String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1979 // Final black list.
1980 for (String[] blackListEntry : blockList.get(MainWebViewActivity.FINAL_BLACKLIST)) {
1981 switch (blackListEntry.length) {
1982 case 2: // There is one entry.
1983 if (resourceUrl.endsWith(blackListEntry[0])) {
1984 // Store the entry in the resource request log.
1985 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1986 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1993 case 3: // There are two entries.
1994 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
1995 // Store the entry in the resource request log.
1996 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1997 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2004 case 4: // There are three entries.
2005 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2006 // Store the entry in the resource request log.
2007 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2008 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2017 // Only check the domain lists if the current domain is not null (like `about:blank`).
2018 if (currentDomain != null) {
2019 // Domain black list.
2020 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_BLACKLIST)) {
2021 switch (blackListEntry.length) {
2022 case 3: // There is one entry.
2023 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2024 // Store the entry in the resource request log.
2025 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2026 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2033 case 4: // There are two entries.
2034 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2035 // Store the entry in the resource request log.
2036 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2037 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2044 case 5: // There are three entries.
2045 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2046 // Store the entry in the resource request log.
2047 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2048 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2049 blackListEntry[4]});
2058 // Domain initial black list.
2059 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST)) {
2060 // Store the entry in the resource request log.
2061 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2062 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2063 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1],
2064 blackListEntry[2]});
2071 // Domain final black list.
2072 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST)) {
2073 switch (blackListEntry.length) {
2074 case 3: // There is one entry.
2075 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
2076 // Store the entry in the resource request log.
2077 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2078 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2085 case 4: // There are two entries.
2086 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2087 // Store the entry in the resource request log.
2088 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2089 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2098 // Domain regular expression black list.
2099 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2100 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2101 // Store the entry in the resource request log.
2102 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2103 String.valueOf(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2111 // Only check the third-party black lists if this is a third-party request.
2112 if (isThirdPartyRequest) {
2113 // Third-party black list.
2114 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_BLACKLIST)) {
2115 switch (blackListEntry.length) {
2116 case 2: // There is one entry.
2117 if (resourceUrl.contains(blackListEntry[0])) {
2118 // Store the entry in the resource request log.
2119 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2120 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2127 case 3: // There are two entries.
2128 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2129 // Store the entry in the resource request log.
2130 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2131 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2138 case 4: // There are three entries.
2139 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2140 // Store the entry in the resource request log.
2141 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2142 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2149 case 5: // There are four entries.
2150 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2151 // Store the entry in the resource request log.
2152 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2153 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2154 blackListEntry[4]});
2163 // Third-party initial black list.
2164 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST)) {
2165 if (blackListEntry.length == 2) { // There is one entry.
2166 if (resourceUrl.startsWith(blackListEntry[0])) {
2167 // Store the entry in the resource request log.
2168 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2169 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2174 } else { // There are two entries.
2175 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2176 // Store the entry in the resource request log.
2177 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2178 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2186 // Third-party domain black list.
2187 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST)) {
2188 if (blackListEntry.length == 3) { // There is one entry.
2189 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2190 // Store the entry in the resource request log.
2191 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2192 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2197 } else { // There are two entries.
2198 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2199 // Store the entry in the resource request log.
2200 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2201 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2209 // Third-party domain initial black list.
2210 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST)) {
2211 switch (blackListEntry.length) {
2212 case 3: // There is one entry.
2213 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2214 // Store the entry in the resource request log.
2215 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2216 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2222 case 4: // There are two entries.
2223 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2224 // Store the entry in the resource request log.
2225 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2226 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2233 case 5: // There are three entries.
2234 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2235 // Store the entry in the resource request log.
2236 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2237 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2238 blackListEntry[4]});
2247 // Third-party regular expression black list.
2248 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST)) {
2249 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2250 // Store the entry in the resource request log.
2251 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2252 String.valueOf(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2259 // Third-party domain regular expression black list.
2260 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2261 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2262 // Store the entry in the resource request log.
2263 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2264 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2272 // Regular expression black list.
2273 for (String[] blackListEntry : blockList.get(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST)) {
2274 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2275 // Store the entry in the resource request log.
2276 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2277 String.valueOf(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});