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 |
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 <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
19 #include "Utils.h" | 19 #include "Utils.h" |
20 #include "JniJsValue.h" | 20 #include "JniJsValue.h" |
21 | |
22 // TODO (rje) apply local_ref | |
23 | 21 |
24 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) | 22 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) |
25 { | 23 { |
26 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get(); | 24 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get(); |
27 } | 25 } |
28 | 26 |
29 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) | 27 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) |
30 { | 28 { |
31 AdblockPlus::NotificationType type; | 29 AdblockPlus::NotificationType type; |
32 try | 30 try |
(...skipping 13 matching lines...) Expand all Loading... |
46 enumName = "INFORMATION"; | 44 enumName = "INFORMATION"; |
47 break; | 45 break; |
48 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: | 46 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: |
49 enumName = "QUESTION"; | 47 enumName = "QUESTION"; |
50 break; | 48 break; |
51 default: | 49 default: |
52 enumName = "INVALID"; | 50 enumName = "INVALID"; |
53 break; | 51 break; |
54 } | 52 } |
55 | 53 |
56 jclass enumClass = env->FindClass(PKG("Notification$Type")); | 54 JniLocalReference<jclass> enumClass( |
57 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Notificat
ion$Type")); | 55 env, |
58 return env->GetStaticObjectField(enumClass, enumField); | 56 env->FindClass(PKG("Notification$Type"))); |
| 57 |
| 58 jfieldID enumField = env->GetStaticFieldID( |
| 59 *enumClass, |
| 60 enumName, |
| 61 TYP("Notification$Type")); |
| 62 |
| 63 return env->GetStaticObjectField(*enumClass, enumField); |
59 } | 64 } |
60 | 65 |
61 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) | 66 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) |
62 { | 67 { |
63 try | 68 try |
64 { | 69 { |
65 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTitle().c_str()); | 70 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTitle().c_str()); |
66 } | 71 } |
67 CATCH_THROW_AND_RETURN(env, 0) | 72 CATCH_THROW_AND_RETURN(env, 0) |
68 } | 73 } |
(...skipping 23 matching lines...) Expand all Loading... |
92 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, | 97 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, |
93 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp
e } | 98 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp
e } |
94 }; | 99 }; |
95 | 100 |
96 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati
on_registerNatives( | 101 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati
on_registerNatives( |
97 JNIEnv *env, jclass clazz) | 102 JNIEnv *env, jclass clazz) |
98 { | 103 { |
99 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 104 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
100 } | 105 } |
101 | 106 |
LEFT | RIGHT |