Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: jni/JniFilterEngine.cpp

Issue 29331923: Issue 3364 - Implement JNI bindings for IsDocument/ElemhideWhitelisted (Closed)
Patch Set: Typo Created Dec. 4, 2015, 5:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dependencies ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 try 305 try
306 { 306 {
307 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l); 307 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l);
308 308
309 return NewJniFilter(env, filter); 309 return NewJniFilter(env, filter);
310 } 310 }
311 CATCH_THROW_AND_RETURN(env, 0) 311 CATCH_THROW_AND_RETURN(env, 0)
312 } 312 }
313 313
314 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
315 std::vector<std::string>& out)
316 {
317 if (jArray)
318 {
319 jsize len = env->GetArrayLength(jArray);
320
321 for (jsize i = 0; i < len; i++)
322 {
323 out.push_back(
324 JniJavaToStdString(env,
325 *JniLocalReference<jstring>(env,
326 static_cast<jstring>(
327 env->GetObjectArrayElement(jArray, i)))));
328 }
329 }
330 }
331
314 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, 332 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
315 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) 333 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
316 { 334 {
317 AdblockPlus::FilterEngine* engine = 335 AdblockPlus::FilterEngine* engine =
318 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 336 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
319 337
320 std::string url = JniJavaToStdString(env, jUrl); 338 std::string url = JniJavaToStdString(env, jUrl);
321 AdblockPlus::FilterEngine::ContentType contentType = 339 AdblockPlus::FilterEngine::ContentType contentType =
322 ConvertContentType(env, jContentType); 340 ConvertContentType(env, jContentType);
323 341
324 std::vector<std::string> documentUrls; 342 std::vector<std::string> documentUrls;
325 343 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
326 jsize len = env->GetArrayLength(jDocumentUrls);
327
328 for (jsize i = 0; i < len; i++)
329 {
330 documentUrls.push_back(
331 JniJavaToStdString(env,
332 *JniLocalReference<jstring>(env,
333 static_cast<jstring>(env->GetObjectArrayElement(jDocumentUrls,
334 i)))));
335 }
336 344
337 try 345 try
338 { 346 {
339 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, 347 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
340 documentUrls); 348 documentUrls);
341 349
342 return NewJniFilter(env, filter); 350 return NewJniFilter(env, filter);
343 } 351 }
344 CATCH_THROW_AND_RETURN(env, 0) 352 CATCH_THROW_AND_RETURN(env, 0)
345 } 353 }
346 354
355 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
356 jstring jUrl, jobjectArray jDocumentUrls)
357 {
358 AdblockPlus::FilterEngine* engine =
359 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
360
361 std::string url = JniJavaToStdString(env, jUrl);
362 std::vector<std::string> documentUrls;
363 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
364 try
365 {
366 return engine->IsDocumentWhitelisted(url, documentUrls) ?
367 JNI_TRUE : JNI_FALSE;
368 }
369 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
370 }
371
372 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
373 jstring jUrl, jobjectArray jDocumentUrls)
374 {
375 AdblockPlus::FilterEngine* engine =
376 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
377
378 std::string url = JniJavaToStdString(env, jUrl);
379 std::vector<std::string> documentUrls;
380 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
381 try
382 {
383 return engine->IsElemhideWhitelisted(url, documentUrls) ?
384 JNI_TRUE : JNI_FALSE;
385 }
386 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
387 }
388
347 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref) 389 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref)
348 { 390 {
349 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi ne > (ptr); 391 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi ne > (ptr);
350 392
351 std::string pref = JniJavaToStdString(env, jPref); 393 std::string pref = JniJavaToStdString(env, jPref);
352 394
353 try 395 try
354 { 396 {
355 AdblockPlus::JsValuePtr value = engine->GetPref(pref); 397 AdblockPlus::JsValuePtr value = engine->GetPref(pref);
356 398
(...skipping 29 matching lines...) Expand all
386 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, 428 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions },
387 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, 429 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions },
388 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback }, 430 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback },
389 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback }, 431 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback },
390 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, 432 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback },
391 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, 433 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback },
392 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, 434 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
393 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors }, 435 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors },
394 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, 436 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
395 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, 437 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
438 { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsDocumentWhitelisted },
439 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsElemhideWhitelisted },
396 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, 440 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
397 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 441 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
398 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 442 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
399 }; 443 };
400 444
401 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) 445 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz)
402 { 446 {
403 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 447 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
404 } 448 }
OLDNEW
« no previous file with comments | « dependencies ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld