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

Side by Side Diff: libadblockplus-android/jni/JniFilterEngine.cpp

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
Patch Set: updated dependencies (..-binaries) Created May 3, 2017, 2:08 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
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus.h> 18 #include <AdblockPlus.h>
19 #include "Utils.h" 19 #include "Utils.h"
20 #include "JniCallbacks.h" 20 #include "JniCallbacks.h"
21 21
22 static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Su bscriptionPtr>& subscriptions) 22 static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Su bscription>& subscriptions)
23 { 23 {
24 jobject list = NewJniArrayList(env); 24 jobject list = NewJniArrayList(env);
25 25
26 for (std::vector<AdblockPlus::SubscriptionPtr>::iterator it = subscriptions.be gin(), end = subscriptions.end(); it != end; it++) 26 for (std::vector<AdblockPlus::Subscription>::iterator it = subscriptions.begin (), end = subscriptions.end(); it != end; it++)
27 { 27 {
28 JniAddObjectToList(env, list, NewJniSubscription(env, *it)); 28 JniAddObjectToList(env, list, NewJniSubscription(env, *it));
29 } 29 }
30 30
31 return list; 31 return list;
32 } 32 }
33 33
34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env, 34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
35 jobject jContentType) 35 jobject jContentType)
36 { 36 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 CATCH_THROW_AND_RETURN(env, JNI_FALSE); 91 CATCH_THROW_AND_RETURN(env, JNI_FALSE);
92 } 92 }
93 93
94 static jobject JNICALL JniGetFilter(JNIEnv* env, jclass clazz, jlong ptr, jstrin g jText) 94 static jobject JNICALL JniGetFilter(JNIEnv* env, jclass clazz, jlong ptr, jstrin g jText)
95 { 95 {
96 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 96 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
97 std::string text = JniJavaToStdString(env, jText); 97 std::string text = JniJavaToStdString(env, jText);
98 98
99 try 99 try
100 { 100 {
101 AdblockPlus::FilterPtr filter = engine->GetFilter(text); 101 AdblockPlus::Filter filter = engine->GetFilter(text);
102 102
103 return NewJniFilter(env, filter); 103 return NewJniFilter(env, filter);
104 } 104 }
105 CATCH_THROW_AND_RETURN(env, 0); 105 CATCH_THROW_AND_RETURN(env, 0);
106 } 106 }
107 107
108 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr) 108 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
109 { 109 {
110 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 110 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
111 111
112 try 112 try
113 { 113 {
114 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters(); 114 std::vector<AdblockPlus::Filter> filters = engine->GetListedFilters();
115 115
116 jobject list = NewJniArrayList(env); 116 jobject list = NewJniArrayList(env);
117 117
118 for (std::vector<AdblockPlus::FilterPtr>::iterator it = filters.begin(), end = filters.end(); it != end; it++) 118 for (std::vector<AdblockPlus::Filter>::iterator it = filters.begin(), end = filters.end(); it != end; it++)
119 { 119 {
120 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it))); 120 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it)));
121 } 121 }
122 122
123 return list; 123 return list;
124 } 124 }
125 CATCH_THROW_AND_RETURN(env, 0); 125 CATCH_THROW_AND_RETURN(env, 0);
126 } 126 }
127 127
128 static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl) 128 static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl)
129 { 129 {
130 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 130 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
131 std::string url = JniJavaToStdString(env, jUrl); 131 std::string url = JniJavaToStdString(env, jUrl);
132 132
133 try 133 try
134 { 134 {
135 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url); 135 AdblockPlus::Subscription subscription = engine->GetSubscription(url);
136 136
137 return NewJniSubscription(env, subscription); 137 return NewJniSubscription(env, subscription);
138 } 138 }
139 CATCH_THROW_AND_RETURN(env, 0); 139 CATCH_THROW_AND_RETURN(env, 0);
140 } 140 }
141 141
142 static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr , jstring jUrl) 142 static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr , jstring jUrl)
143 { 143 {
144 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 144 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
145 std::string url = JniJavaToStdString(env, jUrl); 145 std::string url = JniJavaToStdString(env, jUrl);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 CATCH_AND_THROW(env); 179 CATCH_AND_THROW(env);
180 } 180 }
181 181
182 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr) 182 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr)
183 { 183 {
184 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 184 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
185 185
186 try 186 try
187 { 187 {
188 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions(); 188 std::vector<AdblockPlus::Subscription> subscriptions = engine->GetListedSubs criptions();
189 189
190 return SubscriptionsToArrayList(env, subscriptions); 190 return SubscriptionsToArrayList(env, subscriptions);
191 } 191 }
192 CATCH_THROW_AND_RETURN(env, 0); 192 CATCH_THROW_AND_RETURN(env, 0);
193 } 193 }
194 194
195 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr) 195 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr)
196 { 196 {
197 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 197 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
198 198
199 try 199 try
200 { 200 {
201 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions(); 201 std::vector<AdblockPlus::Subscription> subscriptions = engine->FetchAvailabl eSubscriptions();
202 202
203 return SubscriptionsToArrayList(env, subscriptions); 203 return SubscriptionsToArrayList(env, subscriptions);
204 } 204 }
205 CATCH_THROW_AND_RETURN(env, 0); 205 CATCH_THROW_AND_RETURN(env, 0);
206 } 206 }
207 207
208 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz, 208 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
209 jlong ptr) 209 jlong ptr)
210 { 210 {
211 AdblockPlus::FilterEnginePtr& engine = 211 AdblockPlus::FilterEnginePtr& engine =
212 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 212 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
213 try 213 try
214 { 214 {
215 engine->RemoveUpdateAvailableCallback(); 215 engine->RemoveUpdateAvailableCallback();
216 } 216 }
217 CATCH_AND_THROW(env) 217 CATCH_AND_THROW(env)
218 } 218 }
219 219
220 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, 220 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
221 jlong ptr, jlong callbackPtr) 221 jlong ptr, jlong callbackPtr)
222 { 222 {
223 AdblockPlus::FilterEnginePtr& engine = 223 AdblockPlus::FilterEnginePtr& engine =
224 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 224 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
225 JniUpdateAvailableCallback* const callback = 225 JniUpdateAvailableCallback* const callback =
226 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); 226 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
227 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = 227
228 const AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallba ck =
228 std::bind(&JniUpdateAvailableCallback::Callback, callback, 229 std::bind(&JniUpdateAvailableCallback::Callback, callback,
229 std::placeholders::_1); 230 std::placeholders::_1);
230 try 231 try
231 { 232 {
232 engine->SetUpdateAvailableCallback(updateAvailableCallback); 233 engine->SetUpdateAvailableCallback(updateAvailableCallback);
233 } 234 }
234 CATCH_AND_THROW(env) 235 CATCH_AND_THROW(env)
235 } 236 }
236 237
237 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr) 238 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr)
238 { 239 {
239 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 240 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
240 241
241 try 242 try
242 { 243 {
243 engine->RemoveFilterChangeCallback(); 244 engine->RemoveFilterChangeCallback();
244 } 245 }
245 CATCH_AND_THROW(env) 246 CATCH_AND_THROW(env)
246 } 247 }
247 248
248 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, 249 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
249 jlong ptr, jlong filterPtr) 250 jlong ptr, jlong filterPtr)
250 { 251 {
251 AdblockPlus::FilterEnginePtr& engine = 252 AdblockPlus::FilterEnginePtr& engine =
252 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 253 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
253 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( 254 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
254 filterPtr); 255 filterPtr);
255 256
256 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = 257 const AdblockPlus::FilterEngine::FilterChangeCallback filterCallback =
257 std::bind(&JniFilterChangeCallback::Callback, callback, 258 std::bind(&JniFilterChangeCallback::Callback, callback,
258 std::placeholders::_1, std::placeholders::_2); 259 std::placeholders::_1, std::placeholders::_2);
259 260
260 try 261 try
261 { 262 {
262 engine->SetFilterChangeCallback(filterCallback); 263 engine->SetFilterChangeCallback(filterCallback);
263 } 264 }
264 CATCH_AND_THROW(env) 265 CATCH_AND_THROW(env)
265 } 266 }
266 267
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 { 319 {
319 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 320 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
320 321
321 std::string url = JniJavaToStdString(env, jUrl); 322 std::string url = JniJavaToStdString(env, jUrl);
322 AdblockPlus::FilterEngine::ContentType contentType = 323 AdblockPlus::FilterEngine::ContentType contentType =
323 ConvertContentType(env, jContentType); 324 ConvertContentType(env, jContentType);
324 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); 325 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
325 326
326 try 327 try
327 { 328 {
328 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l); 329 AdblockPlus::FilterPtr filterPtr = engine->Matches(url, contentType, documen tUrl);
329 330
330 return NewJniFilter(env, filter); 331 return (filterPtr.get() ? NewJniFilter(env, *filterPtr.get()) : 0);
331 } 332 }
332 CATCH_THROW_AND_RETURN(env, 0) 333 CATCH_THROW_AND_RETURN(env, 0)
333 } 334 }
334 335
335 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray, 336 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
336 std::vector<std::string>& out) 337 std::vector<std::string>& out)
337 { 338 {
338 if (jArray) 339 if (jArray)
339 { 340 {
340 jsize len = env->GetArrayLength(jArray); 341 jsize len = env->GetArrayLength(jArray);
(...skipping 17 matching lines...) Expand all
358 359
359 std::string url = JniJavaToStdString(env, jUrl); 360 std::string url = JniJavaToStdString(env, jUrl);
360 AdblockPlus::FilterEngine::ContentType contentType = 361 AdblockPlus::FilterEngine::ContentType contentType =
361 ConvertContentType(env, jContentType); 362 ConvertContentType(env, jContentType);
362 363
363 std::vector<std::string> documentUrls; 364 std::vector<std::string> documentUrls;
364 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 365 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
365 366
366 try 367 try
367 { 368 {
368 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, 369 AdblockPlus::FilterPtr filterPtr = engine->Matches(url, contentType, documen tUrls);
369 documentUrls);
370 370
371 return NewJniFilter(env, filter); 371 return (filterPtr.get() ? NewJniFilter(env, *filterPtr) : 0);
372 } 372 }
373 CATCH_THROW_AND_RETURN(env, 0) 373 CATCH_THROW_AND_RETURN(env, 0)
374 } 374 }
375 375
376 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 376 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
377 jstring jUrl, jobjectArray jDocumentUrls) 377 jstring jUrl, jobjectArray jDocumentUrls)
378 { 378 {
379 AdblockPlus::FilterEnginePtr& engine = 379 AdblockPlus::FilterEnginePtr& engine =
380 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 380 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
381 381
(...skipping 26 matching lines...) Expand all
408 } 408 }
409 409
410 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref) 410 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref)
411 { 411 {
412 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 412 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
413 413
414 std::string pref = JniJavaToStdString(env, jPref); 414 std::string pref = JniJavaToStdString(env, jPref);
415 415
416 try 416 try
417 { 417 {
418 AdblockPlus::JsValuePtr value = engine->GetPref(pref); 418 AdblockPlus::JsValue value = engine->GetPref(pref);
419 419
420 return NewJniJsValue(env, value); 420 return NewJniJsValue(env, value);
421 } 421 }
422 CATCH_THROW_AND_RETURN(env, 0) 422 CATCH_THROW_AND_RETURN(env, 0)
423 } 423 }
424 424
425 static void JNICALL JniSetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPr ef, jlong jsValue) 425 static void JNICALL JniSetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPr ef, jlong jsValue)
426 { 426 {
427 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr); 427 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
428 428
429 std::string pref = JniJavaToStdString(env, jPref); 429 std::string pref = JniJavaToStdString(env, jPref);
430 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue); 430 const AdblockPlus::JsValue& value = JniGetJsValue(jsValue);
431 431
432 try 432 try
433 { 433 {
434 engine->SetPref(pref, value); 434 engine->SetPref(pref, value);
435 } 435 }
436 CATCH_AND_THROW(env) 436 CATCH_AND_THROW(env)
437 } 437 }
438 438
439 static jstring JNICALL JniGetHostFromURL(JNIEnv* env, jclass clazz, jlong ptr, j string jurl) 439 static jstring JNICALL JniGetHostFromURL(JNIEnv* env, jclass clazz, jlong ptr, j string jurl)
440 { 440 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL }, 515 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL },
516 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType }, 516 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType },
517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType }, 517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType },
518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
519 }; 519 };
520 520
521 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) 521 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz)
522 { 522 {
523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
524 } 524 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniFilterChangeCallback.cpp ('k') | libadblockplus-android/jni/JniJsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld