OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 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 <AdblockPlus.h> |
| 19 #include "Utils.h" |
| 20 #include "JniJsValue.h" |
| 21 |
| 22 // TODO (rje) apply local_ref |
| 23 |
| 24 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) |
| 25 { |
| 26 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get(); |
| 27 } |
| 28 |
| 29 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) |
| 30 { |
| 31 AdblockPlus::NotificationType type; |
| 32 try |
| 33 { |
| 34 type = GetNotificationPtr(ptr)->GetType(); |
| 35 } |
| 36 CATCH_THROW_AND_RETURN(env, 0) |
| 37 |
| 38 const char* enumName = 0; |
| 39 |
| 40 switch (type) |
| 41 { |
| 42 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_CRITICAL: |
| 43 enumName = "CRITICAL"; |
| 44 break; |
| 45 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_INFORMATION: |
| 46 enumName = "INFORMATION"; |
| 47 break; |
| 48 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: |
| 49 enumName = "QUESTION"; |
| 50 break; |
| 51 default: |
| 52 enumName = "INVALID"; |
| 53 break; |
| 54 } |
| 55 |
| 56 jclass enumClass = env->FindClass(PKG("Notification$Type")); |
| 57 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Notificat
ion$Type")); |
| 58 return env->GetStaticObjectField(enumClass, enumField); |
| 59 } |
| 60 |
| 61 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) |
| 62 { |
| 63 try |
| 64 { |
| 65 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTitle().c_str()); |
| 66 } |
| 67 CATCH_THROW_AND_RETURN(env, 0) |
| 68 } |
| 69 |
| 70 static jstring JniGetMessageString(JNIEnv* env, jclass clazz, jlong ptr) |
| 71 { |
| 72 try |
| 73 { |
| 74 return env->NewStringUTF(GetNotificationPtr(ptr)->GetMessageString().c_str()
); |
| 75 } |
| 76 CATCH_THROW_AND_RETURN(env, 0) |
| 77 } |
| 78 |
| 79 static void JniMarkAsShown(JNIEnv* env, jclass clazz, jlong ptr) |
| 80 { |
| 81 try |
| 82 { |
| 83 GetNotificationPtr(ptr)->MarkAsShown(); |
| 84 } |
| 85 CATCH_AND_THROW(env) |
| 86 } |
| 87 |
| 88 static JNINativeMethod methods[] = |
| 89 { |
| 90 { (char*) "markAsShown", (char*) "(J)V", (void*) JniMarkAsShown }, |
| 91 { (char*) "getMessageString", (char*) "(J)Ljava/lang/String;", (void*) JniGetM
essageString }, |
| 92 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, |
| 93 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp
e } |
| 94 }; |
| 95 |
| 96 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati
on_registerNatives( |
| 97 JNIEnv *env, jclass clazz) |
| 98 { |
| 99 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 100 } |
| 101 |
OLD | NEW |