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

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

Issue 29556582: Issue 5643 - Make v8::Isolate injectable into JsEngine (Closed)
Patch Set: Using JniLongToTypePtr for casting Created Sept. 28, 2017, 8:55 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 <AdblockPlus.h> 18 #include <AdblockPlus.h>
19 #include "Utils.h" 19 #include "Utils.h"
20 #include "JniCallbacks.h" 20 #include "JniCallbacks.h"
21 #include "JniPlatform.h" 21 #include "JniPlatform.h"
22 22
23 /**
24 * V8IsolateHolder accepts v8:::Isolate ptr in ctor and just returns it in Get() .
25 * V8IsolateHolder is not taking ownership so it's not releasing isolate ptr.
26 */
27 class V8IsolateHolder : public AdblockPlus::IV8IsolateProvider
28 {
29 public:
30 V8IsolateHolder(v8::Isolate* isolate_) : isolate(isolate_)
31 {
32 }
33
34 v8::Isolate* Get() override
35 {
36 return isolate;
37 }
38
39 private:
40 V8IsolateHolder(const V8IsolateHolder&);
41 V8IsolateHolder& operator=(const V8IsolateHolder&);
42
43 v8::Isolate* isolate;
44 };
23 45
24 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo) 46 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo)
25 { 47 {
26 jclass clazz = env->GetObjectClass(jAppInfo); 48 jclass clazz = env->GetObjectClass(jAppInfo);
27 49
28 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); 50 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
29 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion"); 51 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion");
30 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); 52 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
31 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); 53 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); 54 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
(...skipping 30 matching lines...) Expand all
63 return JniPtrToLong(jniPlatform); 85 return JniPtrToLong(jniPlatform);
64 } 86 }
65 CATCH_THROW_AND_RETURN(env, 0) 87 CATCH_THROW_AND_RETURN(env, 0)
66 } 88 }
67 89
68 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 90 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
69 { 91 {
70 delete JniLongToTypePtr<JniPlatform>(ptr); 92 delete JniLongToTypePtr<JniPlatform>(ptr);
71 } 93 }
72 94
73 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo) 95 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo, jlong v8IsolatePtr)
74 { 96 {
75 try 97 try
76 { 98 {
77 AdblockPlus::AppInfo appInfo; 99 AdblockPlus::AppInfo appInfo;
78 TransformAppInfo(env, jAppInfo, appInfo); 100 TransformAppInfo(env, jAppInfo, appInfo);
79 GetPlatformRef(ptr).SetUpJsEngine(appInfo); 101 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider;
102 if (v8IsolatePtr)
103 {
104 isolateProvider.reset(new V8IsolateHolder(JniLongToTypePtr<v8::Isolate>(v8 IsolatePtr)));
105 }
106
107 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider));
80 } 108 }
81 CATCH_AND_THROW(env) 109 CATCH_AND_THROW(env)
82 } 110 }
83 111
84 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr) 112 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr)
85 { 113 {
86 try 114 try
87 { 115 {
88 return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine()); 116 return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine());
89 } 117 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 GetPlatformRef(ptr).GetFilterEngine(); 153 GetPlatformRef(ptr).GetFilterEngine();
126 } 154 }
127 CATCH_AND_THROW(env) 155 CATCH_AND_THROW(env)
128 } 156 }
129 157
130 static JNINativeMethod methods[] = 158 static JNINativeMethod methods[] =
131 { 159 {
132 { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/Str ing;)J", (void*)JniCtor }, 160 { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/Str ing;)J", (void*)JniCtor },
133 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, 161 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
134 162
135 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") ")V", (void*)JniSetUpJsEn gine }, 163 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine },
136 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, 164 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr },
137 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine }, 165 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine },
138 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } 166 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine }
139 }; 167 };
140 168
141 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz) 169 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz)
142 { 170 {
143 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 171 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
144 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld