OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 try | 112 try |
113 { | 113 { |
114 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url); | 114 AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url); |
115 | 115 |
116 return NewJniSubscription(env, subscription); | 116 return NewJniSubscription(env, subscription); |
117 } | 117 } |
118 CATCH_THROW_AND_RETURN(env, 0); | 118 CATCH_THROW_AND_RETURN(env, 0); |
119 } | 119 } |
120 | 120 |
121 static jobject JNICALL JniGetNextNotificationToShow(JNIEnv* env, jclass clazz, j
long ptr, jstring jUrl) | 121 static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr
, jstring jUrl) |
122 { | 122 { |
123 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 123 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
124 std::string url = JniJavaToStdString(env, jUrl); | 124 std::string url = JniJavaToStdString(env, jUrl); |
125 | 125 |
126 try | 126 try |
127 { | 127 { |
128 AdblockPlus::NotificationPtr notification = engine->GetNextNotificationToSho
w(url); | 128 engine->ShowNextNotification(url); |
| 129 } |
| 130 CATCH_AND_THROW(env); |
| 131 } |
129 | 132 |
130 return NewJniNotification(env, notification); | 133 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz, |
| 134 jlong ptr, jlong callbackPtr) |
| 135 { |
| 136 AdblockPlus::FilterEngine* const engine = |
| 137 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
| 138 JniShowNotificationCallback* const callback = |
| 139 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr); |
| 140 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback = |
| 141 std::bind(&JniShowNotificationCallback::Callback, callback, |
| 142 std::placeholders::_1); |
| 143 try |
| 144 { |
| 145 engine->SetShowNotificationCallback(showNotificationCallback); |
131 } | 146 } |
132 CATCH_THROW_AND_RETURN(env, 0); | 147 CATCH_AND_THROW(env) |
| 148 } |
| 149 |
| 150 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz,
jlong ptr) |
| 151 { |
| 152 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
| 153 |
| 154 try |
| 155 { |
| 156 engine->RemoveShowNotificationCallback(); |
| 157 } |
| 158 CATCH_AND_THROW(env); |
133 } | 159 } |
134 | 160 |
135 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon
g ptr) | 161 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon
g ptr) |
136 { | 162 { |
137 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 163 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
138 | 164 |
139 try | 165 try |
140 { | 166 { |
141 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS
ubscriptions(); | 167 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS
ubscriptions(); |
142 | 168 |
(...skipping 28 matching lines...) Expand all Loading... |
171 } | 197 } |
172 | 198 |
173 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, | 199 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, |
174 jlong ptr, jlong callbackPtr) | 200 jlong ptr, jlong callbackPtr) |
175 { | 201 { |
176 AdblockPlus::FilterEngine* const engine = | 202 AdblockPlus::FilterEngine* const engine = |
177 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); | 203 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
178 JniUpdateAvailableCallback* const callback = | 204 JniUpdateAvailableCallback* const callback = |
179 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); | 205 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); |
180 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = | 206 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = |
181 std::tr1::bind(&JniUpdateAvailableCallback::Callback, callback, | 207 std::bind(&JniUpdateAvailableCallback::Callback, callback, |
182 std::tr1::placeholders::_1); | 208 std::placeholders::_1); |
183 try | 209 try |
184 { | 210 { |
185 engine->SetUpdateAvailableCallback(updateAvailableCallback); | 211 engine->SetUpdateAvailableCallback(updateAvailableCallback); |
186 } | 212 } |
187 CATCH_AND_THROW(env) | 213 CATCH_AND_THROW(env) |
188 } | 214 } |
189 | 215 |
190 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo
ng ptr) | 216 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo
ng ptr) |
191 { | 217 { |
192 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 218 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
193 | 219 |
194 try | 220 try |
195 { | 221 { |
196 engine->RemoveFilterChangeCallback(); | 222 engine->RemoveFilterChangeCallback(); |
197 } | 223 } |
198 CATCH_AND_THROW(env) | 224 CATCH_AND_THROW(env) |
199 } | 225 } |
200 | 226 |
201 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, | 227 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, |
202 jlong ptr, jlong filterPtr) | 228 jlong ptr, jlong filterPtr) |
203 { | 229 { |
204 AdblockPlus::FilterEngine* engine = | 230 AdblockPlus::FilterEngine* engine = |
205 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); | 231 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
206 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( | 232 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( |
207 filterPtr); | 233 filterPtr); |
208 | 234 |
209 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = | 235 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = |
210 std::tr1::bind(&JniFilterChangeCallback::Callback, callback, | 236 std::bind(&JniFilterChangeCallback::Callback, callback, |
211 std::tr1::placeholders::_1, std::tr1::placeholders::_2); | 237 std::placeholders::_1, std::placeholders::_2); |
212 | 238 |
213 try | 239 try |
214 { | 240 { |
215 engine->SetFilterChangeCallback(filterCallback); | 241 engine->SetFilterChangeCallback(filterCallback); |
216 } | 242 } |
217 CATCH_AND_THROW(env) | 243 CATCH_AND_THROW(env) |
218 } | 244 } |
219 | 245 |
220 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
ong updaterPtr) | 246 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
ong updaterPtr) |
221 { | 247 { |
222 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); | 248 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine
>(ptr); |
223 JniUpdateCheckDoneCallback* callback = | 249 JniUpdateCheckDoneCallback* callback = |
224 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); | 250 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); |
225 | 251 |
226 AdblockPlus::FilterEngine::UpdateCheckDoneCallback | 252 AdblockPlus::FilterEngine::UpdateCheckDoneCallback |
227 updateCheckDoneCallback = 0; | 253 updateCheckDoneCallback = 0; |
228 | 254 |
229 if (updaterPtr) | 255 if (updaterPtr) |
230 { | 256 { |
231 updateCheckDoneCallback = | 257 updateCheckDoneCallback = |
232 std::tr1::bind(&JniUpdateCheckDoneCallback::Callback, callback, | 258 std::bind(&JniUpdateCheckDoneCallback::Callback, callback, |
233 std::tr1::placeholders::_1); | 259 std::placeholders::_1); |
234 } | 260 } |
235 | 261 |
236 try | 262 try |
237 { | 263 { |
238 engine->ForceUpdateCheck(updateCheckDoneCallback); | 264 engine->ForceUpdateCheck(updateCheckDoneCallback); |
239 } | 265 } |
240 CATCH_AND_THROW(env) | 266 CATCH_AND_THROW(env) |
241 } | 267 } |
242 | 268 |
243 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, | 269 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 CATCH_AND_THROW(env) | 373 CATCH_AND_THROW(env) |
348 } | 374 } |
349 | 375 |
350 static JNINativeMethod methods[] = | 376 static JNINativeMethod methods[] = |
351 { | 377 { |
352 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, | 378 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, |
353 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, | 379 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, |
354 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni
GetFilter }, | 380 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni
GetFilter }, |
355 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed
Filters }, | 381 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed
Filters }, |
356 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription")
, (void*)JniGetSubscription }, | 382 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription")
, (void*)JniGetSubscription }, |
357 { (char*)"getNextNotificationToShow", (char*)"(JLjava/lang/String;)" TYP("Noti
fication"), (void*)JniGetNextNotificationToShow }, | 383 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh
owNextNotification }, |
| 384 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif
icationCallback }, |
| 385 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow
NotificationCallback }, |
358 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet
ListedSubscriptions }, | 386 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet
ListedSubscriptions }, |
359 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J
niFetchAvailableSubscriptions }, | 387 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J
niFetchAvailableSubscriptions }, |
360 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai
lableCallback }, | 388 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai
lableCallback }, |
361 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat
eAvailableCallback }, | 389 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat
eAvailableCallback }, |
362 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC
allback }, | 390 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC
allback }, |
363 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh
angeCallback }, | 391 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh
angeCallback }, |
364 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, | 392 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, |
365 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/
List;", (void*)JniGetElementHidingSelectors }, | 393 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/
List;", (void*)JniGetElementHidingSelectors }, |
366 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, | 394 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches }, |
367 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, | 395 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp
e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, |
368 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, | 396 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, |
369 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, | 397 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, |
370 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 398 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
371 }; | 399 }; |
372 | 400 |
373 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) | 401 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi
ne_registerNatives(JNIEnv *env, jclass clazz) |
374 { | 402 { |
375 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 403 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
376 } | 404 } |
OLD | NEW |