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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 26 matching lines...) Expand all Loading... |
37 JniLocalReference<jclass> contentTypeClass(env, | 37 JniLocalReference<jclass> contentTypeClass(env, |
38 env->GetObjectClass(jContentType)); | 38 env->GetObjectClass(jContentType)); |
39 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name", | 39 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name", |
40 "()Ljava/lang/String;"); | 40 "()Ljava/lang/String;"); |
41 JniLocalReference<jstring> jValue(env, | 41 JniLocalReference<jstring> jValue(env, |
42 (jstring) env->CallObjectMethod(jContentType, nameMethod)); | 42 (jstring) env->CallObjectMethod(jContentType, nameMethod)); |
43 const std::string value = JniJavaToStdString(env, *jValue); | 43 const std::string value = JniJavaToStdString(env, *jValue); |
44 return AdblockPlus::FilterEngine::StringToContentType(value); | 44 return AdblockPlus::FilterEngine::StringToContentType(value); |
45 } | 45 } |
46 | 46 |
47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) | 47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsEnginePtr, jlong
isAllowedConnectionCallbackPtr) |
48 { | 48 { |
49 try | 49 try |
50 { | 50 { |
51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine
Ptr>(enginePtr); | 51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine
Ptr>(jsEnginePtr); |
52 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); | 52 AdblockPlus::FilterEnginePtr filterEngine; |
| 53 |
| 54 if (isAllowedConnectionCallbackPtr != 0) |
| 55 { |
| 56 AdblockPlus::FilterEngine::CreateParameters createParameters; |
| 57 JniIsAllowedConnectionTypeCallback* callback = |
| 58 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection
CallbackPtr); |
| 59 |
| 60 AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback = |
| 61 std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std::
placeholders::_1); |
| 62 createParameters.isConnectionAllowed = cppCallback; |
| 63 |
| 64 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParameter
s); |
| 65 } |
| 66 else |
| 67 { |
| 68 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |
| 69 } |
| 70 |
| 71 return JniPtrToLong(filterEngine.get()); |
53 } | 72 } |
54 CATCH_THROW_AND_RETURN(env, 0) | 73 CATCH_THROW_AND_RETURN(env, 0) |
55 } | 74 } |
56 | 75 |
57 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 76 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
58 { | 77 { |
59 delete JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); | 78 delete JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
60 } | 79 } |
61 | 80 |
62 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr) | 81 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 std::string url = JniJavaToStdString(env, jurl); | 446 std::string url = JniJavaToStdString(env, jurl); |
428 try | 447 try |
429 { | 448 { |
430 std::string host = engine->GetHostFromURL(url); | 449 std::string host = engine->GetHostFromURL(url); |
431 | 450 |
432 return JniStdStringToJava(env, host); | 451 return JniStdStringToJava(env, host); |
433 } | 452 } |
434 CATCH_THROW_AND_RETURN(env, 0) | 453 CATCH_THROW_AND_RETURN(env, 0) |
435 } | 454 } |
436 | 455 |
| 456 static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong
ptr, jstring jvalue) |
| 457 { |
| 458 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
| 459 |
| 460 std::string* value = NULL; |
| 461 if (jvalue != NULL) |
| 462 { |
| 463 std::string stdValue = JniJavaToStdString(env, jvalue); |
| 464 value = &stdValue; |
| 465 } |
| 466 |
| 467 try |
| 468 { |
| 469 engine->SetAllowedConnectionType(value); |
| 470 } |
| 471 CATCH_AND_THROW(env) |
| 472 } |
| 473 |
| 474 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl
ong ptr) |
| 475 { |
| 476 try |
| 477 { |
| 478 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngi
ne>(ptr); |
| 479 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType(); |
| 480 |
| 481 if (value == NULL) |
| 482 { |
| 483 return NULL; |
| 484 } |
| 485 |
| 486 return JniStdStringToJava(env, *value.get()); |
| 487 } |
| 488 CATCH_THROW_AND_RETURN(env, 0) |
| 489 } |
| 490 |
437 static JNINativeMethod methods[] = | 491 static JNINativeMethod methods[] = |
438 { | 492 { |
439 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | 493 { (char*)"ctor", (char*)"(JJ)J", (void*)JniCtor }, |
440 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, | 494 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, |
441 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni
GetFilter }, | 495 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni
GetFilter }, |
442 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed
Filters }, | 496 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed
Filters }, |
443 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription")
, (void*)JniGetSubscription }, | 497 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription")
, (void*)JniGetSubscription }, |
444 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh
owNextNotification }, | 498 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh
owNextNotification }, |
445 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif
icationCallback }, | 499 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif
icationCallback }, |
446 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow
NotificationCallback }, | 500 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow
NotificationCallback }, |
447 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet
ListedSubscriptions }, | 501 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet
ListedSubscriptions }, |
448 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J
niFetchAvailableSubscriptions }, | 502 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J
niFetchAvailableSubscriptions }, |
449 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai
lableCallback }, | 503 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai
lableCallback }, |
450 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat
eAvailableCallback }, | 504 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat
eAvailableCallback }, |
451 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC
allback }, | 505 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC
allback }, |
452 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh
angeCallback }, | 506 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh
angeCallback }, |
453 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, | 507 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, |
454 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/
List;", (void*)JniGetElementHidingSelectors }, | 508 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/
List;", (void*)JniGetElementHidingSelectors }, |
455 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, | 509 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, |
456 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, | 510 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, |
457 { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri
ng;)Z", (void*)JniIsDocumentWhitelisted }, | 511 { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri
ng;)Z", (void*)JniIsDocumentWhitelisted }, |
458 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri
ng;)Z", (void*)JniIsElemhideWhitelisted }, | 512 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri
ng;)Z", (void*)JniIsElemhideWhitelisted }, |
459 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, | 513 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, |
460 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, | 514 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, |
461 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", (
void*)JniGetHostFromURL }, | 515 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", (
void*)JniGetHostFromURL }, |
| 516 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J
niSetAllowedConnectionType }, |
| 517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn
iGetAllowedConnectionType }, |
462 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
463 }; | 519 }; |
464 | 520 |
465 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) | 521 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) |
466 { | 522 { |
467 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
468 } | 524 } |
OLD | NEW |