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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, jobject callbackOb
ject) | 34 JniFilterChangeCallback::JniFilterChangeCallback(JNIEnv* env, jobject callbackOb
ject) |
35 : JniCallbackBase(env, callbackObject), jsValueClass(new JniGlobalReference<jc
lass>(env, env->FindClass(PKG("JsValue")))) | 35 : JniCallbackBase(env, callbackObject), jsValueClass(new JniGlobalReference<jc
lass>(env, env->FindClass(PKG("JsValue")))) |
36 { | 36 { |
37 } | 37 } |
38 | 38 |
39 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus
::JsValuePtr jsValue) | 39 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus
::JsValuePtr jsValue) |
40 { | 40 { |
41 JNIEnvAcquire env(GetJavaVM()); | 41 JNIEnvAcquire env(GetJavaVM()); |
42 | 42 |
43 jclass clazz = env->GetObjectClass(GetCallbackObject()); | 43 jmethodID method = env->GetMethodID( |
44 jmethodID method = env->GetMethodID(clazz, "filterChangeCallback", "(Ljava/lan
g/String;" TYP("JsValue") ")V"); | 44 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject()))
, |
| 45 "filterChangeCallback", "(Ljava/lang/String;" TYP("JsValue") ")V"); |
45 | 46 |
46 if (method) | 47 if (method) |
47 { | 48 { |
48 jstring jArg = env->NewStringUTF(arg.c_str()); | 49 JniLocalReference<jstring> jArg(*env, env->NewStringUTF(arg.c_str())); |
49 jobject jJsValue = NewJniJsValue(*env, jsValue, jsValueClass->Get()); | 50 JniLocalReference<jobject> jJsValue(*env, NewJniJsValue(*env, jsValue, jsVal
ueClass->Get())); |
50 env->CallVoidMethod(GetCallbackObject(), method, jArg, jJsValue); | 51 env->CallVoidMethod(GetCallbackObject(), method, *jArg, *jJsValue); |
51 } | 52 } |
52 | 53 |
53 CheckAndLogJavaException(*env); | 54 CheckAndLogJavaException(*env); |
54 } | 55 } |
55 | 56 |
56 static JNINativeMethod methods[] = | 57 static JNINativeMethod methods[] = |
57 { | 58 { |
58 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 59 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
59 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 60 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
60 }; | 61 }; |
61 | 62 |
62 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan
geCallback_registerNatives(JNIEnv *env, jclass clazz) | 63 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FilterChan
geCallback_registerNatives(JNIEnv *env, jclass clazz) |
63 { | 64 { |
64 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 65 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
65 } | 66 } |
OLD | NEW |