| 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 <AdblockPlus.h> | |
| 19 #include "Utils.h" | |
| 20 | |
| 21 static AdblockPlus::Subscription* GetSubscriptionPtr(jlong ptr) | |
| 22 { | |
| 23 return JniLongToTypePtr<AdblockPlus::Subscription>(ptr); | |
| 24 } | |
| 25 | |
| 26 static jboolean JNICALL JniIsDisabled(JNIEnv* env, jclass clazz, jlong ptr) | |
| 27 { | |
| 28 try | |
| 29 { | |
| 30 return GetSubscriptionPtr(ptr)->IsDisabled() ? JNI_TRUE : JNI_FALSE; | |
| 31 } | |
| 32 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
| 33 } | |
| 34 | |
| 35 static void JNICALL JniSetDisabled(JNIEnv* env, jclass clazz, jlong ptr, jboolea
n disabled) | |
| 36 { | |
| 37 try | |
| 38 { | |
| 39 return GetSubscriptionPtr(ptr)->SetDisabled(disabled == JNI_TRUE); | |
| 40 } | |
| 41 CATCH_AND_THROW(env) | |
| 42 } | |
| 43 | |
| 44 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) | |
| 45 { | |
| 46 try | |
| 47 { | |
| 48 return GetSubscriptionPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; | |
| 49 } | |
| 50 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
| 51 } | |
| 52 | |
| 53 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr) | |
| 54 { | |
| 55 try | |
| 56 { | |
| 57 GetSubscriptionPtr(ptr)->AddToList(); | |
| 58 } | |
| 59 CATCH_AND_THROW(env) | |
| 60 } | |
| 61 | |
| 62 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr) | |
| 63 { | |
| 64 try | |
| 65 { | |
| 66 GetSubscriptionPtr(ptr)->RemoveFromList(); | |
| 67 } | |
| 68 CATCH_AND_THROW(env) | |
| 69 } | |
| 70 | |
| 71 static void JNICALL JniUpdateFilters(JNIEnv* env, jclass clazz, jlong ptr) | |
| 72 { | |
| 73 try | |
| 74 { | |
| 75 GetSubscriptionPtr(ptr)->UpdateFilters(); | |
| 76 } | |
| 77 CATCH_AND_THROW(env) | |
| 78 } | |
| 79 | |
| 80 static jboolean JNICALL JniIsUpdating(JNIEnv* env, jclass clazz, jlong ptr) | |
| 81 { | |
| 82 try | |
| 83 { | |
| 84 return GetSubscriptionPtr(ptr)->IsUpdating() ? JNI_TRUE : JNI_FALSE; | |
| 85 } | |
| 86 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
| 87 } | |
| 88 | |
| 89 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr,
jlong otherPtr) | |
| 90 { | |
| 91 AdblockPlus::Subscription* me = GetSubscriptionPtr(ptr); | |
| 92 AdblockPlus::Subscription* other = GetSubscriptionPtr(otherPtr); | |
| 93 | |
| 94 try | |
| 95 { | |
| 96 return *me == *other ? JNI_TRUE : JNI_FALSE; | |
| 97 } | |
| 98 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
| 99 } | |
| 100 | |
| 101 static jboolean JNICALL JniIsAcceptableAds(JNIEnv* env, jclass clazz, jlong ptr) | |
| 102 { | |
| 103 try | |
| 104 { | |
| 105 return (GetSubscriptionPtr(ptr)->IsAA() ? JNI_TRUE : JNI_FALSE); | |
| 106 } | |
| 107 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
| 108 } | |
| 109 | |
| 110 static JNINativeMethod methods[] = | |
| 111 { | |
| 112 { (char*)"isDisabled", (char*)"(J)Z", (void*)JniIsDisabled }, | |
| 113 { (char*)"setDisabled", (char*)"(JZ)V", (void*)JniSetDisabled }, | |
| 114 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, | |
| 115 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, | |
| 116 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, | |
| 117 { (char*)"updateFilters", (char*)"(J)V", (void*)JniUpdateFilters }, | |
| 118 { (char*)"isUpdating", (char*)"(J)Z", (void*)JniIsUpdating }, | |
| 119 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals }, | |
| 120 { (char*)"isAcceptableAds", (char*)"(J)Z", (void*)JniIsAcceptableAds }, | |
| 121 }; | |
| 122 | |
| 123 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Subscripti
on_registerNatives(JNIEnv *env, jclass clazz) | |
| 124 { | |
| 125 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | |
| 126 } | |
| OLD | NEW |