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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
19 #include "Utils.h" | 19 #include "Utils.h" |
20 #include "JniCallbacks.h" | 20 #include "JniCallbacks.h" |
21 | 21 |
22 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo
& appInfo) | 22 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo
& appInfo) |
23 { | 23 { |
24 jclass clazz = env->GetObjectClass(jAppInfo); | 24 jclass clazz = env->GetObjectClass(jAppInfo); |
25 | 25 |
26 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); | 26 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); |
27 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat
ionVersion"); | 27 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat
ionVersion"); |
28 appInfo.id = JniGetStringField(env, clazz, jAppInfo, "id"); | |
29 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); | 28 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); |
30 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); | 29 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); |
31 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); | 30 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); |
32 | 31 |
33 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); | 32 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); |
34 } | 33 } |
35 | 34 |
36 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) | 35 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) |
37 { | 36 { |
38 AdblockPlus::AppInfo appInfo; | 37 AdblockPlus::AppInfo appInfo; |
(...skipping 11 matching lines...) Expand all Loading... |
50 { | 49 { |
51 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); | 50 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
52 } | 51 } |
53 | 52 |
54 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js
tring jEventName, jlong jCallbackPtr) | 53 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js
tring jEventName, jlong jCallbackPtr) |
55 { | 54 { |
56 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>
(ptr); | 55 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>
(ptr); |
57 | 56 |
58 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); | 57 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); |
59 std::string eventName = JniJavaToStdString(env, jEventName); | 58 std::string eventName = JniJavaToStdString(env, jEventName); |
60 AdblockPlus::JsEngine::EventCallback eCallback = std::tr1::bind(&JniEventCallb
ack::Callback, callback, std::tr1::placeholders::_1); | 59 AdblockPlus::JsEngine::EventCallback eCallback = std::bind(&JniEventCallback::
Callback, callback, std::placeholders::_1); |
61 | 60 |
62 try | 61 try |
63 { | 62 { |
64 engine->SetEventCallback(eventName, eCallback); | 63 engine->SetEventCallback(eventName, eCallback); |
65 } | 64 } |
66 CATCH_AND_THROW(env) | 65 CATCH_AND_THROW(env) |
67 } | 66 } |
68 | 67 |
69 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr,
jstring jEventName) | 68 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr,
jstring jEventName) |
70 { | 69 { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 250 |
252 { (char*)"newValue", (char*)"(JJ)"TYP("JsValue"), (void*)JniNewLongValue }, | 251 { (char*)"newValue", (char*)"(JJ)"TYP("JsValue"), (void*)JniNewLongValue }, |
253 { (char*)"newValue", (char*)"(JZ)"TYP("JsValue"), (void*)JniNewBooleanValue }, | 252 { (char*)"newValue", (char*)"(JZ)"TYP("JsValue"), (void*)JniNewBooleanValue }, |
254 { (char*)"newValue", (char*)"(JLjava/lang/String;)"TYP("JsValue"), (void*)JniN
ewStringValue } | 253 { (char*)"newValue", (char*)"(JLjava/lang/String;)"TYP("JsValue"), (void*)JniN
ewStringValue } |
255 }; | 254 }; |
256 | 255 |
257 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) | 256 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) |
258 { | 257 { |
259 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 258 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
260 } | 259 } |
OLD | NEW |