| 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-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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
| 19 #include "Utils.h" | 19 #include "Utils.h" |
| 20 #include "JniCallbacks.h" | 20 #include "JniCallbacks.h" |
| 21 #include <thread> | |
| 21 | 22 |
| 22 static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Su bscription>&& subscriptions) | 23 static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Su bscription>&& subscriptions) |
| 23 { | 24 { |
| 24 jobject list = NewJniArrayList(env); | 25 jobject list = NewJniArrayList(env); |
| 25 | 26 |
| 26 for (std::vector<AdblockPlus::Subscription>::iterator it = subscriptions.begin (), end = subscriptions.end(); it != end; it++) | 27 for (std::vector<AdblockPlus::Subscription>::iterator it = subscriptions.begin (), end = subscriptions.end(); it != end; it++) |
| 27 { | 28 { |
| 28 JniAddObjectToList(env, list, NewJniSubscription(env, std::move(*it))); | 29 JniAddObjectToList(env, list, NewJniSubscription(env, std::move(*it))); |
| 29 } | 30 } |
| 30 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 50 { | 51 { |
| 51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(jsEnginePtr); | 52 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(jsEnginePtr); |
| 52 AdblockPlus::FilterEnginePtr* filterEngine = NULL; | 53 AdblockPlus::FilterEnginePtr* filterEngine = NULL; |
| 53 | 54 |
| 54 if (isAllowedConnectionCallbackPtr != 0) | 55 if (isAllowedConnectionCallbackPtr != 0) |
| 55 { | 56 { |
| 56 AdblockPlus::FilterEngine::CreationParameters creationParameters; | 57 AdblockPlus::FilterEngine::CreationParameters creationParameters; |
| 57 JniIsAllowedConnectionTypeCallback* callback = | 58 JniIsAllowedConnectionTypeCallback* callback = |
| 58 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection CallbackPtr); | 59 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection CallbackPtr); |
| 59 | 60 |
| 60 AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback = | 61 creationParameters.isSubscriptionDowloadAllowedCallback = |
| 61 std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std:: placeholders::_1); | 62 [callback](const std::string* allowedConnectionTypeArg, const std::funct ion<void(bool)>& doneCallback) |
| 62 creationParameters.isConnectionAllowedCallback = cppCallback; | 63 { |
| 64 std::shared_ptr<std::string> allowedConnectionType; | |
| 65 if (allowedConnectionTypeArg) | |
|
anton
2017/06/02 06:55:23
"{" required
sergei
2017/06/02 07:32:43
Done.
| |
| 66 allowedConnectionType = std::make_shared<std::string>(*allowedConnecti onTypeArg); | |
| 67 std::thread([callback, allowedConnectionType, doneCallback] | |
|
sergei
2017/06/01 14:41:57
Detached thread is still a hack with data race, ba
anton
2017/06/02 06:55:23
"}" required
sergei
2017/06/02 07:32:43
Done.
| |
| 68 { | |
| 69 doneCallback(callback->Callback(allowedConnectionType.get())); | |
| 70 }).detach(); | |
| 71 }; | |
| 63 | 72 |
| 64 filterEngine = new AdblockPlus::FilterEnginePtr( | 73 filterEngine = new AdblockPlus::FilterEnginePtr( |
| 65 AdblockPlus::FilterEngine::Create(jsEngine, creationParameters)); | 74 AdblockPlus::FilterEngine::Create(jsEngine, creationParameters)); |
| 66 } | 75 } |
| 67 else | 76 else |
| 68 { | 77 { |
| 69 filterEngine = new AdblockPlus::FilterEnginePtr( | 78 filterEngine = new AdblockPlus::FilterEnginePtr( |
| 70 AdblockPlus::FilterEngine::Create(jsEngine)); | 79 AdblockPlus::FilterEngine::Create(jsEngine)); |
| 71 } | 80 } |
| 72 | 81 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 { (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAds Enabled }, | 554 { (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAds Enabled }, |
| 546 { (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEna bled }, | 555 { (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEna bled }, |
| 547 { (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (v oid*)JniGetAcceptableAdsSubscriptionURL }, | 556 { (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (v oid*)JniGetAcceptableAdsSubscriptionURL }, |
| 548 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 557 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 549 }; | 558 }; |
| 550 | 559 |
| 551 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) | 560 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) |
| 552 { | 561 { |
| 553 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 562 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 554 } | 563 } |
| OLD | NEW |