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-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 |
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 "JniCallbacks.h" | 18 #include "JniCallbacks.h" |
19 | 19 |
20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) | 20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) |
21 { | 21 { |
22 try | 22 try |
23 { | 23 { |
24 return JniPtrToLong(new JniFilterChangeCallback(env, callbackObject)); | 24 return JniPtrToLong(new JniShowNotificationCallback(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<JniShowNotificationCallback>(ptr); |
32 } | 32 } |
33 | 33 |
34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, | 34 JniShowNotificationCallback::JniShowNotificationCallback(JNIEnv* env, |
35 jobject callbackObject) | 35 jobject callbackObject) |
36 : JniCallbackBase(env, callbackObject), jsValueClass( | 36 : JniCallbackBase(env, callbackObject), notificationClass( |
37 new JniGlobalReference<jclass>(env, env->FindClass(PKG("JsValue")))) | 37 new JniGlobalReference<jclass>(env, env->FindClass(PKG("Notification")))
) |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 void JniFilterChangeCallback::Callback(const std::string& arg, | 41 void JniShowNotificationCallback::Callback( |
42 const AdblockPlus::JsValuePtr jsValue) | 42 const AdblockPlus::NotificationPtr& notificationPtr) |
43 { | 43 { |
44 JNIEnvAcquire env(GetJavaVM()); | 44 JNIEnvAcquire env(GetJavaVM()); |
45 | 45 |
46 jmethodID method = env->GetMethodID( | 46 jmethodID method = env->GetMethodID( |
47 *JniLocalReference<jclass>(*env, | 47 *JniLocalReference<jclass>(*env, |
48 env->GetObjectClass(GetCallbackObject())), | 48 env->GetObjectClass(GetCallbackObject())), |
49 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V"); | 49 "showNotificationCallback", "(" TYP("Notification") ")V"); |
50 | 50 |
51 if (method) | 51 if (method) |
52 { | 52 { |
53 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str())); | 53 JniLocalReference<jobject> jNotification(*env, NewJniNotification(*env, |
54 JniLocalReference<jobject> jJsValue(*env, | 54 notificationPtr)); |
55 NewJniJsValue(*env, jsValue, jsValueClass->Get())); | 55 env->CallVoidMethod(GetCallbackObject(), method, *jNotification); |
56 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue); | |
57 } | 56 } |
58 | 57 |
59 CheckAndLogJavaException(*env); | 58 CheckAndLogJavaException(*env); |
60 } | 59 } |
61 | 60 |
62 static JNINativeMethod methods[] = | 61 static JNINativeMethod methods[] = |
63 { | 62 { |
64 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 63 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
65 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 64 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
66 }; | 65 }; |
67 | 66 |
68 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan
geCallback_registerNatives(JNIEnv *env, jclass clazz) | 67 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_ShowNotifi
cationCallback_registerNatives(JNIEnv *env, jclass clazz) |
69 { | 68 { |
70 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 69 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
71 } | 70 } |
OLD | NEW |