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

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

Issue 29536629: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created Sept. 5, 2017, 12:59 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
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
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.libadblockplus; 18 package org.adblockplus.libadblockplus;
19 19
20 import java.util.List; 20 import java.util.List;
21 21
22 public final class FilterEngine implements Disposable 22 public final class FilterEngine
23 { 23 {
24 private final Disposer disposer;
25 protected final long ptr; 24 protected final long ptr;
anton 2017/09/06 06:21:27 since now it's platform ptr, not filter engine ptr
26 25
27 static 26 static
28 { 27 {
29 System.loadLibrary("adblockplus-jni"); 28 System.loadLibrary("adblockplus-jni");
30 registerNatives(); 29 registerNatives();
31 } 30 }
32 31
33 public static enum ContentType 32 public static enum ContentType
34 { 33 {
35 OTHER, SCRIPT, IMAGE, STYLESHEET, OBJECT, SUBDOCUMENT, DOCUMENT, XMLHTTPREQU EST, 34 OTHER, SCRIPT, IMAGE, STYLESHEET, OBJECT, SUBDOCUMENT, DOCUMENT, XMLHTTPREQU EST,
36 OBJECT_SUBREQUEST, FONT, MEDIA 35 OBJECT_SUBREQUEST, FONT, MEDIA
37 } 36 }
38 37
39 public FilterEngine(final JsEngine jsEngine, final IsAllowedConnectionCallback isSubscriptionDownloadAllowedCallback) 38 FilterEngine(/* JniPlatform */long ptr)
anton 2017/09/06 06:21:27 if it's renamed to `platformPtr` there is no need
anton 2017/09/06 06:21:27 `public` here is required. Otherwise it's `package
sergei 2017/09/08 09:45:01 Totally agree with the constructor argument, renam
sergei 2017/09/08 09:45:01 I actually wanted it, so FilterEngine can be creat
anton 2017/09/08 10:19:19 Let's make it `public`. We did not introduce `pack
sergei 2017/09/08 12:25:30 But in this case anyone can call a constructor of
diegocarloslima 2017/09/08 20:42:41 Since this project is meant to be distributed as a
40 { 39 {
41 this.ptr = ctor(jsEngine.ptr, isSubscriptionDownloadAllowedCallback); 40 this.ptr = ptr;
42 this.disposer = new Disposer(this, new DisposeWrapper(this.ptr));
43 }
44
45 public FilterEngine(final JsEngine jsEngine)
46 {
47 this(jsEngine, null);
48 } 41 }
49 42
50 public boolean isFirstRun() 43 public boolean isFirstRun()
51 { 44 {
52 return isFirstRun(this.ptr); 45 return isFirstRun(this.ptr);
53 } 46 }
54 47
55 public Filter getFilter(final String text) 48 public Filter getFilter(final String text)
56 { 49 {
57 return getFilter(this.ptr, text); 50 return getFilter(this.ptr, text);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 /** 188 /**
196 * Schedules updating of a subscription corresponding to the passed URL. 189 * Schedules updating of a subscription corresponding to the passed URL.
197 * @param subscriptionUrl may contain query parameters, only the beginning of the string is used 190 * @param subscriptionUrl may contain query parameters, only the beginning of the string is used
198 * to find a corresponding subscription. 191 * to find a corresponding subscription.
199 */ 192 */
200 public void updateFiltersAsync(String subscriptionUrl) 193 public void updateFiltersAsync(String subscriptionUrl)
201 { 194 {
202 updateFiltersAsync(this.ptr, subscriptionUrl); 195 updateFiltersAsync(this.ptr, subscriptionUrl);
203 } 196 }
204 197
205 @Override
206 public void dispose()
207 {
208 this.disposer.dispose();
209 }
210
211 private final static class DisposeWrapper implements Disposable
212 {
213 private final long ptr;
214
215 public DisposeWrapper(final long ptr)
216 {
217 this.ptr = ptr;
218 }
219
220 @Override
221 public void dispose()
222 {
223 dtor(this.ptr);
224 }
225 }
226
227 private final static native void registerNatives(); 198 private final static native void registerNatives();
228 199
229 private final static native long ctor(long jsEnginePtr, IsAllowedConnectionCal lback isSubscriptionDownloadAllowedCallback);
230
231 private final static native boolean isFirstRun(long ptr); 200 private final static native boolean isFirstRun(long ptr);
anton 2017/09/06 06:21:27 i'd suggest to rename all `ptr` to `platformPtr` i
sergei 2017/09/08 09:45:01 see my thoughts about opaque pointer role, let's d
232 201
233 private final static native Filter getFilter(long ptr, String text); 202 private final static native Filter getFilter(long ptr, String text);
234 203
235 private final static native List<Filter> getListedFilters(long ptr); 204 private final static native List<Filter> getListedFilters(long ptr);
236 205
237 private final static native Subscription getSubscription(long ptr, String url) ; 206 private final static native Subscription getSubscription(long ptr, String url) ;
238 207
239 private final static native List<Subscription> getListedSubscriptions(long ptr ); 208 private final static native List<Subscription> getListedSubscriptions(long ptr );
240 209
241 private final static native List<Subscription> fetchAvailableSubscriptions(lon g ptr); 210 private final static native List<Subscription> fetchAvailableSubscriptions(lon g ptr);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 245
277 private final static native String getAllowedConnectionType(long ptr); 246 private final static native String getAllowedConnectionType(long ptr);
278 247
279 private final static native void setAcceptableAdsEnabled(long ptr, boolean ena bled); 248 private final static native void setAcceptableAdsEnabled(long ptr, boolean ena bled);
280 249
281 private final static native boolean isAcceptableAdsEnabled(long ptr); 250 private final static native boolean isAcceptableAdsEnabled(long ptr);
282 251
283 private final static native String getAcceptableAdsSubscriptionURL(long ptr); 252 private final static native String getAcceptableAdsSubscriptionURL(long ptr);
284 253
285 private final static native void updateFiltersAsync(long ptr, String subscript ionUrl); 254 private final static native void updateFiltersAsync(long ptr, String subscript ionUrl);
286
287 private final static native void dtor(long ptr);
288 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld