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

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

Issue 29600561: Issue 6001 - Pass IV8IsolateProvider to Helper (Closed)
Patch Set: Created Nov. 7, 2017, 7:42 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 };
45
46 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo) 23 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo)
47 { 24 {
48 jclass clazz = env->GetObjectClass(jAppInfo); 25 jclass clazz = env->GetObjectClass(jAppInfo);
49 26
50 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application"); 27 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
51 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion"); 28 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion");
52 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale"); 29 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
53 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name"); 30 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
54 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version"); 31 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
55 32
(...skipping 29 matching lines...) Expand all
85 return JniPtrToLong(jniPlatform); 62 return JniPtrToLong(jniPlatform);
86 } 63 }
87 CATCH_THROW_AND_RETURN(env, 0) 64 CATCH_THROW_AND_RETURN(env, 0)
88 } 65 }
89 66
90 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 67 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
91 { 68 {
92 delete JniLongToTypePtr<JniPlatform>(ptr); 69 delete JniLongToTypePtr<JniPlatform>(ptr);
93 } 70 }
94 71
95 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo, jlong v8IsolatePtr) 72 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz,
73 jlong ptr, jobject jAppInfo, jlong v8Isolat eProviderPtr)
96 { 74 {
97 try 75 try
98 { 76 {
99 AdblockPlus::AppInfo appInfo; 77 AdblockPlus::AppInfo appInfo;
100 TransformAppInfo(env, jAppInfo, appInfo); 78 TransformAppInfo(env, jAppInfo, appInfo);
101 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider; 79 std::unique_ptr<AdblockPlus::IV8IsolateProvider> isolateProvider;
102 if (v8IsolatePtr) 80 if (v8IsolateProviderPtr)
103 { 81 {
104 isolateProvider.reset(new V8IsolateHolder(JniLongToTypePtr<v8::Isolate>(v8 IsolatePtr))); 82 isolateProvider.reset(JniLongToTypePtr<AdblockPlus::IV8IsolateProvider>(v8 IsolateProviderPtr));
105 } 83 }
106 84
107 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider)); 85 GetPlatformRef(ptr).SetUpJsEngine(appInfo, std::move(isolateProvider));
108 } 86 }
109 CATCH_AND_THROW(env) 87 CATCH_AND_THROW(env)
110 } 88 }
111 89
112 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr) 90 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr)
113 { 91 {
114 try 92 try
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine }, 141 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") "J)V", (void*)JniSetUpJsE ngine },
164 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr }, 142 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr },
165 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine }, 143 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine },
166 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine } 144 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine }
167 }; 145 };
168 146
169 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz) 147 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz)
170 { 148 {
171 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 149 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
172 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld