| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 std::string url = engine.GetAAUrl(); | 478 std::string url = engine.GetAAUrl(); |
| 479 return JniStdStringToJava(env, url); | 479 return JniStdStringToJava(env, url); |
| 480 } | 480 } |
| 481 CATCH_THROW_AND_RETURN(env, 0) | 481 CATCH_THROW_AND_RETURN(env, 0) |
| 482 } | 482 } |
| 483 | 483 |
| 484 static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong jniPl atformPtr, jstring jSubscriptionUrl) | 484 static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong jniPl atformPtr, jstring jSubscriptionUrl) |
| 485 { | 485 { |
| 486 std::string subscriptionUrl = JniJavaToStdString(env, jSubscriptionUrl); | 486 std::string subscriptionUrl = JniJavaToStdString(env, jSubscriptionUrl); |
| 487 auto jniPlatform = JniLongToTypePtr<JniPlatform>(jniPlatformPtr); | 487 auto jniPlatform = JniLongToTypePtr<JniPlatform>(jniPlatformPtr); |
| 488 jniPlatform->scheduler([jniPlatform, subscriptionUrl] | 488 auto updateSubscriptionFilters = [jniPlatform, subscriptionUrl] |
| 489 { | 489 { |
| 490 auto& filterEngine = jniPlatform->platform->GetFilterEngine(); | 490 auto& filterEngine = jniPlatform->platform->GetFilterEngine(); |
| 491 for (auto& subscription : filterEngine.GetListedSubscriptions()) | 491 for (auto& subscription : filterEngine.GetListedSubscriptions()) |
| 492 { | 492 { |
| 493 if (stringBeginsWith(subscriptionUrl, subscription.GetProperty("url").AsSt ring())) | 493 if (stringBeginsWith(subscriptionUrl, subscription.GetProperty("url").AsSt ring())) |
| 494 { | 494 { |
| 495 subscription.UpdateFilters(); | 495 subscription.UpdateFilters(); |
| 496 return; | 496 return; |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 }; | |
| 500 jniPlatform->platform->WithTimer([updateSubscriptionFilters](AdblockPlus::ITim er& timer) | |
| 501 { | |
| 502 timer.SetTimer(std::chrono::milliseconds(300), updateSubscriptionFilters); | |
|
anton
2017/10/06 10:38:08
I don't like such timers a lot. It's always introd
sergei
2017/10/06 13:37:03
As discussed in the issue, it does not help.
| |
| 499 }); | 503 }); |
| 500 } | 504 } |
| 501 | 505 |
| 502 static JNINativeMethod methods[] = | 506 static JNINativeMethod methods[] = |
| 503 { | 507 { |
| 504 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, | 508 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, |
| 505 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, | 509 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, |
| 506 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, | 510 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, |
| 507 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, | 511 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, |
| 508 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification }, | 512 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification }, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 528 { (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAds Enabled }, | 532 { (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAds Enabled }, |
| 529 { (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEna bled }, | 533 { (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEna bled }, |
| 530 { (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (v oid*)JniGetAcceptableAdsSubscriptionURL }, | 534 { (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (v oid*)JniGetAcceptableAdsSubscriptionURL }, |
| 531 { (char*)"updateFiltersAsync", (char*)"(JLjava/lang/String;)V", (void*)JniUpda teFiltersAsync } | 535 { (char*)"updateFiltersAsync", (char*)"(JLjava/lang/String;)V", (void*)JniUpda teFiltersAsync } |
| 532 }; | 536 }; |
| 533 | 537 |
| 534 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) | 538 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) |
| 535 { | 539 { |
| 536 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 540 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 537 } | 541 } |
| OLD | NEW |