| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 } | 61 } |
| 62 | 62 |
| 63 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) | 63 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) |
| 64 { | 64 { |
| 65 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan g/Object;)Z"); | 65 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan g/Object;)Z"); |
| 66 env->CallBooleanMethod(list, add, value); | 66 env->CallBooleanMethod(list, add, value); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void JniThrowException(JNIEnv* env, const std::string& message) | 69 void JniThrowException(JNIEnv* env, const std::string& message) |
| 70 { | 70 { |
| 71 jclass clazz = env->FindClass(PKG("AdblockPlusException")); | 71 jclass clazz = env->FindClass(PKG("AdblockPlusException")); |
|
Felix Dahlke
2014/03/28 17:28:41
We're only using AdblockPlusException for native e
René Jeschke
2014/03/31 09:10:38
I would also like to use the "AdblockPlusException
Felix Dahlke
2014/03/31 10:43:23
Alright.
René Jeschke
2014/04/11 12:25:53
Done.
| |
| 72 env->ThrowNew(clazz, message.c_str()); | 72 env->ThrowNew(clazz, message.c_str()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void JniThrowException(JNIEnv* env, const std::exception& e) | 75 void JniThrowException(JNIEnv* env, const std::exception& e) |
| 76 { | 76 { |
| 77 JniThrowException(env, e.what()); | 77 JniThrowException(env, e.what()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void JniThrowException(JNIEnv* env) | 80 void JniThrowException(JNIEnv* env) |
| 81 { | 81 { |
| 82 JniThrowException(env, "Unknown exception from libAdblockPlus"); | 82 JniThrowException(env, "Unknown exception from libadblockplus"); |
|
Felix Dahlke
2014/03/28 17:28:41
We usually call it "libadblockplus".
René Jeschke
2014/04/11 12:25:53
Done.
| |
| 83 } | 83 } |
| 84 | 84 |
| 85 JNIEnvAcquire::JNIEnvAcquire(JavaVM* javaVM) | 85 JNIEnvAcquire::JNIEnvAcquire(JavaVM* javaVM) |
| 86 : javaVM(javaVM), jniEnv(0), attachmentStatus(0) | 86 : javaVM(javaVM), jniEnv(0), attachmentStatus(0) |
| 87 { | 87 { |
| 88 attachmentStatus = javaVM->GetEnv((void **)&jniEnv, ABP_JNI_VERSION); | 88 attachmentStatus = javaVM->GetEnv((void **)&jniEnv, ABP_JNI_VERSION); |
| 89 if (attachmentStatus == JNI_EDETACHED) | 89 if (attachmentStatus == JNI_EDETACHED) |
| 90 { | 90 { |
| 91 if (javaVM->AttachCurrentThread(&jniEnv, 0)) | 91 if (javaVM->AttachCurrentThread(&jniEnv, 0)) |
| 92 { | 92 { |
| 93 // This one is FATAL, we can't recover from this (because without a JVM we 're dead), so | 93 // This one is FATAL, we can't recover from this (because without a JVM we 're dead), so |
| 94 // throwing a runtime_exception in a ctor can be tolerated here IMHO | 94 // throwing a runtime_exception in a ctor can be tolerated here IMHO |
|
Felix Dahlke
2014/03/28 17:28:41
Throwing a std::runtime_error from a constructor i
René Jeschke
2014/03/31 09:10:38
When using 'new' and exceptions from the ctor you
Felix Dahlke
2014/03/31 10:43:23
Are we talking about C++ constructors? I'm absolut
René Jeschke
2014/04/11 12:25:53
Done.
| |
| 95 throw std::runtime_error("Failed to get JNI environment"); | 95 throw std::runtime_error("Failed to get JNI environment"); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 JNIEnvAcquire::~JNIEnvAcquire() | 100 JNIEnvAcquire::~JNIEnvAcquire() |
| 101 { | 101 { |
| 102 if (attachmentStatus == JNI_EDETACHED) | 102 if (attachmentStatus == JNI_EDETACHED) |
| 103 { | 103 { |
| 104 javaVM->DetachCurrentThread(); | 104 javaVM->DetachCurrentThread(); |
| 105 } | 105 } |
| 106 } | 106 } |
| LEFT | RIGHT |