LEFT | RIGHT |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
19 #include "Utils.h" | 19 #include "Utils.h" |
20 #include "JniJsValue.h" | 20 #include "JniJsValue.h" |
21 | 21 |
22 // precached in JNI_OnLoad and released in JNI_OnUnload | 22 // precached in JNI_OnLoad and released in JNI_OnUnload |
23 jclass globalJsValueClass; | 23 jclass globalJsValueClass; |
24 jmethodID jsValueClassCtor; | 24 jmethodID jsValueClassCtor; |
25 | 25 |
26 jint JNI_OnLoad(JavaVM* vm, void* reserved) | 26 void JniJsValue_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved) |
27 { | 27 { |
28 JNIEnv* env; | |
29 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) | |
30 { | |
31 return JNI_ERR; | |
32 } | |
33 | |
34 // precache for performance and avoid attaching threads | 28 // precache for performance and avoid attaching threads |
35 jclass localJsValueClass = env->FindClass(PKG("JsValue")); | 29 jclass localJsValueClass = env->FindClass(PKG("JsValue")); |
36 globalJsValueClass = (jclass)env->NewGlobalRef(localJsValueClass); | 30 globalJsValueClass = (jclass)env->NewGlobalRef(localJsValueClass); |
37 jsValueClassCtor = env->GetMethodID(globalJsValueClass, "<init>", "(J)V"); | 31 jsValueClassCtor = env->GetMethodID(globalJsValueClass, "<init>", "(J)V"); |
38 env->DeleteLocalRef(localJsValueClass); | 32 env->DeleteLocalRef(localJsValueClass); |
39 | 33 } |
40 return JNI_VERSION_1_6; | 34 |
| 35 void JniJsValue_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) |
| 36 { |
| 37 if (globalJsValueClass) |
| 38 { |
| 39 env->DeleteGlobalRef(globalJsValueClass); |
| 40 } |
41 } | 41 } |
42 | 42 |
43 static jboolean JNICALL JniIsUndefined(JNIEnv* env, jclass clazz, jlong ptr) | 43 static jboolean JNICALL JniIsUndefined(JNIEnv* env, jclass clazz, jlong ptr) |
44 { | 44 { |
45 try | 45 try |
46 { | 46 { |
47 return JniGetJsValue(ptr)->IsUndefined() ? JNI_TRUE : JNI_FALSE; | 47 return JniGetJsValue(ptr)->IsUndefined() ? JNI_TRUE : JNI_FALSE; |
48 } | 48 } |
49 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 49 CATCH_THROW_AND_RETURN(env, JNI_FALSE) |
50 } | 50 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, | 224 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, |
225 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, | 225 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, |
226 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, | 226 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, |
227 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 227 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
228 }; | 228 }; |
229 | 229 |
230 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) | 230 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) |
231 { | 231 { |
232 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 232 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
233 } | 233 } |
234 | |
235 void JNI_OnUnload(JavaVM *vm, void *reserved) | |
236 { | |
237 JNIEnv* env; | |
238 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) | |
239 { | |
240 return; | |
241 } | |
242 | |
243 if (globalJsValueClass) | |
244 { | |
245 env->DeleteGlobalRef(globalJsValueClass); | |
246 } | |
247 } | |
LEFT | RIGHT |