Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android/jni/JniIsAllowedConnectionTypeCallback.cpp

Issue 29533572: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created Sept. 1, 2017, 9:41 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 "JniCallbacks.h" 18 #include "JniCallbacks.h"
19 #include "Utils.h" 19 #include "Utils.h"
20 20
21 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
22 {
23 try
24 {
25 JniIsAllowedConnectionTypeCallback* callback =
26 new JniIsAllowedConnectionTypeCallback(env, callbackObject);
27
28 return JniPtrToLong(callback);
29 }
30 CATCH_THROW_AND_RETURN(env, 0)
31 }
32
33 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
34 {
35 delete JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(ptr);
36 }
37
38 JniIsAllowedConnectionTypeCallback::JniIsAllowedConnectionTypeCallback(JNIEnv* e nv, 21 JniIsAllowedConnectionTypeCallback::JniIsAllowedConnectionTypeCallback(JNIEnv* e nv,
39 jobject callbackObject) 22 jobject callbackObject)
40 : JniCallbackBase(env, callbackObject) 23 : JniCallbackBase(env, callbackObject)
41 { 24 {
42 } 25 }
43 26
44 bool JniIsAllowedConnectionTypeCallback::Callback(const std::string* allowedConn ectionType) 27 bool JniIsAllowedConnectionTypeCallback::Callback(const std::string* allowedConn ectionType)
45 { 28 {
46 JNIEnvAcquire env(GetJavaVM()); 29 JNIEnvAcquire env(GetJavaVM());
47 30
48 jmethodID method = env->GetMethodID( 31 jmethodID method = env->GetMethodID(
49 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())) , 32 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())) ,
50 "isConnectionAllowed", 33 "isConnectionAllowed",
51 "(Ljava/lang/String;)Z"); 34 "(Ljava/lang/String;)Z");
52 35
53 jstring jAllowedConnectionType = 36 jstring jAllowedConnectionType =
54 (allowedConnectionType != NULL 37 (allowedConnectionType != NULL
55 ? JniStdStringToJava(*env, *allowedConnectionType) 38 ? JniStdStringToJava(*env, *allowedConnectionType)
56 : NULL); 39 : NULL);
57 bool result = env->CallBooleanMethod(GetCallbackObject(), method, jAllowedConn ectionType); 40 bool result = env->CallBooleanMethod(GetCallbackObject(), method, jAllowedConn ectionType);
58 41
59 CheckAndLogJavaException(*env); 42 CheckAndLogJavaException(*env);
60 return result; 43 return result;
61 } 44 }
62
63 static JNINativeMethod methods[] =
64 {
65 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
66 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
67 };
68
69 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_IsAllowedC onnectionCallback_registerNatives(JNIEnv *env, jclass clazz)
70 {
71 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld