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

Delta Between Two Patch Sets: src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29355386: Issue 4463 - Content blocker unavailable error message (Closed)
Left Patch Set: Created Sept. 30, 2016, 2:44 a.m.
Right Patch Set: Adjusting indentation Created Oct. 7, 2016, 2:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 import android.net.Uri; 48 import android.net.Uri;
49 import android.os.Handler; 49 import android.os.Handler;
50 import android.os.Looper; 50 import android.os.Looper;
51 import android.preference.PreferenceManager; 51 import android.preference.PreferenceManager;
52 import android.util.Log; 52 import android.util.Log;
53 53
54 public final class Engine 54 public final class Engine
55 { 55 {
56 private static final String TAG = Engine.class.getSimpleName(); 56 private static final String TAG = Engine.class.getSimpleName();
57 57
58 public static final String ABP_VERSION = "2.0";
Felix Dahlke 2016/09/30 07:11:41 I think we can safely hard code it (the way it was
diegocarloslima 2016/09/30 14:06:38 OK I'll revert that change
59
60 // TODO make use of this regex's 58 // TODO make use of this regex's
61 public static final Pattern RE_SUBSCRIPTION_HEADER = Pattern.compile( 59 public static final Pattern RE_SUBSCRIPTION_HEADER = Pattern.compile(
62 "\\[Adblock(?:\\s*Plus\\s*([\\d\\.]+)?)?\\]", Pattern.CASE_INSENSITIVE); 60 "\\[Adblock(?:\\s*Plus\\s*([\\d\\.]+)?)?\\]", Pattern.CASE_INSENSITIVE);
63 public static final Pattern RE_FILTER_META = Pattern.compile("^\\s*!\\s*(\\w+) \\s*:\\s*(.*)"); 61 public static final Pattern RE_FILTER_META = Pattern.compile("^\\s*!\\s*(\\w+) \\s*:\\s*(.*)");
64 public static final Pattern RE_FILTER_ELEMHIDE = Pattern 62 public static final Pattern RE_FILTER_ELEMHIDE = Pattern
65 .compile("^([^\\/\\*\\|\\@\"!]*?)#(\\@)?(?:([\\w\\-]+|\\*)((?:\\([\\w\\-]+ (?:[$^*]?=[^\\(\\)\"]*)?\\))*)|#([^{}]+))$"); 63 .compile("^([^\\/\\*\\|\\@\"!]*?)#(\\@)?(?:([\\w\\-]+|\\*)((?:\\([\\w\\-]+ (?:[$^*]?=[^\\(\\)\"]*)?\\))*)|#([^{}]+))$");
66 public static final Pattern RE_FILTER_REGEXP = Pattern 64 public static final Pattern RE_FILTER_REGEXP = Pattern
67 .compile("^(@@)?\\/.*\\/(?:\\$~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:= [^,\\s]+)?)*)?$"); 65 .compile("^(@@)?\\/.*\\/(?:\\$~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:= [^,\\s]+)?)*)?$");
68 public static final Pattern RE_FILTER_OPTIONS = Pattern 66 public static final Pattern RE_FILTER_OPTIONS = Pattern
69 .compile("\\$(~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:=[^,\\s]+)?)*)$") ; 67 .compile("\\$(~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:=[^,\\s]+)?)*)$") ;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 finally 469 finally
472 { 470 {
473 writer.close(); 471 writer.close();
474 } 472 }
475 } 473 }
476 return dummyFilterFile; 474 return dummyFilterFile;
477 } 475 }
478 476
479 public static void writeFilterHeaders(Writer writer) throws IOException 477 public static void writeFilterHeaders(Writer writer) throws IOException
480 { 478 {
481 writer.write("[Adblock Plus" + ABP_VERSION + "]\n"); 479 writer.write("[Adblock Plus 2.0]\n");
Felix Dahlke 2016/09/30 07:11:41 Shouldn't there be a space between "Adblock Plus"
482 writer.write("! This file was automatically created.\n"); 480 writer.write("! This file was automatically created.\n");
483 } 481 }
484 482
485 private static File getCachedFilterFile(Context context) 483 private static File getCachedFilterFile(Context context)
486 { 484 {
487 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(context); 485 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(context);
488 final String cachedFilterPath = prefs.getString(context.getString(R.string.k ey_cached_filter_path), null); 486 final String cachedFilterPath = prefs.getString(context.getString(R.string.k ey_cached_filter_path), null);
489 if (cachedFilterPath != null) 487 if (cachedFilterPath != null)
490 { 488 {
491 return new File(cachedFilterPath); 489 return new File(cachedFilterPath);
492 } 490 }
493 491
494 return null; 492 return null;
495 } 493 }
496 494
497 private static File getDummyFilterFile(Context context) 495 private static File getDummyFilterFile(Context context)
498 { 496 {
499 return new File(getFilterCacheDir(context), "dummy.txt"); 497 return new File(getFilterCacheDir(context), "dummy.txt");
500 } 498 }
501 499
502 private static File getFilterCacheDir(Context context) 500 private static File getFilterCacheDir(Context context)
503 { 501 {
504 return new File(context.getCacheDir(), "subscriptions"); 502 return new File(context.getCacheDir(), "subscriptions");
505 } 503 }
506 504
507 private static File getSubscriptionsDir(Context context) 505 private static File getSubscriptionsDir(Context context)
508 { 506 {
509 return new File(context.getFilesDir(), "subscriptions"); 507 return new File(context.getFilesDir(), "subscriptions");
510 } 508 }
511 509
512 URL createDownloadURL(final Subscription sub) throws IOException 510 URL createDownloadURL(final Subscription sub) throws IOException
513 { 511 {
514 final StringBuilder sb = new StringBuilder(); 512 final StringBuilder sb = new StringBuilder();
515 513
516 sb.append(sub.getURL()); 514 sb.append(sub.getURL());
517 if (sub.getURL().getQuery() != null) 515 if (sub.getURL().getQuery() != null)
518 { 516 {
519 sb.append('&'); 517 sb.append('&');
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 Log.d(TAG, headers.toString()); 710 Log.d(TAG, headers.toString());
713 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers); 711 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers);
714 } 712 }
715 } 713 }
716 714
717 public void connectivityChanged() 715 public void connectivityChanged()
718 { 716 {
719 this.downloader.connectivityChanged(); 717 this.downloader.connectivityChanged();
720 } 718 }
721 } 719 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld