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

Unified Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29524668: Issue 3916 - Supporting Adding filter lists via URL (Closed)
Patch Set: Use TAG constant for log, fix in MoreBlockingPreferenceCategory Created Oct. 10, 2017, 1:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java
===================================================================
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java
@@ -251,16 +251,32 @@ public final class Engine
public void subscriptionStateChanged()
{
if (this.subscriptionUpdateCallback != null)
{
subscriptionUpdateCallback.subscriptionUpdatedApplied();
}
}
+ public void createAndAddSubscriptionFromUrl(final String url,
+ final SubscriptionAddedCallback callback) throws IOException
+ {
+ final Subscription sub = Subscription.create(url);
+ sub.putMeta(Subscription.KEY_TITLE, url);
+ sub.setEnabled(true);
+ subscriptions.add(sub);
+ subscriptions.persistSubscription(sub);
+ callback.subscriptionAdded();
+ }
+
+ public void removeSubscriptionById(final String subscriptionId)
+ {
+ subscriptions.remove(subscriptionId);
+ }
+
void downloadFinished(final String id, final int responseCode, final String response,
final Map<String, String> headers)
{
this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, headers));
}
private void createAndWriteFile()
{
@@ -404,17 +420,18 @@ public final class Engine
{
Log.d(TAG, "Subscription storage was uninitialized, initializing...");
try (final InputStream easylistTxt = context.getResources().openRawResource(R.raw.easylist))
{
final Subscription easylist = engine.subscriptions.add(Subscription
// Use bundled EasyList as default and update it with locale specific list later
// see: https://issues.adblockplus.org/ticket/5237
- .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaultSubscriptions.getAdsSubscriptions()))
+ .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(
+ engine.defaultSubscriptions.getAdsSubscriptions()))
.parseLines(readLines(easylistTxt)));
easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0");
easylist.setEnabled(true);
}
Log.d(TAG, "Added and enabled bundled easylist");
try (final InputStream exceptionsTxt = context.getResources()
.openRawResource(R.raw.exceptionrules))
@@ -606,16 +623,21 @@ public final class Engine
else
{
sb.append("4%2B"); // "4+" URL encoded
}
return new URL(sb.toString());
}
+ public boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo)
+ {
+ return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo.getUrl());
+ }
+
private static class EventHandler implements Runnable
{
private static final String TAG = EventHandler.class.getSimpleName();
private final Engine engine;
public EventHandler(final Engine engine)
{
this.engine = engine;
@@ -782,9 +804,14 @@ public final class Engine
this.downloader.connectivityChanged();
}
public interface SubscriptionUpdateCallback
{
void subscriptionUpdateRequested(boolean enabled);
void subscriptionUpdatedApplied();
}
+
+ public interface SubscriptionAddedCallback
+ {
+ void subscriptionAdded();
+ }
}

Powered by Google App Engine
This is Rietveld