OLD | NEW |
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-2013 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 * |
(...skipping 18 matching lines...) Expand all Loading... |
32 const char *s = pEnv->GetStringUTFChars(str, &iscopy); | 32 const char *s = pEnv->GetStringUTFChars(str, &iscopy); |
33 jsize len = pEnv->GetStringUTFLength(str); | 33 jsize len = pEnv->GetStringUTFLength(str); |
34 | 34 |
35 const std::string value(s, len); | 35 const std::string value(s, len); |
36 | 36 |
37 pEnv->ReleaseStringUTFChars(str, s); | 37 pEnv->ReleaseStringUTFChars(str, s); |
38 | 38 |
39 return value; | 39 return value; |
40 } | 40 } |
41 | 41 |
42 std::string AdblockPlus::Android::JniJava2StdString(JNIEnv* env, jstring str) | 42 std::string JniJava2StdString(JNIEnv* env, jstring str) |
43 { | 43 { |
44 if (!str) | 44 if (!str) |
45 { | 45 { |
46 return std::string(); | 46 return std::string(); |
47 } | 47 } |
48 | 48 |
49 const char* cStr = env->GetStringUTFChars(str, 0); | 49 const char* cStr = env->GetStringUTFChars(str, 0); |
50 std::string ret(cStr); | 50 std::string ret(cStr); |
51 env->ReleaseStringUTFChars(str, cStr); | 51 env->ReleaseStringUTFChars(str, cStr); |
52 | 52 |
53 return ret; | 53 return ret; |
54 } | 54 } |
55 | 55 |
56 jobject AdblockPlus::Android::NewJniArrayList(JNIEnv* env) | 56 jobject NewJniArrayList(JNIEnv* env) |
57 { | 57 { |
58 jclass clazz = env->FindClass("java/util/ArrayList"); | 58 jclass clazz = env->FindClass("java/util/ArrayList"); |
59 jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V"); | 59 jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V"); |
60 return env->NewObject(clazz, ctor); | 60 return env->NewObject(clazz, ctor); |
61 } | 61 } |
62 | 62 |
63 void AdblockPlus::Android::JniAddObjectToList(JNIEnv* env, jobject list, jobject
value) | 63 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) |
64 { | 64 { |
65 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan
g/Object;)Z"); | 65 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan
g/Object;)Z"); |
66 env->CallBooleanMethod(list, add, value); | 66 env->CallBooleanMethod(list, add, value); |
67 } | 67 } |
68 | 68 |
69 void AdblockPlus::Android::JniThrowException(JNIEnv* env, const std::string& mes
sage) | 69 void JniThrowException(JNIEnv* env, const std::string& message) |
70 { | 70 { |
71 jclass clazz = env->FindClass(PKG("AdblockPlusException")); | 71 jclass clazz = env->FindClass(PKG("AdblockPlusException")); |
72 env->ThrowNew(clazz, message.c_str()); | 72 env->ThrowNew(clazz, message.c_str()); |
73 } | 73 } |
74 | 74 |
75 void AdblockPlus::Android::JniThrowException(JNIEnv* env, const std::exception&
e) | 75 void JniThrowException(JNIEnv* env, const std::exception& e) |
76 { | 76 { |
77 JniThrowException(env, e.what()); | 77 JniThrowException(env, e.what()); |
78 } | 78 } |
79 | 79 |
80 void AdblockPlus::Android::JniThrowException(JNIEnv* env) | 80 void JniThrowException(JNIEnv* env) |
81 { | 81 { |
82 JniThrowException(env, "Unknown exception from libAdblockPlus"); | 82 JniThrowException(env, "Unknown exception from libAdblockPlus"); |
83 } | 83 } |
OLD | NEW |