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-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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); | 32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); |
33 | 33 |
34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); | 34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); |
35 } | 35 } |
36 | 36 |
37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr) | 37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr) |
38 { | 38 { |
39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; | 39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; |
40 } | 40 } |
41 | 41 |
42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) | 42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo, jlong
logSystemPtr) |
43 { | 43 { |
44 AdblockPlus::AppInfo appInfo; | 44 AdblockPlus::AppInfo appInfo; |
45 | 45 |
46 TransformAppInfo(env, jAppInfo, appInfo); | 46 TransformAppInfo(env, jAppInfo, appInfo); |
47 | 47 |
48 try | 48 try |
49 { | 49 { |
50 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); | 50 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); |
51 JniJsEngine* jniJsEngine = new JniJsEngine(); | 51 JniJsEngine* jniJsEngine = new JniJsEngine(); |
52 jniJsEngine->timer = timer.get(); | 52 jniJsEngine->timer = timer.get(); |
53 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer)
); | 53 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer)
); |
| 54 if (logSystemPtr) |
| 55 { |
| 56 jniJsEngine->jsEngine->SetLogSystem(*JniLongToTypePtr<AdblockPlus::LogSyst
emPtr>(logSystemPtr)); |
| 57 } |
54 return JniPtrToLong(jniJsEngine); | 58 return JniPtrToLong(jniJsEngine); |
55 } | 59 } |
56 CATCH_THROW_AND_RETURN(env, 0) | 60 CATCH_THROW_AND_RETURN(env, 0) |
57 } | 61 } |
58 | 62 |
59 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 63 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
60 { | 64 { |
61 delete JniLongToTypePtr<JniJsEngine>(ptr); | 65 delete JniLongToTypePtr<JniJsEngine>(ptr); |
62 } | 66 } |
63 | 67 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 auto fileSystem = std::make_shared<AdblockPlus::DefaultFileSystemSync>(); | 147 auto fileSystem = std::make_shared<AdblockPlus::DefaultFileSystemSync>(); |
144 | 148 |
145 std::string basePath = JniJavaToStdString(env, jBasePath); | 149 std::string basePath = JniJavaToStdString(env, jBasePath); |
146 fileSystem->SetBasePath(basePath); | 150 fileSystem->SetBasePath(basePath); |
147 | 151 |
148 engine.SetFileSystem(fileSystem); | 152 engine.SetFileSystem(fileSystem); |
149 } | 153 } |
150 CATCH_AND_THROW(env) | 154 CATCH_AND_THROW(env) |
151 } | 155 } |
152 | 156 |
153 static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr) | |
154 { | |
155 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr); | |
156 | |
157 try | |
158 { | |
159 AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem()); | |
160 | |
161 engine.SetLogSystem(logSystem); | |
162 } | |
163 CATCH_AND_THROW(env) | |
164 } | |
165 | |
166 static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong
logSystemPtr) | |
167 { | |
168 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr); | |
169 | |
170 try | |
171 { | |
172 AdblockPlus::LogSystemPtr logSystem = *JniLongToTypePtr<AdblockPlus::LogSyst
emPtr>(logSystemPtr); | |
173 | |
174 engine.SetLogSystem(logSystem); | |
175 } | |
176 CATCH_AND_THROW(env) | |
177 } | |
178 | |
179 static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong
webRequestPtr) | 157 static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong
webRequestPtr) |
180 { | 158 { |
181 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr); | 159 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr); |
182 | 160 |
183 try | 161 try |
184 { | 162 { |
185 auto& webRequest = *JniLongToTypePtr<AdblockPlus::WebRequestSharedPtr>(webRe
questPtr); | 163 auto& webRequest = *JniLongToTypePtr<AdblockPlus::WebRequestSharedPtr>(webRe
questPtr); |
186 | 164 |
187 engine.SetWebRequest(webRequest); | 165 engine.SetWebRequest(webRequest); |
188 } | 166 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 202 } |
225 | 203 |
226 // TODO: List of functions that lack JNI bindings | 204 // TODO: List of functions that lack JNI bindings |
227 //JsValuePtr NewObject(); | 205 //JsValuePtr NewObject(); |
228 //JsValuePtr NewCallback(v8::InvocationCallback callback); | 206 //JsValuePtr NewCallback(v8::InvocationCallback callback); |
229 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); | 207 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); |
230 //JsValueList ConvertArguments(const v8::Arguments& arguments); | 208 //JsValueList ConvertArguments(const v8::Arguments& arguments); |
231 | 209 |
232 static JNINativeMethod methods[] = | 210 static JNINativeMethod methods[] = |
233 { | 211 { |
234 { (char*)"ctor", (char*)"(" TYP("AppInfo") ")J", (void*)JniCtor }, | 212 { (char*)"ctor", (char*)"(" TYP("AppInfo") "J)J", (void*)JniCtor }, |
235 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, | 213 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, |
236 | 214 |
237 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv
entCallback }, | 215 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv
entCallback }, |
238 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem
oveEventCallback }, | 216 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem
oveEventCallback }, |
239 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE
vent }, | 217 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE
vent }, |
240 | 218 |
241 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV
alue"), (void*)JniEvaluate }, | 219 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV
alue"), (void*)JniEvaluate }, |
242 | 220 |
243 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe
tDefaultFileSystem }, | 221 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe
tDefaultFileSystem }, |
244 { (char*)"setLogSystem", (char*)"(JJ)V", (void*)JniSetLogSystem }, | |
245 { (char*)"setDefaultLogSystem", (char*)"(J)V", (void*)JniSetDefaultLogSystem }
, | |
246 { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest }, | 222 { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest }, |
247 | 223 |
248 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, | 224 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, |
249 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue }
, | 225 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue }
, |
250 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni
NewStringValue } | 226 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni
NewStringValue } |
251 }; | 227 }; |
252 | 228 |
253 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) | 229 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) |
254 { | 230 { |
255 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 231 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
256 } | 232 } |
OLD | NEW |