예제 #1
0
TEST_F(FilterEngineTest, FilterProperties)
{
  AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");

  ASSERT_TRUE(filter->GetProperty("stringFoo")->IsUndefined());
  ASSERT_TRUE(filter->GetProperty("intFoo")->IsUndefined());
  ASSERT_TRUE(filter->GetProperty("boolFoo")->IsUndefined());

  filter->SetProperty("stringFoo", "y");
  filter->SetProperty("intFoo", 24);
  filter->SetProperty("boolFoo", true);
  ASSERT_EQ("y", filter->GetProperty("stringFoo")->AsString());
  ASSERT_EQ(24, filter->GetProperty("intFoo")->AsInt());
  ASSERT_TRUE(filter->GetProperty("boolFoo")->AsBool());
}
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;
}