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

Side by Side Diff: adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java

Issue 29908555: Issue 7035 - Update libadblockplus dependency (Closed) Base URL: git@github.com:adblockplus/libadblockplus-android.git@d150f08d5d72de8938c7ebbdccd9b0c4e06b4070
Patch Set: Issue 7035 - Update libadblockplus dependency Created Oct. 15, 2018, 12:48 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 | « adblock-android/src/org/adblockplus/libadblockplus/Platform.java ('k') | dependencies » ('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-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 21 matching lines...) Expand all
32 import org.adblockplus.libadblockplus.FilterEngine; 32 import org.adblockplus.libadblockplus.FilterEngine;
33 import org.adblockplus.libadblockplus.FilterEngine.ContentType; 33 import org.adblockplus.libadblockplus.FilterEngine.ContentType;
34 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; 34 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback;
35 import org.adblockplus.libadblockplus.JsValue; 35 import org.adblockplus.libadblockplus.JsValue;
36 import org.adblockplus.libadblockplus.LogSystem; 36 import org.adblockplus.libadblockplus.LogSystem;
37 import org.adblockplus.libadblockplus.Platform; 37 import org.adblockplus.libadblockplus.Platform;
38 import org.adblockplus.libadblockplus.ShowNotificationCallback; 38 import org.adblockplus.libadblockplus.ShowNotificationCallback;
39 import org.adblockplus.libadblockplus.Subscription; 39 import org.adblockplus.libadblockplus.Subscription;
40 import org.adblockplus.libadblockplus.UpdateAvailableCallback; 40 import org.adblockplus.libadblockplus.UpdateAvailableCallback;
41 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; 41 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
42 import org.adblockplus.libadblockplus.Updater;
42 import org.adblockplus.libadblockplus.WebRequest; 43 import org.adblockplus.libadblockplus.WebRequest;
43 44
44 import android.content.Context; 45 import android.content.Context;
45 import android.content.pm.PackageInfo; 46 import android.content.pm.PackageInfo;
46 import android.content.pm.PackageManager; 47 import android.content.pm.PackageManager;
47 import android.os.Build.VERSION; 48 import android.os.Build.VERSION;
48 import android.util.Log; 49 import android.util.Log;
49 50
50 public final class AdblockEngine 51 public final class AdblockEngine
51 { 52 {
52 // default base path to store subscription files in android app 53 // default base path to store subscription files in android app
53 public static final String BASE_PATH_DIRECTORY = "adblock"; 54 public static final String BASE_PATH_DIRECTORY = "adblock";
54 55
55 private static final String TAG = Utils.getTag(AdblockEngine.class); 56 private static final String TAG = Utils.getTag(AdblockEngine.class);
56 57
57 /* 58 /*
58 * The fields below are volatile because: 59 * The fields below are volatile because:
59 * 60 *
60 * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I t seemed that under 61 * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I t seemed that under
61 * certain conditions the objects were optimized away which resulted in crashe s when trying to 62 * certain conditions the objects were optimized away which resulted in crashe s when trying to
62 * release the object, sometimes even on access. 63 * release the object, sometimes even on access.
63 * 64 *
64 * The only solution that really worked was to declare the variables holding t he references 65 * The only solution that really worked was to declare the variables holding t he references
65 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile 66 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile
66 * variable might be changed at any time from any thread). 67 * variable might be changed at any time from any thread).
67 */ 68 */
68 private volatile Platform platform; 69 private volatile Platform platform;
69 private volatile FilterEngine filterEngine; 70 private volatile FilterEngine filterEngine;
71 private volatile Updater updater;
70 private volatile LogSystem logSystem; 72 private volatile LogSystem logSystem;
71 private volatile WebRequest webRequest; 73 private volatile WebRequest webRequest;
72 private volatile UpdateAvailableCallback updateAvailableCallback; 74 private volatile UpdateAvailableCallback updateAvailableCallback;
73 private volatile UpdateCheckDoneCallback updateCheckDoneCallback; 75 private volatile UpdateCheckDoneCallback updateCheckDoneCallback;
74 private volatile FilterChangeCallback filterChangeCallback; 76 private volatile FilterChangeCallback filterChangeCallback;
75 private volatile ShowNotificationCallback showNotificationCallback; 77 private volatile ShowNotificationCallback showNotificationCallback;
76 private volatile boolean elemhideEnabled; 78 private volatile boolean elemhideEnabled;
77 private volatile boolean enabled = true; 79 private volatile boolean enabled = true;
78 private volatile List<String> whitelistedDomains; 80 private volatile List<String> whitelistedDomains;
79 81
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 225 }
224 } 226 }
225 }); 227 });
226 228
227 engine.webRequest = wrapper; 229 engine.webRequest = wrapper;
228 } 230 }
229 } 231 }
230 232
231 private void initCallbacks() 233 private void initCallbacks()
232 { 234 {
233 if (engine.updateAvailableCallback != null) 235 if (engine.updater != null && engine.updateAvailableCallback != null)
234 { 236 {
235 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCal lback); 237 engine.updater.setUpdateAvailableCallback(engine.updateAvailableCallback );
236 } 238 }
237 239
238 if (engine.showNotificationCallback != null) 240 if (engine.showNotificationCallback != null)
239 { 241 {
240 engine.filterEngine.setShowNotificationCallback(engine.showNotificationC allback); 242 engine.filterEngine.setShowNotificationCallback(engine.showNotificationC allback);
241 } 243 }
242 244
243 if (engine.filterChangeCallback != null) 245 if (engine.filterChangeCallback != null)
244 { 246 {
245 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback) ; 247 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback) ;
246 } 248 }
247 } 249 }
248 250
249 public AdblockEngine build() 251 public AdblockEngine build()
250 { 252 {
253 return build(false);
254 }
255
256 public AdblockEngine buildWithUpdateCheck()
257 {
258 return build(true);
259 }
260
261 private AdblockEngine build(boolean updateCheckEnabled)
262 {
251 initRequests(); 263 initRequests();
252 264
253 // webRequest should be ready to be used passed right after JsEngine is cr eated 265 // webRequest should be ready to be used passed right after JsEngine is cr eated
254 createEngines(); 266 createEngines(updateCheckEnabled);
255 267
256 initCallbacks(); 268 initCallbacks();
257 269
258 if (!engine.elemhideEnabled) 270 if (!engine.elemhideEnabled)
259 { 271 {
260 androidWebRequest.updateSubscriptionURLs(engine.filterEngine); 272 androidWebRequest.updateSubscriptionURLs(engine.filterEngine);
261 } 273 }
262 274
263 return engine; 275 return engine;
264 } 276 }
265 277
266 private void createEngines() 278 private void createEngines(boolean updateCheckEnabled)
267 { 279 {
268 engine.logSystem = new AndroidLogSystem(); 280 engine.logSystem = new AndroidLogSystem();
269 engine.platform = new Platform(engine.logSystem, engine.webRequest, basePa th); 281 engine.platform = new Platform(engine.logSystem, engine.webRequest, basePa th);
270 if (v8IsolateProviderPtr != null) 282 if (v8IsolateProviderPtr != null)
271 { 283 {
272 engine.platform.setUpJsEngine(appInfo, v8IsolateProviderPtr); 284 engine.platform.setUpJsEngine(appInfo, v8IsolateProviderPtr);
273 } 285 }
274 else 286 else
275 { 287 {
276 engine.platform.setUpJsEngine(appInfo); 288 engine.platform.setUpJsEngine(appInfo);
277 } 289 }
278 engine.platform.setUpFilterEngine(isAllowedConnectionCallback); 290 engine.platform.setUpFilterEngine(isAllowedConnectionCallback);
279 engine.filterEngine = engine.platform.getFilterEngine(); 291 engine.filterEngine = engine.platform.getFilterEngine();
292 if (updateCheckEnabled)
293 {
294 engine.updater = engine.platform.getUpdater();
295 }
280 } 296 }
281 } 297 }
282 298
283 public static Builder builder(AppInfo appInfo, String basePath) 299 public static Builder builder(AppInfo appInfo, String basePath)
284 { 300 {
285 return new Builder(appInfo, basePath); 301 return new Builder(appInfo, basePath);
286 } 302 }
287 303
288 public void dispose() 304 public void dispose()
289 { 305 {
290 Log.w(TAG, "Dispose"); 306 Log.w(TAG, "Dispose");
291 307
308 if (this.updater != null)
309 {
310 if (this.updateAvailableCallback != null)
311 {
312 this.updater.removeUpdateAvailableCallback();
313 }
314 }
315
292 // engines first 316 // engines first
293 if (this.filterEngine != null) 317 if (this.filterEngine != null)
294 { 318 {
295 if (this.updateAvailableCallback != null)
296 {
297 this.filterEngine.removeUpdateAvailableCallback();
298 }
299
300 if (this.filterChangeCallback != null) 319 if (this.filterChangeCallback != null)
301 { 320 {
302 this.filterEngine.removeFilterChangeCallback(); 321 this.filterEngine.removeFilterChangeCallback();
303 } 322 }
304 323
305 if (this.showNotificationCallback != null) 324 if (this.showNotificationCallback != null)
306 { 325 {
307 this.filterEngine.removeShowNotificationCallback(); 326 this.filterEngine.removeShowNotificationCallback();
308 } 327 }
309 328
310 this.platform.dispose(); 329 this.platform.dispose();
311 this.platform = null; 330 this.platform = null;
312 } 331 }
313 332
314 // callbacks then 333 // callbacks then
315 if (this.updateAvailableCallback != null) 334 if (this.updateAvailableCallback != null)
316 { 335 {
317 this.updateAvailableCallback.dispose(); 336 this.updateAvailableCallback.dispose();
318 this.updateAvailableCallback = null; 337 this.updateAvailableCallback = null;
319 } 338 }
320 339
340 if (this.updateCheckDoneCallback != null)
341 {
342 this.updateCheckDoneCallback.dispose();
343 this.updateCheckDoneCallback = null;
344 }
345
321 if (this.filterChangeCallback != null) 346 if (this.filterChangeCallback != null)
322 { 347 {
323 this.filterChangeCallback.dispose(); 348 this.filterChangeCallback.dispose();
324 this.filterChangeCallback = null; 349 this.filterChangeCallback = null;
325 } 350 }
326 351
327 if (this.showNotificationCallback != null) 352 if (this.showNotificationCallback != null)
328 { 353 {
329 this.showNotificationCallback.dispose(); 354 this.showNotificationCallback.dispose();
330 this.showNotificationCallback = null; 355 this.showNotificationCallback = null;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 || this.isDocumentWhitelisted(url, referrerChainArray) 646 || this.isDocumentWhitelisted(url, referrerChainArray)
622 || this.isElemhideWhitelisted(url, referrerChainArray)) 647 || this.isElemhideWhitelisted(url, referrerChainArray))
623 { 648 {
624 return new ArrayList<String>(); 649 return new ArrayList<String>();
625 } 650 }
626 return this.filterEngine.getElementHidingSelectors(domain); 651 return this.filterEngine.getElementHidingSelectors(domain);
627 } 652 }
628 653
629 public void checkForUpdates() 654 public void checkForUpdates()
630 { 655 {
631 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); 656 if (updater == null) throw new IllegalStateException();
657 this.updater.forceUpdateCheck(this.updateCheckDoneCallback);
632 } 658 }
633 659
634 public FilterEngine getFilterEngine() 660 public FilterEngine getFilterEngine()
635 { 661 {
636 return this.filterEngine; 662 return this.filterEngine;
637 } 663 }
638 664
639 public void setWhitelistedDomains(List<String> domains) 665 public void setWhitelistedDomains(List<String> domains)
640 { 666 {
641 this.whitelistedDomains = domains; 667 this.whitelistedDomains = domains;
642 } 668 }
643 669
644 public List<String> getWhitelistedDomains() 670 public List<String> getWhitelistedDomains()
645 { 671 {
646 return whitelistedDomains; 672 return whitelistedDomains;
647 } 673 }
648 } 674 }
OLDNEW
« no previous file with comments | « adblock-android/src/org/adblockplus/libadblockplus/Platform.java ('k') | dependencies » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld