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

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

Issue 29536629: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: address comment Created Sept. 8, 2017, 12:20 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
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include <AdblockPlus.h>
19 #include "Utils.h"
20 #include "JniCallbacks.h"
21 #include "JniPlatform.h"
22
23
24 static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo & appInfo)
25 {
26 jclass clazz = env->GetObjectClass(jAppInfo);
27
28 appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
29 appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicat ionVersion");
30 appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
31 appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
32 appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
33
34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme ntBuild");
35 }
36
37 static AdblockPlus::Platform& GetPlatformRef(jlong ptr)
38 {
39 return *JniLongToTypePtr<JniPlatform>(ptr)->platform;
40 }
41
42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz,
43 jobject logSystem, jobject webRequest, jstring jBas ePath)
44 {
45 try
46 {
47 JniPlatform* jniPlatform = new JniPlatform();
48 AdblockPlus::DefaultPlatformBuilder platformBuilder;
49 jniPlatform->scheduler = platformBuilder.GetDefaultAsyncExecutor();
50 if (logSystem)
51 {
52 platformBuilder.logSystem.reset(new JniLogSystemCallback(env, logSystem));
53 }
54 if (webRequest)
55 {
56 platformBuilder.CreateDefaultWebRequest(AdblockPlus::WebRequestSyncPtr(new JniWebRequest(env, webRequest)));
57 }
58 if (jBasePath)
59 {
60 platformBuilder.CreateDefaultFileSystem(JniJavaToStdString(env, jBasePath) );
61 }
62 jniPlatform->platform = platformBuilder.CreatePlatform();
63 return JniPtrToLong(jniPlatform);
64 }
65 CATCH_THROW_AND_RETURN(env, 0)
66 }
67
68 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
69 {
70 delete JniLongToTypePtr<JniPlatform>(ptr);
71 }
72
73 static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobje ct jAppInfo)
74 {
75 try
76 {
77 AdblockPlus::AppInfo appInfo;
78 TransformAppInfo(env, jAppInfo, appInfo);
79 GetPlatformRef(ptr).SetUpJsEngine(appInfo);
80 }
81 CATCH_AND_THROW(env)
82 }
83
84 static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr)
85 {
86 try
87 {
88 return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine());
89 }
90 CATCH_THROW_AND_RETURN(env, 0)
91 }
92
93 static void JNICALL JniSetUpFilterEngine(JNIEnv* env, jclass clazz, jlong ptr, j object jIsSubscriptionDownloadAllowedCallback)
94 {
95 try
96 {
97 AdblockPlus::FilterEngine::CreationParameters creationParameters;
98 if (jIsSubscriptionDownloadAllowedCallback)
99 {
100 auto callback = std::make_shared<JniIsAllowedConnectionTypeCallback>(env, jIsSubscriptionDownloadAllowedCallback);
101 auto scheduler = JniLongToTypePtr<JniPlatform>(ptr)->scheduler;
102 creationParameters.isSubscriptionDownloadAllowedCallback =
103 [scheduler, callback](const std::string* allowedConnectionTypeArg, const std::function<void(bool)>& doneCallback)
104 {
105 std::shared_ptr<std::string> allowedConnectionType;
106 if (allowedConnectionTypeArg)
107 {
108 allowedConnectionType = std::make_shared<std::string>(*allowedConnec tionTypeArg);
109 }
110 scheduler([callback, allowedConnectionType, doneCallback]
111 {
112 doneCallback(callback->Callback(allowedConnectionType.get()));
113 });
114 };
115 }
116 GetPlatformRef(ptr).CreateFilterEngineAsync(creationParameters);
117 }
118 CATCH_AND_THROW(env)
119 }
120
121 static void JNICALL JniEnsureFilterEngine(JNIEnv* env, jclass clazz, jlong ptr)
122 {
123 try
124 {
125 GetPlatformRef(ptr).GetFilterEngine();
126 }
127 CATCH_AND_THROW(env)
128 }
129
130 static JNINativeMethod methods[] =
131 {
132 { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/Str ing;)J", (void*)JniCtor },
133 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
134
135 { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") ")V", (void*)JniSetUpJsEn gine },
136 { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr },
137 { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") " )V", (void*)JniSetUpFilterEngine },
138 { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine }
139 };
140
141 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_r egisterNatives(JNIEnv *env, jclass clazz)
142 {
143 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
144 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniPlatform.h ('k') | libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld