| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 16 matching lines...) Expand all Loading... | |
| 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, jobject callbackOb ject) |
| 35 : JniCallbackBase(env, callbackObject) | 35 : JniCallbackBase(env, callbackObject) |
| 36 { | 36 { |
| 37 jsValueClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JsV alue")))); | |
|
Felix Dahlke
2014/04/16 15:24:25
Should be initialised in the initialisation list.
René Jeschke
2014/04/16 17:51:47
Done.
| |
| 37 } | 38 } |
| 38 | 39 |
| 39 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus ::JsValuePtr jsValue) | 40 void JniFilterChangeCallback::Callback(const std::string& arg, const AdblockPlus ::JsValuePtr jsValue) |
| 40 { | 41 { |
| 41 JNIEnvAcquire env(GetJavaVM()); | 42 JNIEnvAcquire env(GetJavaVM()); |
| 42 | 43 |
| 43 jclass clazz = env->GetObjectClass(GetCallbackObject()); | 44 jclass clazz = env->GetObjectClass(GetCallbackObject()); |
| 44 jmethodID method = env->GetMethodID(clazz, "filterChangeCallback", "(Ljava/lan g/String;" TYP("JsValue") ")V"); | 45 jmethodID method = env->GetMethodID(clazz, "filterChangeCallback", "(Ljava/lan g/String;" TYP("JsValue") ")V"); |
| 45 | 46 |
| 46 if (method) | 47 if (method) |
| 47 { | 48 { |
| 48 jstring jArg = env->NewStringUTF(arg.c_str()); | 49 jstring jArg = env->NewStringUTF(arg.c_str()); |
| 49 jobject jJsValue = NewJniJsValue(*env, jsValue); | 50 jobject jJsValue = NewJniJsValue(*env, jsValue, jsValueClass->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 |