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