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

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

Issue 29526696: Issue 5556 - remove WebRequest setter (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created Aug. 24, 2017, 5:24 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
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
(...skipping 21 matching lines...) Expand all
32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); 32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
33 33
34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme ntBuild"); 34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme ntBuild");
35 } 35 }
36 36
37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr) 37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr)
38 { 38 {
39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; 39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine;
40 } 40 }
41 41
42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo, jobjec t logSystem) 42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo,
43 jobject logSystem, jlong webRequestPtr)
43 { 44 {
44 AdblockPlus::AppInfo appInfo; 45 AdblockPlus::AppInfo appInfo;
45 46
46 TransformAppInfo(env, jAppInfo, appInfo); 47 TransformAppInfo(env, jAppInfo, appInfo);
47 48
48 try 49 try
49 { 50 {
50 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); 51 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer();
51 JniJsEngine* jniJsEngine = new JniJsEngine(); 52 JniJsEngine* jniJsEngine = new JniJsEngine();
52 jniJsEngine->timer = timer.get(); 53 jniJsEngine->timer = timer.get();
53 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer) ); 54 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer) );
54 if (logSystem) 55 if (logSystem)
55 { 56 {
56 jniJsEngine->jsEngine->SetLogSystem(std::make_shared<JniLogSystemCallback> (env, logSystem)); 57 jniJsEngine->jsEngine->SetLogSystem(std::make_shared<JniLogSystemCallback> (env, logSystem));
57 } 58 }
59 if (webRequestPtr)
60 {
61 jniJsEngine->jsEngine->SetWebRequest(*JniLongToTypePtr<AdblockPlus::WebReq uestSharedPtr>(webRequestPtr));
62 }
63
58 return JniPtrToLong(jniJsEngine); 64 return JniPtrToLong(jniJsEngine);
59 } 65 }
60 CATCH_THROW_AND_RETURN(env, 0) 66 CATCH_THROW_AND_RETURN(env, 0)
61 } 67 }
62 68
63 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 69 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
64 { 70 {
65 delete JniLongToTypePtr<JniJsEngine>(ptr); 71 delete JniLongToTypePtr<JniJsEngine>(ptr);
66 } 72 }
67 73
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 auto fileSystem = std::make_shared<AdblockPlus::DefaultFileSystemSync>(); 153 auto fileSystem = std::make_shared<AdblockPlus::DefaultFileSystemSync>();
148 154
149 std::string basePath = JniJavaToStdString(env, jBasePath); 155 std::string basePath = JniJavaToStdString(env, jBasePath);
150 fileSystem->SetBasePath(basePath); 156 fileSystem->SetBasePath(basePath);
151 157
152 engine.SetFileSystem(fileSystem); 158 engine.SetFileSystem(fileSystem);
153 } 159 }
154 CATCH_AND_THROW(env) 160 CATCH_AND_THROW(env)
155 } 161 }
156 162
157 static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong webRequestPtr)
158 {
159 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr);
160
161 try
162 {
163 auto& webRequest = *JniLongToTypePtr<AdblockPlus::WebRequestSharedPtr>(webRe questPtr);
164
165 engine.SetWebRequest(webRequest);
166 }
167 CATCH_AND_THROW(env)
168 }
169
170 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value) 163 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value)
171 { 164 {
172 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr); 165 AdblockPlus::JsEngine& engine = GetJsEngineRef(ptr);
173 166
174 try 167 try
175 { 168 {
176 return NewJniJsValue(env, engine.NewValue(static_cast<int64_t>(value))); 169 return NewJniJsValue(env, engine.NewValue(static_cast<int64_t>(value)));
177 } 170 }
178 CATCH_THROW_AND_RETURN(env, 0) 171 CATCH_THROW_AND_RETURN(env, 0)
179 } 172 }
(...skipping 22 matching lines...) Expand all
202 } 195 }
203 196
204 // TODO: List of functions that lack JNI bindings 197 // TODO: List of functions that lack JNI bindings
205 //JsValuePtr NewObject(); 198 //JsValuePtr NewObject();
206 //JsValuePtr NewCallback(v8::InvocationCallback callback); 199 //JsValuePtr NewCallback(v8::InvocationCallback callback);
207 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); 200 //static JsEnginePtr FromArguments(const v8::Arguments& arguments);
208 //JsValueList ConvertArguments(const v8::Arguments& arguments); 201 //JsValueList ConvertArguments(const v8::Arguments& arguments);
209 202
210 static JNINativeMethod methods[] = 203 static JNINativeMethod methods[] =
211 { 204 {
212 { (char*)"ctor", (char*)"(" TYP("AppInfo") TYP("LogSystem")")J", (void*)JniCto r }, 205 { (char*)"ctor", (char*)"(" TYP("AppInfo") TYP("LogSystem")"J)J", (void*)JniCt or },
213 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, 206 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
214 207
215 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv entCallback }, 208 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv entCallback },
216 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem oveEventCallback }, 209 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem oveEventCallback },
217 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE vent }, 210 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE vent },
218 211
219 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV alue"), (void*)JniEvaluate }, 212 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV alue"), (void*)JniEvaluate },
220 213
221 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe tDefaultFileSystem }, 214 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe tDefaultFileSystem },
222 { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest },
223 215
224 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, 216 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue },
225 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } , 217 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } ,
226 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue } 218 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue }
227 }; 219 };
228 220
229 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz) 221 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz)
230 { 222 {
231 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 223 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
232 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld