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

Unified Diff: src/org/adblockplus/android/ABPEngine.java

Issue 29331923: Issue 3364 - Implement JNI bindings for IsDocument/ElemhideWhitelisted (Closed)
Patch Set: Typo Created Dec. 4, 2015, 5:44 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
« no previous file with comments | « jni/JniFilterEngine.cpp ('k') | src/org/adblockplus/android/AdblockPlus.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/android/ABPEngine.java
diff --git a/src/org/adblockplus/android/ABPEngine.java b/src/org/adblockplus/android/ABPEngine.java
index 418185e0f0fcde90f0fde593af69e92c206fec8e..7bb1c7d51431cd07b43bb9b4c1ad3a98c60a3d84 100644
--- a/src/org/adblockplus/android/ABPEngine.java
+++ b/src/org/adblockplus/android/ABPEngine.java
@@ -17,6 +17,7 @@
package org.adblockplus.android;
+import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -63,10 +64,12 @@ public final class ABPEngine
private volatile UpdateCheckDoneCallback updateCheckDoneCallback;
private volatile FilterChangeCallback filterChangeCallback;
private volatile ShowNotificationCallback showNotificationCallback;
+ private final boolean elemhideEnabled;
- private ABPEngine(final Context context)
+ private ABPEngine(final Context context, final boolean enableElemhide)
{
this.context = context;
+ this.elemhideEnabled = enableElemhide;
}
public static AppInfo generateAppInfo(final Context context)
@@ -97,7 +100,12 @@ public final class ABPEngine
public static ABPEngine create(final Context context, final AppInfo appInfo, final String basePath)
{
- final ABPEngine engine = new ABPEngine(context);
+ return create(context, appInfo, basePath, false);
+ }
+
+ public static ABPEngine create(final Context context, final AppInfo appInfo, final String basePath, boolean enableElemhide)
+ {
+ final ABPEngine engine = new ABPEngine(context, enableElemhide);
engine.jsEngine = new JsEngine(appInfo);
engine.jsEngine.setDefaultFileSystem(basePath);
@@ -105,7 +113,7 @@ public final class ABPEngine
engine.logSystem = new AndroidLogSystem();
engine.jsEngine.setLogSystem(engine.logSystem);
- engine.webRequest = new AndroidWebRequest();
+ engine.webRequest = new AndroidWebRequest(enableElemhide);
engine.jsEngine.setWebRequest(engine.webRequest);
engine.filterEngine = new FilterEngine(engine.jsEngine);
@@ -182,6 +190,11 @@ public final class ABPEngine
return this.filterEngine.isFirstRun();
}
+ public boolean isElemhideEnabled()
+ {
+ return this.elemhideEnabled;
+ }
+
private static org.adblockplus.android.Subscription convertJsSubscription(final Subscription jsSubscription)
{
final org.adblockplus.android.Subscription subscription = new org.adblockplus.android.Subscription();
@@ -278,6 +291,41 @@ public final class ABPEngine
return filter.getType() != Filter.Type.EXCEPTION;
}
+ public boolean isDocumentWhitelisted(final String url, final String[] referrerChainArray)
+ {
+ return this.filterEngine.isDocumentWhitelisted(url, referrerChainArray);
+ }
+
+ public boolean isElemhideWhitelisted(final String url, final String[] referrerChainArray)
+ {
+ return this.filterEngine.isElemhideWhitelisted(url, referrerChainArray);
+ }
+
+ public List<String> getElementHidingSelectors(final String url, final String[] referrerChainArray)
+ {
+ /*
+ * Issue 3364 (https://issues.adblockplus.org/ticket/3364) introduced the
+ * feature to re-enabled element hiding.
+ *
+ * Nothing changes for Adblock Plus for Android, as `this.elemhideEnabled`
+ * is `false`, which results in an empty list being returned and converted
+ * into a `(String[])null` in AdblockPlus.java, which is the only place
+ * this function here is called from Adblock Plus for Android.
+ *
+ * If element hiding is enabled, then this function now first checks for
+ * possible whitelisting of either the document or element hiding for
+ * the given URL and returns an empty list if so. This is needed to
+ * ensure correct functioning of e.g. acceptable ads.
+ */
+ if (!this.elemhideEnabled
+ || this.isDocumentWhitelisted(url, referrerChainArray)
+ || this.isElemhideWhitelisted(url, referrerChainArray))
+ {
+ return new ArrayList<String>();
+ }
+ return this.filterEngine.getElementHidingSelectors(url);
+ }
+
public void checkForUpdates()
{
this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback);
@@ -291,4 +339,9 @@ public final class ABPEngine
Utils.updateSubscriptionStatus(this.context, sub);
}
}
+
+ public FilterEngine getFilterEngine()
+ {
+ return this.filterEngine;
+ }
}
« no previous file with comments | « jni/JniFilterEngine.cpp ('k') | src/org/adblockplus/android/AdblockPlus.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld