| OLD | NEW | 
|---|
| 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 14 matching lines...) Expand all  Loading... | 
| 25 import java.util.Locale; | 25 import java.util.Locale; | 
| 26 import java.util.Map; | 26 import java.util.Map; | 
| 27 import java.util.Set; | 27 import java.util.Set; | 
| 28 | 28 | 
| 29 import org.adblockplus.libadblockplus.AppInfo; | 29 import org.adblockplus.libadblockplus.AppInfo; | 
| 30 import org.adblockplus.libadblockplus.Filter; | 30 import org.adblockplus.libadblockplus.Filter; | 
| 31 import org.adblockplus.libadblockplus.FilterChangeCallback; | 31 import org.adblockplus.libadblockplus.FilterChangeCallback; | 
| 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.JsEngine; |  | 
| 36 import org.adblockplus.libadblockplus.JsValue; | 35 import org.adblockplus.libadblockplus.JsValue; | 
| 37 import org.adblockplus.libadblockplus.LogSystem; | 36 import org.adblockplus.libadblockplus.LogSystem; | 
|  | 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.WebRequest; | 42 import org.adblockplus.libadblockplus.WebRequest; | 
| 43 | 43 | 
| 44 import android.content.Context; | 44 import android.content.Context; | 
| 45 import android.content.pm.PackageInfo; | 45 import android.content.pm.PackageInfo; | 
| 46 import android.content.pm.PackageManager; | 46 import android.content.pm.PackageManager; | 
| 47 import android.os.Build.VERSION; | 47 import android.os.Build.VERSION; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 60    * The fields below are volatile because: | 60    * The fields below are volatile because: | 
| 61    * | 61    * | 
| 62    * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I
     t seemed that under | 62    * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I
     t seemed that under | 
| 63    * certain conditions the objects were optimized away which resulted in crashe
     s when trying to | 63    * certain conditions the objects were optimized away which resulted in crashe
     s when trying to | 
| 64    * release the object, sometimes even on access. | 64    * release the object, sometimes even on access. | 
| 65    * | 65    * | 
| 66    * The only solution that really worked was to declare the variables holding t
     he references | 66    * The only solution that really worked was to declare the variables holding t
     he references | 
| 67    * volatile, this seems to prevent the JNI from 'optimizing away' those object
     s (as a volatile | 67    * volatile, this seems to prevent the JNI from 'optimizing away' those object
     s (as a volatile | 
| 68    * variable might be changed at any time from any thread). | 68    * variable might be changed at any time from any thread). | 
| 69    */ | 69    */ | 
| 70   private volatile JsEngine jsEngine; | 70   private volatile Platform platform; | 
| 71   private volatile FilterEngine filterEngine; | 71   private volatile FilterEngine filterEngine; | 
| 72   private volatile LogSystem logSystem; | 72   private volatile LogSystem logSystem; | 
| 73   private volatile WebRequest webRequest; | 73   private volatile WebRequest webRequest; | 
| 74   private volatile UpdateAvailableCallback updateAvailableCallback; | 74   private volatile UpdateAvailableCallback updateAvailableCallback; | 
| 75   private volatile UpdateCheckDoneCallback updateCheckDoneCallback; | 75   private volatile UpdateCheckDoneCallback updateCheckDoneCallback; | 
| 76   private volatile FilterChangeCallback filterChangeCallback; | 76   private volatile FilterChangeCallback filterChangeCallback; | 
| 77   private volatile ShowNotificationCallback showNotificationCallback; | 77   private volatile ShowNotificationCallback showNotificationCallback; | 
| 78   private volatile boolean elemhideEnabled; | 78   private volatile boolean elemhideEnabled; | 
| 79   private volatile boolean enabled = true; | 79   private volatile boolean enabled = true; | 
| 80   private volatile List<String> whitelistedDomains; | 80   private volatile List<String> whitelistedDomains; | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 247       initCallbacks(); | 247       initCallbacks(); | 
| 248 | 248 | 
| 249       androidWebRequest.updateSubscriptionURLs(engine.filterEngine); | 249       androidWebRequest.updateSubscriptionURLs(engine.filterEngine); | 
| 250 | 250 | 
| 251       return engine; | 251       return engine; | 
| 252     } | 252     } | 
| 253 | 253 | 
| 254     private void createEngines() | 254     private void createEngines() | 
| 255     { | 255     { | 
| 256       engine.logSystem = new AndroidLogSystem(); | 256       engine.logSystem = new AndroidLogSystem(); | 
| 257       engine.jsEngine = new JsEngine(appInfo, engine.logSystem, engine.webReques
     t, basePath); | 257       engine.platform = new Platform(engine.logSystem, engine.webRequest, basePa
     th); | 
| 258 | 258       engine.platform.setUpJsEngine(appInfo); | 
| 259       engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectio
     nCallback); | 259       engine.platform.setUpFilterEngine(isAllowedConnectionCallback); | 
|  | 260       engine.filterEngine = engine.platform.getFilterEngine(); | 
| 260     } | 261     } | 
| 261   } | 262   } | 
| 262 | 263 | 
| 263   public static Builder builder(AppInfo appInfo, String basePath) | 264   public static Builder builder(AppInfo appInfo, String basePath) | 
| 264   { | 265   { | 
| 265     return new Builder(appInfo, basePath); | 266     return new Builder(appInfo, basePath); | 
| 266   } | 267   } | 
| 267 | 268 | 
| 268   public void dispose() | 269   public void dispose() | 
| 269   { | 270   { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 280       if (this.filterChangeCallback != null) | 281       if (this.filterChangeCallback != null) | 
| 281       { | 282       { | 
| 282         this.filterEngine.removeFilterChangeCallback(); | 283         this.filterEngine.removeFilterChangeCallback(); | 
| 283       } | 284       } | 
| 284 | 285 | 
| 285       if (this.showNotificationCallback != null) | 286       if (this.showNotificationCallback != null) | 
| 286       { | 287       { | 
| 287         this.filterEngine.removeShowNotificationCallback(); | 288         this.filterEngine.removeShowNotificationCallback(); | 
| 288       } | 289       } | 
| 289 | 290 | 
| 290       this.filterEngine.dispose(); | 291       this.platform.dispose(); | 
| 291       this.filterEngine = null; | 292       this.platform = null; | 
| 292     } |  | 
| 293 |  | 
| 294     if (this.jsEngine != null) |  | 
| 295     { |  | 
| 296       this.jsEngine.dispose(); |  | 
| 297       this.jsEngine = null; |  | 
| 298     } | 293     } | 
| 299 | 294 | 
| 300     // callbacks then | 295     // callbacks then | 
| 301     if (this.updateAvailableCallback != null) | 296     if (this.updateAvailableCallback != null) | 
| 302     { | 297     { | 
| 303       this.updateAvailableCallback.dispose(); | 298       this.updateAvailableCallback.dispose(); | 
| 304       this.updateAvailableCallback = null; | 299       this.updateAvailableCallback = null; | 
| 305     } | 300     } | 
| 306 | 301 | 
| 307     if (this.filterChangeCallback != null) | 302     if (this.filterChangeCallback != null) | 
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 615   public void setWhitelistedDomains(List<String> domains) | 610   public void setWhitelistedDomains(List<String> domains) | 
| 616   { | 611   { | 
| 617     this.whitelistedDomains = domains; | 612     this.whitelistedDomains = domains; | 
| 618   } | 613   } | 
| 619 | 614 | 
| 620   public List<String> getWhitelistedDomains() | 615   public List<String> getWhitelistedDomains() | 
| 621   { | 616   { | 
| 622     return whitelistedDomains; | 617     return whitelistedDomains; | 
| 623   } | 618   } | 
| 624 } | 619 } | 
| OLD | NEW | 
|---|