| LEFT | RIGHT |
| 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 16 matching lines...) Expand all Loading... |
| 27 { | 27 { |
| 28 JniAddObjectToList(env, list, NewJniSubscription(env, *it)); | 28 JniAddObjectToList(env, list, NewJniSubscription(env, *it)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 return list; | 31 return list; |
| 32 } | 32 } |
| 33 | 33 |
| 34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env, | 34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env, |
| 35 jobject jContentType) | 35 jobject jContentType) |
| 36 { | 36 { |
| 37 JniLocalReference<jclass> contentTypeClass(env, env->GetObjectClass(jContentTy
pe)); | 37 JniLocalReference<jclass> contentTypeClass(env, |
| 38 env->GetObjectClass(jContentType)); |
| 38 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name", | 39 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name", |
| 39 "()Ljava/lang/String;"); | 40 "()Ljava/lang/String;"); |
| 40 JniLocalReference<jstring> jValue(env, (jstring) env->CallObjectMethod(jConten
tType, nameMethod)); | 41 JniLocalReference<jstring> jValue(env, |
| 42 (jstring) env->CallObjectMethod(jContentType, nameMethod)); |
| 41 const std::string value = JniJavaToStdString(env, *jValue); | 43 const std::string value = JniJavaToStdString(env, *jValue); |
| 42 return AdblockPlus::FilterEngine::StringToContentType(value); | 44 return AdblockPlus::FilterEngine::StringToContentType(value); |
| 43 } | 45 } |
| 44 | 46 |
| 45 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) | 47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) |
| 46 { | 48 { |
| 47 try | 49 try |
| 48 { | 50 { |
| 49 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine
Ptr>(enginePtr); | 51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine
Ptr>(enginePtr); |
| 50 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); | 52 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 { | 177 { |
| 176 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 178 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
| 177 | 179 |
| 178 try | 180 try |
| 179 { | 181 { |
| 180 engine->RemoveFilterChangeCallback(); | 182 engine->RemoveFilterChangeCallback(); |
| 181 } | 183 } |
| 182 CATCH_AND_THROW(env) | 184 CATCH_AND_THROW(env) |
| 183 } | 185 } |
| 184 | 186 |
| 185 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, jlong
ptr, jlong filterPtr) | 187 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, |
| 186 { | 188 jlong ptr, jlong filterPtr) |
| 187 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 189 { |
| 188 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
filterPtr); | 190 AdblockPlus::FilterEngine* engine = |
| 191 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
| 192 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( |
| 193 filterPtr); |
| 189 | 194 |
| 190 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = | 195 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = |
| 191 std::tr1::bind(&JniFilterChangeCallback::Callback, callback, std::tr1::pla
ceholders::_1, std::tr1::placeholders::_2); | 196 std::tr1::bind(&JniFilterChangeCallback::Callback, callback, |
| 197 std::tr1::placeholders::_1, std::tr1::placeholders::_2); |
| 192 | 198 |
| 193 try | 199 try |
| 194 { | 200 { |
| 195 engine->SetFilterChangeCallback(filterCallback); | 201 engine->SetFilterChangeCallback(filterCallback); |
| 196 } | 202 } |
| 197 CATCH_AND_THROW(env) | 203 CATCH_AND_THROW(env) |
| 198 } | 204 } |
| 199 | 205 |
| 200 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
ong updaterPtr) | 206 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
ong updaterPtr) |
| 201 { | 207 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 213 std::tr1::placeholders::_1); | 219 std::tr1::placeholders::_1); |
| 214 } | 220 } |
| 215 | 221 |
| 216 try | 222 try |
| 217 { | 223 { |
| 218 engine->ForceUpdateCheck(updateCheckDoneCallback); | 224 engine->ForceUpdateCheck(updateCheckDoneCallback); |
| 219 } | 225 } |
| 220 CATCH_AND_THROW(env) | 226 CATCH_AND_THROW(env) |
| 221 } | 227 } |
| 222 | 228 |
| 223 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, j
long ptr, jstring jDomain) | 229 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, |
| 224 { | 230 jlong ptr, jstring jDomain) |
| 225 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 231 { |
| 232 AdblockPlus::FilterEngine* engine = |
| 233 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
| 226 | 234 |
| 227 std::string domain = JniJavaToStdString(env, jDomain); | 235 std::string domain = JniJavaToStdString(env, jDomain); |
| 228 | 236 |
| 229 try | 237 try |
| 230 { | 238 { |
| 231 std::vector<std::string> selectors = engine->GetElementHidingSelectors(domai
n); | 239 std::vector<std::string> selectors = engine->GetElementHidingSelectors( |
| 240 domain); |
| 232 | 241 |
| 233 jobject list = NewJniArrayList(env); | 242 jobject list = NewJniArrayList(env); |
| 234 | 243 |
| 235 for (std::vector<std::string>::iterator it = selectors.begin(), end = select
ors.end(); it != end; it++) | 244 for (std::vector<std::string>::iterator it = selectors.begin(), end = |
| 245 selectors.end(); it != end; it++) |
| 236 { | 246 { |
| 237 JniAddObjectToList(env, list, *JniLocalReference<jstring>(env, env->NewStr
ingUTF(it->c_str()))); | 247 JniAddObjectToList(env, list, |
| 248 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str()))); |
| 238 } | 249 } |
| 239 | 250 |
| 240 return list; | 251 return list; |
| 241 } | 252 } |
| 242 CATCH_THROW_AND_RETURN(env, 0) | 253 CATCH_THROW_AND_RETURN(env, 0) |
| 243 } | 254 } |
| 244 | 255 |
| 245 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring
jUrl, jobject jContentType, jstring jDocumentUrl) | 256 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring
jUrl, jobject jContentType, jstring jDocumentUrl) |
| 246 { | 257 { |
| 247 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 258 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
| 248 | 259 |
| 249 std::string url = JniJavaToStdString(env, jUrl); | 260 std::string url = JniJavaToStdString(env, jUrl); |
| 250 AdblockPlus::FilterEngine::ContentType contentType = | 261 AdblockPlus::FilterEngine::ContentType contentType = |
| 251 ConvertContentType(env, jContentType); | 262 ConvertContentType(env, jContentType); |
| 252 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); | 263 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); |
| 253 | 264 |
| 254 try | 265 try |
| 255 { | 266 { |
| 256 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr
l); | 267 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr
l); |
| 257 | 268 |
| 258 return NewJniFilter(env, filter); | 269 return NewJniFilter(env, filter); |
| 259 } | 270 } |
| 260 CATCH_THROW_AND_RETURN(env, 0) | 271 CATCH_THROW_AND_RETURN(env, 0) |
| 261 } | 272 } |
| 262 | 273 |
| 263 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstr
ing jUrl, jobject jContentType, jobjectArray jDocumentUrls) | 274 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, |
| 264 { | 275 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) |
| 265 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 276 { |
| 277 AdblockPlus::FilterEngine* engine = |
| 278 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
| 266 | 279 |
| 267 std::string url = JniJavaToStdString(env, jUrl); | 280 std::string url = JniJavaToStdString(env, jUrl); |
| 268 AdblockPlus::FilterEngine::ContentType contentType = | 281 AdblockPlus::FilterEngine::ContentType contentType = |
| 269 ConvertContentType(env, jContentType); | 282 ConvertContentType(env, jContentType); |
| 270 | 283 |
| 271 std::vector<std::string> documentUrls; | 284 std::vector<std::string> documentUrls; |
| 272 | 285 |
| 273 jsize len = env->GetArrayLength(jDocumentUrls); | 286 jsize len = env->GetArrayLength(jDocumentUrls); |
| 274 | 287 |
| 275 for (jsize i = 0; i < len; i++) | 288 for (jsize i = 0; i < len; i++) |
| 276 { | 289 { |
| 277 documentUrls.push_back(JniJavaToStdString(env, | 290 documentUrls.push_back( |
| 278 *JniLocalReference<jstring>(env, static_cast<jstring>(env->GetObjectArra
yElement(jDocumentUrls, i))))); | 291 JniJavaToStdString(env, |
| 279 } | 292 *JniLocalReference<jstring>(env, |
| 280 | 293 static_cast<jstring>(env->GetObjectArrayElement(jDocumentUrls, |
| 281 try | 294 i))))); |
| 282 { | 295 } |
| 283 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr
ls); | 296 |
| 297 try |
| 298 { |
| 299 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, |
| 300 documentUrls); |
| 284 | 301 |
| 285 return NewJniFilter(env, filter); | 302 return NewJniFilter(env, filter); |
| 286 } | 303 } |
| 287 CATCH_THROW_AND_RETURN(env, 0) | 304 CATCH_THROW_AND_RETURN(env, 0) |
| 288 } | 305 } |
| 289 | 306 |
| 290 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring
jPref) | 307 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring
jPref) |
| 291 { | 308 { |
| 292 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi
ne > (ptr); | 309 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi
ne > (ptr); |
| 293 | 310 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, | 352 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, |
| 336 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, | 353 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, |
| 337 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, | 354 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, |
| 338 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 355 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 339 }; | 356 }; |
| 340 | 357 |
| 341 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) | 358 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) |
| 342 { | 359 { |
| 343 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 360 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 344 } | 361 } |
| LEFT | RIGHT |