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

Side by Side Diff: jni/JniFilterEngine.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Removed a Log.d Created Jan. 22, 2015, 6:56 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
« no previous file with comments | « jni/JniFilterChangeCallback.cpp ('k') | jni/JniJsValue.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 <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 16 matching lines...) Expand all
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, 34 static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
35 jobject jContentType) 35 jobject jContentType)
36 { 36 {
37 jclass contentTypeClass = env->GetObjectClass(jContentType); 37 JniLocalReference<jclass> contentTypeClass(env, env->GetObjectClass(jContentTy pe));
38 jmethodID nameMethod = env->GetMethodID(contentTypeClass, "name", 38 jmethodID nameMethod = env->GetMethodID(*contentTypeClass, "name",
39 "()Ljava/lang/String;"); 39 "()Ljava/lang/String;");
40 jstring jValue = (jstring) env->CallObjectMethod(jContentType, nameMethod); 40 JniLocalReference<jstring> jValue(env, (jstring) env->CallObjectMethod(jConten tType, nameMethod));
41 const std::string value = JniJavaToStdString(env, jValue); 41 const std::string value = JniJavaToStdString(env, *jValue);
42 return AdblockPlus::FilterEngine::StringToContentType(value); 42 return AdblockPlus::FilterEngine::StringToContentType(value);
43 } 43 }
44 44
45 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) 45 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr)
46 { 46 {
47 try 47 try
48 { 48 {
49 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(enginePtr); 49 AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEngine Ptr>(enginePtr);
50 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); 50 return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine));
51 } 51 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 87 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
88 88
89 try 89 try
90 { 90 {
91 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters(); 91 std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters();
92 92
93 jobject list = NewJniArrayList(env); 93 jobject list = NewJniArrayList(env);
94 94
95 for (std::vector<AdblockPlus::FilterPtr>::iterator it = filters.begin(), end = filters.end(); it != end; it++) 95 for (std::vector<AdblockPlus::FilterPtr>::iterator it = filters.begin(), end = filters.end(); it != end; it++)
96 { 96 {
97 JniAddObjectToList(env, list, NewJniFilter(env, *it)); 97 JniAddObjectToList(env, list, *JniLocalReference<jobject>(env, NewJniFilte r(env, *it)));
98 } 98 }
99 99
100 return list; 100 return list;
101 } 101 }
102 CATCH_THROW_AND_RETURN(env, 0); 102 CATCH_THROW_AND_RETURN(env, 0);
103 } 103 }
104 104
105 static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl) 105 static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl)
106 { 106 {
107 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 107 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 std::string domain = JniJavaToStdString(env, jDomain); 227 std::string domain = JniJavaToStdString(env, jDomain);
228 228
229 try 229 try
230 { 230 {
231 std::vector<std::string> selectors = engine->GetElementHidingSelectors(domai n); 231 std::vector<std::string> selectors = engine->GetElementHidingSelectors(domai n);
232 232
233 jobject list = NewJniArrayList(env); 233 jobject list = NewJniArrayList(env);
234 234
235 for (std::vector<std::string>::iterator it = selectors.begin(), end = select ors.end(); it != end; it++) 235 for (std::vector<std::string>::iterator it = selectors.begin(), end = select ors.end(); it != end; it++)
236 { 236 {
237 JniAddObjectToList(env, list, env->NewStringUTF(it->c_str())); 237 JniAddObjectToList(env, list, *JniLocalReference<jstring>(env, env->NewStr ingUTF(it->c_str())));
238 } 238 }
239 239
240 return list; 240 return list;
241 } 241 }
242 CATCH_THROW_AND_RETURN(env, 0) 242 CATCH_THROW_AND_RETURN(env, 0)
243 } 243 }
244 244
245 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl) 245 static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl)
246 { 246 {
247 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr); 247 AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine >(ptr);
(...skipping 19 matching lines...) Expand all
267 std::string url = JniJavaToStdString(env, jUrl); 267 std::string url = JniJavaToStdString(env, jUrl);
268 AdblockPlus::FilterEngine::ContentType contentType = 268 AdblockPlus::FilterEngine::ContentType contentType =
269 ConvertContentType(env, jContentType); 269 ConvertContentType(env, jContentType);
270 270
271 std::vector<std::string> documentUrls; 271 std::vector<std::string> documentUrls;
272 272
273 jsize len = env->GetArrayLength(jDocumentUrls); 273 jsize len = env->GetArrayLength(jDocumentUrls);
274 274
275 for (jsize i = 0; i < len; i++) 275 for (jsize i = 0; i < len; i++)
276 { 276 {
277 documentUrls.push_back(JniJavaToStdString(env, static_cast<jstring>(env->Get ObjectArrayElement(jDocumentUrls, i)))); 277 documentUrls.push_back(JniJavaToStdString(env,
278 *JniLocalReference<jstring>(env, static_cast<jstring>(env->GetObjectArra yElement(jDocumentUrls, i)))));
278 } 279 }
279 280
280 try 281 try
281 { 282 {
282 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr ls); 283 AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUr ls);
283 284
284 return NewJniFilter(env, filter); 285 return NewJniFilter(env, filter);
285 } 286 }
286 CATCH_THROW_AND_RETURN(env, 0) 287 CATCH_THROW_AND_RETURN(env, 0)
287 } 288 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany }, 335 { (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentTyp e") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
335 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref }, 336 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG etPref },
336 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, 337 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
337 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 338 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
338 }; 339 };
339 340
340 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz) 341 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterEngi ne_registerNatives(JNIEnv *env, jclass clazz)
341 { 342 {
342 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 343 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
343 } 344 }
OLDNEW
« no previous file with comments | « jni/JniFilterChangeCallback.cpp ('k') | jni/JniJsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld