OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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.List; | 20 import java.util.List; |
21 import java.util.Locale; | 21 import java.util.Locale; |
22 | 22 |
23 import org.adblockplus.libadblockplus.AppInfo; | 23 import org.adblockplus.libadblockplus.AppInfo; |
24 import org.adblockplus.libadblockplus.EventCallback; | 24 import org.adblockplus.libadblockplus.EventCallback; |
25 import org.adblockplus.libadblockplus.Filter; | 25 import org.adblockplus.libadblockplus.Filter; |
26 import org.adblockplus.libadblockplus.FilterChangeCallback; | 26 import org.adblockplus.libadblockplus.FilterChangeCallback; |
27 import org.adblockplus.libadblockplus.FilterEngine; | 27 import org.adblockplus.libadblockplus.FilterEngine; |
| 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; |
30 import org.adblockplus.libadblockplus.Subscription; | 31 import org.adblockplus.libadblockplus.Subscription; |
31 import org.adblockplus.libadblockplus.UpdaterCallback; | 32 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; |
32 import org.adblockplus.libadblockplus.WebRequest; | 33 import org.adblockplus.libadblockplus.WebRequest; |
33 | 34 |
34 import android.content.Context; | 35 import android.content.Context; |
35 import android.content.pm.PackageInfo; | 36 import android.content.pm.PackageInfo; |
36 import android.content.pm.PackageManager.NameNotFoundException; | 37 import android.content.pm.PackageManager.NameNotFoundException; |
37 import android.os.Build.VERSION; | 38 import android.os.Build.VERSION; |
38 import android.util.Log; | 39 import android.util.Log; |
39 | 40 |
40 public final class ABPEngine | 41 public final class ABPEngine |
41 { | 42 { |
(...skipping 10 matching lines...) Expand all Loading... |
52 * | 53 * |
53 * The only solution that really worked was to declare the variables holding t
he references | 54 * The only solution that really worked was to declare the variables holding t
he references |
54 * volatile, this seems to prevent the JNI from 'optimizing away' those object
s (as a volatile | 55 * volatile, this seems to prevent the JNI from 'optimizing away' those object
s (as a volatile |
55 * variable might be changed at any time from any thread). | 56 * variable might be changed at any time from any thread). |
56 */ | 57 */ |
57 private volatile JsEngine jsEngine; | 58 private volatile JsEngine jsEngine; |
58 private volatile FilterEngine filterEngine; | 59 private volatile FilterEngine filterEngine; |
59 private volatile LogSystem logSystem; | 60 private volatile LogSystem logSystem; |
60 private volatile WebRequest webRequest; | 61 private volatile WebRequest webRequest; |
61 private volatile EventCallback updateCallback; | 62 private volatile EventCallback updateCallback; |
62 private volatile UpdaterCallback updaterCallback; | 63 private volatile UpdateCheckDoneCallback updateCheckDoneCallback; |
63 private volatile FilterChangeCallback filterChangeCallback; | 64 private volatile FilterChangeCallback filterChangeCallback; |
64 | 65 |
65 private ABPEngine(final Context context) | 66 private ABPEngine(final Context context) |
66 { | 67 { |
67 this.context = context; | 68 this.context = context; |
68 } | 69 } |
69 | 70 |
70 public static AppInfo generateAppInfo(final Context context) | 71 public static AppInfo generateAppInfo(final Context context) |
71 { | 72 { |
72 String version = "0"; | 73 String version = "0"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 engine.webRequest = new AndroidWebRequest(); | 105 engine.webRequest = new AndroidWebRequest(); |
105 engine.jsEngine.setWebRequest(engine.webRequest); | 106 engine.jsEngine.setWebRequest(engine.webRequest); |
106 | 107 |
107 engine.updateCallback = new AndroidUpdateAvailableCallback(context); | 108 engine.updateCallback = new AndroidUpdateAvailableCallback(context); |
108 engine.jsEngine.setEventCallback("updateAvailable", engine.updateCallback); | 109 engine.jsEngine.setEventCallback("updateAvailable", engine.updateCallback); |
109 | 110 |
110 engine.filterEngine = new FilterEngine(engine.jsEngine); | 111 engine.filterEngine = new FilterEngine(engine.jsEngine); |
111 engine.filterChangeCallback = new AndroidFilterChangeCallback(context); | 112 engine.filterChangeCallback = new AndroidFilterChangeCallback(context); |
112 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback); | 113 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback); |
113 | 114 |
114 engine.updaterCallback = new AndroidUpdaterCallback(context); | 115 engine.updateCheckDoneCallback = new AndroidUpdateCheckDoneCallback(context)
; |
115 | 116 |
116 return engine; | 117 return engine; |
117 } | 118 } |
118 | 119 |
119 public void dispose() | 120 public void dispose() |
120 { | 121 { |
121 // Safe disposing (just in case) | 122 // Safe disposing (just in case) |
122 if (this.filterEngine != null) | 123 if (this.filterEngine != null) |
123 { | 124 { |
124 this.filterEngine.dispose(); | 125 this.filterEngine.dispose(); |
(...skipping 17 matching lines...) Expand all Loading... |
142 this.webRequest.dispose(); | 143 this.webRequest.dispose(); |
143 this.webRequest = null; | 144 this.webRequest = null; |
144 } | 145 } |
145 | 146 |
146 if (this.updateCallback != null) | 147 if (this.updateCallback != null) |
147 { | 148 { |
148 this.updateCallback.dispose(); | 149 this.updateCallback.dispose(); |
149 this.updateCallback = null; | 150 this.updateCallback = null; |
150 } | 151 } |
151 | 152 |
152 if (this.updaterCallback != null) | 153 if (this.updateCheckDoneCallback != null) |
153 { | 154 { |
154 this.updaterCallback.dispose(); | 155 this.updateCheckDoneCallback.dispose(); |
155 this.updaterCallback = null; | 156 this.updateCheckDoneCallback = null; |
156 } | 157 } |
157 | 158 |
158 if (this.filterChangeCallback != null) | 159 if (this.filterChangeCallback != null) |
159 { | 160 { |
160 this.filterChangeCallback.dispose(); | 161 this.filterChangeCallback.dispose(); |
161 this.filterChangeCallback = null; | 162 this.filterChangeCallback = null; |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 public boolean isFirstRun() | 166 public boolean isFirstRun() |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 sub.removeFromList(); | 237 sub.removeFromList(); |
237 } | 238 } |
238 } | 239 } |
239 } | 240 } |
240 | 241 |
241 public String getDocumentationLink() | 242 public String getDocumentationLink() |
242 { | 243 { |
243 return this.filterEngine.getPref("documentation_link").toString(); | 244 return this.filterEngine.getPref("documentation_link").toString(); |
244 } | 245 } |
245 | 246 |
246 public boolean matches(final String fullUrl, final String contentType, final S
tring[] referrerChainArray) | 247 public boolean matches(final String fullUrl, final ContentType contentType, fi
nal String[] referrerChainArray) |
247 { | 248 { |
248 final Filter filter = this.filterEngine.matches(fullUrl, contentType, referr
erChainArray); | 249 final Filter filter = this.filterEngine.matches(fullUrl, contentType, referr
erChainArray); |
249 | 250 |
250 if (filter == null) | 251 if (filter == null) |
251 { | 252 { |
252 return false; | 253 return false; |
253 } | 254 } |
254 | 255 |
255 // hack: if there is no referrer, block only if filter is domain-specific | 256 // hack: if there is no referrer, block only if filter is domain-specific |
256 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) | 257 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) |
257 // (documentUrls contains the referrers on Android) | 258 // (documentUrls contains the referrers on Android) |
258 if (referrerChainArray.length == 0 && (filter.getProperty("text").toString()
).contains("||")) | 259 if (referrerChainArray.length == 0 && (filter.getProperty("text").toString()
).contains("||")) |
259 { | 260 { |
260 return false; | 261 return false; |
261 } | 262 } |
262 | 263 |
263 return filter.getType() != Filter.Type.EXCEPTION; | 264 return filter.getType() != Filter.Type.EXCEPTION; |
264 } | 265 } |
265 | 266 |
266 public void checkForUpdates() | 267 public void checkForUpdates() |
267 { | 268 { |
268 this.filterEngine.forceUpdateCheck(this.updaterCallback); | 269 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); |
269 } | 270 } |
270 | 271 |
271 public void updateSubscriptionStatus(final String url) | 272 public void updateSubscriptionStatus(final String url) |
272 { | 273 { |
273 final Subscription sub = this.filterEngine.getSubscription(url); | 274 final Subscription sub = this.filterEngine.getSubscription(url); |
274 if (sub != null) | 275 if (sub != null) |
275 { | 276 { |
276 Utils.updateSubscriptionStatus(this.context, sub); | 277 Utils.updateSubscriptionStatus(this.context, sub); |
277 } | 278 } |
278 } | 279 } |
279 } | 280 } |
OLD | NEW |