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

Side by Side Diff: jni/JniFilterEngine.cpp

Issue 29329928: Issue 3297 - Fix issues introduced by recent libadblockplus changes and update dependencies (Closed)
Patch Set: Created Nov. 10, 2015, 4:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-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
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 /**
Felix Dahlke 2015/11/20 07:53:52 I don't really get this part - this is the first t
René Jeschke 2015/11/20 12:19:15 Argh, sry, left-over from copy'n'paste for impleme
122 * Sets the callback invoked when a notification should be shown.
123 * @param callback Callback to invoke.
124 */
125 //void SetShowNotificationCallback(const ShowNotificationCallback& value);
126
127 static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr , jstring jUrl)
122 { 128 {
123 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 129 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
124 std::string url = JniJavaToStdString(env, jUrl); 130 std::string url = JniJavaToStdString(env, jUrl);
125 131
126 try 132 try
127 { 133 {
128 AdblockPlus::NotificationPtr notification = engine->GetNextNotificationToSho w(url); 134 engine->ShowNextNotification(url);
135 }
136 CATCH_AND_THROW(env);
137 }
129 138
130 return NewJniNotification(env, notification); 139 static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
140 jlong ptr, jlong callbackPtr)
141 {
142 AdblockPlus::FilterEngine* const engine =
143 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
144 JniShowNotificationCallback* const callback =
145 JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr);
146 AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback =
147 std::bind(&JniShowNotificationCallback::Callback, callback,
148 std::placeholders::_1);
149 try
150 {
151 engine->SetShowNotificationCallback(showNotificationCallback);
131 } 152 }
132 CATCH_THROW_AND_RETURN(env, 0); 153 CATCH_AND_THROW(env)
154 }
155
156 static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr)
157 {
158 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
159
160 try
161 {
162 engine->RemoveShowNotificationCallback();
163 }
164 CATCH_AND_THROW(env);
133 } 165 }
134 166
135 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr) 167 static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon g ptr)
136 { 168 {
137 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 169 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
138 170
139 try 171 try
140 { 172 {
141 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions(); 173 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedS ubscriptions();
142 174
(...skipping 28 matching lines...) Expand all
171 } 203 }
172 204
173 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, 205 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
174 jlong ptr, jlong callbackPtr) 206 jlong ptr, jlong callbackPtr)
175 { 207 {
176 AdblockPlus::FilterEngine* const engine = 208 AdblockPlus::FilterEngine* const engine =
177 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 209 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
178 JniUpdateAvailableCallback* const callback = 210 JniUpdateAvailableCallback* const callback =
179 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); 211 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
180 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback = 212 AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
181 std::tr1::bind(&JniUpdateAvailableCallback::Callback, callback, 213 std::bind(&JniUpdateAvailableCallback::Callback, callback,
182 std::tr1::placeholders::_1); 214 std::placeholders::_1);
183 try 215 try
184 { 216 {
185 engine->SetUpdateAvailableCallback(updateAvailableCallback); 217 engine->SetUpdateAvailableCallback(updateAvailableCallback);
186 } 218 }
187 CATCH_AND_THROW(env) 219 CATCH_AND_THROW(env)
188 } 220 }
189 221
190 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr) 222 static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo ng ptr)
191 { 223 {
192 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 224 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
193 225
194 try 226 try
195 { 227 {
196 engine->RemoveFilterChangeCallback(); 228 engine->RemoveFilterChangeCallback();
197 } 229 }
198 CATCH_AND_THROW(env) 230 CATCH_AND_THROW(env)
199 } 231 }
200 232
201 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz, 233 static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
202 jlong ptr, jlong filterPtr) 234 jlong ptr, jlong filterPtr)
203 { 235 {
204 AdblockPlus::FilterEngine* engine = 236 AdblockPlus::FilterEngine* engine =
205 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); 237 JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
206 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>( 238 JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
207 filterPtr); 239 filterPtr);
208 240
209 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback = 241 AdblockPlus::FilterEngine::FilterChangeCallback filterCallback =
210 std::tr1::bind(&JniFilterChangeCallback::Callback, callback, 242 std::bind(&JniFilterChangeCallback::Callback, callback,
211 std::tr1::placeholders::_1, std::tr1::placeholders::_2); 243 std::placeholders::_1, std::placeholders::_2);
212 244
213 try 245 try
214 { 246 {
215 engine->SetFilterChangeCallback(filterCallback); 247 engine->SetFilterChangeCallback(filterCallback);
216 } 248 }
217 CATCH_AND_THROW(env) 249 CATCH_AND_THROW(env)
218 } 250 }
219 251
220 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr) 252 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr)
221 { 253 {
222 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 254 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
223 JniUpdateCheckDoneCallback* callback = 255 JniUpdateCheckDoneCallback* callback =
224 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); 256 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
225 257
226 AdblockPlus::FilterEngine::UpdateCheckDoneCallback 258 AdblockPlus::FilterEngine::UpdateCheckDoneCallback
227 updateCheckDoneCallback = 0; 259 updateCheckDoneCallback = 0;
228 260
229 if (updaterPtr) 261 if (updaterPtr)
230 { 262 {
231 updateCheckDoneCallback = 263 updateCheckDoneCallback =
232 std::tr1::bind(&JniUpdateCheckDoneCallback::Callback, callback, 264 std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
233 std::tr1::placeholders::_1); 265 std::placeholders::_1);
234 } 266 }
235 267
236 try 268 try
237 { 269 {
238 engine->ForceUpdateCheck(updateCheckDoneCallback); 270 engine->ForceUpdateCheck(updateCheckDoneCallback);
239 } 271 }
240 CATCH_AND_THROW(env) 272 CATCH_AND_THROW(env)
241 } 273 }
242 274
243 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, 275 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 CATCH_AND_THROW(env) 379 CATCH_AND_THROW(env)
348 } 380 }
349 381
350 static JNINativeMethod methods[] = 382 static JNINativeMethod methods[] =
351 { 383 {
352 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, 384 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor },
353 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, 385 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun },
354 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, 386 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter },
355 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, 387 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters },
356 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, 388 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription },
357 { (char*)"getNextNotificationToShow", (char*)"(JLjava/lang/String;)" TYP("Noti fication"), (void*)JniGetNextNotificationToShow }, 389 { (char*)"showNextNotification", (char*)"(JLjava/lang/String;)V", (void*)JniSh owNextNotification },
390 { (char*)"setShowNotificationCallback", (char*)"(JJ)V", (void*)JniSetShowNotif icationCallback },
391 { (char*)"removeShowNotificationCallback", (char*)"(J)V", (void*)JniRemoveShow NotificationCallback },
358 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, 392 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions },
359 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, 393 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions },
360 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback }, 394 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai lableCallback },
361 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback }, 395 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat eAvailableCallback },
362 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, 396 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback },
363 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, 397 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback },
364 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, 398 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
365 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors }, 399 { (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 }, 400 { (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 }, 401 { (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 }, 402 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
369 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 403 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
370 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 404 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
371 }; 405 };
372 406
373 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) 407 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz)
374 { 408 {
375 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 409 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
376 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld