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-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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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[] document
Urls) |
| 295 { |
| 296 return this.filterEngine.isDocumentWhitelisted(url, documentUrls); |
| 297 } |
| 298 |
| 299 public boolean isElemhideWhitelisted(final String url, final String[] document
Urls) |
| 300 { |
| 301 return this.filterEngine.isElemhideWhitelisted(url, documentUrls); |
| 302 } |
| 303 |
| 304 public List<String> getElementHidingSelectors(final String url, final String[]
documentUrls) |
| 305 { |
| 306 if (!this.elemhideEnabled |
| 307 || this.isDocumentWhitelisted(url, documentUrls) |
| 308 || this.isElemhideWhitelisted(url, documentUrls)) |
| 309 { |
| 310 return new ArrayList<String>(); |
| 311 } |
| 312 return this.filterEngine.getElementHidingSelectors(url); |
| 313 } |
| 314 |
281 public void checkForUpdates() | 315 public void checkForUpdates() |
282 { | 316 { |
283 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); | 317 this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); |
284 } | 318 } |
285 | 319 |
286 public void updateSubscriptionStatus(final String url) | 320 public void updateSubscriptionStatus(final String url) |
287 { | 321 { |
288 final Subscription sub = this.filterEngine.getSubscription(url); | 322 final Subscription sub = this.filterEngine.getSubscription(url); |
289 if (sub != null) | 323 if (sub != null) |
290 { | 324 { |
291 Utils.updateSubscriptionStatus(this.context, sub); | 325 Utils.updateSubscriptionStatus(this.context, sub); |
292 } | 326 } |
293 } | 327 } |
| 328 |
| 329 public FilterEngine getFilterEngine() |
| 330 { |
| 331 return this.filterEngine; |
| 332 } |
294 } | 333 } |
OLD | NEW |