OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 #include <AdblockPlus.h> |
| 19 #include "Utils.h" |
| 20 #include "JniCallbacks.h" |
| 21 #include <thread> |
| 22 #include "JniPlatform.h" |
| 23 |
| 24 namespace |
| 25 { |
| 26 AdblockPlus::Updater& GetUpdaterRef(jlong jniPlatformPtr) |
| 27 { |
| 28 return JniLongToTypePtr<JniPlatform>(jniPlatformPtr)->platform->GetUpdater()
; |
| 29 } |
| 30 } |
| 31 |
| 32 static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz, |
| 33 jlong ptr) |
| 34 { |
| 35 AdblockPlus::Updater& engine = GetUpdaterRef(ptr); |
| 36 try |
| 37 { |
| 38 engine.RemoveUpdateAvailableCallback(); |
| 39 } |
| 40 CATCH_AND_THROW(env) |
| 41 } |
| 42 |
| 43 static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz, |
| 44 jlong ptr, jlong callbackPtr) |
| 45 { |
| 46 AdblockPlus::Updater& updater = GetUpdaterRef(ptr); |
| 47 JniUpdateAvailableCallback* const callback = |
| 48 JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr); |
| 49 |
| 50 const AdblockPlus::Updater::UpdateAvailableCallback updateAvailableCallback = |
| 51 std::bind(&JniUpdateAvailableCallback::Callback, callback, |
| 52 std::placeholders::_1); |
| 53 try |
| 54 { |
| 55 updater.SetUpdateAvailableCallback(updateAvailableCallback); |
| 56 } |
| 57 CATCH_AND_THROW(env) |
| 58 } |
| 59 |
| 60 static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
ong updaterPtr) |
| 61 { |
| 62 AdblockPlus::Updater& updater = GetUpdaterRef(ptr); |
| 63 JniUpdateCheckDoneCallback* callback = |
| 64 JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr); |
| 65 |
| 66 AdblockPlus::Updater::UpdateCheckDoneCallback |
| 67 updateCheckDoneCallback = 0; |
| 68 |
| 69 if (updaterPtr) |
| 70 { |
| 71 updateCheckDoneCallback = |
| 72 std::bind(&JniUpdateCheckDoneCallback::Callback, callback, |
| 73 std::placeholders::_1); |
| 74 } |
| 75 |
| 76 try |
| 77 { |
| 78 updater.ForceUpdateCheck(updateCheckDoneCallback); |
| 79 } |
| 80 CATCH_AND_THROW(env) |
| 81 } |
| 82 |
| 83 static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring
jPref) |
| 84 { |
| 85 AdblockPlus::Updater& updater = GetUpdaterRef(ptr); |
| 86 |
| 87 std::string pref = JniJavaToStdString(env, jPref); |
| 88 |
| 89 try |
| 90 { |
| 91 return NewJniJsValue(env, updater.GetPref(pref)); |
| 92 } |
| 93 CATCH_THROW_AND_RETURN(env, 0) |
| 94 } |
| 95 |
| 96 static void JNICALL JniSetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPr
ef, jlong jsValue) |
| 97 { |
| 98 AdblockPlus::Updater& updater = GetUpdaterRef(ptr); |
| 99 |
| 100 std::string pref = JniJavaToStdString(env, jPref); |
| 101 const AdblockPlus::JsValue& value = JniGetJsValue(jsValue); |
| 102 |
| 103 try |
| 104 { |
| 105 updater.SetPref(pref, value); |
| 106 } |
| 107 CATCH_AND_THROW(env) |
| 108 } |
| 109 |
| 110 static JNINativeMethod methods[] = |
| 111 { |
| 112 { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvai
lableCallback }, |
| 113 { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdat
eAvailableCallback }, |
| 114 { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck }, |
| 115 { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniG
etPref }, |
| 116 { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref } |
| 117 }; |
| 118 |
| 119 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Updater_re
gisterNatives(JNIEnv *env, jclass clazz) |
| 120 { |
| 121 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 122 } |
OLD | NEW |