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: Added missing copyright header Created March 14, 2014, 11:37 a.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 AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::FilterPtr>(ptr)->get ();
25 }
26
27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue)
28 {
29 TRY
30 {
31 return AdblockPlus::Android::JniPtr2Long(
32 new AdblockPlus::FilterPtr(new AdblockPlus::Filter(AdblockPlus::Android: :JniGetJsValuePtr(jsValue))));
33 }
34 CATCH_THROW_AND_RETURN(env, 0)
35 }
36
37 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
38 {
39 AdblockPlus::Filter::Type type;
40 TRY
41 {
42 type = GetFilterPtr(ptr)->GetType();
43 }
44 CATCH_THROW_AND_RETURN(env, 0)
45
46 const char* enumName = 0;
47
48 switch (type)
49 {
50 case AdblockPlus::Filter::TYPE_BLOCKING:
51 enumName = "BLOCKING";
52 break;
53 case AdblockPlus::Filter::TYPE_COMMENT:
54 enumName = "COMMENT";
55 break;
56 case AdblockPlus::Filter::TYPE_ELEMHIDE:
57 enumName = "ELEMHIDE";
58 break;
59 case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION:
60 enumName = "ELEMHIDE_EXCEPTION";
61 break;
62 case AdblockPlus::Filter::TYPE_EXCEPTION:
63 enumName = "EXCEPTION";
64 break;
65 default:
66 enumName = "INVALID";
67 break;
68 }
69
70 jclass enumClass = env->FindClass(PKG("Filter$Type"));
71 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Filter$Ty pe"));
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 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_android_api_Filter_regist erNatives(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