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

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

Issue 29465639: Issue 5309 - Subscriptions update causes ANR (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: rebase Created July 5, 2017, 1:47 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/JniJsEngine.h ('k') | libadblockplus-android/jni/Utils.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
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 #include "JniJsEngine.h"
21 22
22 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo) 23 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo)
23 { 24 {
24 jclass clazz = env->GetObjectClass(jAppInfo); 25 jclass clazz = env->GetObjectClass(jAppInfo);
25 26
26 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); 27 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
27 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion"); 28 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion");
28 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); 29 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
29 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); 30 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
30 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); 31 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
31 32
32 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme ntBuild"); 33 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme ntBuild");
33 } 34 }
34 35
35 static AdblockPlus::JsEnginePtr& GetJsEnginePtrRef(jlong ptr) 36 static AdblockPlus::JsEnginePtr& GetJsEnginePtrRef(jlong ptr)
36 { 37 {
37 return *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); 38 return JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine;
38 } 39 }
39 40
40 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) 41 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo)
41 { 42 {
42 AdblockPlus::AppInfo appInfo; 43 AdblockPlus::AppInfo appInfo;
43 44
44 TransformAppInfo(env, jAppInfo, appInfo); 45 TransformAppInfo(env, jAppInfo, appInfo);
45 46
46 try 47 try
47 { 48 {
48 return JniPtrToLong(new AdblockPlus::JsEnginePtr(AdblockPlus::JsEngine::New( appInfo))); 49 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer();
50 JniJsEngine* jniJsEngine = new JniJsEngine();
51 jniJsEngine->timer = timer.get();
52 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer) );
53 return JniPtrToLong(jniJsEngine);
49 } 54 }
50 CATCH_THROW_AND_RETURN(env, 0) 55 CATCH_THROW_AND_RETURN(env, 0)
51 } 56 }
52 57
53 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 58 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
54 { 59 {
55 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); 60 delete JniLongToTypePtr<JniJsEngine>(ptr);
56 } 61 }
57 62
58 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js tring jEventName, jlong jCallbackPtr) 63 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js tring jEventName, jlong jCallbackPtr)
59 { 64 {
60 AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); 65 AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr);
61 66
62 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); 67 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr);
63 std::string eventName = JniJavaToStdString(env, jEventName); 68 std::string eventName = JniJavaToStdString(env, jEventName);
64 69
65 auto eCallback = [callback](AdblockPlus::JsValueList&& params) 70 auto eCallback = [callback](AdblockPlus::JsValueList&& params)
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 246
242 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, 247 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue },
243 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } , 248 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } ,
244 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue } 249 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue }
245 }; 250 };
246 251
247 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)
248 { 253 {
249 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 254 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
250 } 255 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniJsEngine.h ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld