| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 | 396 |
| 397 final List<String> referrerChain = buildReferrerChain(referrer); | 397 final List<String> referrerChain = buildReferrerChain(referrer); |
| 398 Log.d("Referrer chain", url + ": " + referrerChain.toString()); | 398 Log.d("Referrer chain", url + ": " + referrerChain.toString()); |
| 399 String[] referrerChainArray = referrerChain.toArray(new String[referrerChain .size()]); | 399 String[] referrerChainArray = referrerChain.toArray(new String[referrerChain .size()]); |
| 400 return abpEngine.matches(url, contentType, referrerChainArray); | 400 return abpEngine.matches(url, contentType, referrerChainArray); |
| 401 } | 401 } |
| 402 | 402 |
| 403 private List<String> buildReferrerChain(String url) | 403 private List<String> buildReferrerChain(String url) |
| 404 { | 404 { |
| 405 final List<String> referrerChain = new ArrayList<String>(); | 405 final List<String> referrerChain = new ArrayList<String>(); |
| 406 if (url != null) | 406 // We need to limit the chain length to ensure we don't block indefinitely i f there's |
| 407 // a referrer loop. | |
| 408 final int maxChainLength = 10; | |
| 409 for (int i = 0; i < maxChainLength && url != null; i++) | |
| 407 { | 410 { |
| 408 referrerChain.add(url); | 411 referrerChain.add(url); |
| 409 | 412 url = referrerMapping.get(url); |
| 410 final String referrer = referrerMapping.get(url); | |
| 411 if (referrer != null) | |
| 412 referrerChain.addAll(buildReferrerChain(referrer)); | |
| 413 } | 413 } |
|
Wladimir Palant
2013/11/27 14:00:30
Please don't use recursive algorithms where they d
Felix Dahlke
2013/11/27 14:47:32
Valid points, fixed.
| |
| 414 return referrerChain; | 414 return referrerChain; |
| 415 } | 415 } |
| 416 | 416 |
| 417 /** | 417 /** |
| 418 * Checks if filtering is enabled. | 418 * Checks if filtering is enabled. |
| 419 */ | 419 */ |
| 420 public boolean isFilteringEnabled() | 420 public boolean isFilteringEnabled() |
| 421 { | 421 { |
| 422 return filteringEnabled; | 422 return filteringEnabled; |
| 423 } | 423 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 Log.e(TAG, e.getMessage(), e); | 539 Log.e(TAG, e.getMessage(), e); |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Set crash handler | 542 // Set crash handler |
| 543 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); | 543 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); |
| 544 | 544 |
| 545 // Initiate update check | 545 // Initiate update check |
| 546 scheduleUpdater(0); | 546 scheduleUpdater(0); |
| 547 } | 547 } |
| 548 } | 548 } |
| LEFT | RIGHT |