| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 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/>. | |
| 16 */ | |
| 17 | |
| 18 #include "Utils.h" | |
| 19 #include "JniNotification.h" | |
| 20 | |
| 21 // precached in JNI_OnLoad and released in JNI_OnUnload | |
| 22 JniGlobalReference<jclass>* notificationEnumClass; | |
| 23 | |
| 24 void JniNotification_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved) | |
| 25 { | |
| 26 notificationEnumClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG
("Notification$Type"))); | |
| 27 } | |
| 28 | |
| 29 void JniNotification_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) | |
| 30 { | |
| 31 if (notificationEnumClass) | |
| 32 { | |
| 33 delete notificationEnumClass; | |
| 34 notificationEnumClass = NULL; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) | |
| 39 { | |
| 40 return JniLongToTypePtr<AdblockPlus::Notification>(ptr); | |
| 41 } | |
| 42 | |
| 43 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) | |
| 44 { | |
| 45 AdblockPlus::NotificationType type; | |
| 46 try | |
| 47 { | |
| 48 type = GetNotificationPtr(ptr)->GetType(); | |
| 49 } | |
| 50 CATCH_THROW_AND_RETURN(env, 0) | |
| 51 | |
| 52 const char* enumName = 0; | |
| 53 | |
| 54 switch (type) | |
| 55 { | |
| 56 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_CRITICAL: | |
| 57 enumName = "CRITICAL"; | |
| 58 break; | |
| 59 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_INFORMATION: | |
| 60 enumName = "INFORMATION"; | |
| 61 break; | |
| 62 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: | |
| 63 enumName = "QUESTION"; | |
| 64 break; | |
| 65 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_RELENTLESS: | |
| 66 enumName = "RELENTLESS"; | |
| 67 break; | |
| 68 default: | |
| 69 enumName = "INVALID"; | |
| 70 break; | |
| 71 } | |
| 72 | |
| 73 jfieldID enumField = env->GetStaticFieldID( | |
| 74 notificationEnumClass->Get(), | |
| 75 enumName, | |
| 76 TYP("Notification$Type")); | |
| 77 | |
| 78 return env->GetStaticObjectField(notificationEnumClass->Get(), enumField); | |
| 79 } | |
| 80 | |
| 81 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) | |
| 82 { | |
| 83 try | |
| 84 { | |
| 85 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTexts().title.c_str()); | |
| 86 } | |
| 87 CATCH_THROW_AND_RETURN(env, 0) | |
| 88 } | |
| 89 | |
| 90 static jstring JniGetMessageString(JNIEnv* env, jclass clazz, jlong ptr) | |
| 91 { | |
| 92 try | |
| 93 { | |
| 94 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTexts().message.c_str()
); | |
| 95 } | |
| 96 CATCH_THROW_AND_RETURN(env, 0) | |
| 97 } | |
| 98 | |
| 99 static void JniMarkAsShown(JNIEnv* env, jclass clazz, jlong ptr) | |
| 100 { | |
| 101 try | |
| 102 { | |
| 103 GetNotificationPtr(ptr)->MarkAsShown(); | |
| 104 } | |
| 105 CATCH_AND_THROW(env) | |
| 106 } | |
| 107 | |
| 108 static JNINativeMethod methods[] = | |
| 109 { | |
| 110 { (char*) "markAsShown", (char*) "(J)V", (void*) JniMarkAsShown }, | |
| 111 { (char*) "getMessageString", (char*) "(J)Ljava/lang/String;", (void*) JniGetM
essageString }, | |
| 112 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, | |
| 113 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp
e } | |
| 114 }; | |
| 115 | |
| 116 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati
on_registerNatives( | |
| 117 JNIEnv *env, jclass clazz) | |
| 118 { | |
| 119 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | |
| 120 } | |
| 121 | |
| OLD | NEW |