| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 { | 159 { |
| 160 if (attachmentStatus == JNI_EDETACHED) | 160 if (attachmentStatus == JNI_EDETACHED) |
| 161 { | 161 { |
| 162 javaVM->DetachCurrentThread(); | 162 javaVM->DetachCurrentThread(); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 template<typename T> | 166 template<typename T> |
| 167 static jobject NewJniObject(JNIEnv* env, const T& value, jclass clazz, jmethodID
ctor) | 167 static jobject NewJniObject(JNIEnv* env, const T& value, jclass clazz, jmethodID
ctor) |
| 168 { | 168 { |
| 169 if (!value.get()) | |
| 170 { | |
| 171 return 0; | |
| 172 } | |
| 173 | |
| 174 return env->NewObject(clazz, ctor, JniPtrToLong(new T(value))); | 169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(value))); |
| 175 } | 170 } |
| 176 | 171 |
| 177 template<typename T> | 172 template<typename T> |
| 178 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass) | 173 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass) |
| 179 { | 174 { |
| 180 JniLocalReference<jclass> clazz( env, env->FindClass(javaClass)); | 175 JniLocalReference<jclass> clazz( env, env->FindClass(javaClass)); |
| 181 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V"); | 176 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V"); |
| 182 return NewJniObject(env, value, *clazz, ctor); | 177 return NewJniObject(env, value, *clazz, ctor); |
| 183 } | 178 } |
| 184 | 179 |
| 185 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter) | 180 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::Filter& filter) |
| 186 { | 181 { |
| 187 return NewJniObject(env, filter, filterClass->Get(), filterCtor); | 182 return NewJniObject(env, filter, filterClass->Get(), filterCtor); |
| 188 } | 183 } |
| 189 | 184 |
| 190 jobject NewJniSubscription(JNIEnv* env, | 185 jobject NewJniSubscription(JNIEnv* env, const AdblockPlus::Subscription& subscri
ption) |
| 191 const AdblockPlus::SubscriptionPtr& subscription) | |
| 192 { | 186 { |
| 193 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC
tor); | 187 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC
tor); |
| 194 } | 188 } |
| 195 | 189 |
| 196 jobject NewJniNotification(JNIEnv* env, | 190 jobject NewJniNotification(JNIEnv* env, const AdblockPlus::Notification& notific
ation) |
| 197 const AdblockPlus::NotificationPtr& notification) | |
| 198 { | 191 { |
| 199 return NewJniObject(env, notification, notificationClass->Get(), notificationC
tor); | 192 return NewJniObject(env, notification, notificationClass->Get(), notificationC
tor); |
| 200 } | 193 } |
| OLD | NEW |