OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValuePtr& jsValue, jclas
s jsValueClass) | 137 jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValuePtr& jsValue, jclas
s jsValueClass) |
138 { | 138 { |
139 if (!jsValue.get()) | 139 if (!jsValue.get()) |
140 { | 140 { |
141 return 0; | 141 return 0; |
142 } | 142 } |
143 | 143 |
144 jclass clazz = jsValueClass ? jsValueClass : env->FindClass(PKG("JsValue")); | 144 jclass clazz = jsValueClass ? jsValueClass : env->FindClass(PKG("JsValue")); |
145 jmethodID ctor = env->GetMethodID(clazz, "<init>", "(J)V"); | 145 jmethodID ctor = env->GetMethodID(clazz, "<init>", "(J)V"); |
146 jlong ptr = JniPtrToLong(new AdblockPlus::JsValuePtr(jsValue)); | 146 jlong ptr = JniPtrToLong(new AdblockPlus::JsValuePtr(jsValue)); |
147 return env->NewObject(clazz, ctor, ptr); | 147 jobject ret = env->NewObject(clazz, ctor, ptr); |
| 148 |
| 149 if (!jsValueClass) |
| 150 { |
| 151 env->DeleteLocalRef(clazz); |
| 152 } |
| 153 |
| 154 return ret; |
148 } | 155 } |
149 | 156 |
150 AdblockPlus::JsValue* JniGetJsValue(jlong ptr) | 157 AdblockPlus::JsValue* JniGetJsValue(jlong ptr) |
151 { | 158 { |
152 return JniLongToTypePtr<AdblockPlus::JsValuePtr>(ptr)->get(); | 159 return JniLongToTypePtr<AdblockPlus::JsValuePtr>(ptr)->get(); |
153 } | 160 } |
154 | 161 |
155 AdblockPlus::JsValuePtr& JniGetJsValuePtr(jlong ptr) | 162 AdblockPlus::JsValuePtr& JniGetJsValuePtr(jlong ptr) |
156 { | 163 { |
157 return *JniLongToTypePtr<AdblockPlus::JsValuePtr>(ptr); | 164 return *JniLongToTypePtr<AdblockPlus::JsValuePtr>(ptr); |
158 } | 165 } |
159 | 166 |
160 jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList& list) | 167 jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList& list) |
161 { | 168 { |
162 jobject arrayList = NewJniArrayList(env); | 169 jobject arrayList = NewJniArrayList(env); |
163 | 170 |
164 for (AdblockPlus::JsValueList::iterator it = list.begin(), end = list.end(); i
t != end; ++it) | 171 for (AdblockPlus::JsValueList::iterator it = list.begin(), end = list.end(); i
t != end; ++it) |
165 { | 172 { |
166 JniAddObjectToList(env, arrayList, NewJniJsValue(env, *it)); | 173 JniAddObjectToList(env, arrayList, |
| 174 *JniLocalReference<jobject>(env, NewJniJsValue(env, *it))); |
167 } | 175 } |
168 | 176 |
169 return arrayList; | 177 return arrayList; |
170 } | 178 } |
171 | 179 |
172 // TODO: List of functions that lack JNI bindings | 180 // TODO: List of functions that lack JNI bindings |
173 //std::vector<std::string> GetOwnPropertyNames() const; | 181 //std::vector<std::string> GetOwnPropertyNames() const; |
174 //void SetProperty(const std::string& name, const std::string& val); | 182 //void SetProperty(const std::string& name, const std::string& val); |
175 //void SetProperty(const std::string& name, int64_t val); | 183 //void SetProperty(const std::string& name, int64_t val); |
176 //void SetProperty(const std::string& name, bool val); | 184 //void SetProperty(const std::string& name, bool val); |
(...skipping 17 matching lines...) Expand all Loading... |
194 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, | 202 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, |
195 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, | 203 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, |
196 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, | 204 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)
JniGetProperty }, |
197 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 205 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
198 }; | 206 }; |
199 | 207 |
200 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) | 208 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re
gisterNatives(JNIEnv *env, jclass clazz) |
201 { | 209 { |
202 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 210 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
203 } | 211 } |
OLD | NEW |