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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 13 matching lines...) Expand all Loading... |
24 return JniPtrToLong(new JniFilterChangeCallback(env, callbackObject)); | 24 return JniPtrToLong(new JniFilterChangeCallback(env, callbackObject)); |
25 } | 25 } |
26 CATCH_THROW_AND_RETURN(env, 0) | 26 CATCH_THROW_AND_RETURN(env, 0) |
27 } | 27 } |
28 | 28 |
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
30 { | 30 { |
31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr); | 31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr); |
32 } | 32 } |
33 | 33 |
34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, jobject callbackOb
ject) | 34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, |
35 : JniCallbackBase(env, callbackObject), jsValueClass(new JniGlobalReference<jc
lass>(env, env->FindClass(PKG("JsValue")))) | 35 jobject callbackObject) |
| 36 : JniCallbackBase(env, callbackObject), jsValueClass( |
| 37 new JniGlobalReference<jclass>(env, env->FindClass(PKG("JsValue")))) |
36 { | 38 { |
37 } | 39 } |
38 | 40 |
39 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus
::JsValuePtr jsValue) | 41 void JniFilterChangeCallback::Callback(const std::string& arg, |
| 42 const AdblockPlus::JsValuePtr jsValue) |
40 { | 43 { |
41 JNIEnvAcquire env(GetJavaVM()); | 44 JNIEnvAcquire env(GetJavaVM()); |
42 | 45 |
43 jmethodID method = env->GetMethodID( | 46 jmethodID method = env->GetMethodID( |
44 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject()))
, | 47 *JniLocalReference<jclass>(*env, |
| 48 env->GetObjectClass(GetCallbackObject())), |
45 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V"); | 49 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V"); |
46 | 50 |
47 if (method) | 51 if (method) |
48 { | 52 { |
49 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str())); | 53 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str())); |
50 JniLocalReference<jobject> jJsValue(*env, NewJniJsValue(*env, jsValue, jsVal
ueClass->Get())); | 54 JniLocalReference<jobject> jJsValue(*env, |
| 55 NewJniJsValue(*env, jsValue, jsValueClass->Get())); |
51 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue); | 56 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue); |
52 } | 57 } |
53 | 58 |
54 CheckAndLogJavaException(*env); | 59 CheckAndLogJavaException(*env); |
55 } | 60 } |
56 | 61 |
57 static JNINativeMethod methods[] = | 62 static JNINativeMethod methods[] = |
58 { | 63 { |
59 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 64 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
60 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 65 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
61 }; | 66 }; |
62 | 67 |
63 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan
geCallback_registerNatives(JNIEnv *env, jclass clazz) | 68 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan
geCallback_registerNatives(JNIEnv *env, jclass clazz) |
64 { | 69 { |
65 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 70 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
66 } | 71 } |
LEFT | RIGHT |