AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, ContentType contentType, const std::vector<std::string>& documentUrls) const { if (documentUrls.empty()) return CheckFilterMatch(url, contentType, ""); std::string lastDocumentUrl = documentUrls.front(); for (std::vector<std::string>::const_iterator it = documentUrls.begin(); it != documentUrls.end(); it++) { const std::string documentUrl = *it; AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, CONTENT_TYPE_DOCUMENT, lastDocumentUrl); if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) return match; lastDocumentUrl = documentUrl; } return CheckFilterMatch(url, contentType, lastDocumentUrl); }
JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches( JNIEnv *pEnv, jobject, jstring url, jstring contentType, jobjectArray documentUrls) { try { const std::string surl = GetString(pEnv, url); const std::string stype = GetString(pEnv, contentType); const int documentUrlsLength = pEnv->GetArrayLength(documentUrls); std::vector<std::string> sdocumentUrls; for(int i = 0; i < documentUrlsLength; i++) { jstring documentUrl = static_cast<jstring>(pEnv->GetObjectArrayElement(documentUrls, i)); sdocumentUrls.push_back(GetString(pEnv, documentUrl)); } AdblockPlus::FilterPtr filter = filterEngine->Matches(surl, stype, sdocumentUrls); if (! filter) return JNI_FALSE; // hack: if there is no referrer, block only if filter is domain-specific // (to re-enable in-app ads blocking, proposed on 12.11.2012 Monday meeting) // (documentUrls contains the referrers on Android) if (!sdocumentUrls.size() && (filter->GetProperty("text")->AsString()).find("||") != std::string::npos) return JNI_FALSE; return filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION ? JNI_FALSE : JNI_TRUE; } catch (const std::exception& e) { ThrowJavaException(pEnv, e); } catch (...) { ThrowJavaException(pEnv); } return JNI_FALSE; }