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

Side by Side 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.
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 | « jni/JniFilterEngine.cpp ('k') | src/org/adblockplus/android/AdblockPlus.java » ('j') | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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.util.ArrayList;
20 import java.util.List; 21 import java.util.List;
21 import java.util.Locale; 22 import java.util.Locale;
22 23
23 import org.adblockplus.libadblockplus.AppInfo; 24 import org.adblockplus.libadblockplus.AppInfo;
24 import org.adblockplus.libadblockplus.Filter; 25 import org.adblockplus.libadblockplus.Filter;
25 import org.adblockplus.libadblockplus.FilterChangeCallback; 26 import org.adblockplus.libadblockplus.FilterChangeCallback;
26 import org.adblockplus.libadblockplus.FilterEngine; 27 import org.adblockplus.libadblockplus.FilterEngine;
27 import org.adblockplus.libadblockplus.FilterEngine.ContentType; 28 import org.adblockplus.libadblockplus.FilterEngine.ContentType;
28 import org.adblockplus.libadblockplus.JsEngine; 29 import org.adblockplus.libadblockplus.JsEngine;
29 import org.adblockplus.libadblockplus.LogSystem; 30 import org.adblockplus.libadblockplus.LogSystem;
(...skipping 26 matching lines...) Expand all
56 * variable might be changed at any time from any thread). 57 * variable might be changed at any time from any thread).
57 */ 58 */
58 private volatile JsEngine jsEngine; 59 private volatile JsEngine jsEngine;
59 private volatile FilterEngine filterEngine; 60 private volatile FilterEngine filterEngine;
60 private volatile LogSystem logSystem; 61 private volatile LogSystem logSystem;
61 private volatile AndroidWebRequest webRequest; 62 private volatile AndroidWebRequest webRequest;
62 private volatile UpdateAvailableCallback updateAvailableCallback; 63 private volatile UpdateAvailableCallback updateAvailableCallback;
63 private volatile UpdateCheckDoneCallback updateCheckDoneCallback; 64 private volatile UpdateCheckDoneCallback updateCheckDoneCallback;
64 private volatile FilterChangeCallback filterChangeCallback; 65 private volatile FilterChangeCallback filterChangeCallback;
65 private volatile ShowNotificationCallback showNotificationCallback; 66 private volatile ShowNotificationCallback showNotificationCallback;
67 private final boolean elemhideEnabled;
66 68
67 private ABPEngine(final Context context) 69 private ABPEngine(final Context context, final boolean enableElemhide)
68 { 70 {
69 this.context = context; 71 this.context = context;
72 this.elemhideEnabled = enableElemhide;
70 } 73 }
71 74
72 public static AppInfo generateAppInfo(final Context context) 75 public static AppInfo generateAppInfo(final Context context)
73 { 76 {
74 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release); 77 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release);
75 String version = "0"; 78 String version = "0";
76 try 79 try
77 { 80 {
78 final PackageInfo info = context.getPackageManager().getPackageInfo(contex t.getPackageName(), 0); 81 final PackageInfo info = context.getPackageManager().getPackageInfo(contex t.getPackageName(), 0);
79 version = info.versionName; 82 version = info.versionName;
(...skipping 10 matching lines...) Expand all
90 return AppInfo.builder() 93 return AppInfo.builder()
91 .setVersion(version) 94 .setVersion(version)
92 .setApplicationVersion(sdkVersion) 95 .setApplicationVersion(sdkVersion)
93 .setLocale(locale) 96 .setLocale(locale)
94 .setDevelopmentBuild(developmentBuild) 97 .setDevelopmentBuild(developmentBuild)
95 .build(); 98 .build();
96 } 99 }
97 100
98 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath) 101 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath)
99 { 102 {
100 final ABPEngine engine = new ABPEngine(context); 103 return create(context, appInfo, basePath, false);
104 }
105
106 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath, boolean enableElemhide)
107 {
108 final ABPEngine engine = new ABPEngine(context, enableElemhide);
101 109
102 engine.jsEngine = new JsEngine(appInfo); 110 engine.jsEngine = new JsEngine(appInfo);
103 engine.jsEngine.setDefaultFileSystem(basePath); 111 engine.jsEngine.setDefaultFileSystem(basePath);
104 112
105 engine.logSystem = new AndroidLogSystem(); 113 engine.logSystem = new AndroidLogSystem();
106 engine.jsEngine.setLogSystem(engine.logSystem); 114 engine.jsEngine.setLogSystem(engine.logSystem);
107 115
108 engine.webRequest = new AndroidWebRequest(); 116 engine.webRequest = new AndroidWebRequest(enableElemhide);
109 engine.jsEngine.setWebRequest(engine.webRequest); 117 engine.jsEngine.setWebRequest(engine.webRequest);
110 118
111 engine.filterEngine = new FilterEngine(engine.jsEngine); 119 engine.filterEngine = new FilterEngine(engine.jsEngine);
112 120
113 engine.webRequest.updateSubscriptionURLs(engine.filterEngine); 121 engine.webRequest.updateSubscriptionURLs(engine.filterEngine);
114 122
115 engine.updateAvailableCallback = new AndroidUpdateAvailableCallback(context) ; 123 engine.updateAvailableCallback = new AndroidUpdateAvailableCallback(context) ;
116 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCallbac k); 124 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCallbac k);
117 engine.filterChangeCallback = new AndroidFilterChangeCallback(context); 125 engine.filterChangeCallback = new AndroidFilterChangeCallback(context);
118 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback); 126 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 this.showNotificationCallback.dispose(); 183 this.showNotificationCallback.dispose();
176 this.showNotificationCallback = null; 184 this.showNotificationCallback = null;
177 } 185 }
178 } 186 }
179 187
180 public boolean isFirstRun() 188 public boolean isFirstRun()
181 { 189 {
182 return this.filterEngine.isFirstRun(); 190 return this.filterEngine.isFirstRun();
183 } 191 }
184 192
193 public boolean isElemhideEnabled()
194 {
195 return this.elemhideEnabled;
196 }
197
185 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription jsSubscription) 198 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription jsSubscription)
186 { 199 {
187 final org.adblockplus.android.Subscription subscription = new org.adblockplu s.android.Subscription(); 200 final org.adblockplus.android.Subscription subscription = new org.adblockplu s.android.Subscription();
188 201
189 subscription.title = jsSubscription.getProperty("title").toString(); 202 subscription.title = jsSubscription.getProperty("title").toString();
190 subscription.url = jsSubscription.getProperty("url").toString(); 203 subscription.url = jsSubscription.getProperty("url").toString();
191 204
192 return subscription; 205 return subscription;
193 } 206 }
194 207
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) 284 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting)
272 // (documentUrls contains the referrers on Android) 285 // (documentUrls contains the referrers on Android)
273 if (referrerChainArray.length == 0 && (filter.getProperty("text").toString() ).contains("||")) 286 if (referrerChainArray.length == 0 && (filter.getProperty("text").toString() ).contains("||"))
274 { 287 {
275 return false; 288 return false;
276 } 289 }
277 290
278 return filter.getType() != Filter.Type.EXCEPTION; 291 return filter.getType() != Filter.Type.EXCEPTION;
279 } 292 }
280 293
294 public boolean isDocumentWhitelisted(final String url, final String[] referrer ChainArray)
295 {
296 return this.filterEngine.isDocumentWhitelisted(url, referrerChainArray);
297 }
298
299 public boolean isElemhideWhitelisted(final String url, final String[] referrer ChainArray)
300 {
301 return this.filterEngine.isElemhideWhitelisted(url, referrerChainArray);
302 }
303
304 public List<String> getElementHidingSelectors(final String url, final String[] referrerChainArray)
305 {
306 /*
307 * Issue 3364 (https://issues.adblockplus.org/ticket/3364) introduced the
308 * feature to re-enabled element hiding.
309 *
310 * Nothing changes for Adblock Plus for Android, as `this.elemhideEnabled`
311 * is `false`, which results in an empty list being returned and converted
312 * into a `(String[])null` in AdblockPlus.java, which is the only place
313 * this function here is called from Adblock Plus for Android.
314 *
315 * If element hiding is enabled, then this function now first checks for
316 * possible whitelisting of either the document or element hiding for
317 * the given URL and returns an empty list if so. This is needed to
318 * ensure correct functioning of e.g. acceptable ads.
319 */
320 if (!this.elemhideEnabled
321 || this.isDocumentWhitelisted(url, referrerChainArray)
322 || this.isElemhideWhitelisted(url, referrerChainArray))
323 {
324 return new ArrayList<String>();
325 }
326 return this.filterEngine.getElementHidingSelectors(url);
327 }
328
281 public void checkForUpdates() 329 public void checkForUpdates()
282 { 330 {
283 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); 331 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback);
284 } 332 }
285 333
286 public void updateSubscriptionStatus(final String url) 334 public void updateSubscriptionStatus(final String url)
287 { 335 {
288 final Subscription sub = this.filterEngine.getSubscription(url); 336 final Subscription sub = this.filterEngine.getSubscription(url);
289 if (sub != null) 337 if (sub != null)
290 { 338 {
291 Utils.updateSubscriptionStatus(this.context, sub); 339 Utils.updateSubscriptionStatus(this.context, sub);
292 } 340 }
293 } 341 }
342
343 public FilterEngine getFilterEngine()
344 {
345 return this.filterEngine;
346 }
294 } 347 }
OLDNEW
« 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