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: Created March 10, 2017, 6:40 a.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 (jstring) env->CallObjectMethod(jContentType, nameMethod)); 42 (jstring) env->CallObjectMethod(jContentType, nameMethod));
43 const std::string value = JniJavaToStdString(env, *jValue); 43 const std::string value = JniJavaToStdString(env, *jValue);
44 return AdblockPlus::FilterEngine::StringToContentType(value); 44 return AdblockPlus::FilterEngine::StringToContentType(value);
45 } 45 }
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 filterEnginePtr = NULL; 52 AdblockPlus::FilterEnginePtr* filterEngine = NULL;
sergei 2017/03/15 10:01:38 smart pointer is already initialized to nullptr, s
sergei 2017/03/15 10:01:38 I would just call the variable as filterEngine, wi
anton 2017/03/15 10:13:52 Acknowledged.
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 filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine, createParame ters); // here (1) - create engine sync 64 filterEngine = new AdblockPlus::FilterEnginePtr(
65 AdblockPlus::FilterEngine::Create(jsEngine, creationParameters));
65 } 66 }
66 else 67 else
67 { 68 {
68 filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine); 69 filterEngine = new AdblockPlus::FilterEnginePtr(
70 AdblockPlus::FilterEngine::Create(jsEngine));
69 } 71 }
70 72
71 return JniPtrToLong(filterEnginePtr.get()); 73 return JniPtrToLong(filterEngine);
anton 2017/03/10 06:50:40 for some (unknown) reason new static methods (inst
sergei 2017/03/15 10:01:38 TL;DR: Actually here is a bug, but my vote is to a
anton 2017/03/15 10:13:52 Acknowledged.
72 } 74 }
73 CATCH_THROW_AND_RETURN(env, 0) 75 CATCH_THROW_AND_RETURN(env, 0)
74 } 76 }
75 77
76 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 78 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
77 { 79 {
78 delete JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 80 delete JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
79 } 81 }
80 82
81 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr) 83 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
82 { 84 {
83 try 85 try
84 { 86 {
85 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngi ne>(ptr); 87 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
86 88
87 return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE; 89 return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE;
88 } 90 }
89 CATCH_THROW_AND_RETURN(env, JNI_FALSE); 91 CATCH_THROW_AND_RETURN(env, JNI_FALSE);
90 } 92 }
91 93
92 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)
93 { 95 {
94 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 96 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
95 std::string text = JniJavaToStdString(env, jText); 97 std::string text = JniJavaToStdString(env, jText);
96 98
97 try 99 try
98 { 100 {
99 AdblockPlus::FilterPtr filter = engine->GetFilter(text); 101 AdblockPlus::FilterPtr filter = engine->GetFilter(text);
100 102
101 return NewJniFilter(env, filter); 103 return NewJniFilter(env, filter);
102 } 104 }
103 CATCH_THROW_AND_RETURN(env, 0); 105 CATCH_THROW_AND_RETURN(env, 0);
104 } 106 }
105 107
106 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr) 108 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
107 { 109 {
108 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 110 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
109 111
110 try 112 try
111 { 113 {
112 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters(); 114 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters();
113 115
114 jobject list = NewJniArrayList(env); 116 jobject list = NewJniArrayList(env);
115 117
116 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++)
117 { 119 {
118 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it))); 120 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it)));
119 } 121 }
120 122
121 return list; 123 return list;
122 } 124 }
123 CATCH_THROW_AND_RETURN(env, 0); 125 CATCH_THROW_AND_RETURN(env, 0);
124 } 126 }
125 127
126 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)
127 { 129 {
128 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 130 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
129 std::string url = JniJavaToStdString(env, jUrl); 131 std::string url = JniJavaToStdString(env, jUrl);
130 132
131 try 133 try
132 { 134 {
133 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url); 135 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url);
134 136
135 return NewJniSubscription(env, subscription); 137 return NewJniSubscription(env, subscription);
136 } 138 }
137 CATCH_THROW_AND_RETURN(env, 0); 139 CATCH_THROW_AND_RETURN(env, 0);
138 } 140 }
139 141
140 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)
141 { 143 {
142 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 144 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
143 std::string url = JniJavaToStdString(env, jUrl); 145 std::string url = JniJavaToStdString(env, jUrl);
144 146
145 try 147 try
146 { 148 {
147 engine->ShowNextNotification(url); 149 engine->ShowNextNotification(url);
148 } 150 }
149 CATCH_AND_THROW(env); 151 CATCH_AND_THROW(env);
150 } 152 }
151 153
152 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz, 154 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
153 jlong ptr, jlong callbackPtr) 155 jlong ptr, jlong callbackPtr)
154 { 156 {
155 AdblockPlus::FilterEngine* const engine = 157 AdblockPlus::FilterEnginePtr& engine =
156 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 158 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
157 JniShowNotificationCallback* const callback = 159 JniShowNotificationCallback* const callback =
158 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr); 160 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr);
159 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback = 161 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback =
160 std::bind(&JniShowNotificationCallback::Callback, callback, 162 std::bind(&JniShowNotificationCallback::Callback, callback,
161 std::placeholders::_1); 163 std::placeholders::_1);
162 try 164 try
163 { 165 {
164 engine->SetShowNotificationCallback(showNotificationCallback); 166 engine->SetShowNotificationCallback(showNotificationCallback);
165 } 167 }
166 CATCH_AND_THROW(env) 168 CATCH_AND_THROW(env)
167 } 169 }
168 170
169 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr) 171 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr)
170 { 172 {
171 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 173 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
172 174
173 try 175 try
174 { 176 {
175 engine->RemoveShowNotificationCallback(); 177 engine->RemoveShowNotificationCallback();
176 } 178 }
177 CATCH_AND_THROW(env); 179 CATCH_AND_THROW(env);
178 } 180 }
179 181
180 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr) 182 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr)
181 { 183 {
182 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 184 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
183 185
184 try 186 try
185 { 187 {
186 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions(); 188 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions();
187 189
188 return SubscriptionsToArrayList(env, subscriptions); 190 return SubscriptionsToArrayList(env, subscriptions);
189 } 191 }
190 CATCH_THROW_AND_RETURN(env, 0); 192 CATCH_THROW_AND_RETURN(env, 0);
191 } 193 }
192 194
193 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr) 195 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr)
194 { 196 {
195 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 197 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
196 198
197 try 199 try
198 { 200 {
199 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions(); 201 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions();
200 202
201 return SubscriptionsToArrayList(env, subscriptions); 203 return SubscriptionsToArrayList(env, subscriptions);
202 } 204 }
203 CATCH_THROW_AND_RETURN(env, 0); 205 CATCH_THROW_AND_RETURN(env, 0);
204 } 206 }
205 207
206 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz, 208 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
207 jlong ptr) 209 jlong ptr)
208 { 210 {
209 AdblockPlus::FilterEngine* const engine = 211 AdblockPlus::FilterEnginePtr& engine =
210 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 212 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
211 try 213 try
212 { 214 {
213 engine->RemoveUpdateAvailableCallback(); 215 engine->RemoveUpdateAvailableCallback();
214 } 216 }
215 CATCH_AND_THROW(env) 217 CATCH_AND_THROW(env)
216 } 218 }
217 219
218 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, 220 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
219 jlong ptr, jlong callbackPtr) 221 jlong ptr, jlong callbackPtr)
220 { 222 {
221 AdblockPlus::FilterEngine* const engine = 223 AdblockPlus::FilterEnginePtr& engine =
222 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 224 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
223 JniUpdateAvailableCallback* const callback = 225 JniUpdateAvailableCallback* const callback =
224 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); 226 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
225 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = 227 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
226 std::bind(&JniUpdateAvailableCallback::Callback, callback, 228 std::bind(&JniUpdateAvailableCallback::Callback, callback,
227 std::placeholders::_1); 229 std::placeholders::_1);
228 try 230 try
229 { 231 {
230 engine->SetUpdateAvailableCallback(updateAvailableCallback); 232 engine->SetUpdateAvailableCallback(updateAvailableCallback);
231 } 233 }
232 CATCH_AND_THROW(env) 234 CATCH_AND_THROW(env)
233 } 235 }
234 236
235 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr) 237 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr)
236 { 238 {
237 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 239 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
238 240
239 try 241 try
240 { 242 {
241 engine->RemoveFilterChangeCallback(); 243 engine->RemoveFilterChangeCallback();
242 } 244 }
243 CATCH_AND_THROW(env) 245 CATCH_AND_THROW(env)
244 } 246 }
245 247
246 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, 248 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
247 jlong ptr, jlong filterPtr) 249 jlong ptr, jlong filterPtr)
248 { 250 {
249 AdblockPlus::FilterEngine* engine = 251 AdblockPlus::FilterEnginePtr& engine =
250 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 252 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
251 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( 253 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
252 filterPtr); 254 filterPtr);
253 255
254 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = 256 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback =
255 std::bind(&JniFilterChangeCallback::Callback, callback, 257 std::bind(&JniFilterChangeCallback::Callback, callback,
256 std::placeholders::_1, std::placeholders::_2); 258 std::placeholders::_1, std::placeholders::_2);
257 259
258 try 260 try
259 { 261 {
260 engine->SetFilterChangeCallback(filterCallback); 262 engine->SetFilterChangeCallback(filterCallback);
261 } 263 }
262 CATCH_AND_THROW(env) 264 CATCH_AND_THROW(env)
263 } 265 }
264 266
265 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)
266 { 268 {
267 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 269 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
268 JniUpdateCheckDoneCallback* callback = 270 JniUpdateCheckDoneCallback* callback =
269 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); 271 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
270 272
271 AdblockPlus::FilterEngine::UpdateCheckDoneCallback 273 AdblockPlus::FilterEngine::UpdateCheckDoneCallback
272 updateCheckDoneCallback = 0; 274 updateCheckDoneCallback = 0;
273 275
274 if (updaterPtr) 276 if (updaterPtr)
275 { 277 {
276 updateCheckDoneCallback = 278 updateCheckDoneCallback =
277 std::bind(&JniUpdateCheckDoneCallback::Callback, callback, 279 std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
278 std::placeholders::_1); 280 std::placeholders::_1);
279 } 281 }
280 282
281 try 283 try
282 { 284 {
283 engine->ForceUpdateCheck(updateCheckDoneCallback); 285 engine->ForceUpdateCheck(updateCheckDoneCallback);
284 } 286 }
285 CATCH_AND_THROW(env) 287 CATCH_AND_THROW(env)
286 } 288 }
287 289
288 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, 290 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
289 jlong ptr, jstring jDomain) 291 jlong ptr, jstring jDomain)
290 { 292 {
291 AdblockPlus::FilterEngine* engine = 293 AdblockPlus::FilterEnginePtr& engine =
292 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 294 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
293 295
294 std::string domain = JniJavaToStdString(env, jDomain); 296 std::string domain = JniJavaToStdString(env, jDomain);
295 297
296 try 298 try
297 { 299 {
298 std::vector<std::string> selectors = engine->GetElementHidingSelectors( 300 std::vector<std::string> selectors = engine->GetElementHidingSelectors(
299 domain); 301 domain);
300 302
301 jobject list = NewJniArrayList(env); 303 jobject list = NewJniArrayList(env);
302 304
303 for (std::vector<std::string>::iterator it = selectors.begin(), end = 305 for (std::vector<std::string>::iterator it = selectors.begin(), end =
304 selectors.end(); it != end; it++) 306 selectors.end(); it != end; it++)
305 { 307 {
306 JniAddObjectToList(env, list, 308 JniAddObjectToList(env, list,
307 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str()))); 309 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str())));
308 } 310 }
309 311
310 return list; 312 return list;
311 } 313 }
312 CATCH_THROW_AND_RETURN(env, 0) 314 CATCH_THROW_AND_RETURN(env, 0)
313 } 315 }
314 316
315 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)
316 { 318 {
317 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 319 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
318 320
319 std::string url = JniJavaToStdString(env, jUrl); 321 std::string url = JniJavaToStdString(env, jUrl);
320 AdblockPlus::FilterEngine::ContentType contentType = 322 AdblockPlus::FilterEngine::ContentType contentType =
321 ConvertContentType(env, jContentType); 323 ConvertContentType(env, jContentType);
322 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); 324 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
323 325
324 try 326 try
325 { 327 {
326 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l); 328 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l);
327 329
(...skipping 16 matching lines...) Expand all
344 *JniLocalReference<jstring>(env, 346 *JniLocalReference<jstring>(env,
345 static_cast<jstring>( 347 static_cast<jstring>(
346 env->GetObjectArrayElement(jArray, i))))); 348 env->GetObjectArrayElement(jArray, i)))));
347 } 349 }
348 } 350 }
349 } 351 }
350 352
351 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, 353 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
352 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) 354 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
353 { 355 {
354 AdblockPlus::FilterEngine* engine = 356 AdblockPlus::FilterEnginePtr& engine =
355 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 357 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
356 358
357 std::string url = JniJavaToStdString(env, jUrl); 359 std::string url = JniJavaToStdString(env, jUrl);
358 AdblockPlus::FilterEngine::ContentType contentType = 360 AdblockPlus::FilterEngine::ContentType contentType =
359 ConvertContentType(env, jContentType); 361 ConvertContentType(env, jContentType);
360 362
361 std::vector<std::string> documentUrls; 363 std::vector<std::string> documentUrls;
362 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 364 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
363 365
364 try 366 try
365 { 367 {
366 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, 368 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
367 documentUrls); 369 documentUrls);
368 370
369 return NewJniFilter(env, filter); 371 return NewJniFilter(env, filter);
370 } 372 }
371 CATCH_THROW_AND_RETURN(env, 0) 373 CATCH_THROW_AND_RETURN(env, 0)
372 } 374 }
373 375
374 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 376 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
375 jstring jUrl, jobjectArray jDocumentUrls) 377 jstring jUrl, jobjectArray jDocumentUrls)
376 { 378 {
377 AdblockPlus::FilterEngine* engine = 379 AdblockPlus::FilterEnginePtr& engine =
378 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 380 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
379 381
380 std::string url = JniJavaToStdString(env, jUrl); 382 std::string url = JniJavaToStdString(env, jUrl);
381 std::vector<std::string> documentUrls; 383 std::vector<std::string> documentUrls;
382 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 384 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
383 try 385 try
384 { 386 {
385 return engine->IsDocumentWhitelisted(url, documentUrls) ? 387 return engine->IsDocumentWhitelisted(url, documentUrls) ?
386 JNI_TRUE : JNI_FALSE; 388 JNI_TRUE : JNI_FALSE;
387 } 389 }
388 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 390 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
389 } 391 }
390 392
391 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 393 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
392 jstring jUrl, jobjectArray jDocumentUrls) 394 jstring jUrl, jobjectArray jDocumentUrls)
393 { 395 {
394 AdblockPlus::FilterEngine* engine = 396 AdblockPlus::FilterEnginePtr& engine =
395 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 397 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
396 398
397 std::string url = JniJavaToStdString(env, jUrl); 399 std::string url = JniJavaToStdString(env, jUrl);
398 std::vector<std::string> documentUrls; 400 std::vector<std::string> documentUrls;
399 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 401 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
400 try 402 try
401 { 403 {
402 return engine->IsElemhideWhitelisted(url, documentUrls) ? 404 return engine->IsElemhideWhitelisted(url, documentUrls) ?
403 JNI_TRUE : JNI_FALSE; 405 JNI_TRUE : JNI_FALSE;
404 } 406 }
405 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 407 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
406 } 408 }
407 409
408 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)
409 { 411 {
410 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi ne > (ptr); 412 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
411 413
412 std::string pref = JniJavaToStdString(env, jPref); 414 std::string pref = JniJavaToStdString(env, jPref);
413 415
414 try 416 try
415 { 417 {
416 AdblockPlus::JsValuePtr value = engine->GetPref(pref); 418 AdblockPlus::JsValuePtr value = engine->GetPref(pref);
417 419
418 return NewJniJsValue(env, value); 420 return NewJniJsValue(env, value);
419 } 421 }
420 CATCH_THROW_AND_RETURN(env, 0) 422 CATCH_THROW_AND_RETURN(env, 0)
421 } 423 }
422 424
423 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)
424 { 426 {
425 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 427 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
426 428
427 std::string pref = JniJavaToStdString(env, jPref); 429 std::string pref = JniJavaToStdString(env, jPref);
428 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue); 430 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue);
429 431
430 try 432 try
431 { 433 {
432 engine->SetPref(pref, value); 434 engine->SetPref(pref, value);
433 } 435 }
434 CATCH_AND_THROW(env) 436 CATCH_AND_THROW(env)
435 } 437 }
436 438
437 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)
438 { 440 {
439 if (jurl == NULL) 441 if (jurl == NULL)
440 { 442 {
441 return NULL; 443 return NULL;
442 } 444 }
443 445
444 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 446 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
445 447
446 std::string url = JniJavaToStdString(env, jurl); 448 std::string url = JniJavaToStdString(env, jurl);
447 try 449 try
448 { 450 {
449 std::string host = engine->GetHostFromURL(url); 451 std::string host = engine->GetHostFromURL(url);
450 452
451 return JniStdStringToJava(env, host); 453 return JniStdStringToJava(env, host);
452 } 454 }
453 CATCH_THROW_AND_RETURN(env, 0) 455 CATCH_THROW_AND_RETURN(env, 0)
454 } 456 }
455 457
456 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)
457 { 459 {
458 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 460 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
459 461
460 std::string* value = NULL; 462 std::string stdValue;
461 if (jvalue != NULL) 463 const std::string* value = (jvalue != NULL
462 { 464 ? &(stdValue = JniJavaToStdString(env, jvalue))
463 std::string stdValue = JniJavaToStdString(env, jvalue); 465 : NULL);
464 value = &stdValue;
465 }
466 466
467 try 467 try
468 { 468 {
469 engine->SetAllowedConnectionType(value); 469 engine->SetAllowedConnectionType(value);
470 } 470 }
471 CATCH_AND_THROW(env) 471 CATCH_AND_THROW(env)
472 } 472 }
473 473
474
475 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr) 474 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr)
476 { 475 {
477 try 476 try
478 { 477 {
479 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngi ne>(ptr); 478 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
480 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType(); 479 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType();
481 480
482 if (value == NULL) 481 if (value == NULL)
483 { 482 {
484 return NULL; 483 return NULL;
485 } 484 }
486 485
487 return JniStdStringToJava(env, *value.get()); 486 return JniStdStringToJava(env, *value.get());
488 } 487 }
489 CATCH_THROW_AND_RETURN(env, 0) 488 CATCH_THROW_AND_RETURN(env, 0)
(...skipping 26 matching lines...) Expand all
516 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL }, 515 { (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", ( void*)JniGetHostFromURL },
517 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType }, 516 { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)J niSetAllowedConnectionType },
518 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType }, 517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType },
519 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
520 }; 519 };
521 520
522 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)
523 { 522 {
524 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
525 } 524 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld