Index: libadblockplus-android/jni/JniJsEngine.h
diff --git a/libadblockplus-android/jni/JniJsEngine.h b/libadblockplus-android/jni/JniJsEngine.h
deleted file mode 100644
index 513918dea0de91ba91e8cd0f0fbc7496bcf7727e..0000000000000000000000000000000000000000
--- a/libadblockplus-android/jni/JniJsEngine.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * This file is part of Adblock Plus ,
- * Copyright (C) 2006-present eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Adblock Plus. If not, see .
- */
-
-#ifndef JNI_JS_ENGINE_H
-#define JNI_JS_ENGINE_H
-
-#include
-#include
-
-struct JniJsEngine
-{
- AdblockPlus::ITimer* timer;
- AdblockPlus::JsEnginePtr jsEngine;
-};
-
-#endif /* JNI_JS_ENGINE_H */
\ No newline at end of file
Index: dependencies
diff --git a/dependencies b/dependencies
index cb94422a361b9e5132c451a2d5ecd36840ffd68a..96d1f1ac7ca93f34fb29eeb021604cf3aec8bc62 100644
--- a/dependencies
+++ b/dependencies
@@ -1,4 +1,4 @@
_root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
_self = buildtools/ensure_dependencies.py
buildtools = buildtools hg:2f744887c675 git:96b22c9
-libadblockplus-android/jni/libadblockplus-binaries = libadblockplus-binaries hg:8748632996d3 git:35f08a07853f78a0475044392d453184388cf2fe
+libadblockplus-android/jni/libadblockplus-binaries = libadblockplus-binaries hg:38831304a6cd git:25f4d037c7a5baf3009001a525aef2cb50196119
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java
index 02060dbbe9d355dea2a70012a48312cc10141036..53200e191bc817a1d2edb9b6cd40a800b8232bae 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java
@@ -17,6 +17,7 @@
package org.adblockplus.libadblockplus.tests;
+import org.adblockplus.libadblockplus.JsEngine;
import org.adblockplus.libadblockplus.WebRequest;
import org.adblockplus.libadblockplus.android.AndroidWebRequest;
import org.adblockplus.libadblockplus.FilterEngine;
@@ -43,6 +44,7 @@ public class AndroidWebRequestTest extends BaseFilterEngineTest
@Test
public void testRealWebRequest()
{
+ JsEngine jsEngine = platform.getJsEngine();
// This URL should redirect to easylist-downloads.adblockplus.org and we
// should get the actual filter list back.
jsEngine.evaluate(
@@ -83,6 +85,7 @@ public class AndroidWebRequestTest extends BaseFilterEngineTest
@Test
public void testXMLHttpRequest()
{
+ JsEngine jsEngine = platform.getJsEngine();
jsEngine.evaluate(
"var result;\n" +
"var request = new XMLHttpRequest();\n" +
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java
index a82e0f05cb4c651ddf7a0dc05ddb448e714b0708..4023a79a091959c578d7173c6f01a3dcccc9879b 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java
@@ -22,7 +22,7 @@ import org.adblockplus.libadblockplus.JsEngine;
import org.junit.Test;
-public class AppInfoJsObjectTest extends BaseJsEngineTest
+public class AppInfoJsObjectTest extends BasePlatformTest
{
@Test
public void testAllProperties()
@@ -37,7 +37,8 @@ public class AppInfoJsObjectTest extends BaseJsEngineTest
.setDevelopmentBuild(true)
.build();
- JsEngine jsEngine = new JsEngine(appInfo);
+ platform.setUpJsEngine(appInfo);
+ JsEngine jsEngine = platform.getJsEngine();
assertEquals("1", jsEngine.evaluate("_appInfo.version").asString());
assertEquals("3", jsEngine.evaluate("_appInfo.name").asString());
assertEquals("4", jsEngine.evaluate("_appInfo.application").asString());
@@ -52,8 +53,8 @@ public class AppInfoJsObjectTest extends BaseJsEngineTest
AppInfo appInfo = AppInfo
.builder()
.build();
-
- JsEngine jsEngine = new JsEngine(appInfo);
+ platform.setUpJsEngine(appInfo);
+ JsEngine jsEngine = platform.getJsEngine();
assertEquals("1.0", jsEngine.evaluate("_appInfo.version").asString());
assertEquals("libadblockplus-android", jsEngine.evaluate("_appInfo.name").asString());
assertEquals("android", jsEngine.evaluate("_appInfo.application").asString());
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseFilterEngineTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseFilterEngineTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseFilterEngineTest.java
index 49e61f85029901d27841b156fa6283d28d0f6864..2741bb8e70b172460c52829e9609683b7e965a99 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseFilterEngineTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseFilterEngineTest.java
@@ -21,7 +21,7 @@ import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.LazyWebRequest;
import org.adblockplus.libadblockplus.WebRequest;
-public abstract class BaseFilterEngineTest extends BaseJsEngineTest
+public abstract class BaseFilterEngineTest extends BasePlatformTest
{
protected FilterEngine filterEngine;
@@ -29,7 +29,7 @@ public abstract class BaseFilterEngineTest extends BaseJsEngineTest
protected void setUp() throws Exception
{
super.setUp();
- filterEngine = new FilterEngine(jsEngine);
+ filterEngine = platform.getFilterEngine();
}
@Override
@@ -44,7 +44,6 @@ public abstract class BaseFilterEngineTest extends BaseJsEngineTest
if (filterEngine != null)
{
Thread.sleep(200); // let FS finish its operations
- filterEngine.dispose();
filterEngine = null;
}
}
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
index 2f512c2ea5a77ddec4fac9aa8fa7d180acbad844..2516c6769f913cb515b3d3814b2be801842d3290 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
@@ -27,7 +27,7 @@ import org.adblockplus.libadblockplus.WebRequest;
import android.content.Context;
import android.test.InstrumentationTestCase;
-public abstract class BaseJsEngineTest extends InstrumentationTestCase
+public abstract class BaseJsEngineTest extends BasePlatformTest
{
protected JsEngine jsEngine;
@@ -35,35 +35,6 @@ public abstract class BaseJsEngineTest extends InstrumentationTestCase
protected void setUp() throws Exception
{
super.setUp();
-
- jsEngine = new JsEngine(AppInfo.builder().build(), createLogSystem(), createWebRequest(),
- getContext().getFilesDir().getAbsolutePath());
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- if (jsEngine != null)
- {
- jsEngine.dispose();
- jsEngine = null;
- }
- }
-
- // If the method returns null then a default implementation of the Log System
- // provided by libadblockplus is used.
- protected LogSystem createLogSystem()
- {
- return null;
- }
-
- protected WebRequest createWebRequest()
- {
- return new ThrowingWebRequest();
- }
-
- protected Context getContext()
- {
- return getInstrumentation().getTargetContext();
+ jsEngine = platform.getJsEngine();
}
}
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BasePlatformTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BasePlatformTest.java
similarity index 79%
copy from libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
copy to libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BasePlatformTest.java
index 2f512c2ea5a77ddec4fac9aa8fa7d180acbad844..74d2dc1b6715d95ab7e294d506bb7ba00018890e 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsEngineTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BasePlatformTest.java
@@ -17,9 +17,7 @@
package org.adblockplus.libadblockplus.tests;
-import org.adblockplus.libadblockplus.AppInfo;
-import org.adblockplus.libadblockplus.JsEngine;
-import org.adblockplus.libadblockplus.LazyLogSystem;
+import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.LogSystem;
import org.adblockplus.libadblockplus.ThrowingWebRequest;
import org.adblockplus.libadblockplus.WebRequest;
@@ -27,27 +25,27 @@ import org.adblockplus.libadblockplus.WebRequest;
import android.content.Context;
import android.test.InstrumentationTestCase;
-public abstract class BaseJsEngineTest extends InstrumentationTestCase
+public abstract class BasePlatformTest extends InstrumentationTestCase
{
- protected JsEngine jsEngine;
+ protected Platform platform;
@Override
protected void setUp() throws Exception
{
super.setUp();
-
- jsEngine = new JsEngine(AppInfo.builder().build(), createLogSystem(), createWebRequest(),
+ platform = new Platform(createLogSystem(), createWebRequest(),
getContext().getFilesDir().getAbsolutePath());
}
@Override
protected void tearDown() throws Exception
{
- if (jsEngine != null)
+ if (platform != null)
{
- jsEngine.dispose();
- jsEngine = null;
+ platform.dispose();
+ platform = null;
}
+ super.tearDown();
}
// If the method returns null then a default implementation of the Log System
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
index 6b71cef6ec749858f7fa602f18286b86bfd74194..37e2be56fc18417f4e04e97655d89aaf859a4eb6 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
@@ -19,11 +19,10 @@ package org.adblockplus.libadblockplus.tests;
import android.os.SystemClock;
-import org.adblockplus.libadblockplus.AppInfo;
import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.HeaderEntry;
import org.adblockplus.libadblockplus.IsAllowedConnectionCallback;
-import org.adblockplus.libadblockplus.JsEngine;
+import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.ServerResponse;
import org.adblockplus.libadblockplus.Subscription;
import org.adblockplus.libadblockplus.WebRequest;
@@ -96,10 +95,11 @@ public class IsAllowedConnectionCallbackTest extends BaseFilterEngineTest
@Override
protected void setUp() throws Exception
{
- jsEngine = new JsEngine(AppInfo.builder().build(), createLogSystem(), createWebRequest(),
+ platform = new Platform(createLogSystem(), createWebRequest(),
getContext().getFilesDir().getAbsolutePath());
callback = new TestCallback();
- filterEngine = new FilterEngine(jsEngine, callback);
+ platform.setUpFilterEngine(callback);
+ filterEngine = platform.getFilterEngine();
}
@Override
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
index 162d15544fc9aef8ce501331c707f0dbd56e52ed..4d551eca0f9174a149ed4c8c4ed2718e65d06561 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
@@ -34,7 +34,7 @@ public class NotificationTest extends BaseFilterEngineTest
protected void addNotification(String notification)
{
- jsEngine.evaluate(
+ platform.getJsEngine().evaluate(
"(function()\n" +
"{\n" +
"require('notification').Notification.addNotification(" + notification + ");\n" +
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
index 53148428a490a3161463af5d74d0ab53144c5fa2..42bc190988b46ecb497a58c523eca4cd675cf36e 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
@@ -25,6 +25,7 @@ import org.adblockplus.libadblockplus.JsEngine;
import org.adblockplus.libadblockplus.JsValue;
import org.adblockplus.libadblockplus.LazyLogSystem;
import org.adblockplus.libadblockplus.LazyWebRequest;
+import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.ServerResponse;
import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
@@ -84,14 +85,15 @@ public class UpdateCheckTest extends BaseFilterEngineTest
public void reset() throws InterruptedException
{
disposeFilterEngine();
- if (jsEngine != null)
+ if (platform != null)
{
- jsEngine.dispose();
+ platform.dispose();
}
- jsEngine = new JsEngine(appInfo, new LazyLogSystem(), webRequest,
+ platform = new Platform(new LazyLogSystem(), webRequest,
getContext().getFilesDir().getAbsolutePath());
- jsEngine.setEventCallback("updateAvailable", eventCallback);
- filterEngine = new FilterEngine(jsEngine);
+ platform.setUpJsEngine(appInfo);
+ platform.getJsEngine().setEventCallback("updateAvailable", eventCallback);
+ filterEngine = platform.getFilterEngine();
}
@Override
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdaterTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdaterTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdaterTest.java
index 8e482f809539f2d123c07b850b7f948cae1e3e04..4a8130497a3dee3a92ed1bd4ed21848d0b4b598a 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdaterTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdaterTest.java
@@ -21,6 +21,7 @@ import org.adblockplus.libadblockplus.AppInfo;
import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.JsEngine;
import org.adblockplus.libadblockplus.MockWebRequest;
+import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.WebRequest;
import android.test.AndroidTestCase;
@@ -37,11 +38,10 @@ public class UpdaterTest extends BaseFilterEngineTest
.setName("test")
.setVersion("1.0.1")
.build();
-
mockWebRequest = new MockWebRequest();
- jsEngine = new JsEngine(appInfo, null, mockWebRequest,
+ platform = new Platform(null, mockWebRequest,
getContext().getFilesDir().getAbsolutePath());
-
- filterEngine = new FilterEngine(jsEngine);
+ platform.setUpJsEngine(appInfo);
+ filterEngine = platform.getFilterEngine();
}
}
Index: libadblockplus-android/jni/Android.mk
diff --git a/libadblockplus-android/jni/Android.mk b/libadblockplus-android/jni/Android.mk
index 92cad0762a7ee62e8ac52de238babe540a0547ab..d152a10bfe00bfc1360a9bef4cbe44cebf132adc 100755
--- a/libadblockplus-android/jni/Android.mk
+++ b/libadblockplus-android/jni/Android.mk
@@ -46,6 +46,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libadblockplus-jni
LOCAL_SRC_FILES := JniLibrary.cpp
+LOCAL_SRC_FILES += JniPlatform.cpp
LOCAL_SRC_FILES += JniJsEngine.cpp JniFilterEngine.cpp JniJsValue.cpp
LOCAL_SRC_FILES += JniFilter.cpp JniSubscription.cpp JniEventCallback.cpp
LOCAL_SRC_FILES += JniLogSystem.cpp JniWebRequest.cpp
Index: libadblockplus-android/jni/JniCallbacks.h
diff --git a/libadblockplus-android/jni/JniCallbacks.h b/libadblockplus-android/jni/JniCallbacks.h
index 684b563214019272ab2981b146949f32f3696edd..73014c16af999afa512df53b2be55c11c74cb0f7 100644
--- a/libadblockplus-android/jni/JniCallbacks.h
+++ b/libadblockplus-android/jni/JniCallbacks.h
@@ -91,11 +91,11 @@ public:
void Callback(AdblockPlus::Notification&&);
};
-class JniWebRequest : public JniCallbackBase, public AdblockPlus::WebRequest
+class JniWebRequest : public JniCallbackBase, public AdblockPlus::IWebRequestSync
{
public:
JniWebRequest(JNIEnv* env, jobject callbackObject);
- AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const;
+ AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const override;
private:
jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) const;
Index: libadblockplus-android/jni/JniFilter.cpp
diff --git a/libadblockplus-android/jni/JniFilter.cpp b/libadblockplus-android/jni/JniFilter.cpp
index 2500b140facc04584de0eb71e5c4746e704df613..2113788c659ecc5943c06d691b61a306b21688ff 100644
--- a/libadblockplus-android/jni/JniFilter.cpp
+++ b/libadblockplus-android/jni/JniFilter.cpp
@@ -67,6 +67,9 @@ static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION:
enumName = "ELEMHIDE_EXCEPTION";
break;
+ case AdblockPlus::Filter::TYPE_TYPE_ELEMHIDE_EMULATION:
+ enumName = "ELEMHIDE_EMULATION";
+ break;
case AdblockPlus::Filter::TYPE_EXCEPTION:
enumName = "EXCEPTION";
break;
Index: libadblockplus-android/jni/JniFilterEngine.cpp
diff --git a/libadblockplus-android/jni/JniFilterEngine.cpp b/libadblockplus-android/jni/JniFilterEngine.cpp
index 3f6c0d4870391cabf213397131cf11c53a34153c..1f59aac630f338d3a92483dddde2b57cc2018b3f 100644
--- a/libadblockplus-android/jni/JniFilterEngine.cpp
+++ b/libadblockplus-android/jni/JniFilterEngine.cpp
@@ -19,7 +19,7 @@
#include "Utils.h"
#include "JniCallbacks.h"
#include
-#include "JniJsEngine.h"
+#include "JniPlatform.h"
static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector&& subscriptions)
{
@@ -48,63 +48,12 @@ static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
namespace
{
- struct JniFilterEngine
+ AdblockPlus::FilterEngine& GetFilterEngineRef(jlong jniPlatformPtr)
{
- AdblockPlus::ITimer* timer;
- AdblockPlus::FilterEnginePtr filterEngine;
- };
-
- AdblockPlus::FilterEngine& GetFilterEngineRef(jlong ptr)
- {
- return *JniLongToTypePtr(ptr)->filterEngine;
+ return JniLongToTypePtr(jniPlatformPtr)->platform->GetFilterEngine();
}
}
-static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jniJsEnginePtr, jobject jIsSubscriptionDownloadAllowedCallback)
-{
- try
- {
- auto jniJsEngine = JniLongToTypePtr(jniJsEnginePtr);
- auto jsEngine = jniJsEngine->jsEngine;
- auto jniFilterEngine = new JniFilterEngine();
- jniFilterEngine->timer = jniJsEngine->timer;
-
- if (jIsSubscriptionDownloadAllowedCallback)
- {
- AdblockPlus::FilterEngine::CreationParameters creationParameters;
- auto callback = std::make_shared(env, jIsSubscriptionDownloadAllowedCallback);
-
- creationParameters.isSubscriptionDownloadAllowedCallback =
- [callback](const std::string* allowedConnectionTypeArg, const std::function& doneCallback)
- {
- std::shared_ptr allowedConnectionType;
- if (allowedConnectionTypeArg)
- {
- allowedConnectionType = std::make_shared(*allowedConnectionTypeArg);
- }
- std::thread([callback, allowedConnectionType, doneCallback]
- {
- doneCallback(callback->Callback(allowedConnectionType.get()));
- }).detach();
- };
-
- jniFilterEngine->filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, creationParameters);
- }
- else
- {
- jniFilterEngine->filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
- }
-
- return JniPtrToLong(jniFilterEngine);
- }
- CATCH_THROW_AND_RETURN(env, 0)
-}
-
-static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
-{
- delete JniLongToTypePtr(ptr);
-}
-
static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
{
try
@@ -532,13 +481,13 @@ static jstring JNICALL JniGetAcceptableAdsSubscriptionURL(JNIEnv* env, jclass cl
CATCH_THROW_AND_RETURN(env, 0)
}
-static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong ptr, jstring jSubscriptionUrl)
+static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong jniPlatformPtr, jstring jSubscriptionUrl)
{
std::string subscriptionUrl = JniJavaToStdString(env, jSubscriptionUrl);
- auto jniFilterEngine = JniLongToTypePtr(ptr);
- jniFilterEngine->timer->SetTimer(std::chrono::milliseconds(0), [jniFilterEngine, subscriptionUrl]
+ auto jniPlatform = JniLongToTypePtr(jniPlatformPtr);
+ jniPlatform->scheduler([jniPlatform, subscriptionUrl]
{
- auto& filterEngine = *jniFilterEngine->filterEngine;
+ auto& filterEngine = jniPlatform->platform->GetFilterEngine();
for (auto& subscription : filterEngine.GetListedSubscriptions())
{
if (stringBeginsWith(subscriptionUrl, subscription.GetProperty("url").AsString()))
@@ -552,7 +501,6 @@ static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong ptr,
static JNINativeMethod methods[] =
{
- { (char*)"ctor", (char*)"(J" TYP("IsAllowedConnectionCallback") ")J", (void*)JniCtor },
{ (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun },
{ (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)JniGetFilter },
{ (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListedFilters },
@@ -580,7 +528,6 @@ static JNINativeMethod methods[] =
{ (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAdsEnabled },
{ (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEnabled },
{ (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (void*)JniGetAcceptableAdsSubscriptionURL },
- { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
{ (char*)"updateFiltersAsync", (char*)"(JLjava/lang/String;)V", (void*)JniUpdateFiltersAsync }
};
Index: libadblockplus-android/jni/JniJsEngine.cpp
diff --git a/libadblockplus-android/jni/JniJsEngine.cpp b/libadblockplus-android/jni/JniJsEngine.cpp
index 6faa79eeaca583d14a74fc8ad59eb1a41e07fe97..574045fb6df26118d6b2385e61d04c0b6972b76b 100644
--- a/libadblockplus-android/jni/JniJsEngine.cpp
+++ b/libadblockplus-android/jni/JniJsEngine.cpp
@@ -16,66 +16,12 @@
*/
#include
-#include
#include "Utils.h"
#include "JniCallbacks.h"
-#include "JniJsEngine.h"
-
-static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo& appInfo)
-{
- jclass clazz = env->GetObjectClass(jAppInfo);
-
- appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
- appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicationVersion");
- appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
- appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
- appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
-
- appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developmentBuild");
-}
static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr)
{
- return *JniLongToTypePtr(ptr)->jsEngine;
-}
-
-static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo,
- jobject logSystem, jobject webRequest, jstring jBasePath)
-{
- AdblockPlus::AppInfo appInfo;
-
- TransformAppInfo(env, jAppInfo, appInfo);
-
- try
- {
- AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer();
- JniJsEngine* jniJsEngine = new JniJsEngine();
- jniJsEngine->timer = timer.get();
- jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer));
- if (logSystem)
- {
- jniJsEngine->jsEngine->SetLogSystem(std::make_shared(env, logSystem));
- }
- if (webRequest)
- {
- jniJsEngine->jsEngine->SetWebRequest(std::make_shared(env, webRequest));
- }
- if (jBasePath)
- {
- auto fileSystem = std::make_shared();
- std::string basePath = JniJavaToStdString(env, jBasePath);
- fileSystem->SetBasePath(basePath);
- jniJsEngine->jsEngine->SetFileSystem(fileSystem);
- }
-
- return JniPtrToLong(jniJsEngine);
- }
- CATCH_THROW_AND_RETURN(env, 0)
-}
-
-static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
-{
- delete JniLongToTypePtr(ptr);
+ return *JniLongToTypePtr(ptr);
}
static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName, jlong jCallbackPtr)
@@ -193,9 +139,6 @@ static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, j
static JNINativeMethod methods[] =
{
- { (char*)"ctor", (char*)"(" TYP("AppInfo") TYP("LogSystem") TYP("WebRequest") "Ljava/lang/String;)J", (void*)JniCtor },
- { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
-
{ (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEventCallback },
{ (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRemoveEventCallback },
{ (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerEvent },
Index: libadblockplus-android/jni/JniNotification.cpp
diff --git a/libadblockplus-android/jni/JniNotification.cpp b/libadblockplus-android/jni/JniNotification.cpp
index 817c087ab7b45f9ad77cf5180d51ddd615cd7961..1d79bbcb0f4b43543e4344211a7a885a45d2a09d 100644
--- a/libadblockplus-android/jni/JniNotification.cpp
+++ b/libadblockplus-android/jni/JniNotification.cpp
@@ -62,6 +62,9 @@ static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION:
enumName = "QUESTION";
break;
+ case AdblockPlus::NotificationType::NOTIFICATION_TYPE_RELENTLESS:
+ enumName = "RELENTLESS";
+ break;
default:
enumName = "INVALID";
break;
Index: libadblockplus-android/jni/JniPlatform.cpp
diff --git a/libadblockplus-android/jni/JniPlatform.cpp b/libadblockplus-android/jni/JniPlatform.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5e067088bca47d2d487fea3fbb728260a6dd696c
--- /dev/null
+++ b/libadblockplus-android/jni/JniPlatform.cpp
@@ -0,0 +1,144 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+#include
+#include "Utils.h"
+#include "JniCallbacks.h"
+#include "JniPlatform.h"
+
+
+static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo& appInfo)
+{
+ jclass clazz = env->GetObjectClass(jAppInfo);
+
+ appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
+ appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicationVersion");
+ appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
+ appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
+ appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
+
+ appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developmentBuild");
+}
+
+static AdblockPlus::Platform& GetPlatformRef(jlong ptr)
+{
+ return *JniLongToTypePtr(ptr)->platform;
+}
+
+static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz,
+ jobject logSystem, jobject webRequest, jstring jBasePath)
+{
+ try
+ {
+ JniPlatform* jniPlatform = new JniPlatform();
+ AdblockPlus::DefaultPlatformBuilder platformBuilder;
+ jniPlatform->scheduler = platformBuilder.GetDefaultAsyncExecutor();
+ if (logSystem)
+ {
+ platformBuilder.logSystem.reset(new JniLogSystemCallback(env, logSystem));
+ }
+ if (webRequest)
+ {
+ platformBuilder.CreateDefaultWebRequest(AdblockPlus::WebRequestSyncPtr(new JniWebRequest(env, webRequest)));
+ }
+ if (jBasePath)
+ {
+ platformBuilder.CreateDefaultFileSystem(JniJavaToStdString(env, jBasePath));
+ }
+ jniPlatform->platform = platformBuilder.CreatePlatform();
+ return JniPtrToLong(jniPlatform);
+ }
+ CATCH_THROW_AND_RETURN(env, 0)
+}
+
+static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
+{
+ delete JniLongToTypePtr(ptr);
+}
+
+static void JNICALL JniSetUpJsEngine(JNIEnv* env, jclass clazz, jlong ptr, jobject jAppInfo)
+{
+ try
+ {
+ AdblockPlus::AppInfo appInfo;
+ TransformAppInfo(env, jAppInfo, appInfo);
+ GetPlatformRef(ptr).SetUpJsEngine(appInfo);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static long JNICALL JniGetJsEnginePtr(JNIEnv* env, jclass clazz, jlong ptr)
+{
+ try
+ {
+ return JniPtrToLong(&GetPlatformRef(ptr).GetJsEngine());
+ }
+ CATCH_THROW_AND_RETURN(env, 0)
+}
+
+static void JNICALL JniSetUpFilterEngine(JNIEnv* env, jclass clazz, jlong ptr, jobject jIsSubscriptionDownloadAllowedCallback)
+{
+ try
+ {
+ AdblockPlus::FilterEngine::CreationParameters creationParameters;
+ if (jIsSubscriptionDownloadAllowedCallback)
+ {
+ auto callback = std::make_shared(env, jIsSubscriptionDownloadAllowedCallback);
+ auto scheduler = JniLongToTypePtr(ptr)->scheduler;
+ creationParameters.isSubscriptionDownloadAllowedCallback =
+ [scheduler, callback](const std::string* allowedConnectionTypeArg, const std::function& doneCallback)
+ {
+ std::shared_ptr allowedConnectionType;
+ if (allowedConnectionTypeArg)
+ {
+ allowedConnectionType = std::make_shared(*allowedConnectionTypeArg);
+ }
+ scheduler([callback, allowedConnectionType, doneCallback]
+ {
+ doneCallback(callback->Callback(allowedConnectionType.get()));
+ });
+ };
+ }
+ GetPlatformRef(ptr).CreateFilterEngineAsync(creationParameters);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static void JNICALL JniEnsureFilterEngine(JNIEnv* env, jclass clazz, jlong ptr)
+{
+ try
+ {
+ GetPlatformRef(ptr).GetFilterEngine();
+ }
+ CATCH_AND_THROW(env)
+}
+
+static JNINativeMethod methods[] =
+{
+ { (char*)"ctor", (char*)"(" TYP("LogSystem") TYP("WebRequest") "Ljava/lang/String;)J", (void*)JniCtor },
+ { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
+
+ { (char*)"setUpJsEngine", (char*)"(J" TYP("AppInfo") ")V", (void*)JniSetUpJsEngine },
+ { (char*)"getJsEnginePtr", (char*)"(J)J", (void*)JniGetJsEnginePtr },
+ { (char*)"setUpFilterEngine", (char*)"(J" TYP("IsAllowedConnectionCallback") ")V", (void*)JniSetUpFilterEngine },
+ { (char*)"ensureFilterEngine", (char*)"(J)V", (void*)JniEnsureFilterEngine }
+};
+
+extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Platform_registerNatives(JNIEnv *env, jclass clazz)
+{
+ env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
+}
Index: libadblockplus-android/jni/JniPlatform.h
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/WebRequest.java b/libadblockplus-android/jni/JniPlatform.h
similarity index 76%
copy from libadblockplus-android/src/org/adblockplus/libadblockplus/WebRequest.java
copy to libadblockplus-android/jni/JniPlatform.h
index 35f43f58235984a73851a3ad928b366642d48ffa..d3510322a17d0ae62243fccad04539673a96066c 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/WebRequest.java
+++ b/libadblockplus-android/jni/JniPlatform.h
@@ -15,11 +15,15 @@
* along with Adblock Plus. If not, see .
*/
-package org.adblockplus.libadblockplus;
+#ifndef JNI_PLATFORM_H
+#define JNI_PLATFORM_H
-import java.util.List;
+#include
-public interface WebRequest
+struct JniPlatform
{
- ServerResponse httpGET(String url, List headers);
-}
+ AdblockPlus::Scheduler scheduler;
+ std::unique_ptr platform;
+};
+
+#endif /* JNI_PLATFORM_H */
\ No newline at end of file
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java
index 97b6f317c7fb6522f1079a70a1f777dd401f97b8..40238037c9f43ff22d6a8db8ce22cd58ed9ed509 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/Filter.java
@@ -69,7 +69,8 @@ public final class Filter extends JsValue
public static enum Type
{
- BLOCKING, EXCEPTION, ELEMHIDE, ELEMHIDE_EXCEPTION, COMMENT, INVALID;
+ BLOCKING, EXCEPTION, ELEMHIDE, ELEMHIDE_EXCEPTION, ELEMHIDE_EMULATION,
+ COMMENT, INVALID;
}
private final static native void registerNatives();
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java
index f3d72d8fcd5fb844e30ee7c6b77be9986f149884..720223e4d5a6363e2c5623722a5159c293bc7e0a 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java
@@ -19,9 +19,8 @@ package org.adblockplus.libadblockplus;
import java.util.List;
-public final class FilterEngine implements Disposable
+public final class FilterEngine
{
- private final Disposer disposer;
protected final long ptr;
static
@@ -32,19 +31,14 @@ public final class FilterEngine implements Disposable
public static enum ContentType
{
- OTHER, SCRIPT, IMAGE, STYLESHEET, OBJECT, SUBDOCUMENT, DOCUMENT, XMLHTTPREQUEST,
- OBJECT_SUBREQUEST, FONT, MEDIA
+ OTHER, SCRIPT, IMAGE, STYLESHEET, OBJECT, SUBDOCUMENT, DOCUMENT, WEBSOCKET,
+ WEBRTC, PING, XMLHTTPREQUEST, OBJECT_SUBREQUEST, MEDIA, FONT, GENERICBLOCK,
+ ELEMHIDE, GENERICHIDE
}
- public FilterEngine(final JsEngine jsEngine, final IsAllowedConnectionCallback isSubscriptionDownloadAllowedCallback)
+ FilterEngine(long jniPlatformPtr)
{
- this.ptr = ctor(jsEngine.ptr, isSubscriptionDownloadAllowedCallback);
- this.disposer = new Disposer(this, new DisposeWrapper(this.ptr));
- }
-
- public FilterEngine(final JsEngine jsEngine)
- {
- this(jsEngine, null);
+ this.ptr = jniPlatformPtr;
}
public boolean isFirstRun()
@@ -202,32 +196,8 @@ public final class FilterEngine implements Disposable
updateFiltersAsync(this.ptr, subscriptionUrl);
}
- @Override
- public void dispose()
- {
- this.disposer.dispose();
- }
-
- private final static class DisposeWrapper implements Disposable
- {
- private final long ptr;
-
- public DisposeWrapper(final long ptr)
- {
- this.ptr = ptr;
- }
-
- @Override
- public void dispose()
- {
- dtor(this.ptr);
- }
- }
-
private final static native void registerNatives();
- private final static native long ctor(long jsEnginePtr, IsAllowedConnectionCallback isSubscriptionDownloadAllowedCallback);
-
private final static native boolean isFirstRun(long ptr);
private final static native Filter getFilter(long ptr, String text);
@@ -283,6 +253,4 @@ public final class FilterEngine implements Disposable
private final static native String getAcceptableAdsSubscriptionURL(long ptr);
private final static native void updateFiltersAsync(long ptr, String subscriptionUrl);
-
- private final static native void dtor(long ptr);
}
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/JsEngine.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/JsEngine.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/JsEngine.java
index f122c7142e2401d73202d99572058a087ccd728c..331a7ac7dfb5f0ad91c2938ef154d43af0b9b3a8 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/JsEngine.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/JsEngine.java
@@ -19,9 +19,8 @@ package org.adblockplus.libadblockplus;
import java.util.List;
-public final class JsEngine implements Disposable
+public final class JsEngine
{
- private final Disposer disposer;
protected final long ptr;
static
@@ -30,20 +29,9 @@ public final class JsEngine implements Disposable
registerNatives();
}
- public JsEngine(final AppInfo appInfo, final LogSystem logSystem, final WebRequest webRequest, final String basePath)
- {
- this(ctor(appInfo, logSystem, webRequest, basePath));
- }
-
- public JsEngine(final AppInfo appInfo)
- {
- this(appInfo, null, null, null);
- }
-
- protected JsEngine(final long ptr)
+ JsEngine(final long ptr)
{
this.ptr = ptr;
- this.disposer = new Disposer(this, new DisposeWrapper(ptr));
}
public void setEventCallback(final String eventName, final EventCallback callback)
@@ -98,33 +86,8 @@ public final class JsEngine implements Disposable
return newValue(this.ptr, value);
}
- @Override
- public void dispose()
- {
- this.disposer.dispose();
- }
-
- private final static class DisposeWrapper implements Disposable
- {
- private final long ptr;
-
- public DisposeWrapper(final long ptr)
- {
- this.ptr = ptr;
- }
-
- @Override
- public void dispose()
- {
- dtor(this.ptr);
- }
- }
-
private final static native void registerNatives();
- private final static native long ctor(AppInfo appInfo, LogSystem logSystem, WebRequest webRequest,
- String basePath);
-
private final static native void setEventCallback(long ptr, String eventName, long callback);
private final static native void removeEventCallback(long ptr, String eventName);
@@ -138,6 +101,4 @@ public final class JsEngine implements Disposable
private final static native JsValue newValue(long ptr, boolean value);
private final static native JsValue newValue(long ptr, String value);
-
- private final static native void dtor(long ptr);
}
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/Notification.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/Notification.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/Notification.java
index e1b3b1bec2b2dfd7b58a6221a95bb016a15e3df0..eed35f63a9745b84815bb9617bc4844f26efdce9 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/Notification.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/Notification.java
@@ -34,6 +34,7 @@ public class Notification extends JsValue
{
INFORMATION,
QUESTION,
+ RELENTLESS,
CRITICAL,
INVALID
}
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/Platform.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/Platform.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/Platform.java
new file mode 100644
index 0000000000000000000000000000000000000000..727af68691a6432c26b8cf06e2fbe51646739448
--- /dev/null
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/Platform.java
@@ -0,0 +1,108 @@
+/*
+ * This file is part of Adblock Plus ,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see .
+ */
+
+package org.adblockplus.libadblockplus;
+
+public class Platform implements Disposable
+{
+ private final Disposer disposer;
+ protected final long ptr;
+
+ static
+ {
+ System.loadLibrary("adblockplus-jni");
+ registerNatives();
+ }
+
+ /**
+ * If an interface parameter value is null then a default implementation is
+ * chosen.
+ * If basePath is null then paths are not resolved to a full path, thus
+ * current working directory is used.
+ */
+ public Platform(final LogSystem logSystem, final WebRequest webRequest, final String basePath)
+ {
+ this(ctor(logSystem, webRequest, basePath));
+ }
+
+ protected Platform(final long ptr)
+ {
+ this.ptr = ptr;
+ this.disposer = new Disposer(this, new DisposeWrapper(ptr));
+ }
+
+ public void setUpJsEngine(final AppInfo appInfo)
+ {
+ setUpJsEngine(this.ptr, appInfo);
+ }
+
+ public JsEngine getJsEngine()
+ {
+ return new JsEngine(getJsEnginePtr(this.ptr));
+ }
+
+ public void setUpFilterEngine(final IsAllowedConnectionCallback isSubscriptionDownloadAllowedCallback)
+ {
+ setUpFilterEngine(this.ptr, isSubscriptionDownloadAllowedCallback);
+ }
+
+ public FilterEngine getFilterEngine()
+ {
+ // Initially FilterEngine is not constructed when Platform is instantiated
+ // and in addition FilterEngine is being created asynchronously, the call
+ // of `ensureFilterEngine` causes a construction of FilterEngine if it's
+ // not created yet and waits for it.
+ ensureFilterEngine(this.ptr);
+ return new FilterEngine(this.ptr);
+ }
+
+ @Override
+ public void dispose()
+ {
+ this.disposer.dispose();
+ }
+
+ private final static class DisposeWrapper implements Disposable
+ {
+ private final long ptr;
+
+ public DisposeWrapper(final long ptr)
+ {
+ this.ptr = ptr;
+ }
+
+ @Override
+ public void dispose()
+ {
+ dtor(this.ptr);
+ }
+ }
+
+ private final static native void registerNatives();
+
+ private final static native long ctor(LogSystem logSystem, WebRequest webRequest, String basePath);
+
+ private final static native void setUpJsEngine(long ptr, AppInfo appInfo);
+
+ private final static native long getJsEnginePtr(long ptr);
+
+ private final static native void setUpFilterEngine(long ptr, IsAllowedConnectionCallback isSubscriptionDownloadAllowedCallback);
+
+ private final static native void ensureFilterEngine(long ptr);
+
+ private final static native void dtor(long ptr);
+}
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
index 95b79a99fadb3563ead38b3987a172a661181390..f7d2ec6e40ff4e783aeda8515d9c0337fc1953a6 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
@@ -32,9 +32,9 @@ import org.adblockplus.libadblockplus.FilterChangeCallback;
import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.FilterEngine.ContentType;
import org.adblockplus.libadblockplus.IsAllowedConnectionCallback;
-import org.adblockplus.libadblockplus.JsEngine;
import org.adblockplus.libadblockplus.JsValue;
import org.adblockplus.libadblockplus.LogSystem;
+import org.adblockplus.libadblockplus.Platform;
import org.adblockplus.libadblockplus.ShowNotificationCallback;
import org.adblockplus.libadblockplus.Subscription;
import org.adblockplus.libadblockplus.UpdateAvailableCallback;
@@ -67,7 +67,7 @@ public final class AdblockEngine
* volatile, this seems to prevent the JNI from 'optimizing away' those objects (as a volatile
* variable might be changed at any time from any thread).
*/
- private volatile JsEngine jsEngine;
+ private volatile Platform platform;
private volatile FilterEngine filterEngine;
private volatile LogSystem logSystem;
private volatile WebRequest webRequest;
@@ -254,9 +254,10 @@ public final class AdblockEngine
private void createEngines()
{
engine.logSystem = new AndroidLogSystem();
- engine.jsEngine = new JsEngine(appInfo, engine.logSystem, engine.webRequest, basePath);
-
- engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectionCallback);
+ engine.platform = new Platform(engine.logSystem, engine.webRequest, basePath);
+ engine.platform.setUpJsEngine(appInfo);
+ engine.platform.setUpFilterEngine(isAllowedConnectionCallback);
+ engine.filterEngine = engine.platform.getFilterEngine();
}
}
@@ -287,14 +288,8 @@ public final class AdblockEngine
this.filterEngine.removeShowNotificationCallback();
}
- this.filterEngine.dispose();
- this.filterEngine = null;
- }
-
- if (this.jsEngine != null)
- {
- this.jsEngine.dispose();
- this.jsEngine = null;
+ this.platform.dispose();
+ this.platform = null;
}
// callbacks then