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

Side by Side Diff: src/org/adblockplus/android/api/JsEngine.java

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Added LICENSE, moved callback impls into cpp files. Created March 20, 2014, 3:12 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
(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.android.api;
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 class JsEngine implements Disposable
25 {
26 private final Disposer disposer;
27 protected final long ptr;
28
29 static
30 {
31 System.loadLibrary("abpEngine");
32 registerNatives();
33 }
34
35 public JsEngine(final AppInfo appInfo)
36 {
37 this(ctor(appInfo));
38 }
39
40 protected JsEngine(final long ptr)
41 {
42 this.ptr = ptr;
43 this.disposer = new Disposer(this, new DisposeWrapper(ptr));
44 }
45
46 public void setEventCallback(final String eventName, final EventCallback callb ack)
47 {
48 setEventCallback(this.ptr, eventName, callback.ptr);
49 }
50
51 public void removeEventCallback(final String eventName)
52 {
53 removeEventCallback(this.ptr, eventName);
54 }
55
56 public JsValue evaluate(final String source, final String filename)
57 {
58 return evaluate(this.ptr, source, filename);
59 }
60
61 public JsValue evaluate(final String source)
62 {
63 return evaluate(this.ptr, source, "");
64 }
65
66 public void triggerEvent(final String eventName, final List<JsValue> params)
67 {
68 final long[] args = new long[params.size()];
69
70 for (int i = 0; i < args.length; i++)
71 {
72 args[i] = params.get(i).ptr;
73 }
74
75 triggerEvent(this.ptr, eventName, args);
76 }
77
78 public void triggerEvent(final String eventName)
79 {
80 triggerEvent(this.ptr, eventName, null);
81 }
82
83 public void setDefaultFileSystem(final String basePath)
84 {
85 setDefaultFileSystem(this.ptr, basePath);
86 }
87
88 public void setDefaultLogSystem()
89 {
90 setDefaultLogSystem(this.ptr);
91 }
92
93 public void setLogSystem(final LogSystem logSystem)
94 {
95 setLogSystem(this.ptr, logSystem.ptr);
96 }
97
98 public void setDefaultWebRequest()
99 {
100 setDefaultWebRequest(this.ptr);
101 }
102
103 public void setWebRequest(final WebRequest webRequest)
104 {
105 setWebRequest(this.ptr, webRequest.ptr);
106 }
107
108 public JsValue newValue(final long value)
109 {
110 return newValue(this.ptr, value);
111 }
112
113 public JsValue newValue(final boolean value)
114 {
115 return newValue(this.ptr, value);
116 }
117
118 public JsValue newValue(final String value)
119 {
120 return newValue(this.ptr, value);
121 }
122
123 @Override
124 public void dispose()
125 {
126 this.disposer.dispose();
127 }
128
129 private final static class DisposeWrapper implements Disposable
130 {
131 private final long ptr;
132
133 public DisposeWrapper(final long ptr)
134 {
135 this.ptr = ptr;
136 }
137
138 @Override
139 public void dispose()
140 {
141 dtor(this.ptr);
142 }
143 }
144
145 private final static native void registerNatives();
146
147 private final static native long ctor(AppInfo appInfo);
148
149 private final static native void setEventCallback(long ptr, String eventName, long callback);
150
151 private final static native void removeEventCallback(long ptr, String eventNam e);
152
153 private final static native JsValue evaluate(long ptr, String source, String f ilename);
154
155 private final static native void triggerEvent(long ptr, String eventName, long [] args);
156
157 private final static native void setDefaultFileSystem(long ptr, String basePat h);
158
159 private final static native void setLogSystem(long ptr, long logSystemPtr);
160
161 private final static native void setDefaultLogSystem(long ptr);
162
163 private final static native void setWebRequest(long ptr, long webRequestPtr);
164
165 private final static native void setDefaultWebRequest(long ptr);
166
167 private final static native JsValue newValue(long ptr, long value);
168
169 private final static native JsValue newValue(long ptr, boolean value);
170
171 private final static native JsValue newValue(long ptr, String value);
172
173 private final static native void dtor(long ptr);
174 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/api/JniExceptionHandler.java ('k') | src/org/adblockplus/android/api/JsValue.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld