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

Delta Between Two Patch Sets: libadblockplus-android/jni/JniFilterEngine.cpp

Issue 29379647: Issue 4948 - add possibility to not send data depending on connection properties (Closed)
Left Patch Set: migrated from FilterEngine* to FilterEnginePtr*, minor improvements Created March 15, 2017, 12:48 p.m.
Right Patch Set: updated dependency to binaries, updated comment for allowed connection type Created March 30, 2017, 2:12 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
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsEnginePtr, jlong isAllowedConnectionCallbackPtr) 47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsEnginePtr, jlong isAllowedConnectionCallbackPtr)
48 { 48 {
49 try 49 try
50 { 50 {
51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(jsEnginePtr); 51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(jsEnginePtr);
52 AdblockPlus::FilterEnginePtr* filterEngine = NULL; 52 AdblockPlus::FilterEnginePtr* filterEngine = NULL;
53 53
54 if (isAllowedConnectionCallbackPtr != 0) 54 if (isAllowedConnectionCallbackPtr != 0)
55 { 55 {
56 AdblockPlus::FilterEngine::CreateParameters createParameters; 56 AdblockPlus::FilterEngine::CreationParameters creationParameters;
57 JniIsAllowedConnectionTypeCallback* callback = 57 JniIsAllowedConnectionTypeCallback* callback =
58 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection CallbackPtr); 58 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection CallbackPtr);
59 59
60 AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback = 60 AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback =
61 std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std:: placeholders::_1); 61 std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std:: placeholders::_1);
62 createParameters.isConnectionAllowed = cppCallback; 62 creationParameters.isConnectionAllowedCallback = cppCallback;
63 63
64 filterEngine = new AdblockPlus::FilterEnginePtr( 64 filterEngine = new AdblockPlus::FilterEnginePtr(
65 AdblockPlus::FilterEngine::Create(jsEngine, createParameters)); 65 AdblockPlus::FilterEngine::Create(jsEngine, creationParameters));
66 } 66 }
67 else 67 else
68 { 68 {
69 filterEngine = new AdblockPlus::FilterEnginePtr( 69 filterEngine = new AdblockPlus::FilterEnginePtr(
70 AdblockPlus::FilterEngine::Create(jsEngine)); 70 AdblockPlus::FilterEngine::Create(jsEngine));
71 } 71 }
72 72
73 return JniPtrToLong(filterEngine); 73 return JniPtrToLong(filterEngine);
anton 2017/03/15 12:52:54 i had to migrate from FilterEngine* to FilterEngin
sergei 2017/03/15 13:41:48 It's not removed in internals of libadblockplus, i
74 } 74 }
75 CATCH_THROW_AND_RETURN(env, 0) 75 CATCH_THROW_AND_RETURN(env, 0)
76 } 76 }
77 77
78 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 78 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
79 { 79 {
80 delete JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 80 delete JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
81 } 81 }
82 82
83 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr) 83 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
84 { 84 {
85 try 85 try
86 { 86 {
87 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterE nginePtr>(ptr); 87 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
88 88
89 return engine->get()->IsFirstRun() ? JNI_TRUE : JNI_FALSE; 89 return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE;
90 } 90 }
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::FilterEng inePtr>(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->get()->GetFilter(text); 101 AdblockPlus::FilterPtr 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::FilterEng inePtr>(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->get()->GetListedFilter s(); 114 std::vector<AdblockPlus::FilterPtr> 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::FilterPtr>::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::FilterEng inePtr>(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->get()->GetSubscription(u rl); 135 AdblockPlus::SubscriptionPtr 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::FilterEng inePtr>(ptr); 144 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
145 std::string url = JniJavaToStdString(env, jUrl); 145 std::string url = JniJavaToStdString(env, jUrl);
146 146
147 try 147 try
148 { 148 {
149 engine->get()->ShowNextNotification(url); 149 engine->ShowNextNotification(url);
150 } 150 }
151 CATCH_AND_THROW(env); 151 CATCH_AND_THROW(env);
152 } 152 }
153 153
154 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz, 154 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
155 jlong ptr, jlong callbackPtr) 155 jlong ptr, jlong callbackPtr)
156 { 156 {
157 AdblockPlus::FilterEnginePtr* engine = 157 AdblockPlus::FilterEnginePtr& engine =
158 JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 158 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
159 JniShowNotificationCallback* const callback = 159 JniShowNotificationCallback* const callback =
160 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr); 160 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr);
161 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback = 161 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback =
162 std::bind(&JniShowNotificationCallback::Callback, callback, 162 std::bind(&JniShowNotificationCallback::Callback, callback,
163 std::placeholders::_1); 163 std::placeholders::_1);
164 try 164 try
165 { 165 {
166 engine->get()->SetShowNotificationCallback(showNotificationCallback); 166 engine->SetShowNotificationCallback(showNotificationCallback);
167 } 167 }
168 CATCH_AND_THROW(env) 168 CATCH_AND_THROW(env)
169 } 169 }
170 170
171 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr) 171 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr)
172 { 172 {
173 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 173 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
174 174
175 try 175 try
176 { 176 {
177 engine->get()->RemoveShowNotificationCallback(); 177 engine->RemoveShowNotificationCallback();
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::FilterEng inePtr>(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->get()->Get ListedSubscriptions(); 188 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions();
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::FilterEng inePtr>(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->get()->Fet chAvailableSubscriptions(); 201 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions();
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->get()->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 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
228 std::bind(&JniUpdateAvailableCallback::Callback, callback, 228 std::bind(&JniUpdateAvailableCallback::Callback, callback,
229 std::placeholders::_1); 229 std::placeholders::_1);
230 try 230 try
231 { 231 {
232 engine->get()->SetUpdateAvailableCallback(updateAvailableCallback); 232 engine->SetUpdateAvailableCallback(updateAvailableCallback);
233 } 233 }
234 CATCH_AND_THROW(env) 234 CATCH_AND_THROW(env)
235 } 235 }
236 236
237 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr) 237 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr)
238 { 238 {
239 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 239 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
240 240
241 try 241 try
242 { 242 {
243 engine->get()->RemoveFilterChangeCallback(); 243 engine->RemoveFilterChangeCallback();
244 } 244 }
245 CATCH_AND_THROW(env) 245 CATCH_AND_THROW(env)
246 } 246 }
247 247
248 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, 248 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
249 jlong ptr, jlong filterPtr) 249 jlong ptr, jlong filterPtr)
250 { 250 {
251 AdblockPlus::FilterEnginePtr* engine = 251 AdblockPlus::FilterEnginePtr& engine =
252 JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 252 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
253 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( 253 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
254 filterPtr); 254 filterPtr);
255 255
256 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = 256 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback =
257 std::bind(&JniFilterChangeCallback::Callback, callback, 257 std::bind(&JniFilterChangeCallback::Callback, callback,
258 std::placeholders::_1, std::placeholders::_2); 258 std::placeholders::_1, std::placeholders::_2);
259 259
260 try 260 try
261 { 261 {
262 engine->get()->SetFilterChangeCallback(filterCallback); 262 engine->SetFilterChangeCallback(filterCallback);
263 } 263 }
264 CATCH_AND_THROW(env) 264 CATCH_AND_THROW(env)
265 } 265 }
266 266
267 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr) 267 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr)
268 { 268 {
269 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 269 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
270 JniUpdateCheckDoneCallback* callback = 270 JniUpdateCheckDoneCallback* callback =
271 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); 271 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
272 272
273 AdblockPlus::FilterEngine::UpdateCheckDoneCallback 273 AdblockPlus::FilterEngine::UpdateCheckDoneCallback
274 updateCheckDoneCallback = 0; 274 updateCheckDoneCallback = 0;
275 275
276 if (updaterPtr) 276 if (updaterPtr)
277 { 277 {
278 updateCheckDoneCallback = 278 updateCheckDoneCallback =
279 std::bind(&JniUpdateCheckDoneCallback::Callback, callback, 279 std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
280 std::placeholders::_1); 280 std::placeholders::_1);
281 } 281 }
282 282
283 try 283 try
284 { 284 {
285 engine->get()->ForceUpdateCheck(updateCheckDoneCallback); 285 engine->ForceUpdateCheck(updateCheckDoneCallback);
286 } 286 }
287 CATCH_AND_THROW(env) 287 CATCH_AND_THROW(env)
288 } 288 }
289 289
290 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, 290 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
291 jlong ptr, jstring jDomain) 291 jlong ptr, jstring jDomain)
292 { 292 {
293 AdblockPlus::FilterEnginePtr* engine = 293 AdblockPlus::FilterEnginePtr& engine =
294 JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 294 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
295 295
296 std::string domain = JniJavaToStdString(env, jDomain); 296 std::string domain = JniJavaToStdString(env, jDomain);
297 297
298 try 298 try
299 { 299 {
300 std::vector<std::string> selectors = engine->get()->GetElementHidingSelector s( 300 std::vector<std::string> selectors = engine->GetElementHidingSelectors(
301 domain); 301 domain);
302 302
303 jobject list = NewJniArrayList(env); 303 jobject list = NewJniArrayList(env);
304 304
305 for (std::vector<std::string>::iterator it = selectors.begin(), end = 305 for (std::vector<std::string>::iterator it = selectors.begin(), end =
306 selectors.end(); it != end; it++) 306 selectors.end(); it != end; it++)
307 { 307 {
308 JniAddObjectToList(env, list, 308 JniAddObjectToList(env, list,
309 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str()))); 309 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str())));
310 } 310 }
311 311
312 return list; 312 return list;
313 } 313 }
314 CATCH_THROW_AND_RETURN(env, 0) 314 CATCH_THROW_AND_RETURN(env, 0)
315 } 315 }
316 316
317 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl) 317 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl)
318 { 318 {
319 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 319 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
320 320
321 std::string url = JniJavaToStdString(env, jUrl); 321 std::string url = JniJavaToStdString(env, jUrl);
322 AdblockPlus::FilterEngine::ContentType contentType = 322 AdblockPlus::FilterEngine::ContentType contentType =
323 ConvertContentType(env, jContentType); 323 ConvertContentType(env, jContentType);
324 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); 324 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
325 325
326 try 326 try
327 { 327 {
328 AdblockPlus::FilterPtr filter = engine->get()->Matches(url, contentType, doc umentUrl); 328 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l);
329 329
330 return NewJniFilter(env, filter); 330 return NewJniFilter(env, filter);
331 } 331 }
332 CATCH_THROW_AND_RETURN(env, 0) 332 CATCH_THROW_AND_RETURN(env, 0)
333 } 333 }
334 334
335 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray, 335 static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
336 std::vector<std::string>& out) 336 std::vector<std::string>& out)
337 { 337 {
338 if (jArray) 338 if (jArray)
339 { 339 {
340 jsize len = env->GetArrayLength(jArray); 340 jsize len = env->GetArrayLength(jArray);
341 341
342 for (jsize i = 0; i < len; i++) 342 for (jsize i = 0; i < len; i++)
343 { 343 {
344 out.push_back( 344 out.push_back(
345 JniJavaToStdString(env, 345 JniJavaToStdString(env,
346 *JniLocalReference<jstring>(env, 346 *JniLocalReference<jstring>(env,
347 static_cast<jstring>( 347 static_cast<jstring>(
348 env->GetObjectArrayElement(jArray, i))))); 348 env->GetObjectArrayElement(jArray, i)))));
349 } 349 }
350 } 350 }
351 } 351 }
352 352
353 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, 353 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
354 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) 354 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
355 { 355 {
356 AdblockPlus::FilterEnginePtr* engine = 356 AdblockPlus::FilterEnginePtr& engine =
357 JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 357 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
358 358
359 std::string url = JniJavaToStdString(env, jUrl); 359 std::string url = JniJavaToStdString(env, jUrl);
360 AdblockPlus::FilterEngine::ContentType contentType = 360 AdblockPlus::FilterEngine::ContentType contentType =
361 ConvertContentType(env, jContentType); 361 ConvertContentType(env, jContentType);
362 362
363 std::vector<std::string> documentUrls; 363 std::vector<std::string> documentUrls;
364 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 364 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
365 365
366 try 366 try
367 { 367 {
368 AdblockPlus::FilterPtr filter = engine->get()->Matches(url, contentType, 368 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
369 documentUrls); 369 documentUrls);
370 370
371 return NewJniFilter(env, filter); 371 return NewJniFilter(env, filter);
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
382 std::string url = JniJavaToStdString(env, jUrl); 382 std::string url = JniJavaToStdString(env, jUrl);
383 std::vector<std::string> documentUrls; 383 std::vector<std::string> documentUrls;
384 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 384 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
385 try 385 try
386 { 386 {
387 return engine->get()->IsDocumentWhitelisted(url, documentUrls) ? 387 return engine->IsDocumentWhitelisted(url, documentUrls) ?
388 JNI_TRUE : JNI_FALSE; 388 JNI_TRUE : JNI_FALSE;
389 } 389 }
390 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 390 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
391 } 391 }
392 392
393 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 393 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
394 jstring jUrl, jobjectArray jDocumentUrls) 394 jstring jUrl, jobjectArray jDocumentUrls)
395 { 395 {
396 AdblockPlus::FilterEnginePtr* engine = 396 AdblockPlus::FilterEnginePtr& engine =
397 JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr); 397 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
398 398
399 std::string url = JniJavaToStdString(env, jUrl); 399 std::string url = JniJavaToStdString(env, jUrl);
400 std::vector<std::string> documentUrls; 400 std::vector<std::string> documentUrls;
401 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 401 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
402 try 402 try
403 { 403 {
404 return engine->get()->IsElemhideWhitelisted(url, documentUrls) ? 404 return engine->IsElemhideWhitelisted(url, documentUrls) ?
405 JNI_TRUE : JNI_FALSE; 405 JNI_TRUE : JNI_FALSE;
406 } 406 }
407 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 407 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
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::FilterEng inePtr>(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->get()->GetPref(pref); 418 AdblockPlus::JsValuePtr 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::FilterEng inePtr>(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 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue);
431 431
432 try 432 try
433 { 433 {
434 engine->get()->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 {
441 if (jurl == NULL) 441 if (jurl == NULL)
442 { 442 {
443 return NULL; 443 return NULL;
444 } 444 }
445 445
446 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 446 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
447 447
448 std::string url = JniJavaToStdString(env, jurl); 448 std::string url = JniJavaToStdString(env, jurl);
449 try 449 try
450 { 450 {
451 std::string host = engine->get()->GetHostFromURL(url); 451 std::string host = engine->GetHostFromURL(url);
452 452
453 return JniStdStringToJava(env, host); 453 return JniStdStringToJava(env, host);
454 } 454 }
455 CATCH_THROW_AND_RETURN(env, 0) 455 CATCH_THROW_AND_RETURN(env, 0)
456 } 456 }
457 457
458 static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr, jstring jvalue) 458 static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr, jstring jvalue)
459 { 459 {
460 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEng inePtr>(ptr); 460 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
461 461
462 const std::string* value = NULL; 462 std::string stdValue;
463 if (jvalue != NULL) 463 const std::string* value = (jvalue != NULL
464 { 464 ? &(stdValue = JniJavaToStdString(env, jvalue))
465 std::string stdValue = JniJavaToStdString(env, jvalue); 465 : NULL);
466 value = &stdValue; 466
sergei 2017/03/15 13:41:48 here is a bug: you assign a pointer to stdValue wh
467 } 467 try
468 468 {
469 try 469 engine->SetAllowedConnectionType(value);
470 {
471 engine->get()->SetAllowedConnectionType(value);
472 } 470 }
473 CATCH_AND_THROW(env) 471 CATCH_AND_THROW(env)
474 } 472 }
475 473
476 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr) 474 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr)
477 { 475 {
478 try 476 try
479 { 477 {
480 AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterE nginePtr>(ptr); 478 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
481 std::unique_ptr<std::string> value = engine->get()->GetAllowedConnectionType (); 479 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType();
482 480
483 if (value == NULL) 481 if (value == NULL)
484 { 482 {
485 return NULL; 483 return NULL;
486 } 484 }
487 485
488 return JniStdStringToJava(env, *value.get()); 486 return JniStdStringToJava(env, *value.get());
489 } 487 }
490 CATCH_THROW_AND_RETURN(env, 0) 488 CATCH_THROW_AND_RETURN(env, 0)
491 } 489 }
(...skipping 25 matching lines...) Expand all
517 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL }, 515 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL },
518 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType }, 516 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType },
519 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType }, 517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType },
520 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
521 }; 519 };
522 520
523 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)
524 { 522 {
525 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
526 } 524 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld