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

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

Issue 5172657418928128: Determine the frame structure (Closed)
Patch Set: Created Nov. 23, 2013, 12:03 a.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 | « src/org/adblockplus/android/ABPEngine.java ('k') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.android;
19 19
20 import java.io.BufferedReader; 20 import java.io.BufferedReader;
21 import java.io.File; 21 import java.io.File;
22 import java.io.FileNotFoundException; 22 import java.io.FileNotFoundException;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.InputStream; 24 import java.io.InputStream;
25 import java.io.InputStreamReader; 25 import java.io.InputStreamReader;
26 import java.util.ArrayList;
26 import java.util.Calendar; 27 import java.util.Calendar;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
27 import java.util.TimeZone; 34 import java.util.TimeZone;
28 import java.util.regex.Pattern; 35 import java.util.regex.Pattern;
29 36
30 import org.adblockplus.android.updater.AlarmReceiver; 37 import org.adblockplus.android.updater.AlarmReceiver;
31 38
32 import android.app.ActivityManager; 39 import android.app.ActivityManager;
33 import android.app.ActivityManager.RunningServiceInfo; 40 import android.app.ActivityManager.RunningServiceInfo;
34 import android.app.AlarmManager; 41 import android.app.AlarmManager;
35 import android.app.Application; 42 import android.app.Application;
36 import android.app.PendingIntent; 43 import android.app.PendingIntent;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 82
76 /** 83 /**
77 * Indicates whether filtering is enabled or not. 84 * Indicates whether filtering is enabled or not.
78 */ 85 */
79 private boolean filteringEnabled = false; 86 private boolean filteringEnabled = false;
80 87
81 private ABPEngine abpEngine; 88 private ABPEngine abpEngine;
82 89
83 private static AdblockPlus instance; 90 private static AdblockPlus instance;
84 91
92 private Map<String, Set<String>> referrerMapping = new HashMap<String, Set<Str ing>>();
93
85 /** 94 /**
86 * Returns pointer to itself (singleton pattern). 95 * Returns pointer to itself (singleton pattern).
87 */ 96 */
88 public static AdblockPlus getApplication() 97 public static AdblockPlus getApplication()
89 { 98 {
90 return instance; 99 return instance;
91 } 100 }
92 101
93 public int getBuildNumber() 102 public int getBuildNumber()
94 { 103 {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 * Request query string 316 * Request query string
308 * @param referrer 317 * @param referrer
309 * Request referrer header 318 * Request referrer header
310 * @param accept 319 * @param accept
311 * Request accept header 320 * Request accept header
312 * @return true if matched filter was found 321 * @return true if matched filter was found
313 * @throws Exception 322 * @throws Exception
314 */ 323 */
315 public boolean matches(String url, String query, String referrer, String accep t) 324 public boolean matches(String url, String query, String referrer, String accep t)
316 { 325 {
326 if (referrer != null)
327 recordReferrer(url, referrer);
328
317 if (!filteringEnabled) 329 if (!filteringEnabled)
318 return false; 330 return false;
319 331
320 String contentType = null; 332 String contentType = null;
321 333
322 if (accept != null) 334 if (accept != null)
323 { 335 {
324 if (accept.contains("text/css")) 336 if (accept.contains("text/css"))
325 contentType = "STYLESHEET"; 337 contentType = "STYLESHEET";
326 else if (accept.contains("image/*")) 338 else if (accept.contains("image/*"))
(...skipping 10 matching lines...) Expand all
337 contentType = "IMAGE"; 349 contentType = "IMAGE";
338 else if (RE_FONT.matcher(url).matches()) 350 else if (RE_FONT.matcher(url).matches())
339 contentType = "FONT"; 351 contentType = "FONT";
340 } 352 }
341 if (contentType == null) 353 if (contentType == null)
342 contentType = "OTHER"; 354 contentType = "OTHER";
343 355
344 if (!"".equals(query)) 356 if (!"".equals(query))
345 url = url + "?" + query; 357 url = url + "?" + query;
346 358
347 return abpEngine.matches(url, contentType, referrer); 359 final List<List<String>> referrerChains = referrer != null
360 ? buildReferrerChains(referrer)
361 : Collections.singletonList(Collections.<String>emptyList());
362 for (List<String> referrerChain : referrerChains)
363 {
364 Log.d("Referrer chain", url + ": " + referrerChain.toString());
365 String[] referrerChainArray = referrerChain.toArray(new String[referrerCha in.size()]);
366 if (abpEngine.matches(url, contentType, referrerChainArray))
367 return true;
368 }
369 return false;
370 }
371
372 private void recordReferrer(String url, String referrer)
373 {
374 // TODO: Garbage collect the mapping - currently it will grow out of control .
375 // In addition, we might have to persist mappings, because clients are
376 // likely to cache some requests in the chain.
377 if (!referrerMapping.containsKey(url))
378 referrerMapping.put(url, new HashSet<String>());
379 Set<String> referrers = referrerMapping.get(url);
380 referrers.add(referrer);
Wladimir Palant 2013/11/25 10:24:41 Do you think that this is really necessary? We are
Felix Dahlke 2013/11/27 12:19:32 Yes, I think it makes sense to not have a single c
Wladimir Palant 2013/11/27 12:59:01 Not with the same parameters - they have to know s
Felix Dahlke 2013/11/27 13:38:59 Alright, didn't think of that. Makes the code much
381 }
382
383 private List<List<String>> buildReferrerChains(String url)
384 {
385 List<List<String>> referrerChains = new ArrayList<List<String>>();
386 Set<String> referrers = referrerMapping.get(url);
387 if (referrers == null)
388 {
389 List<String> referrerChain = new ArrayList<String>();
390 referrerChain.add(url);
391 referrerChains.add(referrerChain);
392 return referrerChains;
393 }
394
395 for (String referrer : referrers) {
396 List<List<String>> currentReferrerChains = buildReferrerChains(referrer);
397 for (List<String> referrerChain : currentReferrerChains)
398 {
399 referrerChain.add(0, url);
400 referrerChains.add(referrerChain);
401 }
402 }
403 return referrerChains;
348 } 404 }
349 405
350 /** 406 /**
351 * Checks if filtering is enabled. 407 * Checks if filtering is enabled.
352 */ 408 */
353 public boolean isFilteringEnabled() 409 public boolean isFilteringEnabled()
354 { 410 {
355 return filteringEnabled; 411 return filteringEnabled;
356 } 412 }
357 413
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 Log.e(TAG, e.getMessage(), e); 528 Log.e(TAG, e.getMessage(), e);
473 } 529 }
474 530
475 // Set crash handler 531 // Set crash handler
476 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); 532 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this));
477 533
478 // Initiate update check 534 // Initiate update check
479 scheduleUpdater(0); 535 scheduleUpdater(0);
480 } 536 }
481 } 537 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/ABPEngine.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld