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

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

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: TRY, abpEngine, statics Created April 1, 2014, 11:40 a.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
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17 package org.adblockplus.libadblockplus;
18
19 import java.util.List;
20
21 import com.github.rjeschke.neetutils.dispose.Disposable;
22 import com.github.rjeschke.neetutils.dispose.Disposer;
23
24 public final class FilterEngine implements Disposable
25 {
26 private final Disposer disposer;
27 protected final long ptr;
28
29 static
30 {
31 System.loadLibrary("adblockplus-jni");
32 registerNatives();
33 }
34
35 public FilterEngine(final JsEngine jsEngine)
36 {
37 this.ptr = ctor(jsEngine.ptr);
38 this.disposer = new Disposer(this, new DisposeWrapper(this.ptr));
39 }
40
41 public boolean isFirstRun()
42 {
43 return isFirstRun(this.ptr);
44 }
45
46 public Filter getFilter(final String text)
47 {
48 return getFilter(this.ptr, text);
49 }
50
51 public List<Filter> getListedFilters()
52 {
53 return getListedFilters(this.ptr);
54 }
55
56 public Subscription getSubscription(final String url)
57 {
58 return getSubscription(this.ptr, url);
59 }
60
61 public List<Subscription> getListedSubscriptions()
62 {
63 return getListedSubscriptions(this.ptr);
64 }
65
66 public List<Subscription> fetchAvailableSubscriptions()
67 {
68 return fetchAvailableSubscriptions(this.ptr);
69 }
70
71 public void removeFilterChangeCallback()
72 {
73 removeFilterChangeCallback(this.ptr);
74 }
75
76 public void setFilterChangeCallback(final FilterChangeCallback callback)
77 {
78 setFilterChangeCallback(this.ptr, callback.ptr);
79 }
80
81 public void forceUpdateCheck()
82 {
83 forceUpdateCheck(this.ptr, 0);
84 }
85
86 public void forceUpdateCheck(final UpdaterCallback callback)
87 {
88 forceUpdateCheck(this.ptr, callback != null ? callback.ptr : 0);
89 }
90
91 public List<String> getElementHidingSelectors(final String domain)
92 {
93 return getElementHidingSelectors(this.ptr, domain);
94 }
95
96 public Filter matches(final String url, final String contentType, final String documentUrl)
97 {
98 return matches(this.ptr, url, contentType, documentUrl);
99 }
100
101 public Filter matches(final String url, final String contentType, final String [] documentUrls)
102 {
103 return matches(this.ptr, url, contentType, documentUrls);
104 }
105
106 public JsValue getPref(final String pref)
107 {
108 return getPref(this.ptr, pref);
109 }
110
111 public void setPref(final String pref, final JsValue value)
112 {
113 setPref(this.ptr, pref, value.ptr);
114 }
115
116 @Override
117 public void dispose()
118 {
119 this.disposer.dispose();
120 }
121
122 private final static class DisposeWrapper implements Disposable
123 {
124 private final long ptr;
125
126 public DisposeWrapper(final long ptr)
127 {
128 this.ptr = ptr;
129 }
130
131 @Override
132 public void dispose()
133 {
134 dtor(this.ptr);
135 }
136 }
137
138 private final static native void registerNatives();
139
140 private final static native long ctor(long jsEnginePtr);
141
142 private final static native boolean isFirstRun(long ptr);
143
144 private final static native Filter getFilter(long ptr, String text);
145
146 private final static native List<Filter> getListedFilters(long ptr);
147
148 private final static native Subscription getSubscription(long ptr, String url) ;
149
150 private final static native List<Subscription> getListedSubscriptions(long ptr );
151
152 private final static native List<Subscription> fetchAvailableSubscriptions(lon g ptr);
153
154 private final static native void removeFilterChangeCallback(long ptr);
155
156 private final static native void setFilterChangeCallback(long ptr, long filter Ptr);
157
158 private final static native void forceUpdateCheck(long ptr, long updatePtr);
159
160 private final static native List<String> getElementHidingSelectors(long ptr, S tring domain);
161
162 private final static native JsValue getPref(long ptr, String pref);
163
164 private final static native Filter matches(long ptr, String url, String conten tType, String documentUrl);
165
166 private final static native Filter matches(long ptr, String url, String conten tType, String[] documentUrls);
167
168 private final static native void setPref(long ptr, String pref, long valuePtr) ;
169
170 private final static native void dtor(long ptr);
171 }
OLDNEW

Powered by Google App Engine
This is Rietveld