| 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-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 "JniCallbacks.h" | 18 #include "JniCallbacks.h" |
| 19 #include "Utils.h" |
| 19 | 20 |
| 20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) | 21 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) |
| 21 { | 22 { |
| 22 try | 23 try |
| 23 { | 24 { |
| 24 return JniPtrToLong(new JniShowNotificationCallback(env, callbackObject)); | 25 JniIsAllowedConnectionTypeCallback* callback = |
| 26 new JniIsAllowedConnectionTypeCallback(env, callbackObject); |
| 27 |
| 28 return JniPtrToLong(callback); |
| 25 } | 29 } |
| 26 CATCH_THROW_AND_RETURN(env, 0) | 30 CATCH_THROW_AND_RETURN(env, 0) |
| 27 } | 31 } |
| 28 | 32 |
| 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 33 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
| 30 { | 34 { |
| 31 delete JniLongToTypePtr<JniShowNotificationCallback>(ptr); | 35 delete JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(ptr); |
| 32 } | 36 } |
| 33 | 37 |
| 34 JniShowNotificationCallback::JniShowNotificationCallback(JNIEnv* env, | 38 JniIsAllowedConnectionTypeCallback::JniIsAllowedConnectionTypeCallback(JNIEnv* e
nv, |
| 35 jobject callbackObject) | 39 jobject callbackObject) |
| 36 : JniCallbackBase(env, callbackObject) | 40 : JniCallbackBase(env, callbackObject) |
| 37 { | 41 { |
| 38 } | 42 } |
| 39 | 43 |
| 40 void JniShowNotificationCallback::Callback( | 44 bool JniIsAllowedConnectionTypeCallback::Callback(const std::string* allowedConn
ectionType) |
| 41 const AdblockPlus::NotificationPtr& notificationPtr) | |
| 42 { | 45 { |
| 43 JNIEnvAcquire env(GetJavaVM()); | 46 JNIEnvAcquire env(GetJavaVM()); |
| 44 | 47 |
| 45 jmethodID method = env->GetMethodID( | 48 jmethodID method = env->GetMethodID( |
| 46 *JniLocalReference<jclass>(*env, | 49 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject()))
, |
| 47 env->GetObjectClass(GetCallbackObject())), | 50 "isConnectionAllowed", |
| 48 "showNotificationCallback", "(" TYP("Notification") ")V"); | 51 "(Ljava/lang/String;)Z"); |
| 49 | 52 |
| 50 if (method) | 53 jstring jAllowedConnectionType = |
| 51 { | 54 (allowedConnectionType != NULL |
| 52 JniLocalReference<jobject> jNotification(*env, NewJniNotification(*env, | 55 ? JniStdStringToJava(*env, *allowedConnectionType) |
| 53 notificationPtr)); | 56 : NULL); |
| 54 env->CallVoidMethod(GetCallbackObject(), method, *jNotification); | 57 bool result = env->CallBooleanMethod(GetCallbackObject(), method, jAllowedConn
ectionType); |
| 55 } | |
| 56 | 58 |
| 57 CheckAndLogJavaException(*env); | 59 CheckAndLogJavaException(*env); |
| 60 return result; |
| 58 } | 61 } |
| 59 | 62 |
| 60 static JNINativeMethod methods[] = | 63 static JNINativeMethod methods[] = |
| 61 { | 64 { |
| 62 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 65 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
| 63 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 66 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 64 }; | 67 }; |
| 65 | 68 |
| 66 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_ShowNotifi
cationCallback_registerNatives(JNIEnv *env, jclass clazz) | 69 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_IsAllowedC
onnectionCallback_registerNatives(JNIEnv *env, jclass clazz) |
| 67 { | 70 { |
| 68 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 71 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 69 } | 72 } |
| OLD | NEW |