Left: | ||
Right: |
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 filterEnginePtr = NULL; |
sergei
2017/03/15 10:01:38
smart pointer is already initialized to nullptr, s
sergei
2017/03/15 10:01:38
I would just call the variable as filterEngine, wi
anton
2017/03/15 10:13:52
Acknowledged.
| |
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 filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine, createParame ters); // here (1) - create engine sync | |
65 } | |
66 else | |
67 { | |
68 filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine); | |
69 } | |
70 | |
71 return JniPtrToLong(filterEnginePtr.get()); | |
anton
2017/03/10 06:50:40
for some (unknown) reason new static methods (inst
sergei
2017/03/15 10:01:38
TL;DR: Actually here is a bug, but my vote is to a
anton
2017/03/15 10:13:52
Acknowledged.
| |
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 | |
475 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr) | |
476 { | |
477 try | |
478 { | |
479 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngi ne>(ptr); | |
480 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType(); | |
481 | |
482 if (value == NULL) | |
483 { | |
484 return NULL; | |
485 } | |
486 | |
487 return JniStdStringToJava(env, *value.get()); | |
488 } | |
489 CATCH_THROW_AND_RETURN(env, 0) | |
490 } | |
491 | |
437 static JNINativeMethod methods[] = | 492 static JNINativeMethod methods[] = |
438 { | 493 { |
439 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | 494 { (char*)"ctor", (char*)"(JJ)J", (void*)JniCtor }, |
440 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, | 495 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, |
441 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, | 496 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, |
442 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, | 497 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, |
443 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, | 498 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, |
444 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification }, | 499 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification }, |
445 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif icationCallback }, | 500 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif icationCallback }, |
446 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow NotificationCallback }, | 501 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow NotificationCallback }, |
447 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, | 502 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, |
448 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, | 503 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, |
449 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback }, | 504 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback }, |
450 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback }, | 505 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback }, |
451 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, | 506 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, |
452 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, | 507 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, |
453 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, | 508 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, |
454 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors }, | 509 { (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 }, | 510 { (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 }, | 511 { (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 }, | 512 { (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 }, | 513 { (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 }, | 514 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, |
460 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, | 515 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, |
461 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL }, | 516 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL }, |
517 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType }, | |
518 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType }, | |
462 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 519 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
463 }; | 520 }; |
464 | 521 |
465 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) | 522 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) |
466 { | 523 { |
467 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 524 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
468 } | 525 } |
OLD | NEW |