Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/android/AdblockPlus.java

Issue 6227976249147392: Fix whitelisting issues (Closed)
Patch Set: Created Nov. 29, 2013, 3:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 import android.util.Log; 54 import android.util.Log;
55 55
56 public class AdblockPlus extends Application 56 public class AdblockPlus extends Application
57 { 57 {
58 private final static String TAG = "Application"; 58 private final static String TAG = "Application";
59 59
60 private final static Pattern RE_JS = Pattern.compile(".*\\.js$", Pattern.CASE_ INSENSITIVE); 60 private final static Pattern RE_JS = Pattern.compile(".*\\.js$", Pattern.CASE_ INSENSITIVE);
61 private final static Pattern RE_CSS = Pattern.compile(".*\\.css$", Pattern.CAS E_INSENSITIVE); 61 private final static Pattern RE_CSS = Pattern.compile(".*\\.css$", Pattern.CAS E_INSENSITIVE);
62 private final static Pattern RE_IMAGE = Pattern.compile(".*\\.(?:gif|png|jpe?g |bmp|ico)$", Pattern.CASE_INSENSITIVE); 62 private final static Pattern RE_IMAGE = Pattern.compile(".*\\.(?:gif|png|jpe?g |bmp|ico)$", Pattern.CASE_INSENSITIVE);
63 private final static Pattern RE_FONT = Pattern.compile(".*\\.(?:ttf|woff)$", P attern.CASE_INSENSITIVE); 63 private final static Pattern RE_FONT = Pattern.compile(".*\\.(?:ttf|woff)$", P attern.CASE_INSENSITIVE);
64 private final static Pattern RE_HTML = Pattern.compile(".*\\.html?$", Pattern. CASE_INSENSITIVE);
64 65
65 /** 66 /**
66 * Broadcasted when filtering is enabled or disabled. 67 * Broadcasted when filtering is enabled or disabled.
67 */ 68 */
68 public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro id.filtering.status"; 69 public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro id.filtering.status";
69 /** 70 /**
70 * Broadcasted when subscription status changes. 71 * Broadcasted when subscription status changes.
71 */ 72 */
72 public final static String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an droid.subscription.status"; 73 public final static String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an droid.subscription.status";
73 /** 74 /**
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 * Request query string 365 * Request query string
365 * @param referrer 366 * @param referrer
366 * Request referrer header 367 * Request referrer header
367 * @param accept 368 * @param accept
368 * Request accept header 369 * Request accept header
369 * @return true if matched filter was found 370 * @return true if matched filter was found
370 * @throws Exception 371 * @throws Exception
371 */ 372 */
372 public boolean matches(String url, String query, String referrer, String accep t) 373 public boolean matches(String url, String query, String referrer, String accep t)
373 { 374 {
375 final String fullUrl = !"".equals(query) ? url + "?" + query : url;
374 if (referrer != null) 376 if (referrer != null)
375 referrerMapping.put(url, referrer); 377 referrerMapping.put(fullUrl, referrer);
376 378
377 if (!filteringEnabled) 379 if (!filteringEnabled)
378 return false; 380 return false;
379 381
380 String contentType = null; 382 String contentType = null;
381 383
382 if (accept != null) 384 if (accept != null)
383 { 385 {
384 if (accept.contains("text/css")) 386 if (accept.contains("text/css"))
385 contentType = "STYLESHEET"; 387 contentType = "STYLESHEET";
386 else if (accept.contains("image/*")) 388 else if (accept.contains("image/*"))
387 contentType = "IMAGE"; 389 contentType = "IMAGE";
390 else if (accept.contains("text/html"))
391 contentType = "SUBDOCUMENT";
388 } 392 }
389 393
390 if (contentType == null) 394 if (contentType == null)
391 { 395 {
392 if (RE_JS.matcher(url).matches()) 396 if (RE_JS.matcher(url).matches())
393 contentType = "SCRIPT"; 397 contentType = "SCRIPT";
394 else if (RE_CSS.matcher(url).matches()) 398 else if (RE_CSS.matcher(url).matches())
395 contentType = "STYLESHEET"; 399 contentType = "STYLESHEET";
396 else if (RE_IMAGE.matcher(url).matches()) 400 else if (RE_IMAGE.matcher(url).matches())
397 contentType = "IMAGE"; 401 contentType = "IMAGE";
398 else if (RE_FONT.matcher(url).matches()) 402 else if (RE_FONT.matcher(url).matches())
399 contentType = "FONT"; 403 contentType = "FONT";
404 else if (RE_HTML.matcher(url).matches())
405 contentType = "SUBDOCUMENT";
400 } 406 }
401 if (contentType == null) 407 if (contentType == null)
402 contentType = "OTHER"; 408 contentType = "OTHER";
403 409
404 if (!"".equals(query))
405 url = url + "?" + query;
406
407 final List<String> referrerChain = buildReferrerChain(referrer); 410 final List<String> referrerChain = buildReferrerChain(referrer);
408 Log.d("Referrer chain", url + ": " + referrerChain.toString()); 411 Log.d("Referrer chain", fullUrl + ": " + referrerChain.toString());
409 String[] referrerChainArray = referrerChain.toArray(new String[referrerChain .size()]); 412 String[] referrerChainArray = referrerChain.toArray(new String[referrerChain .size()]);
410 return abpEngine.matches(url, contentType, referrerChainArray); 413 return abpEngine.matches(fullUrl, contentType, referrerChainArray);
411 } 414 }
412 415
413 private List<String> buildReferrerChain(String url) 416 private List<String> buildReferrerChain(String url)
414 { 417 {
415 final List<String> referrerChain = new ArrayList<String>(); 418 final List<String> referrerChain = new ArrayList<String>();
416 // We need to limit the chain length to ensure we don't block indefinitely i f there's 419 // We need to limit the chain length to ensure we don't block indefinitely i f there's
417 // a referrer loop. 420 // a referrer loop.
418 final int maxChainLength = 10; 421 final int maxChainLength = 10;
419 for (int i = 0; i < maxChainLength && url != null; i++) 422 for (int i = 0; i < maxChainLength && url != null; i++)
420 { 423 {
421 referrerChain.add(url); 424 referrerChain.add(0, url);
422 url = referrerMapping.get(url); 425 url = referrerMapping.get(url);
423 } 426 }
424 return referrerChain; 427 return referrerChain;
425 } 428 }
426 429
427 /** 430 /**
428 * Checks if filtering is enabled. 431 * Checks if filtering is enabled.
429 */ 432 */
430 public boolean isFilteringEnabled() 433 public boolean isFilteringEnabled()
431 { 434 {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 Log.e(TAG, e.getMessage(), e); 552 Log.e(TAG, e.getMessage(), e);
550 } 553 }
551 554
552 // Set crash handler 555 // Set crash handler
553 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); 556 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this));
554 557
555 // Initiate update check 558 // Initiate update check
556 scheduleUpdater(0); 559 scheduleUpdater(0);
557 } 560 }
558 } 561 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld