| 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 <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
| 19 #include "Utils.h" | 19 #include "Utils.h" |
| 20 #include "JniJsValue.h" | 20 #include "JniJsValue.h" |
| 21 #include "JniFilter.h" |
| 22 |
| 23 // precached in JNI_OnLoad and released in JNI_OnUnload |
| 24 JniGlobalReference<jclass>* filterEnumClass; |
| 25 |
| 26 void JniFilter_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved) |
| 27 { |
| 28 filterEnumClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("Filt
er$Type"))); |
| 29 } |
| 30 |
| 31 void JniFilter_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) |
| 32 { |
| 33 if (filterEnumClass) |
| 34 { |
| 35 delete filterEnumClass; |
| 36 filterEnumClass = NULL; |
| 37 } |
| 38 } |
| 21 | 39 |
| 22 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) | 40 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) |
| 23 { | 41 { |
| 24 return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); | 42 return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); |
| 25 } | 43 } |
| 26 | 44 |
| 27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) | 45 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) |
| 28 { | 46 { |
| 29 try | 47 try |
| 30 { | 48 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 59 enumName = "ELEMHIDE_EXCEPTION"; | 77 enumName = "ELEMHIDE_EXCEPTION"; |
| 60 break; | 78 break; |
| 61 case AdblockPlus::Filter::TYPE_EXCEPTION: | 79 case AdblockPlus::Filter::TYPE_EXCEPTION: |
| 62 enumName = "EXCEPTION"; | 80 enumName = "EXCEPTION"; |
| 63 break; | 81 break; |
| 64 default: | 82 default: |
| 65 enumName = "INVALID"; | 83 enumName = "INVALID"; |
| 66 break; | 84 break; |
| 67 } | 85 } |
| 68 | 86 |
| 69 JniLocalReference<jclass> enumClass(env, env->FindClass(PKG("Filter$Type"))); | 87 jfieldID enumField = env->GetStaticFieldID(filterEnumClass->Get(), enumName, T
YP("Filter$Type")); |
| 70 jfieldID enumField = env->GetStaticFieldID(*enumClass, enumName, | 88 return env->GetStaticObjectField(filterEnumClass->Get(), enumField); |
| 71 TYP("Filter$Type")); | |
| 72 return env->GetStaticObjectField(*enumClass, enumField); | |
| 73 } | 89 } |
| 74 | 90 |
| 75 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) | 91 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) |
| 76 { | 92 { |
| 77 try | 93 try |
| 78 { | 94 { |
| 79 return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; | 95 return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; |
| 80 } | 96 } |
| 81 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 97 CATCH_THROW_AND_RETURN(env, JNI_FALSE) |
| 82 } | 98 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, | 134 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, |
| 119 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, | 135 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, |
| 120 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, | 136 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, |
| 121 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } | 137 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } |
| 122 }; | 138 }; |
| 123 | 139 |
| 124 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg
isterNatives(JNIEnv *env, jclass clazz) | 140 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg
isterNatives(JNIEnv *env, jclass clazz) |
| 125 { | 141 { |
| 126 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 142 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 127 } | 143 } |
| OLD | NEW |