OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 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 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) | |
23 { | |
24 return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); | |
25 } | |
26 | |
27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) | |
28 { | |
29 try | |
30 { | |
31 return JniPtrToLong(new AdblockPlus::FilterPtr(new AdblockPlus::Filter(JniGe
tJsValuePtr(jsValue)))); | |
32 } | |
33 CATCH_THROW_AND_RETURN(env, 0) | |
34 } | |
35 | |
36 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) | |
37 { | |
38 AdblockPlus::Filter::Type type; | |
39 try | |
40 { | |
41 type = GetFilterPtr(ptr)->GetType(); | |
42 } | |
43 CATCH_THROW_AND_RETURN(env, 0) | |
44 | |
45 const char* enumName = 0; | |
46 | |
47 switch (type) | |
48 { | |
49 case AdblockPlus::Filter::TYPE_BLOCKING: | |
50 enumName = "BLOCKING"; | |
51 break; | |
52 case AdblockPlus::Filter::TYPE_COMMENT: | |
53 enumName = "COMMENT"; | |
54 break; | |
55 case AdblockPlus::Filter::TYPE_ELEMHIDE: | |
56 enumName = "ELEMHIDE"; | |
57 break; | |
58 case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION: | |
59 enumName = "ELEMHIDE_EXCEPTION"; | |
60 break; | |
61 case AdblockPlus::Filter::TYPE_EXCEPTION: | |
62 enumName = "EXCEPTION"; | |
63 break; | |
64 default: | |
65 enumName = "INVALID"; | |
66 break; | |
67 } | |
68 | |
69 JniLocalReference<jclass> enumClass(env, env->FindClass(PKG("Filter$Type"))); | |
70 jfieldID enumField = env->GetStaticFieldID(*enumClass, enumName, | |
71 TYP("Filter$Type")); | |
72 return env->GetStaticObjectField(*enumClass, enumField); | |
73 } | |
74 | |
75 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) | |
76 { | |
77 try | |
78 { | |
79 return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; | |
80 } | |
81 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
82 } | |
83 | |
84 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr) | |
85 { | |
86 try | |
87 { | |
88 GetFilterPtr(ptr)->AddToList(); | |
89 } | |
90 CATCH_AND_THROW(env) | |
91 } | |
92 | |
93 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr) | |
94 { | |
95 try | |
96 { | |
97 GetFilterPtr(ptr)->RemoveFromList(); | |
98 } | |
99 CATCH_AND_THROW(env) | |
100 } | |
101 | |
102 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr,
jlong otherPtr) | |
103 { | |
104 AdblockPlus::Filter* me = GetFilterPtr(ptr); | |
105 AdblockPlus::Filter* other = GetFilterPtr(otherPtr); | |
106 | |
107 try | |
108 { | |
109 return *me == *other ? JNI_TRUE : JNI_FALSE; | |
110 } | |
111 CATCH_THROW_AND_RETURN(env, JNI_FALSE) | |
112 } | |
113 | |
114 static JNINativeMethod methods[] = | |
115 { | |
116 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | |
117 { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType }, | |
118 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, | |
119 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, | |
120 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, | |
121 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } | |
122 }; | |
123 | |
124 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg
isterNatives(JNIEnv *env, jclass clazz) | |
125 { | |
126 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | |
127 } | |
OLD | NEW |