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

Side by Side Diff: jni/JniFilterChangeCallback.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: More formatting issues Created Feb. 4, 2015, 12:03 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/JniFilter.cpp ('k') | jni/JniFilterEngine.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 13 matching lines...) Expand all
24 return JniPtrToLong(new JniFilterChangeCallback(env, callbackObject)); 24 return JniPtrToLong(new JniFilterChangeCallback(env, callbackObject));
25 } 25 }
26 CATCH_THROW_AND_RETURN(env, 0) 26 CATCH_THROW_AND_RETURN(env, 0)
27 } 27 }
28 28
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
30 { 30 {
31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr); 31 delete JniLongToTypePtr<JniFilterChangeCallback>(ptr);
32 } 32 }
33 33
34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, jobject callbackOb ject) 34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env,
35 : JniCallbackBase(env, callbackObject), jsValueClass(new JniGlobalReference<jc lass>(env, env->FindClass(PKG("JsValue")))) 35 jobject callbackObject)
36 : JniCallbackBase(env, callbackObject), jsValueClass(
37 new JniGlobalReference<jclass>(env, env->FindClass(PKG("JsValue"))))
36 { 38 {
37 } 39 }
38 40
39 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus ::JsValuePtr jsValue) 41 void JniFilterChangeCallback::Callback(const std::string& arg,
42 const AdblockPlus::JsValuePtr jsValue)
40 { 43 {
41 JNIEnvAcquire env(GetJavaVM()); 44 JNIEnvAcquire env(GetJavaVM());
42 45
43 jclass clazz = env->GetObjectClass(GetCallbackObject()); 46 jmethodID method = env->GetMethodID(
44 jmethodID method = env->GetMethodID(clazz, "filterChangeCallback", "(Ljava/lan g/String;" TYP("JsValue") ")V"); 47 *JniLocalReference<jclass>(*env,
48 env->GetObjectClass(GetCallbackObject())),
49 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V");
45 50
46 if (method) 51 if (method)
47 { 52 {
48 jstring jArg = env->NewStringUTF(arg.c_str()); 53 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str()));
49 jobject jJsValue = NewJniJsValue(*env, jsValue, jsValueClass->Get()); 54 JniLocalReference<jobject> jJsValue(*env,
50 env->CallVoidMethod(GetCallbackObject(), method, jArg, jJsValue); 55 NewJniJsValue(*env, jsValue, jsValueClass->Get()));
56 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue);
51 } 57 }
52 58
53 CheckAndLogJavaException(*env); 59 CheckAndLogJavaException(*env);
54 } 60 }
55 61
56 static JNINativeMethod methods[] = 62 static JNINativeMethod methods[] =
57 { 63 {
58 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 64 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
59 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 65 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
60 }; 66 };
61 67
62 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan geCallback_registerNatives(JNIEnv *env, jclass clazz) 68 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan geCallback_registerNatives(JNIEnv *env, jclass clazz)
63 { 69 {
64 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 70 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
65 } 71 }
OLDNEW
« no previous file with comments | « jni/JniFilter.cpp ('k') | jni/JniFilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld