OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 25 matching lines...) Expand all Loading... |
36 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_isFirstRun(J
NIEnv *pEnv, jobject); | 36 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_isFirstRun(J
NIEnv *pEnv, jobject); |
37 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getListe
dSubscriptions(JNIEnv *pEnv, jobject); | 37 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getListe
dSubscriptions(JNIEnv *pEnv, jobject); |
38 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getRecom
mendedSubscriptions(JNIEnv *pEnv, jobject); | 38 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getRecom
mendedSubscriptions(JNIEnv *pEnv, jobject); |
39 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_addSubscription(
JNIEnv *pEnv, jobject, jstring url); | 39 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_addSubscription(
JNIEnv *pEnv, jobject, jstring url); |
40 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscripti
on(JNIEnv *pEnv, jobject, jstring url); | 40 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscripti
on(JNIEnv *pEnv, jobject, jstring url); |
41 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_refreshSubscript
ion(JNIEnv *pEnv, jobject, jstring url); | 41 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_refreshSubscript
ion(JNIEnv *pEnv, jobject, jstring url); |
42 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_actualizeSubscri
ptionStatus(JNIEnv *pEnv, jobject, jstring url); | 42 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_actualizeSubscri
ptionStatus(JNIEnv *pEnv, jobject, jstring url); |
43 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_setAcceptableAds
Enabled(JNIEnv *pEnv, jobject, jboolean enabled); | 43 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_setAcceptableAds
Enabled(JNIEnv *pEnv, jobject, jboolean enabled); |
44 JNIEXPORT jstring JNICALL Java_org_adblockplus_android_ABPEngine_getDocumentat
ionLink( | 44 JNIEXPORT jstring JNICALL Java_org_adblockplus_android_ABPEngine_getDocumentat
ionLink( |
45 JNIEnv *env, jobject object); | 45 JNIEnv *env, jobject object); |
46 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches(JNIE
nv *pEnv, jobject, jstring url, jstring contentType, jstring documentUrl); | 46 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches( |
| 47 JNIEnv *pEnv, jobject, jstring url, jstring contentType, jobjectArray docu
mentUrls); |
47 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getSelec
torsForDomain(JNIEnv *pEnv, jobject, jstring domain); | 48 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getSelec
torsForDomain(JNIEnv *pEnv, jobject, jstring domain); |
48 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_checkUpdates(JNI
Env *pEnv, jobject); | 49 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_checkUpdates(JNI
Env *pEnv, jobject); |
49 }; | 50 }; |
50 | 51 |
51 jobjectArray subscriptionsAsJavaArray(JNIEnv *pEnv, std::vector<AdblockPlus::Sub
scriptionPtr> subscriptions) | 52 jobjectArray subscriptionsAsJavaArray(JNIEnv *pEnv, std::vector<AdblockPlus::Sub
scriptionPtr> subscriptions) |
52 { | 53 { |
53 D(D_WARN, "subscriptionsAsJavaArray()"); | 54 D(D_WARN, "subscriptionsAsJavaArray()"); |
54 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("org/adblockplus/android/Subscription"))); | 55 static jclass cls = reinterpret_cast<jclass>(pEnv->NewGlobalRef(pEnv->FindClas
s("org/adblockplus/android/Subscription"))); |
55 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "()V"); | 56 static jmethodID cid = pEnv->GetMethodID(cls, "<init>", "()V"); |
56 static jfieldID ftitle = pEnv->GetFieldID(cls, "title", "Ljava/lang/String;"); | 57 static jfieldID ftitle = pEnv->GetFieldID(cls, "title", "Ljava/lang/String;"); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 } | 458 } |
458 } | 459 } |
459 | 460 |
460 JNIEXPORT jstring JNICALL Java_org_adblockplus_android_ABPEngine_getDocumentatio
nLink( | 461 JNIEXPORT jstring JNICALL Java_org_adblockplus_android_ABPEngine_getDocumentatio
nLink( |
461 JNIEnv *env, jobject object) | 462 JNIEnv *env, jobject object) |
462 { | 463 { |
463 const std::string documentationLink = filterEngine->GetPref("documentation_lin
k")->AsString(); | 464 const std::string documentationLink = filterEngine->GetPref("documentation_lin
k")->AsString(); |
464 return env->NewStringUTF(documentationLink.c_str()); | 465 return env->NewStringUTF(documentationLink.c_str()); |
465 } | 466 } |
466 | 467 |
467 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches(JNIEnv
*pEnv, jobject, jstring url, jstring contentType, jstring documentUrl) | 468 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches( |
| 469 JNIEnv *pEnv, jobject, jstring url, jstring contentType, jobjectArray document
Urls) |
468 { | 470 { |
469 try | 471 try |
470 { | 472 { |
471 const std::string surl = GetString(pEnv, url); | 473 const std::string surl = GetString(pEnv, url); |
472 const std::string stype = GetString(pEnv, contentType); | 474 const std::string stype = GetString(pEnv, contentType); |
473 const std::string sdoc = GetString(pEnv, documentUrl); | 475 const int documentUrlsLength = pEnv->GetArrayLength(documentUrls); |
| 476 std::vector<std::string> sdocumentUrls; |
| 477 for(int i = 0; i < documentUrlsLength; i++) |
| 478 { |
| 479 jstring documentUrl = static_cast<jstring>(pEnv->GetObjectArrayElement(do
cumentUrls, i)); |
| 480 sdocumentUrls.push_back(GetString(pEnv, documentUrl)); |
| 481 } |
474 | 482 |
475 AdblockPlus::FilterPtr filter = filterEngine->Matches(surl, stype, sdoc); | 483 AdblockPlus::FilterPtr filter = filterEngine->Matches(surl, stype, sdocument
Urls); |
476 | 484 |
477 if (! filter) | 485 if (! filter) |
478 return JNI_FALSE; | 486 return JNI_FALSE; |
479 | 487 |
480 // hack: if there is no referrer block only if filter is domain-specific | 488 // hack: if there is no referrer, block only if filter is domain-specific |
481 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) | 489 // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) |
482 // documentUrl contains the referrer (Android application special case) | 490 // (documentUrls contains the referrers on Android) |
483 if (sdoc.empty() && (filter->GetProperty("text")->AsString()).find("||") !=
std::string::npos) | 491 if (!sdocumentUrls.size() && |
| 492 (filter->GetProperty("text")->AsString()).find("||") != std::string::npo
s) |
484 return JNI_FALSE; | 493 return JNI_FALSE; |
485 | 494 |
486 return filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION ? JNI_FALSE
: JNI_TRUE; | 495 return filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION ? JNI_FALSE
: JNI_TRUE; |
487 } | 496 } |
488 catch (const std::exception& e) | 497 catch (const std::exception& e) |
489 { | 498 { |
490 ThrowJavaException(pEnv, e); | 499 ThrowJavaException(pEnv, e); |
491 } | 500 } |
492 catch (...) | 501 catch (...) |
493 { | 502 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 549 } |
541 catch (const std::exception& e) | 550 catch (const std::exception& e) |
542 { | 551 { |
543 ThrowJavaException(pEnv, e); | 552 ThrowJavaException(pEnv, e); |
544 } | 553 } |
545 catch (...) | 554 catch (...) |
546 { | 555 { |
547 ThrowJavaException(pEnv); | 556 ThrowJavaException(pEnv); |
548 } | 557 } |
549 } | 558 } |
OLD | NEW |