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

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

Issue 29379647: Issue 4948 - add possibility to not send data depending on connection properties (Closed)
Patch Set: felix's comments Created March 24, 2017, 9:46 a.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-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 26 matching lines...) Expand all
37 JniLocalReference<jclass> contentTypeClass(env, 37 JniLocalReference<jclass> contentTypeClass(env,
38 env->GetObjectClass(jContentType)); 38 env->GetObjectClass(jContentType));
39 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name", 39 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name",
40 "()Ljava/lang/String;"); 40 "()Ljava/lang/String;");
41 JniLocalReference<jstring> jValue(env, 41 JniLocalReference<jstring> jValue(env,
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 enginePtr) 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>(enginePtr); 51 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(jsEnginePtr);
52 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); 52 AdblockPlus::FilterEnginePtr* filterEngine = NULL;
53
54 if (isAllowedConnectionCallbackPtr != 0)
55 {
56 AdblockPlus::FilterEngine::CreationParameters creationParameters;
57 JniIsAllowedConnectionTypeCallback* callback =
58 JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnection CallbackPtr);
59
60 AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback =
61 std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std:: placeholders::_1);
62 creationParameters.isConnectionAllowedCallback = cppCallback;
63
64 filterEngine = new AdblockPlus::FilterEnginePtr(
65 AdblockPlus::FilterEngine::Create(jsEngine, creationParameters));
66 }
67 else
68 {
69 filterEngine = new AdblockPlus::FilterEnginePtr(
70 AdblockPlus::FilterEngine::Create(jsEngine));
71 }
72
73 return JniPtrToLong(filterEngine);
53 } 74 }
54 CATCH_THROW_AND_RETURN(env, 0) 75 CATCH_THROW_AND_RETURN(env, 0)
55 } 76 }
56 77
57 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 78 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
58 { 79 {
59 delete JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 80 delete JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
60 } 81 }
61 82
62 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr) 83 static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
63 { 84 {
64 try 85 try
65 { 86 {
66 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngi ne>(ptr); 87 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
67 88
68 return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE; 89 return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE;
69 } 90 }
70 CATCH_THROW_AND_RETURN(env, JNI_FALSE); 91 CATCH_THROW_AND_RETURN(env, JNI_FALSE);
71 } 92 }
72 93
73 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)
74 { 95 {
75 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 96 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
76 std::string text = JniJavaToStdString(env, jText); 97 std::string text = JniJavaToStdString(env, jText);
77 98
78 try 99 try
79 { 100 {
80 AdblockPlus::FilterPtr filter = engine->GetFilter(text); 101 AdblockPlus::FilterPtr filter = engine->GetFilter(text);
81 102
82 return NewJniFilter(env, filter); 103 return NewJniFilter(env, filter);
83 } 104 }
84 CATCH_THROW_AND_RETURN(env, 0); 105 CATCH_THROW_AND_RETURN(env, 0);
85 } 106 }
86 107
87 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr) 108 static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
88 { 109 {
89 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 110 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
90 111
91 try 112 try
92 { 113 {
93 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters(); 114 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters();
94 115
95 jobject list = NewJniArrayList(env); 116 jobject list = NewJniArrayList(env);
96 117
97 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++)
98 { 119 {
99 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it))); 120 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it)));
100 } 121 }
101 122
102 return list; 123 return list;
103 } 124 }
104 CATCH_THROW_AND_RETURN(env, 0); 125 CATCH_THROW_AND_RETURN(env, 0);
105 } 126 }
106 127
107 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)
108 { 129 {
109 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 130 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
110 std::string url = JniJavaToStdString(env, jUrl); 131 std::string url = JniJavaToStdString(env, jUrl);
111 132
112 try 133 try
113 { 134 {
114 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url); 135 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url);
115 136
116 return NewJniSubscription(env, subscription); 137 return NewJniSubscription(env, subscription);
117 } 138 }
118 CATCH_THROW_AND_RETURN(env, 0); 139 CATCH_THROW_AND_RETURN(env, 0);
119 } 140 }
120 141
121 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)
122 { 143 {
123 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 144 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
124 std::string url = JniJavaToStdString(env, jUrl); 145 std::string url = JniJavaToStdString(env, jUrl);
125 146
126 try 147 try
127 { 148 {
128 engine->ShowNextNotification(url); 149 engine->ShowNextNotification(url);
129 } 150 }
130 CATCH_AND_THROW(env); 151 CATCH_AND_THROW(env);
131 } 152 }
132 153
133 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz, 154 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
134 jlong ptr, jlong callbackPtr) 155 jlong ptr, jlong callbackPtr)
135 { 156 {
136 AdblockPlus::FilterEngine* const engine = 157 AdblockPlus::FilterEnginePtr& engine =
137 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 158 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
138 JniShowNotificationCallback* const callback = 159 JniShowNotificationCallback* const callback =
139 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr); 160 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr);
140 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback = 161 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback =
141 std::bind(&JniShowNotificationCallback::Callback, callback, 162 std::bind(&JniShowNotificationCallback::Callback, callback,
142 std::placeholders::_1); 163 std::placeholders::_1);
143 try 164 try
144 { 165 {
145 engine->SetShowNotificationCallback(showNotificationCallback); 166 engine->SetShowNotificationCallback(showNotificationCallback);
146 } 167 }
147 CATCH_AND_THROW(env) 168 CATCH_AND_THROW(env)
148 } 169 }
149 170
150 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr) 171 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr)
151 { 172 {
152 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 173 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
153 174
154 try 175 try
155 { 176 {
156 engine->RemoveShowNotificationCallback(); 177 engine->RemoveShowNotificationCallback();
157 } 178 }
158 CATCH_AND_THROW(env); 179 CATCH_AND_THROW(env);
159 } 180 }
160 181
161 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr) 182 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr)
162 { 183 {
163 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 184 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
164 185
165 try 186 try
166 { 187 {
167 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions(); 188 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions();
168 189
169 return SubscriptionsToArrayList(env, subscriptions); 190 return SubscriptionsToArrayList(env, subscriptions);
170 } 191 }
171 CATCH_THROW_AND_RETURN(env, 0); 192 CATCH_THROW_AND_RETURN(env, 0);
172 } 193 }
173 194
174 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr) 195 static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr)
175 { 196 {
176 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 197 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
177 198
178 try 199 try
179 { 200 {
180 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions(); 201 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvail ableSubscriptions();
181 202
182 return SubscriptionsToArrayList(env, subscriptions); 203 return SubscriptionsToArrayList(env, subscriptions);
183 } 204 }
184 CATCH_THROW_AND_RETURN(env, 0); 205 CATCH_THROW_AND_RETURN(env, 0);
185 } 206 }
186 207
187 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz, 208 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
188 jlong ptr) 209 jlong ptr)
189 { 210 {
190 AdblockPlus::FilterEngine* const engine = 211 AdblockPlus::FilterEnginePtr& engine =
191 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 212 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
192 try 213 try
193 { 214 {
194 engine->RemoveUpdateAvailableCallback(); 215 engine->RemoveUpdateAvailableCallback();
195 } 216 }
196 CATCH_AND_THROW(env) 217 CATCH_AND_THROW(env)
197 } 218 }
198 219
199 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, 220 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
200 jlong ptr, jlong callbackPtr) 221 jlong ptr, jlong callbackPtr)
201 { 222 {
202 AdblockPlus::FilterEngine* const engine = 223 AdblockPlus::FilterEnginePtr& engine =
203 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 224 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
204 JniUpdateAvailableCallback* const callback = 225 JniUpdateAvailableCallback* const callback =
205 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); 226 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
206 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = 227 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
207 std::bind(&JniUpdateAvailableCallback::Callback, callback, 228 std::bind(&JniUpdateAvailableCallback::Callback, callback,
208 std::placeholders::_1); 229 std::placeholders::_1);
209 try 230 try
210 { 231 {
211 engine->SetUpdateAvailableCallback(updateAvailableCallback); 232 engine->SetUpdateAvailableCallback(updateAvailableCallback);
212 } 233 }
213 CATCH_AND_THROW(env) 234 CATCH_AND_THROW(env)
214 } 235 }
215 236
216 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr) 237 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr)
217 { 238 {
218 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 239 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
219 240
220 try 241 try
221 { 242 {
222 engine->RemoveFilterChangeCallback(); 243 engine->RemoveFilterChangeCallback();
223 } 244 }
224 CATCH_AND_THROW(env) 245 CATCH_AND_THROW(env)
225 } 246 }
226 247
227 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, 248 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
228 jlong ptr, jlong filterPtr) 249 jlong ptr, jlong filterPtr)
229 { 250 {
230 AdblockPlus::FilterEngine* engine = 251 AdblockPlus::FilterEnginePtr& engine =
231 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 252 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
232 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( 253 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
233 filterPtr); 254 filterPtr);
234 255
235 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = 256 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback =
236 std::bind(&JniFilterChangeCallback::Callback, callback, 257 std::bind(&JniFilterChangeCallback::Callback, callback,
237 std::placeholders::_1, std::placeholders::_2); 258 std::placeholders::_1, std::placeholders::_2);
238 259
239 try 260 try
240 { 261 {
241 engine->SetFilterChangeCallback(filterCallback); 262 engine->SetFilterChangeCallback(filterCallback);
242 } 263 }
243 CATCH_AND_THROW(env) 264 CATCH_AND_THROW(env)
244 } 265 }
245 266
246 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)
247 { 268 {
248 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 269 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
249 JniUpdateCheckDoneCallback* callback = 270 JniUpdateCheckDoneCallback* callback =
250 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); 271 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
251 272
252 AdblockPlus::FilterEngine::UpdateCheckDoneCallback 273 AdblockPlus::FilterEngine::UpdateCheckDoneCallback
253 updateCheckDoneCallback = 0; 274 updateCheckDoneCallback = 0;
254 275
255 if (updaterPtr) 276 if (updaterPtr)
256 { 277 {
257 updateCheckDoneCallback = 278 updateCheckDoneCallback =
258 std::bind(&JniUpdateCheckDoneCallback::Callback, callback, 279 std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
259 std::placeholders::_1); 280 std::placeholders::_1);
260 } 281 }
261 282
262 try 283 try
263 { 284 {
264 engine->ForceUpdateCheck(updateCheckDoneCallback); 285 engine->ForceUpdateCheck(updateCheckDoneCallback);
265 } 286 }
266 CATCH_AND_THROW(env) 287 CATCH_AND_THROW(env)
267 } 288 }
268 289
269 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, 290 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
270 jlong ptr, jstring jDomain) 291 jlong ptr, jstring jDomain)
271 { 292 {
272 AdblockPlus::FilterEngine* engine = 293 AdblockPlus::FilterEnginePtr& engine =
273 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 294 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
274 295
275 std::string domain = JniJavaToStdString(env, jDomain); 296 std::string domain = JniJavaToStdString(env, jDomain);
276 297
277 try 298 try
278 { 299 {
279 std::vector<std::string> selectors = engine->GetElementHidingSelectors( 300 std::vector<std::string> selectors = engine->GetElementHidingSelectors(
280 domain); 301 domain);
281 302
282 jobject list = NewJniArrayList(env); 303 jobject list = NewJniArrayList(env);
283 304
284 for (std::vector<std::string>::iterator it = selectors.begin(), end = 305 for (std::vector<std::string>::iterator it = selectors.begin(), end =
285 selectors.end(); it != end; it++) 306 selectors.end(); it != end; it++)
286 { 307 {
287 JniAddObjectToList(env, list, 308 JniAddObjectToList(env, list,
288 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str()))); 309 *JniLocalReference<jstring>(env, env->NewStringUTF(it->c_str())));
289 } 310 }
290 311
291 return list; 312 return list;
292 } 313 }
293 CATCH_THROW_AND_RETURN(env, 0) 314 CATCH_THROW_AND_RETURN(env, 0)
294 } 315 }
295 316
296 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)
297 { 318 {
298 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 319 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
299 320
300 std::string url = JniJavaToStdString(env, jUrl); 321 std::string url = JniJavaToStdString(env, jUrl);
301 AdblockPlus::FilterEngine::ContentType contentType = 322 AdblockPlus::FilterEngine::ContentType contentType =
302 ConvertContentType(env, jContentType); 323 ConvertContentType(env, jContentType);
303 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); 324 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
304 325
305 try 326 try
306 { 327 {
307 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l); 328 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l);
308 329
(...skipping 16 matching lines...) Expand all
325 *JniLocalReference<jstring>(env, 346 *JniLocalReference<jstring>(env,
326 static_cast<jstring>( 347 static_cast<jstring>(
327 env->GetObjectArrayElement(jArray, i))))); 348 env->GetObjectArrayElement(jArray, i)))));
328 } 349 }
329 } 350 }
330 } 351 }
331 352
332 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, 353 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
333 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls) 354 jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
334 { 355 {
335 AdblockPlus::FilterEngine* engine = 356 AdblockPlus::FilterEnginePtr& engine =
336 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 357 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
337 358
338 std::string url = JniJavaToStdString(env, jUrl); 359 std::string url = JniJavaToStdString(env, jUrl);
339 AdblockPlus::FilterEngine::ContentType contentType = 360 AdblockPlus::FilterEngine::ContentType contentType =
340 ConvertContentType(env, jContentType); 361 ConvertContentType(env, jContentType);
341 362
342 std::vector<std::string> documentUrls; 363 std::vector<std::string> documentUrls;
343 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 364 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
344 365
345 try 366 try
346 { 367 {
347 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, 368 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
348 documentUrls); 369 documentUrls);
349 370
350 return NewJniFilter(env, filter); 371 return NewJniFilter(env, filter);
351 } 372 }
352 CATCH_THROW_AND_RETURN(env, 0) 373 CATCH_THROW_AND_RETURN(env, 0)
353 } 374 }
354 375
355 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 376 static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
356 jstring jUrl, jobjectArray jDocumentUrls) 377 jstring jUrl, jobjectArray jDocumentUrls)
357 { 378 {
358 AdblockPlus::FilterEngine* engine = 379 AdblockPlus::FilterEnginePtr& engine =
359 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 380 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
360 381
361 std::string url = JniJavaToStdString(env, jUrl); 382 std::string url = JniJavaToStdString(env, jUrl);
362 std::vector<std::string> documentUrls; 383 std::vector<std::string> documentUrls;
363 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 384 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
364 try 385 try
365 { 386 {
366 return engine->IsDocumentWhitelisted(url, documentUrls) ? 387 return engine->IsDocumentWhitelisted(url, documentUrls) ?
367 JNI_TRUE : JNI_FALSE; 388 JNI_TRUE : JNI_FALSE;
368 } 389 }
369 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 390 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
370 } 391 }
371 392
372 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr, 393 static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon g ptr,
373 jstring jUrl, jobjectArray jDocumentUrls) 394 jstring jUrl, jobjectArray jDocumentUrls)
374 { 395 {
375 AdblockPlus::FilterEngine* engine = 396 AdblockPlus::FilterEnginePtr& engine =
376 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 397 *JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
377 398
378 std::string url = JniJavaToStdString(env, jUrl); 399 std::string url = JniJavaToStdString(env, jUrl);
379 std::vector<std::string> documentUrls; 400 std::vector<std::string> documentUrls;
380 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls); 401 JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
381 try 402 try
382 { 403 {
383 return engine->IsElemhideWhitelisted(url, documentUrls) ? 404 return engine->IsElemhideWhitelisted(url, documentUrls) ?
384 JNI_TRUE : JNI_FALSE; 405 JNI_TRUE : JNI_FALSE;
385 } 406 }
386 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 407 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
387 } 408 }
388 409
389 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)
390 { 411 {
391 AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngi ne > (ptr); 412 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
392 413
393 std::string pref = JniJavaToStdString(env, jPref); 414 std::string pref = JniJavaToStdString(env, jPref);
394 415
395 try 416 try
396 { 417 {
397 AdblockPlus::JsValuePtr value = engine->GetPref(pref); 418 AdblockPlus::JsValuePtr value = engine->GetPref(pref);
398 419
399 return NewJniJsValue(env, value); 420 return NewJniJsValue(env, value);
400 } 421 }
401 CATCH_THROW_AND_RETURN(env, 0) 422 CATCH_THROW_AND_RETURN(env, 0)
402 } 423 }
403 424
404 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)
405 { 426 {
406 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 427 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
407 428
408 std::string pref = JniJavaToStdString(env, jPref); 429 std::string pref = JniJavaToStdString(env, jPref);
409 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue); 430 AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue);
410 431
411 try 432 try
412 { 433 {
413 engine->SetPref(pref, value); 434 engine->SetPref(pref, value);
414 } 435 }
415 CATCH_AND_THROW(env) 436 CATCH_AND_THROW(env)
416 } 437 }
417 438
418 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)
419 { 440 {
420 if (jurl == NULL) 441 if (jurl == NULL)
421 { 442 {
422 return NULL; 443 return NULL;
423 } 444 }
424 445
425 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 446 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
426 447
427 std::string url = JniJavaToStdString(env, jurl); 448 std::string url = JniJavaToStdString(env, jurl);
428 try 449 try
429 { 450 {
430 std::string host = engine->GetHostFromURL(url); 451 std::string host = engine->GetHostFromURL(url);
431 452
432 return JniStdStringToJava(env, host); 453 return JniStdStringToJava(env, host);
433 } 454 }
434 CATCH_THROW_AND_RETURN(env, 0) 455 CATCH_THROW_AND_RETURN(env, 0)
435 } 456 }
436 457
458 static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr, jstring jvalue)
459 {
460 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::FilterEn ginePtr>(ptr);
461
462 std::string stdValue;
463 const std::string* value = (jvalue != NULL
464 ? &(stdValue = JniJavaToStdString(env, jvalue))
465 : NULL);
466
467 try
468 {
469 engine->SetAllowedConnectionType(value);
470 }
471 CATCH_AND_THROW(env)
472 }
473
474 static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jl ong ptr)
475 {
476 try
477 {
478 AdblockPlus::FilterEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::Filter EnginePtr>(ptr);
479 std::unique_ptr<std::string> value = engine->GetAllowedConnectionType();
480
481 if (value == NULL)
482 {
483 return NULL;
484 }
485
486 return JniStdStringToJava(env, *value.get());
487 }
488 CATCH_THROW_AND_RETURN(env, 0)
489 }
490
437 static JNINativeMethod methods[] = 491 static JNINativeMethod methods[] =
438 { 492 {
439 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, 493 { (char*)"ctor", (char*)"(JJ)J", (void*)JniCtor },
440 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, 494 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun },
441 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, 495 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter },
442 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, 496 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters },
443 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, 497 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription },
444 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification }, 498 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification },
445 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif icationCallback }, 499 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif icationCallback },
446 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow NotificationCallback }, 500 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow NotificationCallback },
447 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, 501 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions },
448 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, 502 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions },
449 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback }, 503 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback },
450 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback }, 504 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback },
451 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, 505 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback },
452 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, 506 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback },
453 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, 507 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
454 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors }, 508 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors },
455 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, 509 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
456 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, 510 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
457 { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsDocumentWhitelisted }, 511 { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsDocumentWhitelisted },
458 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsElemhideWhitelisted }, 512 { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/Stri ng;)Z", (void*)JniIsElemhideWhitelisted },
459 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, 513 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
460 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 514 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
461 { (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 },
517 { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)Jn iGetAllowedConnectionType },
462 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 518 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
463 }; 519 };
464 520
465 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)
466 { 522 {
467 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 523 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
468 } 524 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniCallbacks.h ('k') | libadblockplus-android/jni/JniIsAllowedConnectionTypeCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld