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: Created Sept. 26, 2017, 8:54 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 ~V8IsolateHolder()
sergei 2017/09/26 09:44:13 I would propose to remove the destructor here.
anton 2017/09/26 10:55:06 Acknowledged.
35 {
36 isolate = nullptr;
37 }
38
39 v8::Isolate* Get() override
40 {
41 return isolate;
42 }
43
44 private:
45 V8IsolateHolder(const V8IsolateHolder&);
46 V8IsolateHolder& operator=(const V8IsolateHolder&);
47
48 v8::Isolate* isolate;
49 };
23 50
24 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo) 51 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo)
25 { 52 {
26 jclass clazz = env->GetObjectClass(jAppInfo); 53 jclass clazz = env->GetObjectClass(jAppInfo);
27 54
28 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); 55 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
29 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion"); 56 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion");
30 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); 57 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
31 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); 58 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); 59 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
(...skipping 30 matching lines...) Expand all
63 return JniPtrToLong(jniPlatform); 90 return JniPtrToLong(jniPlatform);
64 } 91 }
65 CATCH_THROW_AND_RETURN(env, 0) 92 CATCH_THROW_AND_RETURN(env, 0)
66 } 93 }
67 94
68 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 95 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
69 { 96 {
70 delete JniLongToTypePtr<JniPlatform>(ptr); 97 delete JniLongToTypePtr<JniPlatform>(ptr);
71 } 98 }
72 99
73 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo) 100 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo, jlong v8IsolatePtr)
74 { 101 {
75 try 102 try
76 { 103 {
77 AdblockPlus::AppInfo appInfo; 104 AdblockPlus::AppInfo appInfo;
78 TransformAppInfo(env, jAppInfo, appInfo); 105 TransformAppInfo(env, jAppInfo, appInfo);
79 GetPlatformRef(ptr).SetUpJsEngine(appInfo); 106 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider = nullptr;
sergei 2017/09/26 09:44:13 There is no need in initializing it to nullptr.
anton 2017/09/26 10:55:06 Acknowledged.
107 if (v8IsolatePtr)
108 {
109 isolateProvider = std::unique_ptr<AdblockPlus::IV8IsolateProvider>(
sergei 2017/09/26 09:44:13 I think it would be shorter isolateProvider.reset(
anton 2017/09/26 10:55:06 Acknowledged.
anton 2017/09/26 11:04:25 "Error:(104, 87) error: invalid static_cast from t
110 new V8IsolateHolder((v8::Isolate*)v8IsolatePtr));
111 }
112
113 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider));
80 } 114 }
81 CATCH_AND_THROW(env) 115 CATCH_AND_THROW(env)
82 } 116 }
83 117
84 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr) 118 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr)
85 { 119 {
86 try 120 try
87 { 121 {
88 return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine()); 122 return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine());
89 } 123 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 GetPlatformRef(ptr).GetFilterEngine(); 159 GetPlatformRef(ptr).GetFilterEngine();
126 } 160 }
127 CATCH_AND_THROW(env) 161 CATCH_AND_THROW(env)
128 } 162 }
129 163
130 static JNINativeMethod methods[] = 164 static JNINativeMethod methods[] =
131 { 165 {
132 { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/Str ing;)J", (void*)JniCtor }, 166 { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/Str ing;)J", (void*)JniCtor },
133 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, 167 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
134 168
135 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") ")V", (void*)JniSetUpJsEn gine }, 169 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine },
136 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, 170 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr },
137 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine }, 171 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine },
138 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } 172 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine }
139 }; 173 };
140 174
141 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz) 175 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz)
142 { 176 {
143 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 177 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
144 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld