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;
23 import android.net.Uri;
25 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
27 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.regex.Pattern;
34 public class BlockListHelper {
35 public ArrayList<List<String[]>> parseBlockList(AssetManager assets, String blockListName) {
36 // Initialize the header list.
37 List<String[]> headers = new ArrayList<>(); // 0.
39 // Initialize the white lists.
40 List<String[]> mainWhiteList = new ArrayList<>(); // 1.
41 List<String[]> finalWhiteList = new ArrayList<>(); // 2.
42 List<String[]> domainWhiteList = new ArrayList<>(); // 3.
43 List<String[]> domainInitialWhiteList = new ArrayList<>(); // 4.
44 List<String[]> domainFinalWhiteList = new ArrayList<>(); // 5.
45 List<String[]> thirdPartyWhiteList = new ArrayList<>(); // 6.
46 List<String[]> thirdPartyDomainWhiteList = new ArrayList<>(); // 7.
47 List<String[]> thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8.
49 // Initialize the black lists
50 List<String[]> mainBlackList = new ArrayList<>(); // 9.
51 List<String[]> initialBlackList = new ArrayList<>(); // 10.
52 List<String[]> finalBlackList = new ArrayList<>(); // 11.
53 List<String[]> domainBlackList = new ArrayList<>(); // 12.
54 List<String[]> domainInitialBlackList = new ArrayList<>(); // 13.
55 List<String[]> domainFinalBlackList = new ArrayList<>(); // 14.
56 List<String[]> domainRegularExpressionBlackList = new ArrayList<>(); // 15.
57 List<String[]> thirdPartyBlackList = new ArrayList<>(); // 16.
58 List<String[]> thirdPartyInitialBlackList = new ArrayList<>(); // 17.
59 List<String[]> thirdPartyDomainBlackList = new ArrayList<>(); // 18.
60 List<String[]> thirdPartyDomainInitialBlackList = new ArrayList<>(); // 19.
61 List<String[]> regularExpressionBlackList = new ArrayList<>(); // 20.
62 List<String[]> thirdPartyRegularExpressionBlackList = new ArrayList<>(); // 21.
63 List<String[]> thirdPartyDomainRegularExpressionBlackList = new ArrayList<>(); // 22.
66 // Populate the block lists. The `try` is required by `InputStreamReader`.
68 // Load the block list into a `BufferedReader`.
69 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assets.open(blockListName)));
71 // Create a string for storing the block list entries.
72 String blockListEntry;
74 // Parse the block list.
75 while ((blockListEntry = bufferedReader.readLine()) != null) {
76 // Store the original block list entry.
77 String originalBlockListEntry = blockListEntry;
79 // Remove any `^` from the block list entry. Privacy Browser does not process them in the interest of efficiency.
80 blockListEntry = blockListEntry.replace("^", "");
82 //noinspection StatementWithEmptyBody
83 if (blockListEntry.contains("##") || blockListEntry.contains("#?#") || blockListEntry.contains("#@#") || blockListEntry.startsWith("[")) {
84 // Entries that contain `##`, `#?#`, and `#@#` are for hiding elements in the main page's HTML. Entries that start with `[` describe the AdBlock compatibility level.
85 // Do nothing. Privacy Browser does not currently use these entries.
87 //Log.i("BlockLists", "Not added: " + blockListEntry);
88 } else if (blockListEntry.startsWith("!")) { // Comment entries.
89 if (blockListEntry.startsWith("! Version:")) {
90 // Get the list version number.
91 String[] listVersion = {blockListEntry.substring(11)};
93 // Store the list version in the headers list.
94 headers.add(listVersion);
97 if (blockListEntry.startsWith("! Title:")) {
98 // Get the list title.
99 String[] listTitle = {blockListEntry.substring(9)};
101 // Store the list title in the headers list.
102 headers.add(listTitle);
105 //Log.i("BlockLists", "Not added: " + blockListEntry);
106 } else if (blockListEntry.startsWith("@@")) { // Entries that begin with `@@` are whitelists.
108 blockListEntry = blockListEntry.substring(2);
110 // Strip out any initial `||`. Privacy Browser doesn't differentiate items that only match against the end of the domain name.
111 if (blockListEntry.startsWith("||")) {
112 blockListEntry = blockListEntry.substring(2);
115 if (blockListEntry.contains("$")) { // Filter entries.
116 //noinspection StatementWithEmptyBody
117 if (blockListEntry.contains("~third-party")) { // Ignore entries that contain `~third-party`.
120 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
121 } else if (blockListEntry.contains("third-party")) { // Third-party white list entries.
122 if (blockListEntry.contains("domain=")) { // Third-party domain white list entries.
124 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
125 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
126 String domains = filters.substring(filters.indexOf("domain=") + 7);
128 //noinspection StatementWithEmptyBody
129 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
132 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
133 } else if (blockListEntry.startsWith("|")) { // Third-party domain initial white list entries.
134 // Strip out the initial `|`.
135 entry = entry.substring(1);
137 //noinspection StatementWithEmptyBody
138 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
139 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
141 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
142 } else { // Process third-party domain initial white list entries.
143 // Process each domain.
145 // Create a string to keep track of the current domain.
148 if (domains.contains("|")) { // There is more than one domain in the list.
149 // Get the first domain from the list.
150 domain = domains.substring(0, domains.indexOf("|"));
152 // Remove the first domain from the list.
153 domains = domains.substring(domains.indexOf("|") + 1);
154 } else { // There is only one domain in the list.
158 if (entry.contains("*")) { // Process a third-party domain initial white list double entry.
159 // Get the index of the wildcard.
160 int wildcardIndex = entry.indexOf("*");
162 // Split the entry into components.
163 String firstEntry = entry.substring(0, wildcardIndex);
164 String secondEntry = entry.substring(wildcardIndex + 1);
166 // Create an entry string array.
167 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
169 // Add the entry to the white list.
170 thirdPartyDomainInitialWhiteList.add(domainDoubleEntry);
172 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + firstEntry + " , " + secondEntry +
173 // " - " + originalBlockListEntry);
174 } else { // Process a third-party domain initial white list single entry.
175 // Create a domain entry string array.
176 String[] domainEntry = {domain, entry, originalBlockListEntry};
178 // Add the entry to the third party domain initial white list.
179 thirdPartyDomainInitialWhiteList.add(domainEntry);
181 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
183 } while (domains.contains("|"));
185 } else { // Third-party domain entries.
186 // Process each domain.
188 // Create a string to keep track of the current domain.
191 if (domains.contains("|")) { // three is more than one domain in the list.
192 // Get the first domain from the list.
193 domain = domains.substring(0, domains.indexOf("|"));
195 // Remove the first domain from the list.
196 domains = domains.substring(domains.indexOf("|") + 1);
197 } else { // There is only one domain in the list.
201 // Remove any trailing `*` from the entry.
202 if (entry.endsWith("*")) {
203 entry = entry.substring(0, entry.length() - 1);
206 if (entry.contains("*")) { // Process a third-party domain double entry.
207 // Get the index of the wildcard.
208 int wildcardIndex = entry.indexOf("*");
210 // Split the entry into components.
211 String firstEntry = entry.substring(0, wildcardIndex);
212 String secondEntry = entry.substring(wildcardIndex + 1);
214 // Create an entry string array.
215 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
217 // Add the entry to the white list.
218 thirdPartyDomainWhiteList.add(domainDoubleEntry);
220 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
221 // originalBlockListEntry);
222 } else { // Process a third-party domain single entry.
223 // Create an entry string array.
224 String[] domainEntry = {domain, entry, originalBlockListEntry};
226 // Add the entry to the white list.
227 thirdPartyDomainWhiteList.add(domainEntry);
229 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
231 } while (domains.contains("|"));
233 } else { // Process third-party white list entries.
235 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
237 if (entry.contains("*")) { // There are two or more entries.
238 // Get the index of the wildcard.
239 int wildcardIndex = entry.indexOf("*");
241 // Split the entry into components.
242 String firstEntry = entry.substring(0, wildcardIndex);
243 String secondEntry = entry.substring(wildcardIndex + 1);
245 if (secondEntry.contains("*")) { // There are three or more entries.
246 // Get the index of the wildcard.
247 int secondWildcardIndex = secondEntry.indexOf("*");
249 // Split the entry into components.
250 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
251 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
253 if (thirdEntry.contains("*")) { // There are four or more entries.
254 // Get the index of the wildcard.
255 int thirdWildcardIndex = thirdEntry.indexOf("*");
257 // Split the entry into components.
258 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
259 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
261 if (fourthEntry.contains("*")) { // Process a third-party white list quintuple entry.
262 // Get the index of the wildcard.
263 int fourthWildcardIndex = fourthEntry.indexOf("*");
265 // Split the entry into components.
266 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
267 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
269 // Create an entry string array.
270 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
272 // Add the entry to the white list.
273 thirdPartyWhiteList.add(quintupleEntry);
275 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
276 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
277 } else { // Process a third-party white list quadruple entry.
278 // Create an entry string array.
279 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
281 // Add the entry to the white list.
282 thirdPartyWhiteList.add(quadrupleEntry);
284 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
285 // fourthEntry + " - " + originalBlockListEntry);
287 } else { // Process a third-party white list triple entry.
288 // Create an entry string array.
289 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
291 // Add the entry to the white list.
292 thirdPartyWhiteList.add(tripleEntry);
294 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
295 // originalBlockListEntry);
297 } else { // Process a third-party white list double entry.
298 // Create an entry string array.
299 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
301 // Add the entry to the white list.
302 thirdPartyWhiteList.add(doubleEntry);
304 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
306 } else { // Process a third-party white list single entry.
307 // Create an entry string array.
308 String[] singleEntry = {entry, originalBlockListEntry};
310 // Add the entry to the white list.
311 thirdPartyWhiteList.add(singleEntry);
313 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + entry + " - " + originalBlockListEntry);
316 } else if (blockListEntry.contains("domain=")) { // Process domain white list entries.
318 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
319 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
320 String domains = filters.substring(filters.indexOf("domain=") + 7);
322 if (entry.startsWith("|")) { // Initial domain white list entries.
323 // Strip the initial `|`.
324 entry = entry.substring(1);
326 //noinspection StatementWithEmptyBody
327 if (entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
328 // Do nothing. These entries are designed for filter options that Privacy Browser does not use.
330 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
331 } else { // Initial domain white list entry.
332 // Process each domain.
334 // Create a string to keep track of the current domain.
337 if (domains.contains("|")) { // There is more than one domain in the list.
338 // Get the first domain from the list.
339 domain = domains.substring(0, domains.indexOf("|"));
341 // Remove the first domain from the list.
342 domains = domains.substring(domains.indexOf("|") + 1);
343 } else { // There is only one domain in the list.
347 if (entry.contains("*")) { // There are two or more entries.
348 // Get the index of the wildcard.
349 int wildcardIndex = entry.indexOf("*");
351 // Split the entry into components.
352 String firstEntry = entry.substring(0, wildcardIndex);
353 String secondEntry = entry.substring(wildcardIndex + 1);
355 if (secondEntry.contains("*")) { // Process a domain initial triple entry.
356 // Get the index of the wildcard.
357 int secondWildcardIndex = secondEntry.indexOf("*");
359 // Split the entry into components.
360 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
361 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
363 // Create an entry string array.
364 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
366 // Add the entry to the white list.
367 domainInitialWhiteList.add(domainTripleEntry);
369 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
370 // thirdEntry + " - " + originalBlockListEntry);
371 } else { // Process a domain initial double entry.
372 // Create an entry string array.
373 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
375 // Add the entry to the white list.
376 domainInitialWhiteList.add(domainDoubleEntry);
378 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
379 // originalBlockListEntry);
381 } else { // Process a domain initial single entry.
382 // Create an entry string array.
383 String[] domainEntry = {domain, entry, originalBlockListEntry};
385 // Add the entry to the white list.
386 domainInitialWhiteList.add(domainEntry);
388 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + entry + " - " + originalBlockListEntry);
390 } while (domains.contains("|"));
392 } else if (entry.endsWith("|")) { // Final domain white list entries.
393 // Strip the `|` from the end of the entry.
394 entry = entry.substring(0, entry.length() - 1);
396 // Process each domain.
398 // Create a string to keep track of the current domain.
401 if (domains.contains("|")) { // There is more than one domain in the list.
402 // Get the first domain from the list.
403 domain = domains.substring(0, domains.indexOf("|"));
405 // Remove the first domain from the list.
406 domains = domains.substring(domains.indexOf("|") + 1);
407 } else { // There is only one domain in the list.
411 if (entry.contains("*")) { // Process a domain final white list double entry.
412 // Get the index of the wildcard.
413 int wildcardIndex = entry.indexOf("*");
415 // Split the entry into components.
416 String firstEntry = entry.substring(0, wildcardIndex);
417 String secondEntry = entry.substring(wildcardIndex + 1);
419 // Create an entry string array.
420 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
422 // Add the entry to the white list.
423 domainFinalWhiteList.add(domainDoubleEntry);
425 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
426 // originalBlockListEntry);
427 } else { // Process a domain final white list single entry.
428 // create an entry string array.
429 String[] domainEntry = {domain, entry, originalBlockListEntry};
431 // Add the entry to the white list.
432 domainFinalWhiteList.add(domainEntry);
434 //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
436 } while (domains.contains("|"));
438 } else { // Standard domain white list entries with filters.
439 //noinspection StatementWithEmptyBody
440 if (domains.contains("~")) { // It is uncertain what a `~` domain means inside an `@@` entry.
443 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
445 // Process each domain.
447 // Create a string to keep track of the current domain.
450 if (domains.contains("|")) { // There is more than one domain in the list.
451 // Get the first domain from the list.
452 domain = domains.substring(0, domains.indexOf("|"));
454 // Remove the first domain from the list.
455 domains = domains.substring(domains.indexOf("|") + 1);
456 } else { // There is only one domain in the list.
460 if (entry.contains("*")) { // There are two or more entries.
461 // Get the index of the wildcard.
462 int wildcardIndex = entry.indexOf("*");
464 // Split the entry into components.
465 String firstEntry = entry.substring(0, wildcardIndex);
466 String secondEntry = entry.substring(wildcardIndex + 1);
468 if (secondEntry.contains("*")) { // There are three or more entries.
469 // Get the index of the wildcard.
470 int secondWildcardIndex = secondEntry.indexOf("*");
472 // Split the entry into components.
473 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
474 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
476 if (thirdEntry.contains("*")) { // Process a domain white list quadruple entry.
477 // Get the index of the wildcard.
478 int thirdWildcardIndex = thirdEntry.indexOf("*");
480 // Split the entry into components.
481 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
482 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
484 // Create an entry string array.
485 String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
487 // Add the entry to the white list.
488 domainWhiteList.add(domainQuadrupleEntry);
490 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
491 // realThirdEntry + " , " + fourthEntry + " - " + originalBlockListEntry);
492 } else { // Process a domain white list triple entry.
493 // Create an entry string array.
494 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
496 // Add the entry to the white list.
497 domainWhiteList.add(domainTripleEntry);
499 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
500 // thirdEntry + " - " + originalBlockListEntry);
502 } else { // Process a domain white list double entry.
503 // Create an entry string array.
504 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
506 // Add the entry to the white list.
507 domainWhiteList.add(domainDoubleEntry);
509 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
510 // originalBlockListEntry);
512 } else { // Process a domain white list single entry.
513 // Create an entry string array.
514 String[] domainEntry = {domain, entry, originalBlockListEntry};
516 // Add the entry to the white list.
517 domainWhiteList.add(domainEntry);
519 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + entry + " - " + originalBlockListEntry);
521 } while (domains.contains("|"));
524 } // Ignore all other filter entries.
525 } else if (blockListEntry.endsWith("|")) { // Final white list entries.
526 // Remove the final `|` from the entry.
527 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
529 if (entry.contains("*")) { // Process a final white list double entry
530 // Get the index of the wildcard.
531 int wildcardIndex = entry.indexOf("*");
533 // split the entry into components.
534 String firstEntry = entry.substring(0, wildcardIndex);
535 String secondEntry = entry.substring(wildcardIndex + 1);
537 // Create an entry string array.
538 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
540 // Add the entry to the white list.
541 finalWhiteList.add(doubleEntry);
543 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
544 } else { // Process a final white list single entry.
545 // Create an entry string array.
546 String[] singleEntry = {entry, originalBlockListEntry};
548 // Add the entry to the white list.
549 finalWhiteList.add(singleEntry);
551 //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + entry + " - " + originalBlockListEntry);
553 } else { // Main white list entries.
554 if (blockListEntry.contains("*")) { // There are two or more entries.
555 // Get the index of the wildcard.
556 int wildcardIndex = blockListEntry.indexOf("*");
558 // Split the entry into components.
559 String firstEntry = blockListEntry.substring(0, wildcardIndex);
560 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
562 if (secondEntry.contains("*")) { // Process a main white list triple entry.
563 // Get the index of the wildcard.
564 int secondWildcardIndex = secondEntry.indexOf("*");
566 // Split the entry into components.
567 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
568 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
570 // Create an entry string array.
571 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
573 // Add the entry to the white list.
574 mainWhiteList.add(tripleEntry);
576 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
577 } else { // Process a main white list double entry.
578 // Create an entry string array.
579 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
581 // Add the entry to the white list.
582 mainWhiteList.add(doubleEntry);
584 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
586 } else { // Process a main white list single entry.
587 // Create an entry string array.
588 String[] singleEntry = {blockListEntry, originalBlockListEntry};
590 // Add the entry to the white list.
591 mainWhiteList.add(singleEntry);
593 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - " + originalBlockListEntry);
596 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
597 // Strip out the final "|"
598 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
600 // Strip out any initial `||`. They are redundant in this case because the block list entry is being matched against the end of the URL.
601 if (entry.startsWith("||")) {
602 entry = entry.substring(2);
605 if (entry.contains("*")) { // Process a final black list double entry.
606 // Get the index of the wildcard.
607 int wildcardIndex = entry.indexOf("*");
609 // Split the entry into components.
610 String firstEntry = entry.substring(0, wildcardIndex);
611 String secondEntry = entry.substring(wildcardIndex + 1);
613 // Create an entry string array.
614 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
616 // Add the entry to the black list.
617 finalBlackList.add(doubleEntry);
619 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
620 } else { // Process a final black list single entry.
621 // create an entry string array.
622 String[] singleEntry = {entry, originalBlockListEntry};
624 // Add the entry to the black list.
625 finalBlackList.add(singleEntry);
627 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
629 } else if (blockListEntry.contains("$")) { // Entries with filter options.
630 // Strip out any initial `||`. These will be treated like any other entry.
631 if (blockListEntry.startsWith("||")) {
632 blockListEntry = blockListEntry.substring(2);
635 if (blockListEntry.contains("third-party")) { // Third-party entries.
636 //noinspection StatementWithEmptyBody
637 if (blockListEntry.contains("~third-party")) { // Third-party filter white list entries.
638 // 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`.
640 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
641 } else if (blockListEntry.contains("domain=")) { // Third-party domain entries.
642 if (blockListEntry.startsWith("|")) { // Third-party domain initial entries.
643 // Strip the initial `|`.
644 blockListEntry = blockListEntry.substring(1);
647 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
648 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
649 String domains = filters.substring(filters.indexOf("domain=") + 7);
651 //noinspection StatementWithEmptyBody
652 if (entry.equals("http:") || entry.equals("https:") || entry.equals("http://") || entry.equals("https://")) { // Ignore generic entries.
653 // Do nothing. These entries will almost entirely disable the website.
654 // Often the original entry blocks filter options like `$script`, which Privacy Browser does not differentiate.
656 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
657 } else { // Third-party domain initial entries.
658 // Process each domain.
660 // Create a string to keep track of the current domain.
663 if (domains.contains("|")) { // There is more than one domain in the list.
664 // Get the first domain from the list.
665 domain = domains.substring(0, domains.indexOf("|"));
667 // Remove the first domain from the list.
668 domains = domains.substring(domains.indexOf("|") + 1);
669 } else { // There is only one domain in the list.
673 if (entry.contains("*")) { // Three are two or more entries.
674 // Get the index of the wildcard.
675 int wildcardIndex = entry.indexOf("*");
677 // Split the entry into components.
678 String firstEntry = entry.substring(0, wildcardIndex);
679 String secondEntry = entry.substring(wildcardIndex + 1);
681 if (secondEntry.contains("*")) { // Process a third-party domain initial black list triple entry.
682 // Get the index of the wildcard.
683 int secondWildcardIndex = secondEntry.indexOf("*");
685 // Split the entry into components.
686 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
687 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
689 // Create an entry string array.
690 String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
692 // Add the entry to the black list.
693 thirdPartyDomainInitialBlackList.add(tripleDomainEntry);
695 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry +
696 // " , " + thirdEntry + " - " + originalBlockListEntry);
697 } else { // Process a third-party domain initial black list double entry.
698 // Create an entry string array.
699 String[] doubleDomainEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
701 // Add the entry to the black list.
702 thirdPartyDomainInitialBlackList.add(doubleDomainEntry);
704 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + secondEntry +
705 // " - " + originalBlockListEntry);
707 } else { // Process a third-party domain initial black list single entry.
708 // Create an entry string array.
709 String[] singleEntry = {domain, entry, originalBlockListEntry};
711 // Add the entry to the black list.
712 thirdPartyDomainInitialBlackList.add(singleEntry);
714 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
716 } while (domains.contains("|"));
718 } else if (blockListEntry.contains("\\")) { // Process a third-party domain black list regular expression.
719 // Parse the entry. At least one regular expression in this entry contains `$`, so the parser uses `/$`.
720 String entry = blockListEntry.substring(0, blockListEntry.indexOf("/$") + 1);
721 String filters = blockListEntry.substring(blockListEntry.indexOf("/$") + 2);
722 String domains = filters.substring(filters.indexOf("domain=") + 7);
724 // Process each domain.
726 // Create a string to keep track of the current domain.
729 if (domains.contains("|")) { // There is more than one domain in the list.
730 // Get the first domain from the list.
731 domain = domains.substring(0, domains.indexOf("|"));
733 // Remove the first domain from the list.
734 domains = domains.substring(domains.indexOf("|") + 1);
735 } else { // There is only one domain in the list.
739 // Create an entry string array.
740 String[] domainEntry = {domain, entry, originalBlockListEntry};
742 // Add the entry to the black list.
743 thirdPartyDomainRegularExpressionBlackList.add(domainEntry);
745 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
746 } while (domains.contains("|"));
747 } else { // Third-party domain entries.
749 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
750 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
751 String domains = filters.substring(filters.indexOf("domain=") + 7);
753 // Strip any trailing "*" from the entry.
754 if (entry.endsWith("*")) {
755 entry = entry.substring(0, entry.length() - 1);
758 // Track if any third-party white list filters are applied.
759 boolean whiteListDomain = false;
761 // Process each domain.
763 // Create a string to keep track of the current domain.
766 if (domains.contains("|")) { // There is more than one domain in the list.
767 // Get the first domain from the list.
768 domain = domains.substring(0, domains.indexOf("|"));
770 // Remove the first domain from the list.
771 domains = domains.substring(domains.indexOf("|") + 1);
772 } else { // The is only one domain in the list.
776 // Differentiate between block list domains and white list domains.
777 if (domain.startsWith("~")) { // White list third-party domain entry.
778 // Strip the initial `~`.
779 domain = domain.substring(1);
781 // Set the white list domain flag.
782 whiteListDomain = true;
784 if (entry.contains("*")) { // Process a third-party domain white list double entry.
785 // Get the index of the wildcard.
786 int wildcardIndex = entry.indexOf("*");
788 // Split the entry into components.
789 String firstEntry = entry.substring(0, wildcardIndex);
790 String secondEntry = entry.substring(wildcardIndex + 1);
792 // Create an entry string array.
793 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
795 // Add the entry to the white list.
796 thirdPartyDomainWhiteList.add(domainDoubleEntry);
798 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
799 // originalBlockListEntry);
800 } else { // Process a third-party domain white list single entry.
801 // Create an entry string array.
802 String[] domainEntry = {domain, entry, originalBlockListEntry};
804 // Add the entry to the white list.
805 thirdPartyDomainWhiteList.add(domainEntry);
807 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
809 } else { // Third-party domain black list entries.
810 if (entry.contains("*")) { // Process a third-party domain black list double entry.
811 // Get the index of the wildcard.
812 int wildcardIndex = entry.indexOf("*");
814 // Split the entry into components.
815 String firstEntry = entry.substring(0, wildcardIndex);
816 String secondEntry = entry.substring(wildcardIndex + 1);
818 // Create an entry string array.
819 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
821 // Add the entry to the black list
822 thirdPartyDomainBlackList.add(domainDoubleEntry);
824 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
825 // originalBlockListEntry);
826 } else { // Process a third-party domain black list single entry.
827 // Create an entry string array.
828 String[] domainEntry = {domain, entry, originalBlockListEntry};
830 // Add the entry to the black list.
831 thirdPartyDomainBlackList.add(domainEntry);
833 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain block list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
836 } while (domains.contains("|"));
838 // Add a third-party black list entry if a white list domain was processed.
839 if (whiteListDomain) {
840 if (entry.contains("*")) { // Process a third-party black list double entry.
841 // Get the index of the wildcard.
842 int wildcardIndex = entry.indexOf("*");
844 // Split the entry into components.
845 String firstEntry = entry.substring(0, wildcardIndex);
846 String secondEntry = entry.substring(wildcardIndex + 1);
848 // Create an entry string array.
849 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
851 // Add the entry to the black list.
852 thirdPartyBlackList.add(doubleEntry);
854 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
855 } else { // Process a third-party black list single entry.
856 // Create an entry string array.
857 String[] singleEntry = {entry, originalBlockListEntry};
859 // Add an entry to the black list.
860 thirdPartyBlackList.add(singleEntry);
862 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + entry + " - " + originalBlockListEntry);
866 } else if (blockListEntry.startsWith("|")) { // Third-party initial black list entries.
867 // Strip the initial `|`.
868 blockListEntry = blockListEntry.substring(1);
871 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
873 if (entry.contains("*")) { // Process a third-party initial black list double entry.
874 // Get the index of the wildcard.
875 int wildcardIndex = entry.indexOf("*");
877 // Split the entry into components.
878 String firstEntry = entry.substring(0, wildcardIndex);
879 String secondEntry = entry.substring(wildcardIndex + 1);
881 // Create an entry string array.
882 String[] thirdPartyDoubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
884 // Add the entry to the black list.
885 thirdPartyInitialBlackList.add(thirdPartyDoubleEntry);
887 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
888 } else { // Process a third-party initial black list single entry.
889 // Create an entry string array.
890 String[] singleEntry = {entry, originalBlockListEntry};
892 // Add the entry to the black list.
893 thirdPartyInitialBlackList.add(singleEntry);
895 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + entry + " - " + originalBlockListEntry);
897 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
898 // Prepare a string to hold the entry.
902 if (blockListEntry.contains("$/$")) { // The first `$` is part of the regular expression.
903 entry = blockListEntry.substring(0, blockListEntry.indexOf("$/$") + 2);
904 } else { // The only `$` indicates the filter options.
905 entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
908 // Create an entry string array.
909 String[] singleEntry = {entry, originalBlockListEntry};
911 // Add the entry to the black list.
912 thirdPartyRegularExpressionBlackList.add(singleEntry);
914 //Log.i("BlockLists", headers.get(1)[0] + " third-party regular expression black list added: " + entry + " - " + originalBlockListEntry);
915 } else if (blockListEntry.contains("*")) { // Third-party and regular expression black list entries.
917 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
919 if (entry.endsWith("*")) { // Process a third-party black list single entry.
920 // Strip the final `*`.
921 entry = entry.substring(0, entry.length() - 1);
923 // Create an entry string array.
924 String[] singleEntry = {entry, originalBlockListEntry};
926 // Add the entry to the black list.
927 thirdPartyBlackList.add(singleEntry);
929 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
930 } else { // There are two or more entries.
931 // Get the index of the wildcard.
932 int wildcardIndex = entry.indexOf("*");
934 // Split the entry into components.
935 String firstEntry = entry.substring(0, wildcardIndex);
936 String secondEntry = entry.substring(wildcardIndex + 1);
938 if (secondEntry.contains("*")) { // There are three or more entries.
939 // Get the index of the wildcard.
940 int secondWildcardIndex = secondEntry.indexOf("*");
942 // Split the entry into components.
943 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
944 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
946 if (thirdEntry.contains("*")) { // Process a third-party black list quadruple entry.
947 // Get the index of the wildcard.
948 int thirdWildcardIndex = thirdEntry.indexOf("*");
950 // Split the entry into components.
951 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
952 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
954 // Create an entry string array.
955 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
957 // Add the entry to the black list.
958 thirdPartyBlackList.add(quadrupleEntry);
960 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
961 // fourthEntry + " - " + originalBlockListEntry);
962 } else { // Process a third-party black list triple entry.
963 // Create an entry string array.
964 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
966 // Add the entry to the black list.
967 thirdPartyBlackList.add(tripleEntry);
969 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
970 // originalBlockListEntry);
972 } else { // Process a third-party black list double entry.
973 // Create an entry string array.
974 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
976 // Add the entry to the black list.
977 thirdPartyBlackList.add(doubleEntry);
979 //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
982 } else { // Process a third party black list single entry.
984 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
986 // Create an entry string array.
987 String[] singleEntry = {entry, originalBlockListEntry};
989 // Add the entry to the black list.
990 thirdPartyBlackList.add(singleEntry);
992 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + " - " + originalBlockListEntry);
994 } else if (blockListEntry.substring(blockListEntry.indexOf("$")).contains("domain=")) { // Domain entries.
995 if (blockListEntry.contains("~")) { // Domain white list entries.
996 // Separate the filters.
997 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
998 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
999 String domains = filters.substring(filters.indexOf("domain=") + 7);
1001 // Strip any final `*` from the entry. They are redundant.
1002 if (entry.endsWith("*")) {
1003 entry = entry.substring(0, entry.length() - 1);
1006 // Process each domain.
1008 // Create a string to keep track of the current domain.
1011 if (domains.contains("|")) { // There is more than one domain in the list.
1012 // Get the first domain from the list.
1013 domain = domains.substring(0, domains.indexOf("|"));
1015 // Remove the first domain from the list.
1016 domains = domains.substring(domains.indexOf("|") + 1);
1017 } else { // There is only one domain in the list.
1021 // Strip the initial `~`.
1022 domain = domain.substring(1);
1024 if (entry.contains("*")) { // There are two or more entries.
1025 // Get the index of the wildcard.
1026 int wildcardIndex = entry.indexOf("*");
1028 // Split the entry into components.
1029 String firstEntry = entry.substring(0, wildcardIndex);
1030 String secondEntry = entry.substring(wildcardIndex + 1);
1032 if (secondEntry.contains("*")) { // Process a domain white list triple entry.
1033 // Get the index of the wildcard.
1034 int secondWildcardIndex = secondEntry.indexOf("*");
1036 // Split the entry into components.
1037 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1038 String thirdEntry = secondEntry.substring((secondWildcardIndex + 1));
1040 // Create an entry string array.
1041 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1043 // Add the entry to the white list.
1044 domainWhiteList.add(domainTripleEntry);
1046 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1047 // " - " + originalBlockListEntry);
1048 } else { // Process a domain white list double entry.
1049 // Create an entry string array.
1050 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1052 // Add the entry to the white list.
1053 domainWhiteList.add(domainDoubleEntry);
1055 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1057 } else { // Process a domain white list single entry.
1058 // Create an entry string array.
1059 String[] domainEntry = {domain, entry, originalBlockListEntry};
1061 // Add the entry to the white list.
1062 domainWhiteList.add(domainEntry);
1064 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1066 } while (domains.contains("|"));
1067 } else { // Domain black list entries.
1068 // Separate the filters.
1069 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1070 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1071 String domains = filters.substring(filters.indexOf("domain=") + 7);
1073 // Only process the item if the entry is not null. For example, some lines begin with `$websocket`, which create a null entry.
1074 if (!entry.equals("")) {
1075 // Process each domain.
1077 // Create a string to keep track of the current domain.
1080 if (domains.contains("|")) { // There is more than one domain in the list.
1081 // Get the first domain from the list.
1082 domain = domains.substring(0, domains.indexOf("|"));
1084 // Remove the first domain from the list.
1085 domains = domains.substring(domains.indexOf("|") + 1);
1086 } else { // There is only one domain in the list.
1090 if (entry.startsWith("|")) { // Domain initial black list entries.
1091 // Remove the initial `|`;
1092 String entryBase = entry.substring(1);
1094 //noinspection StatementWithEmptyBody
1095 if (entryBase.equals("http://") || entryBase.equals("https://")) {
1096 // Do nothing. These entries will entirely block the website.
1097 // Often the original entry blocks `$script` but Privacy Browser does not currently differentiate between scripts and other entries.
1099 //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
1100 } else { // Process a domain initial black list entry
1101 // Create an entry string array.
1102 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1104 // Add the entry to the black list.
1105 domainInitialBlackList.add(domainEntry);
1107 //Log.i("BlockLists", headers.get(1)[0] + " domain initial black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1109 } else if (entry.endsWith("|")) { // Domain final black list entries.
1110 // Remove the final `|`.
1111 String entryBase = entry.substring(0, entry.length() - 1);
1113 if (entryBase.contains("*")) { // Process a domain final black list double entry.
1114 // Get the index of the wildcard.
1115 int wildcardIndex = entry.indexOf("*");
1117 // Split the entry into components.
1118 String firstEntry = entryBase.substring(0, wildcardIndex);
1119 String secondEntry = entryBase.substring(wildcardIndex + 1);
1121 // Create an entry string array.
1122 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1124 // Add the entry to the black list.
1125 domainFinalBlackList.add(domainDoubleEntry);
1127 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1128 // originalBlockListEntry);
1129 } else { // Process a domain final black list single entry.
1130 // Create an entry string array.
1131 String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1133 // Add the entry to the black list.
1134 domainFinalBlackList.add(domainEntry);
1136 //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + entryBase + " - " + originalBlockListEntry);
1138 } else if (entry.contains("\\")) { // Process a domain regular expression black list entry.
1139 // Create an entry string array.
1140 String[] domainEntry = {domain, entry, originalBlockListEntry};
1142 // Add the entry to the black list.
1143 domainRegularExpressionBlackList.add(domainEntry);
1145 //Log.i("BlockLists", headers.get(1)[0] + " domain regular expression black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1146 } else if (entry.contains("*")) { // There are two or more entries.
1147 // Get the index of the wildcard.
1148 int wildcardIndex = entry.indexOf("*");
1150 // Split the entry into components.
1151 String firstEntry = entry.substring(0, wildcardIndex);
1152 String secondEntry = entry.substring(wildcardIndex + 1);
1154 if (secondEntry.contains("*")) { // Process a domain black list triple entry.
1155 // Get the index of the wildcard.
1156 int secondWildcardIndex = secondEntry.indexOf("*");
1158 // Split the entry into components.
1159 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1160 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1162 // Create an entry string array.
1163 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1165 // Add the entry to the black list.
1166 domainBlackList.add(domainTripleEntry);
1168 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1169 // " - " + originalBlockListEntry);
1170 } else { // Process a domain black list double entry.
1171 // Create an entry string array.
1172 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1174 // Add the entry to the black list.
1175 domainBlackList.add(domainDoubleEntry);
1177 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + " - " +
1178 // originalBlockListEntry);
1180 } else { // Process a domain black list single entry.
1181 // Create an entry string array.
1182 String[] domainEntry = {domain, entry, originalBlockListEntry};
1184 // Add the entry to the black list.
1185 domainBlackList.add(domainEntry);
1187 //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + entry + " - " + originalBlockListEntry);
1189 } while (domains.contains("|"));
1192 } else if (blockListEntry.contains("~")) { // White list entries. Privacy Browser does not differentiate against these filter options, so they are just generally white listed.
1193 // Remove the filter options.
1194 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1196 // Strip any trailing `*`.
1197 if (blockListEntry.endsWith("*")) {
1198 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1201 if (blockListEntry.contains("*")) { // Process a white list double entry.
1202 // Get the index of the wildcard.
1203 int wildcardIndex = blockListEntry.indexOf("*");
1205 // Split the entry into components.
1206 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1207 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1209 // Create an entry string array.
1210 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1212 // Add the entry to the white list.
1213 mainWhiteList.add(doubleEntry);
1215 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1216 } else { // Process a white list single entry.
1217 // Create an entry string array.
1218 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1220 // Add the entry to the white list.
1221 mainWhiteList.add(singleEntry);
1223 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + " - + " + originalBlockListEntry);
1225 } else if (blockListEntry.contains("\\")) { // Process a regular expression black list entry.
1226 // Remove the filter options.
1227 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1229 // Create an entry string array.
1230 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1232 // Add the entry to the black list.
1233 regularExpressionBlackList.add(singleEntry);
1235 //Log.i("BlockLists", headers.get(1)[0] + " regular expression black list added: " + blockListEntry + " - " + originalBlockListEntry);
1236 } else { // Black list entries.
1237 // Remove the filter options.
1238 if (!blockListEntry.contains("$file")) { // EasyPrivacy contains an entry with `$file` that does not have filter options.
1239 blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1242 // Strip any trailing `*`. These are redundant.
1243 if (blockListEntry.endsWith("*")) {
1244 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1247 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1248 // Strip the initial `|`.
1249 String entry = blockListEntry.substring(1);
1251 if (entry.contains("*")) { // Process an initial black list double entry.
1252 // Get the index of the wildcard.
1253 int wildcardIndex = entry.indexOf("*");
1255 // Split the entry into components.
1256 String firstEntry = entry.substring(0, wildcardIndex);
1257 String secondEntry = entry.substring(wildcardIndex + 1);
1259 // Create an entry string array.
1260 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1262 // Add the entry to the black list.
1263 initialBlackList.add(doubleEntry);
1265 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1266 } else { // Process an initial black list single entry.
1267 // Create an entry string array.
1268 String[] singleEntry = {entry, originalBlockListEntry};
1270 // Add the entry to the black list.
1271 initialBlackList.add(singleEntry);
1273 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1275 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1276 // Ignore entries with `object` filters. They can block entire websites and don't have any meaning in the context of Privacy Browser.
1277 if (!originalBlockListEntry.contains("$object")) {
1278 // Strip the final `|`.
1279 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1281 if (entry.contains("*")) { // There are two or more entries.
1282 // Get the index of the wildcard.
1283 int wildcardIndex = entry.indexOf("*");
1285 // Split the entry into components.
1286 String firstEntry = entry.substring(0, wildcardIndex);
1287 String secondEntry = entry.substring(wildcardIndex + 1);
1289 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1290 // Get the index of the wildcard.
1291 int secondWildcardIndex = secondEntry.indexOf("*");
1293 // Split the entry into components.
1294 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1295 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1297 // Create an entry string array.
1298 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1300 // Add the entry to the black list.
1301 finalBlackList.add(tripleEntry);
1303 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1304 // originalBlockListEntry);
1305 } else { // Process a final black list double entry.
1306 // Create an entry string array.
1307 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1309 // Add the entry to the black list.
1310 finalBlackList.add(doubleEntry);
1312 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1314 } else { // Process a final black list single entry.
1315 // Create an entry sting array.
1316 String[] singleEntry = {entry, originalBlockListEntry};
1318 // Add the entry to the black list.
1319 finalBlackList.add(singleEntry);
1321 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1324 } else if (blockListEntry.contains("*")) { // There are two or more entries.
1325 // Get the index of the wildcard.
1326 int wildcardIndex = blockListEntry.indexOf("*");
1328 // Split the entry into components.
1329 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1330 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1332 if (secondEntry.contains("*")) { // Process a main black list triple entry.
1333 // Get the index of the wildcard.
1334 int secondWildcardIndex = secondEntry.indexOf("*");
1336 // Split the entry into components.
1337 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1338 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1340 // Create an entry string array.
1341 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1343 // Add the entry to the black list.
1344 mainBlackList.add(tripleEntry);
1346 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1347 } else { // Process a main black list double entry.
1348 // Create an entry string array.
1349 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1351 // Add the entry to the black list.
1352 mainBlackList.add(doubleEntry);
1354 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1356 } else { // Process a main black list single entry.
1357 // Create an entry string array.
1358 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1360 // Add the entry to the black list.
1361 mainBlackList.add(singleEntry);
1363 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1366 } else { // Main black list entries
1367 // Strip out any initial `||`. These will be treated like any other entry.
1368 if (blockListEntry.startsWith("||")) {
1369 blockListEntry = blockListEntry.substring(2);
1372 // Strip out any initial `*`.
1373 if (blockListEntry.startsWith("*")) {
1374 blockListEntry = blockListEntry.substring(1);
1377 // Strip out any trailing `*`.
1378 if (blockListEntry.endsWith("*")) {
1379 blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1382 if (blockListEntry.startsWith("|")) { // Initial black list entries.
1383 // Strip the initial `|`.
1384 String entry = blockListEntry.substring(1);
1386 if (entry.contains("*")) { // Process an initial black list double entry.
1387 // Get the index of the wildcard.
1388 int wildcardIndex = entry.indexOf("*");
1390 // Split the entry into components.
1391 String firstEntry = entry.substring(0, wildcardIndex);
1392 String secondEntry = entry.substring(wildcardIndex + 1);
1394 // Create an entry string array.
1395 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1397 // Add the entry to the black list.
1398 initialBlackList.add(doubleEntry);
1400 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1401 } else { // Process an initial black list single entry.
1402 // Create an entry string array.
1403 String[] singleEntry = {entry, originalBlockListEntry};
1405 // Add the entry to the black list.
1406 initialBlackList.add(singleEntry);
1408 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + " - " + originalBlockListEntry);
1410 } else if (blockListEntry.endsWith("|")) { // Final black list entries.
1411 // Strip the final `|`.
1412 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1414 if (entry.contains("*")) { // There are two or more entries.
1415 // Get the index of the wildcard.
1416 int wildcardIndex = entry.indexOf("*");
1418 // Split the entry into components.
1419 String firstEntry = entry.substring(0, wildcardIndex);
1420 String secondEntry = entry.substring(wildcardIndex + 1);
1422 if (secondEntry.contains("*")) { // Process a final black list triple entry.
1423 // Get the index of the wildcard.
1424 int secondWildcardIndex = secondEntry.indexOf("*");
1426 // Split the entry into components.
1427 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1428 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1430 // Create an entry string array.
1431 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1433 // Add the entry to the black list.
1434 finalBlackList.add(tripleEntry);
1436 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " +
1437 // originalBlockListEntry);
1438 } else { // Process a final black list double entry.
1439 // Create an entry string array.
1440 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1442 // Add the entry to the black list.
1443 finalBlackList.add(doubleEntry);
1445 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1447 } else { // Process a final black list single entry.
1448 // Create an entry string array.
1449 String[] singleEntry = {entry, originalBlockListEntry};
1451 // Add the entry to the black list.
1452 finalBlackList.add(singleEntry);
1454 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + " - " + originalBlockListEntry);
1456 } else { // Main black list entries.
1457 if (blockListEntry.contains("*")) { // There are two or more entries.
1458 // Get the index of the wildcard.
1459 int wildcardIndex = blockListEntry.indexOf("*");
1461 // Split the entry into components.
1462 String firstEntry = blockListEntry.substring(0, wildcardIndex);
1463 String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1465 if (secondEntry.contains("*")) { // There are three or more entries.
1466 // Get the index of the wildcard.
1467 int secondWildcardIndex = secondEntry.indexOf("*");
1469 // Split the entry into components.
1470 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1471 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1473 if (thirdEntry.contains("*")) { // There are four or more entries.
1474 // Get the index of the wildcard.
1475 int thirdWildcardIndex = thirdEntry.indexOf("*");
1477 // Split the entry into components.
1478 String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
1479 String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
1481 if (fourthEntry.contains("*")) { // Process a main black list quintuple entry.
1482 // Get the index of the wildcard.
1483 int fourthWildcardIndex = fourthEntry.indexOf("*");
1485 // Split the entry into components.
1486 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
1487 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
1489 // Create an entry string array.
1490 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
1492 // Add the entry to the black list.
1493 mainBlackList.add(quintupleEntry);
1495 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1496 // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry);
1497 } else { // Process a main black list quadruple entry.
1498 // Create an entry string array.
1499 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
1501 // Add the entry to the black list.
1502 mainBlackList.add(quadrupleEntry);
1504 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1505 // fourthEntry + " - " + originalBlockListEntry);
1507 } else { // Process a main black list triple entry.
1508 // Create an entry string array.
1509 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1511 // Add the entry to the black list.
1512 mainBlackList.add(tripleEntry);
1514 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry);
1516 } else { // Process a main black list double entry.
1517 // Create an entry string array.
1518 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1520 // Add the entry to the black list.
1521 mainBlackList.add(doubleEntry);
1523 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry);
1525 } else { // Process a main black list single entry.
1526 // Create an entry string array.
1527 String[] singleEntry = {blockListEntry, originalBlockListEntry};
1529 // Add the entry to the black list.
1530 mainBlackList.add(singleEntry);
1532 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + " - " + originalBlockListEntry);
1537 // Close `bufferedReader`.
1538 bufferedReader.close();
1539 } catch (IOException e) {
1540 // The asset exists, so the `IOException` will never be thrown.
1543 // Initialize the combined list.
1544 ArrayList<List<String[]>> combinedLists = new ArrayList<>();
1546 // Add the headers (0).
1547 combinedLists.add(headers); // 0.
1549 // Add the white lists (1-8).
1550 combinedLists.add(mainWhiteList); // 1.
1551 combinedLists.add(finalWhiteList); // 2.
1552 combinedLists.add(domainWhiteList); // 3.
1553 combinedLists.add(domainInitialWhiteList); // 4.
1554 combinedLists.add(domainFinalWhiteList); // 5.
1555 combinedLists.add(thirdPartyWhiteList); // 6.
1556 combinedLists.add(thirdPartyDomainWhiteList); // 7.
1557 combinedLists.add(thirdPartyDomainInitialWhiteList); // 8.
1559 // Add the black lists (9-22).
1560 combinedLists.add(mainBlackList); // 9.
1561 combinedLists.add(initialBlackList); // 10.
1562 combinedLists.add(finalBlackList); // 11.
1563 combinedLists.add(domainBlackList); // 12.
1564 combinedLists.add(domainInitialBlackList); // 13.
1565 combinedLists.add(domainFinalBlackList); // 14.
1566 combinedLists.add(domainRegularExpressionBlackList); // 15.
1567 combinedLists.add(thirdPartyBlackList); // 16.
1568 combinedLists.add(thirdPartyInitialBlackList); // 17.
1569 combinedLists.add(thirdPartyDomainBlackList); // 18.
1570 combinedLists.add(thirdPartyDomainInitialBlackList); // 19.
1571 combinedLists.add(thirdPartyRegularExpressionBlackList); // 20.
1572 combinedLists.add(thirdPartyDomainRegularExpressionBlackList); // 21.
1573 combinedLists.add(regularExpressionBlackList); // 22.
1575 return combinedLists;
1578 public boolean isBlocked(String currentUrl, String resourceUrl, ArrayList<List<String[]>> blockList) {
1579 // Get the block list name.
1580 String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0];
1582 // Get the current domain.
1583 Uri currentUri = Uri.parse(currentUrl);
1584 String currentDomain = currentUri.getHost();
1586 // Get the resource domain.
1587 Uri resourceUri = Uri.parse(resourceUrl);
1588 String resourceDomain = resourceUri.getHost();
1590 // Initialize the third-party request tracker.
1591 boolean thirdPartyRequest = false;
1593 // If one of the domains is `about:blank` it will throw a null object reference on the string comparison.
1594 if ((currentDomain != null) && (resourceDomain != null)) {
1595 thirdPartyRequest = !resourceDomain.equals(currentDomain);
1598 // Process the white lists.
1600 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.MAIN_WHITELIST)) {
1601 switch (whiteListEntry.length) {
1602 case 2: // There is one entry.
1603 if (resourceUrl.contains(whiteListEntry[0])) {
1604 // Store the entry in the resource request log.
1605 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1606 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1613 case 3: // There are two entries.
1614 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1615 // Store the entry in the resource request log.
1616 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1617 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1],
1625 case 4: // There are three entries.
1626 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1627 // Store the entry in the resource request log.
1628 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1629 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1638 // Final white list.
1639 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.FINAL_WHITELIST)) {
1640 if (whiteListEntry.length == 2) { // There is one entry.
1641 if (resourceUrl.contains(whiteListEntry[0])) {
1642 // Store the entry in the resource request log.
1643 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1644 String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1649 } else { // There are two entries.
1650 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1651 // Store the entry in the resource request log.
1652 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1653 String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1661 // Only check the domain lists if the current domain is not null (like `about:blank`).
1662 if (currentDomain != null) {
1663 // Domain white list.
1664 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_WHITELIST)) {
1665 switch (whiteListEntry.length) {
1666 case 3: // There is one entry.
1667 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1668 // Store the entry in the resource request log.
1669 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1670 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1677 case 4: // There are two entries.
1678 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1679 // Store the entry in the resource request log.
1680 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1681 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1688 case 5: // There are three entries.
1689 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1690 // Store the entry in the resource request log.
1691 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1692 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1700 case 6: // There are four entries.
1701 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1702 resourceUrl.contains(whiteListEntry[4])) {
1703 // Store the entry in the resource request log.
1704 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1705 String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1706 whiteListEntry[4], whiteListEntry[5]};
1715 // Domain initial white list.
1716 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST)) {
1717 switch (whiteListEntry.length) {
1718 case 3: // There is one entry.
1719 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1720 // Store the entry in the resource request log.
1721 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1722 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1729 case 4: // There are two entries.
1730 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1731 // Store the entry in the resource request log.
1732 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1733 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1740 case 5: // There are three entries.
1741 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) {
1742 // Store the entry in the resource request log.
1743 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1744 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1754 // Domain final white list.
1755 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_WHITELIST)) {
1756 switch (whiteListEntry.length) {
1757 case 3: // There is one entry;
1758 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) {
1759 // Store the entry in the resource request log.
1760 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1761 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1768 case 4: // There are two entries;
1769 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) {
1770 // Store the entry in the resource request log.
1771 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1772 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1783 // Only check the third-party white lists if this is a third-party request.
1784 if (thirdPartyRequest) {
1785 // Third-party white list.
1786 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_WHITELIST)) {
1787 switch (whiteListEntry.length) {
1788 case 2: // There is one entry
1789 if (resourceUrl.contains(whiteListEntry[0])) {
1790 // Store the entry in the resource request log.
1791 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1792 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1799 case 3: // There are two entries.
1800 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1801 // Store the entry in the resource request log.
1802 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1803 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1810 case 4: // There are three entries.
1811 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1812 // Store the entry in the resource request log.
1813 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1814 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1821 case 5: // There are four entries.
1822 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1823 // Store the entry in the resource request log.
1824 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1825 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1832 case 6: // There are five entries.
1833 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1834 resourceUrl.contains(whiteListEntry[4])) {
1835 // Store the entry in the resource request log.
1836 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1837 String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1838 whiteListEntry[4], whiteListEntry[5]};
1847 // Third-party domain white list.
1848 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST)) {
1849 if (whiteListEntry.length == 3) { // There is one entry.
1850 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1851 // Store the entry in the resource request log.
1852 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1853 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1858 } else { // There are two entries.
1859 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1860 // Store the entry in the resource request log.
1861 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1862 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1870 // Third-party domain initial white list.
1871 for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST)) {
1872 if (whiteListEntry.length == 3) { // There is one entry.
1873 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1874 // Store the entry in the resource request log.
1875 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1876 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1881 } else { // There are two entries.
1882 if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1883 // Store the entry in the resource request log.
1884 MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1885 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1894 // Process the black lists.
1896 for (String[] blackListEntry : blockList.get(MainWebViewActivity.MAIN_BLACKLIST)) {
1897 switch (blackListEntry.length) {
1898 case 2: // There is one entry.
1899 if (resourceUrl.contains(blackListEntry[0])) {
1900 // Store the entry in the resource request log.
1901 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1902 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1909 case 3: // There are two entries.
1910 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1911 // Store the entry in the resource request log.
1912 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1913 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1920 case 4: // There are three entries.
1921 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
1922 // Store the entry in the resource request log.
1923 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1924 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
1931 case 5: // There are four entries.
1932 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
1933 // Store the entry in the resource request log.
1934 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1935 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]});
1942 case 6: // There are five entries.
1943 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) &&
1944 resourceUrl.contains(blackListEntry[4])) {
1945 // Store the entry in the resource request log.
1946 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1947 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3] + "\n" +
1948 blackListEntry[4], blackListEntry[5]});
1957 // Initial black list.
1958 for (String[] blackListEntry : blockList.get(MainWebViewActivity.INITIAL_BLACKLIST)) {
1959 if (blackListEntry.length == 2) { // There is one entry.
1960 if (resourceUrl.startsWith(blackListEntry[0])) {
1961 // Store the entry in the resource request log.
1962 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1963 String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1968 } else { // There are two entries
1969 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1970 // Store the entry in the resource request log.
1971 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1972 String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1980 // Final black list.
1981 for (String[] blackListEntry : blockList.get(MainWebViewActivity.FINAL_BLACKLIST)) {
1982 switch (blackListEntry.length) {
1983 case 2: // There is one entry.
1984 if (resourceUrl.endsWith(blackListEntry[0])) {
1985 // Store the entry in the resource request log.
1986 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1987 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1994 case 3: // There are two entries.
1995 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
1996 // Store the entry in the resource request log.
1997 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1998 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2005 case 4: // There are three entries.
2006 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2007 // Store the entry in the resource request log.
2008 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2009 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2018 // Only check the domain lists if the current domain is not null (like `about:blank`).
2019 if (currentDomain != null) {
2020 // Domain black list.
2021 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_BLACKLIST)) {
2022 switch (blackListEntry.length) {
2023 case 3: // There is one entry.
2024 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2025 // Store the entry in the resource request log.
2026 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2027 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2034 case 4: // There are two entries.
2035 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2036 // Store the entry in the resource request log.
2037 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2038 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2045 case 5: // There are three entries.
2046 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2047 // Store the entry in the resource request log.
2048 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2049 String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2050 blackListEntry[4]});
2059 // Domain initial black list.
2060 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST)) {
2061 // Store the entry in the resource request log.
2062 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2063 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2064 String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1],
2065 blackListEntry[2]});
2072 // Domain final black list.
2073 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST)) {
2074 switch (blackListEntry.length) {
2075 case 3: // There is one entry.
2076 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
2077 // Store the entry in the resource request log.
2078 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2079 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2086 case 4: // There are two entries.
2087 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2088 // Store the entry in the resource request log.
2089 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2090 String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2099 // Domain regular expression black list.
2100 for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2101 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2102 // Store the entry in the resource request log.
2103 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2104 String.valueOf(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2112 // Only check the third-party black lists if this is a third-party request.
2113 if (thirdPartyRequest) {
2114 // Third-party black list.
2115 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_BLACKLIST)) {
2116 switch (blackListEntry.length) {
2117 case 2: // There is one entry.
2118 if (resourceUrl.contains(blackListEntry[0])) {
2119 // Store the entry in the resource request log.
2120 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2121 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2128 case 3: // There are two entries.
2129 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2130 // Store the entry in the resource request log.
2131 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2132 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2139 case 4: // There are three entries.
2140 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2141 // Store the entry in the resource request log.
2142 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2143 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2150 case 5: // There are four entries.
2151 if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2152 // Store the entry in the resource request log.
2153 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2154 String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2155 blackListEntry[4]});
2164 // Third-party initial black list.
2165 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST)) {
2166 if (blackListEntry.length == 2) { // There is one entry.
2167 if (resourceUrl.startsWith(blackListEntry[0])) {
2168 // Store the entry in the resource request log.
2169 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2170 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2175 } else { // There are two entries.
2176 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2177 // Store the entry in the resource request log.
2178 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2179 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2187 // Third-party domain black list.
2188 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST)) {
2189 if (blackListEntry.length == 3) { // There is one entry.
2190 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2191 // Store the entry in the resource request log.
2192 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2193 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2198 } else { // There are two entries.
2199 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2200 // Store the entry in the resource request log.
2201 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2202 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2210 // Third-party domain initial black list.
2211 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST)) {
2212 switch (blackListEntry.length) {
2213 case 3: // There is one entry.
2214 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2215 // Store the entry in the resource request log.
2216 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2217 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2223 case 4: // There are two entries.
2224 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2225 // Store the entry in the resource request log.
2226 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2227 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2234 case 5: // There are three entries.
2235 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2236 // Store the entry in the resource request log.
2237 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2238 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2239 blackListEntry[4]});
2248 // Third-party regular expression black list.
2249 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST)) {
2250 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2251 // Store the entry in the resource request log.
2252 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2253 String.valueOf(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2260 // Third-party domain regular expression black list.
2261 for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2262 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2263 // Store the entry in the resource request log.
2264 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2265 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2273 // Regular expression black list.
2274 for (String[] blackListEntry : blockList.get(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST)) {
2275 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2276 // Store the entry in the resource request log.
2277 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2278 String.valueOf(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});