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

Delta Between Two Patch Sets: jni/JniFilterEngine.cpp

Issue 29331923: Issue 3364 - Implement JNI bindings for IsDocument/ElemhideWhitelisted (Closed)
Left Patch Set: Created Dec. 4, 2015, 3:14 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 JavaStringArrayIntoStringVector(JNIEnv* env, jobjectArray jArray, 314 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
315 std::vector<std::string>& out) 315 std::vector<std::string>& out)
316 { 316 {
317 if (jArray) 317 if (jArray)
318 { 318 {
319 jsize len = env->GetArrayLength(jArray); 319 jsize len = env->GetArrayLength(jArray);
320 320
321 for (jsize i = 0; i < len; i++) 321 for (jsize i = 0; i < len; i++)
322 { 322 {
323 out.push_back( 323 out.push_back(
324 JniJavaToStdString(env, 324 JniJavaToStdString(env,
325 *JniLocalReference<jstring>(env, 325 *JniLocalReference<jstring>(env,
326 static_cast<jstring>( 326 static_cast<jstring>(
327 env->GetObjectArrayElement(jArray, i))))); 327 env->GetObjectArrayElement(jArray, i)))));
328 } 328 }
329 } 329 }
330 } 330 }
331 331
332 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, 332 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
333 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) 333 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
334 { 334 {
335 AdblockPlus::FilterEngine* engine = 335 AdblockPlus::FilterEngine* engine =
336 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 336 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
337 337
338 std::string url = JniJavaToStdString(env, jUrl); 338 std::string url = JniJavaToStdString(env, jUrl);
339 AdblockPlus::FilterEngine::ContentType contentType = 339 AdblockPlus::FilterEngine::ContentType contentType =
340 ConvertContentType(env, jContentType); 340 ConvertContentType(env, jContentType);
341 341
342 std::vector<std::string> documentUrls; 342 std::vector<std::string> documentUrls;
343 JavaStringArrayIntoStringVector(env, jDocumentUrls, documentUrls); 343 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
344 344
345 try 345 try
346 { 346 {
347 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, 347 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
348 documentUrls); 348 documentUrls);
349 349
350 return NewJniFilter(env, filter); 350 return NewJniFilter(env, filter);
351 } 351 }
352 CATCH_THROW_AND_RETURN(env, 0) 352 CATCH_THROW_AND_RETURN(env, 0)
353 } 353 }
354 354
355 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 355 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
356 jstring jUrl, jobjectArray jDocumentUrls) 356 jstring jUrl, jobjectArray jDocumentUrls)
357 { 357 {
358 AdblockPlus::FilterEngine* engine = 358 AdblockPlus::FilterEngine* engine =
359 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 359 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
360 360
361 std::string url = JniJavaToStdString(env, jUrl); 361 std::string url = JniJavaToStdString(env, jUrl);
362 std::vector<std::string> documentUrls; 362 std::vector<std::string> documentUrls;
363 JavaStringArrayIntoStringVector(env, jDocumentUrls, documentUrls); 363 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
364 try 364 try
365 { 365 {
366 return engine->IsDocumentWhitelisted(url, documentUrls) ? 366 return engine->IsDocumentWhitelisted(url, documentUrls) ?
367 JNI_TRUE : JNI_FALSE; 367 JNI_TRUE : JNI_FALSE;
368 } 368 }
369 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 369 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
370 } 370 }
371 371
372 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 372 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
373 jstring jUrl, jobjectArray jDocumentUrls) 373 jstring jUrl, jobjectArray jDocumentUrls)
374 { 374 {
375 AdblockPlus::FilterEngine* engine = 375 AdblockPlus::FilterEngine* engine =
376 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 376 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
377 377
378 std::string url = JniJavaToStdString(env, jUrl); 378 std::string url = JniJavaToStdString(env, jUrl);
379 std::vector<std::string> documentUrls; 379 std::vector<std::string> documentUrls;
380 JavaStringArrayIntoStringVector(env, jDocumentUrls, documentUrls); 380 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
381 try 381 try
382 { 382 {
383 return engine->IsElemhideWhitelisted(url, documentUrls) ? 383 return engine->IsElemhideWhitelisted(url, documentUrls) ?
384 JNI_TRUE : JNI_FALSE; 384 JNI_TRUE : JNI_FALSE;
385 } 385 }
386 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 386 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
387 } 387 }
388 388
389 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)
390 { 390 {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsElemhideWhitelisted }, 439 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsElemhideWhitelisted },
440 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, 440 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
441 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 441 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
442 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 442 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
443 }; 443 };
444 444
445 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)
446 { 446 {
447 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 447 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
448 } 448 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld