Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: jni/JniFilter.cpp

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Bug fix for global references (shadowing) Created March 31, 2014, 2:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « jni/JniEventCallback.cpp ('k') | jni/JniFilterChangeCallback.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 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 jclass enumClass = env->FindClass(PKG("Filter$Type"));
70 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Filter$Ty pe"));
71 return env->GetStaticObjectField(enumClass, enumField);
72 }
73
74 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr)
75 {
76 TRY
77 {
78 return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE;
79 }
80 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
81 }
82
83 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr)
84 {
85 TRY
86 {
87 GetFilterPtr(ptr)->AddToList();
88 }
89 CATCH_AND_THROW(env)
90 }
91
92 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr)
93 {
94 TRY
95 {
96 GetFilterPtr(ptr)->RemoveFromList();
97 }
98 CATCH_AND_THROW(env)
99 }
100
101 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr, jlong otherPtr)
102 {
103 AdblockPlus::Filter* me = GetFilterPtr(ptr);
104 AdblockPlus::Filter* other = GetFilterPtr(otherPtr);
105
106 TRY
107 {
108 return *me == *other ? JNI_TRUE : JNI_FALSE;
109 }
110 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
111 }
112
113 static JNINativeMethod methods[] =
114 {
115 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor },
116 { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType },
117 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed },
118 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList },
119 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList },
120 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals }
121 };
122
123 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg isterNatives(JNIEnv *env, jclass clazz)
124 {
125 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
126 }
OLDNEW
« no previous file with comments | « jni/JniEventCallback.cpp ('k') | jni/JniFilterChangeCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld