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

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

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
Patch Set: updated dependencies (..-binaries) Created May 3, 2017, 2:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus-android/jni/JniFilterEngine.cpp ('k') | libadblockplus-android/jni/JniJsValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 { 49 {
50 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); 50 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
51 } 51 }
52 52
53 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)
54 { 54 {
55 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 55 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
56 56
57 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); 57 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr);
58 std::string eventName = JniJavaToStdString(env, jEventName); 58 std::string eventName = JniJavaToStdString(env, jEventName);
59 AdblockPlus::JsEngine::EventCallback eCallback = std::bind(&JniEventCallback:: Callback, callback, std::placeholders::_1); 59 AdblockPlus::JsEngine::EventCallback eCallback =
60 std::bind(&JniEventCallback::Callback, callback, std::placeholders::_1);
60 61
61 try 62 try
62 { 63 {
63 engine->SetEventCallback(eventName, eCallback); 64 engine->SetEventCallback(eventName, eCallback);
64 } 65 }
65 CATCH_AND_THROW(env) 66 CATCH_AND_THROW(env)
66 } 67 }
67 68
68 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName) 69 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName)
69 { 70 {
(...skipping 10 matching lines...) Expand all
80 81
81 static jobject JNICALL JniEvaluate(JNIEnv* env, jclass clazz, jlong ptr, jstring jSource, jstring jFilename) 82 static jobject JNICALL JniEvaluate(JNIEnv* env, jclass clazz, jlong ptr, jstring jSource, jstring jFilename)
82 { 83 {
83 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 84 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
84 85
85 std::string source = JniJavaToStdString(env, jSource); 86 std::string source = JniJavaToStdString(env, jSource);
86 std::string filename = JniJavaToStdString(env, jFilename); 87 std::string filename = JniJavaToStdString(env, jFilename);
87 88
88 try 89 try
89 { 90 {
90 AdblockPlus::JsValuePtr jsValue = engine->Evaluate(source, filename); 91 return NewJniJsValue(env, engine->Evaluate(source, filename));
91 return NewJniJsValue(env, jsValue);
92 } 92 }
93 CATCH_THROW_AND_RETURN(env, 0) 93 CATCH_THROW_AND_RETURN(env, 0)
94 } 94 }
95 95
96 static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstrin g jEventName, jarray jJsPtrs) 96 static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstrin g jEventName, jarray jJsPtrs)
97 { 97 {
98 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 98 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
99 std::string eventName = JniJavaToStdString(env, jEventName); 99 std::string eventName = JniJavaToStdString(env, jEventName);
100 AdblockPlus::JsValueList args; 100 AdblockPlus::JsValueList args;
101 101
102 if (jJsPtrs) 102 if (jJsPtrs)
103 { 103 {
104 jlong* ptrs = (jlong*)env->GetPrimitiveArrayCritical(jJsPtrs, 0); 104 jlong* ptrs = (jlong*)env->GetPrimitiveArrayCritical(jJsPtrs, 0);
105 105
106 jsize length = env->GetArrayLength(jJsPtrs); 106 jsize length = env->GetArrayLength(jJsPtrs);
107 107
108 for (jsize i = 0; i < length; i++) 108 for (jsize i = 0; i < length; i++)
109 { 109 {
110 args.push_back(JniGetJsValuePtr(ptrs[i])); 110 args.push_back(JniGetJsValue(ptrs[i]));
111 } 111 }
112 112
113 env->ReleasePrimitiveArrayCritical(jJsPtrs, ptrs, JNI_ABORT); 113 env->ReleasePrimitiveArrayCritical(jJsPtrs, ptrs, JNI_ABORT);
114 } 114 }
115 115
116 try 116 try
117 { 117 {
118 engine->TriggerEvent(eventName, args); 118 engine->TriggerEvent(eventName, args);
119 } 119 }
120 CATCH_AND_THROW(env) 120 CATCH_AND_THROW(env)
(...skipping 15 matching lines...) Expand all
136 CATCH_AND_THROW(env) 136 CATCH_AND_THROW(env)
137 } 137 }
138 138
139 static void JNICALL JniSetDefaultWebRequest(JNIEnv* env, jclass clazz, jlong ptr ) 139 static void JNICALL JniSetDefaultWebRequest(JNIEnv* env, jclass clazz, jlong ptr )
140 { 140 {
141 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 141 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
142 142
143 try 143 try
144 { 144 {
145 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 145 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
146
147 engine->SetWebRequest(webRequest); 146 engine->SetWebRequest(webRequest);
148 } 147 }
149 CATCH_AND_THROW(env) 148 CATCH_AND_THROW(env)
150 } 149 }
151 150
152 static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr) 151 static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr)
153 { 152 {
154 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 153 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
155 154
156 try 155 try
(...skipping 30 matching lines...) Expand all
187 } 186 }
188 CATCH_AND_THROW(env) 187 CATCH_AND_THROW(env)
189 } 188 }
190 189
191 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value) 190 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value)
192 { 191 {
193 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 192 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
194 193
195 try 194 try
196 { 195 {
197 AdblockPlus::JsValuePtr jsValue = engine->NewValue(static_cast<int64_t>(valu e)); 196 return NewJniJsValue(env, engine->NewValue(static_cast<int64_t>(value)));
198 return NewJniJsValue(env, jsValue);
199 } 197 }
200 CATCH_THROW_AND_RETURN(env, 0) 198 CATCH_THROW_AND_RETURN(env, 0)
201 } 199 }
202 200
203 static jobject JNICALL JniNewBooleanValue(JNIEnv* env, jclass clazz, jlong ptr, jboolean value) 201 static jobject JNICALL JniNewBooleanValue(JNIEnv* env, jclass clazz, jlong ptr, jboolean value)
204 { 202 {
205 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 203 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
206 204
207 try 205 try
208 { 206 {
209 AdblockPlus::JsValuePtr jsValue = engine->NewValue(value == JNI_TRUE ? true : false); 207 return NewJniJsValue(env, engine->NewValue(value == JNI_TRUE ? true : false) );
210 return NewJniJsValue(env, jsValue);
211 } 208 }
212 CATCH_THROW_AND_RETURN(env, 0) 209 CATCH_THROW_AND_RETURN(env, 0)
213 } 210 }
214 211
215 static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, j string value) 212 static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, j string value)
216 { 213 {
217 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); 214 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr);
218 215
219 try 216 try
220 { 217 {
221 std::string strValue = JniJavaToStdString(env, value); 218 std::string strValue = JniJavaToStdString(env, value);
222 AdblockPlus::JsValuePtr jsValue = engine->NewValue(strValue); 219 return NewJniJsValue(env, engine->NewValue(strValue));
223 return NewJniJsValue(env, jsValue);
224 } 220 }
225 CATCH_THROW_AND_RETURN(env, 0) 221 CATCH_THROW_AND_RETURN(env, 0)
226 } 222 }
227 223
228 // TODO: List of functions that lack JNI bindings 224 // TODO: List of functions that lack JNI bindings
229 //JsValuePtr NewObject(); 225 //JsValuePtr NewObject();
230 //JsValuePtr NewCallback(v8::InvocationCallback callback); 226 //JsValuePtr NewCallback(v8::InvocationCallback callback);
231 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); 227 //static JsEnginePtr FromArguments(const v8::Arguments& arguments);
232 //JsValueList ConvertArguments(const v8::Arguments& arguments); 228 //JsValueList ConvertArguments(const v8::Arguments& arguments);
233 229
(...skipping 16 matching lines...) Expand all
250 246
251 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, 247 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue },
252 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } , 248 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } ,
253 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue } 249 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue }
254 }; 250 };
255 251
256 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz) 252 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz)
257 { 253 {
258 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 254 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
259 } 255 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniFilterEngine.cpp ('k') | libadblockplus-android/jni/JniJsValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld