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

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

Issue 29524668: Issue 3916 - Supporting Adding filter lists via URL (Closed)
Left Patch Set: Issue 3916 - Supporting Adding filer lists via URL Created Aug. 23, 2017, 2:20 p.m.
Right Patch Set: Use TAG constant for log, fix in MoreBlockingPreferenceCategory Created Oct. 10, 2017, 1:57 p.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 25 matching lines...) Expand all
36 import java.util.HashMap; 36 import java.util.HashMap;
37 import java.util.List; 37 import java.util.List;
38 import java.util.Map; 38 import java.util.Map;
39 import java.util.Set; 39 import java.util.Set;
40 import java.util.TreeSet; 40 import java.util.TreeSet;
41 import java.util.concurrent.LinkedBlockingQueue; 41 import java.util.concurrent.LinkedBlockingQueue;
42 import java.util.concurrent.TimeUnit; 42 import java.util.concurrent.TimeUnit;
43 import java.util.concurrent.locks.ReentrantLock; 43 import java.util.concurrent.locks.ReentrantLock;
44 44
45 import org.adblockplus.adblockplussbrowser.R; 45 import org.adblockplus.adblockplussbrowser.R;
46 import org.adblockplus.sbrowser.contentblocker.MoreBlockingPreferenceCategory;
47 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; 46 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
48 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; 47 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils;
49 48
50 import android.content.Context; 49 import android.content.Context;
51 import android.content.Intent; 50 import android.content.Intent;
52 import android.content.pm.PackageInfo; 51 import android.content.pm.PackageInfo;
53 import android.content.pm.PackageManager; 52 import android.content.pm.PackageManager;
54 import android.content.pm.ResolveInfo; 53 import android.content.pm.ResolveInfo;
55 import android.net.ConnectivityManager; 54 import android.net.ConnectivityManager;
56 import android.net.NetworkInfo; 55 import android.net.NetworkInfo;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 249 }
251 250
252 public void subscriptionStateChanged() 251 public void subscriptionStateChanged()
253 { 252 {
254 if (this.subscriptionUpdateCallback != null) 253 if (this.subscriptionUpdateCallback != null)
255 { 254 {
256 subscriptionUpdateCallback.subscriptionUpdatedApplied(); 255 subscriptionUpdateCallback.subscriptionUpdatedApplied();
257 } 256 }
258 } 257 }
259 258
260 public void createAndAddSubscriptionFromUrl(final String url, final Subscripti onAddedCallback callback) throws IOException 259 public void createAndAddSubscriptionFromUrl(final String url,
260 final SubscriptionAddedCallback callback) throws IOException
261 { 261 {
262 final Subscription sub = Subscription.create(url); 262 final Subscription sub = Subscription.create(url);
263 sub.putMeta(Subscription.KEY_TITLE, url); 263 sub.putMeta(Subscription.KEY_TITLE, url);
264 sub.setEnabled(true); 264 sub.setEnabled(true);
265 subscriptions.add(sub); 265 subscriptions.add(sub);
266 subscriptions.persistSubscription(sub); 266 subscriptions.persistSubscription(sub);
267 callback.subscriptionAdded(); 267 callback.subscriptionAdded();
268 } 268 }
269 269
270 public void removeSubscriptionById(final String subscriptionId) 270 public void removeSubscriptionById(final String subscriptionId)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); 418 engine.wasFirstRun = engine.subscriptions.wasUnitialized();
419 if (engine.subscriptions.wasUnitialized()) 419 if (engine.subscriptions.wasUnitialized())
420 { 420 {
421 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); 421 Log.d(TAG, "Subscription storage was uninitialized, initializing...");
422 422
423 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist)) 423 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist))
424 { 424 {
425 final Subscription easylist = engine.subscriptions.add(Subscription 425 final Subscription easylist = engine.subscriptions.add(Subscription
426 // Use bundled EasyList as default and update it with locale specifi c list later 426 // Use bundled EasyList as default and update it with locale specifi c list later
427 // see: https://issues.adblockplus.org/ticket/5237 427 // see: https://issues.adblockplus.org/ticket/5237
428 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaul tSubscriptions.getAdsSubscriptions())) 428 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(
429 engine.defaultSubscriptions.getAdsSubscriptions()))
429 .parseLines(readLines(easylistTxt))); 430 .parseLines(readLines(easylistTxt)));
430 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); 431 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0");
431 easylist.setEnabled(true); 432 easylist.setEnabled(true);
432 } 433 }
433 Log.d(TAG, "Added and enabled bundled easylist"); 434 Log.d(TAG, "Added and enabled bundled easylist");
434 435
435 try (final InputStream exceptionsTxt = context.getResources() 436 try (final InputStream exceptionsTxt = context.getResources()
436 .openRawResource(R.raw.exceptionrules)) 437 .openRawResource(R.raw.exceptionrules))
437 { 438 {
438 final Subscription exceptions = engine.subscriptions.add(Subscription 439 final Subscription exceptions = engine.subscriptions.add(Subscription
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 sb.append(downloadCount); 621 sb.append(downloadCount);
621 } 622 }
622 else 623 else
623 { 624 {
624 sb.append("4%2B"); // "4+" URL encoded 625 sb.append("4%2B"); // "4+" URL encoded
625 } 626 }
626 627
627 return new URL(sb.toString()); 628 return new URL(sb.toString());
628 } 629 }
629 630
630 public List<SubscriptionInfo> getMoreBlockingPreferenceSubscriptions() 631 public boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo)
631 {
632 List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<> (5);
633 for(SubscriptionInfo sub : getListedSubscriptions())
anton 2017/08/25 10:40:40 it seems that space is required after `for`
jens 2017/08/25 11:35:06 Acknowledged.
634 {
635 final DefaultSubscriptionInfo info = getDefaultSubscriptionInfoForUrl(sub. getUrl());
636 Integer resInt = MoreBlockingPreferenceCategory.URL_TO_RES_ID_MAP.get(sub. getUrl());
637
638 if (sub.getType() == SubscriptionInfo.Type.CUSTOM)
639 {
640 moreBlockingPreferenceSubscriptions.add(sub);
641 }
642
643 if (info != null && !info.isComplete() && sub.isEnabled())
644 {
645 moreBlockingPreferenceSubscriptions.add(sub);
646 }
647
648 if ((!(isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__"))
649 && resInt != null
650 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != S ubscriptionInfo.Type.ADS))
651 {
652 moreBlockingPreferenceSubscriptions.add(sub);
653 }
654 }
655
656 return moreBlockingPreferenceSubscriptions;
657 }
658
659 private boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo)
660 { 632 {
661 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl()); 633 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl());
662 } 634 }
663 635
664 private static class EventHandler implements Runnable 636 private static class EventHandler implements Runnable
665 { 637 {
666 private static final String TAG = EventHandler.class.getSimpleName(); 638 private static final String TAG = EventHandler.class.getSimpleName();
667 private final Engine engine; 639 private final Engine engine;
668 640
669 public EventHandler(final Engine engine) 641 public EventHandler(final Engine engine)
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 { 808 {
837 void subscriptionUpdateRequested(boolean enabled); 809 void subscriptionUpdateRequested(boolean enabled);
838 void subscriptionUpdatedApplied(); 810 void subscriptionUpdatedApplied();
839 } 811 }
840 812
841 public interface SubscriptionAddedCallback 813 public interface SubscriptionAddedCallback
842 { 814 {
843 void subscriptionAdded(); 815 void subscriptionAdded();
844 } 816 }
845 } 817 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld