| LEFT | RIGHT | 
|    1 /* |    1 /* | 
|    2  * This file is part of Adblock Plus <http://adblockplus.org/>, |    2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
|    3  * Copyright (C) 2006-2014 Eyeo GmbH |    3  * Copyright (C) 2006-2014 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  |   21  | 
|   22 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) |   22 static AdblockPlus::Filter* GetFilterPtr(jlong ptr) | 
|   23 { |   23 { | 
|   24   return AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::FilterPtr>(ptr)->get
     (); |   24   return JniLongToTypePtr<AdblockPlus::FilterPtr>(ptr)->get(); | 
|   25 } |   25 } | 
|   26  |   26  | 
|   27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) |   27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue) | 
|   28 { |   28 { | 
|   29   TRY |   29   try | 
|   30   { |   30   { | 
|   31     return AdblockPlus::Android::JniPtr2Long( |   31     return JniPtrToLong(new AdblockPlus::FilterPtr(new AdblockPlus::Filter(JniGe
     tJsValuePtr(jsValue)))); | 
|   32         new AdblockPlus::FilterPtr(new AdblockPlus::Filter(AdblockPlus::Android:
     :JniGetJsValuePtr(jsValue)))); |  | 
|   33   } |   32   } | 
|   34   CATCH_THROW_AND_RETURN(env, 0) |   33   CATCH_THROW_AND_RETURN(env, 0) | 
|   35 } |   34 } | 
|   36  |   35  | 
|   37 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) |   36 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) | 
|   38 { |   37 { | 
|   39   AdblockPlus::Filter::Type type; |   38   AdblockPlus::Filter::Type type; | 
|   40   TRY |   39   try | 
|   41   { |   40   { | 
|   42     type = GetFilterPtr(ptr)->GetType(); |   41     type = GetFilterPtr(ptr)->GetType(); | 
|   43   } |   42   } | 
|   44   CATCH_THROW_AND_RETURN(env, 0) |   43   CATCH_THROW_AND_RETURN(env, 0) | 
|   45  |   44  | 
|   46   const char* enumName = 0; |   45   const char* enumName = 0; | 
|   47  |   46  | 
|   48   switch (type) |   47   switch (type) | 
|   49   { |   48   { | 
|   50   case AdblockPlus::Filter::TYPE_BLOCKING: |   49   case AdblockPlus::Filter::TYPE_BLOCKING: | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|   67     break; |   66     break; | 
|   68   } |   67   } | 
|   69  |   68  | 
|   70   jclass enumClass = env->FindClass(PKG("Filter$Type")); |   69   jclass enumClass = env->FindClass(PKG("Filter$Type")); | 
|   71   jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Filter$Ty
     pe")); |   70   jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Filter$Ty
     pe")); | 
|   72   return env->GetStaticObjectField(enumClass, enumField); |   71   return env->GetStaticObjectField(enumClass, enumField); | 
|   73 } |   72 } | 
|   74  |   73  | 
|   75 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) |   74 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr) | 
|   76 { |   75 { | 
|   77   TRY |   76   try | 
|   78   { |   77   { | 
|   79     return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; |   78     return GetFilterPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE; | 
|   80   } |   79   } | 
|   81   CATCH_THROW_AND_RETURN(env, JNI_FALSE) |   80   CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 
|   82 } |   81 } | 
|   83  |   82  | 
|   84 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr) |   83 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr) | 
|   85 { |   84 { | 
|   86   TRY |   85   try | 
|   87   { |   86   { | 
|   88     GetFilterPtr(ptr)->AddToList(); |   87     GetFilterPtr(ptr)->AddToList(); | 
|   89   } |   88   } | 
|   90   CATCH_AND_THROW(env) |   89   CATCH_AND_THROW(env) | 
|   91 } |   90 } | 
|   92  |   91  | 
|   93 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr) |   92 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr) | 
|   94 { |   93 { | 
|   95   TRY |   94   try | 
|   96   { |   95   { | 
|   97     GetFilterPtr(ptr)->RemoveFromList(); |   96     GetFilterPtr(ptr)->RemoveFromList(); | 
|   98   } |   97   } | 
|   99   CATCH_AND_THROW(env) |   98   CATCH_AND_THROW(env) | 
|  100 } |   99 } | 
|  101  |  100  | 
|  102 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr, 
     jlong otherPtr) |  101 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr, 
     jlong otherPtr) | 
|  103 { |  102 { | 
|  104   AdblockPlus::Filter* me = GetFilterPtr(ptr); |  103   AdblockPlus::Filter* me = GetFilterPtr(ptr); | 
|  105   AdblockPlus::Filter* other = GetFilterPtr(otherPtr); |  104   AdblockPlus::Filter* other = GetFilterPtr(otherPtr); | 
|  106  |  105  | 
|  107   TRY |  106   try | 
|  108   { |  107   { | 
|  109     return *me == *other ? JNI_TRUE : JNI_FALSE; |  108     return *me == *other ? JNI_TRUE : JNI_FALSE; | 
|  110   } |  109   } | 
|  111   CATCH_THROW_AND_RETURN(env, JNI_FALSE) |  110   CATCH_THROW_AND_RETURN(env, JNI_FALSE) | 
|  112 } |  111 } | 
|  113  |  112  | 
|  114 static JNINativeMethod methods[] = |  113 static JNINativeMethod methods[] = | 
|  115 { |  114 { | 
|  116 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, |  115   { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | 
|  117 { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType }, |  116   { (char*)"getType", (char*)"(J)" TYP("Filter$Type"), (void*)JniGetType }, | 
|  118 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, |  117   { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed }, | 
|  119 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, |  118   { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList }, | 
|  120 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, |  119   { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList }, | 
|  121 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals }, }; |  120   { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals } | 
 |  121 }; | 
|  122  |  122  | 
|  123 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_android_api_Filter_regist
     erNatives(JNIEnv *env, jclass clazz) |  123 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Filter_reg
     isterNatives(JNIEnv *env, jclass clazz) | 
|  124 { |  124 { | 
|  125   env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |  125   env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 
|  126 } |  126 } | 
| LEFT | RIGHT |