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

Side by Side Diff: jni/JniFilterEngine.cpp

Issue 6245218638626816: Issue 1424 - Update libadblockplus-binaries to 6f79af14ad4e (Closed)
Patch Set: Created Sept. 22, 2014, 4:44 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
« no previous file with comments | « jni/JniCallbacks.h ('k') | jni/JniUpdateCheckDoneCallback.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 13 matching lines...) Expand all
24 jobject list = NewJniArrayList(env); 24 jobject list = NewJniArrayList(env);
25 25
26 for (std::vector<AdblockPlus::SubscriptionPtr>::iterator it = subscriptions.be gin(), end = subscriptions.end(); it != end; it++) 26 for (std::vector<AdblockPlus::SubscriptionPtr>::iterator it = subscriptions.be gin(), end = subscriptions.end(); it != end; it++)
27 { 27 {
28 JniAddObjectToList(env, list, NewJniSubscription(env, *it)); 28 JniAddObjectToList(env, list, NewJniSubscription(env, *it));
29 } 29 }
30 30
31 return list; 31 return list;
32 } 32 }
33 33
34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
35 jobject jContentType)
36 {
37 jclass enumClass = env->FindClass("java/lang/Enum");
René Jeschke 2014/09/22 12:56:26 Could you please use "env->GetObjectClass(jContent
Felix Dahlke 2014/09/22 13:20:16 Done.
38 jmethodID nameMethod = env->GetMethodID(enumClass, "name",
René Jeschke 2014/09/22 12:56:26 Is this line break really necessary?
Felix Dahlke 2014/09/22 13:20:16 IMO yes - we have an 80 column rule in C++ code af
René Jeschke 2014/09/22 13:30:06 Ah, right. The Android project can be confusing wh
39 "()Ljava/lang/String;");
40 jstring jValue = (jstring) env->CallObjectMethod(jContentType, nameMethod);
41 const std::string value = JniJavaToStdString(env, jValue);
42 return AdblockPlus::FilterEngine::StringToContentType(value);
43 }
44
34 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) 45 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr)
35 { 46 {
36 try 47 try
37 { 48 {
38 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(enginePtr); 49 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(enginePtr);
39 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); 50 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine));
40 } 51 }
41 CATCH_THROW_AND_RETURN(env, 0) 52 CATCH_THROW_AND_RETURN(env, 0)
42 } 53 }
43 54
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 try 164 try
154 { 165 {
155 engine->SetFilterChangeCallback(filterCallback); 166 engine->SetFilterChangeCallback(filterCallback);
156 } 167 }
157 CATCH_AND_THROW(env) 168 CATCH_AND_THROW(env)
158 } 169 }
159 170
160 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr) 171 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl ong updaterPtr)
161 { 172 {
162 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 173 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
163 JniUpdaterCallback* callback = JniLongToTypePtr<JniUpdaterCallback>(updaterPtr ); 174 JniUpdateCheckDoneCallback* callback =
René Jeschke 2014/09/22 12:56:26 Are those new line breaks really needed? (See also
Felix Dahlke 2014/09/22 13:20:16 IMO yes, see above.
175 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
164 176
165 AdblockPlus::FilterEngine::UpdaterCallback updaterCallback = 0; 177 AdblockPlus::FilterEngine::UpdateCheckDoneCallback
178 updateCheckDoneCallback = 0;
166 179
167 if (updaterPtr) 180 if (updaterPtr)
168 { 181 {
169 updaterCallback = std::tr1::bind(&JniUpdaterCallback::Callback, callback, st d::tr1::placeholders::_1); 182 updateCheckDoneCallback =
183 std::tr1::bind(&JniUpdateCheckDoneCallback::Callback, callback,
184 std::tr1::placeholders::_1);
170 } 185 }
171 186
172 try 187 try
173 { 188 {
174 engine->ForceUpdateCheck(updaterCallback); 189 engine->ForceUpdateCheck(updateCheckDoneCallback);
175 } 190 }
176 CATCH_AND_THROW(env) 191 CATCH_AND_THROW(env)
177 } 192 }
178 193
179 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, j long ptr, jstring jDomain) 194 static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz, j long ptr, jstring jDomain)
180 { 195 {
181 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 196 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
182 197
183 std::string domain = JniJavaToStdString(env, jDomain); 198 std::string domain = JniJavaToStdString(env, jDomain);
184 199
185 try 200 try
186 { 201 {
187 std::vector<std::string> selectors = engine->GetElementHidingSelectors(domai n); 202 std::vector<std::string> selectors = engine->GetElementHidingSelectors(domai n);
188 203
189 jobject list = NewJniArrayList(env); 204 jobject list = NewJniArrayList(env);
190 205
191 for (std::vector<std::string>::iterator it = selectors.begin(), end = select ors.end(); it != end; it++) 206 for (std::vector<std::string>::iterator it = selectors.begin(), end = select ors.end(); it != end; it++)
192 { 207 {
193 JniAddObjectToList(env, list, env->NewStringUTF(it->c_str())); 208 JniAddObjectToList(env, list, env->NewStringUTF(it->c_str()));
194 } 209 }
195 210
196 return list; 211 return list;
197 } 212 }
198 CATCH_THROW_AND_RETURN(env, 0) 213 CATCH_THROW_AND_RETURN(env, 0)
199 } 214 }
200 215
201 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jstring jContentType, jstring jDocumentUrl) 216 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl)
202 { 217 {
203 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 218 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
204 219
205 std::string url = JniJavaToStdString(env, jUrl); 220 std::string url = JniJavaToStdString(env, jUrl);
206 std::string contentType = JniJavaToStdString(env, jContentType); 221 AdblockPlus::FilterEngine::ContentType contentType =
222 ConvertContentType(env, jContentType);
207 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl); 223 std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
208 224
209 try 225 try
210 { 226 {
211 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l); 227 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr l);
212 228
213 return NewJniFilter(env, filter); 229 return NewJniFilter(env, filter);
214 } 230 }
215 CATCH_THROW_AND_RETURN(env, 0) 231 CATCH_THROW_AND_RETURN(env, 0)
216 } 232 }
217 233
218 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstr ing jUrl, jstring jContentType, jobjectArray jDocumentUrls) 234 static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstr ing jUrl, jobject jContentType, jobjectArray jDocumentUrls)
219 { 235 {
220 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 236 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
221 237
222 std::string url = JniJavaToStdString(env, jUrl); 238 std::string url = JniJavaToStdString(env, jUrl);
223 std::string contentType = JniJavaToStdString(env, jContentType); 239 AdblockPlus::FilterEngine::ContentType contentType =
240 ConvertContentType(env, jContentType);
224 241
225 std::vector<std::string> documentUrls; 242 std::vector<std::string> documentUrls;
226 243
227 jsize len = env->GetArrayLength(jDocumentUrls); 244 jsize len = env->GetArrayLength(jDocumentUrls);
228 245
229 for (jsize i = 0; i < len; i++) 246 for (jsize i = 0; i < len; i++)
230 { 247 {
231 documentUrls.push_back(JniJavaToStdString(env, static_cast<jstring>(env->Get ObjectArrayElement(jDocumentUrls, i)))); 248 documentUrls.push_back(JniJavaToStdString(env, static_cast<jstring>(env->Get ObjectArrayElement(jDocumentUrls, i))));
232 } 249 }
233 250
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, 292 { (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun },
276 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter }, 293 { (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)Jni GetFilter },
277 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters }, 294 { (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListed Filters },
278 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription }, 295 { (char*)"getSubscription", (char*)"(JLjava/lang/String;)" TYP("Subscription") , (void*)JniGetSubscription },
279 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions }, 296 { (char*)"getListedSubscriptions", (char*)"(J)Ljava/util/List;", (void*)JniGet ListedSubscriptions },
280 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions }, 297 { (char*)"fetchAvailableSubscriptions", (char*)"(J)Ljava/util/List;", (void*)J niFetchAvailableSubscriptions },
281 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback }, 298 { (char*)"setFilterChangeCallback", (char*)"(JJ)V", (void*)JniSetFilterChangeC allback },
282 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback }, 299 { (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterCh angeCallback },
283 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, 300 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
284 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors }, 301 { (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/ List;", (void*)JniGetElementHidingSelectors },
285 { (char*)"matches", (char*)"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/S tring;)" TYP("Filter"), (void*)JniMatches }, 302 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
286 { (char*)"matches", (char*)"(JLjava/lang/String;Ljava/lang/String;[Ljava/lang/ String;)" TYP("Filter"), (void*)JniMatchesMany }, 303 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
287 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, 304 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
288 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 305 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
289 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 306 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
290 }; 307 };
291 308
292 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) 309 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz)
293 { 310 {
294 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 311 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
295 } 312 }
OLDNEW
« no previous file with comments | « jni/JniCallbacks.h ('k') | jni/JniUpdateCheckDoneCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld