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

Unified Diff: libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java

Issue 29671734: Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background (Closed)
Patch Set: addressed Diego's comments Created Jan. 19, 2018, 12:23 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java
diff --git a/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java b/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java
index 70b6c0cd46162ce3d38ebb92f5f5ae9c044f82ef..b3fc893057fc13e48376b0a7a78101156ff4e586 100644
--- a/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java
+++ b/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java
@@ -49,7 +49,7 @@ import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.Subscription;
import org.adblockplus.libadblockplus.android.AdblockEngine;
import org.adblockplus.libadblockplus.android.AdblockEngineProvider;
-import org.adblockplus.libadblockplus.android.SingletonEngineProvider;
+import org.adblockplus.libadblockplus.android.SingleInstanceEngineProvider;
import org.adblockplus.libadblockplus.android.Utils;
import java.io.IOException;
@@ -97,7 +97,7 @@ public class AdblockWebView extends WebView
private volatile boolean addDomListener = true;
private boolean adblockEnabled = true;
private boolean debugMode;
- private AdblockEngineProvider adblockEngineProvider;
+ private AdblockEngineProvider provider;
private Integer loadError;
private int allowDrawDelay = ALLOW_DRAW_DELAY;
private WebChromeClient extWebChromeClient;
@@ -234,9 +234,9 @@ public class AdblockWebView extends WebView
d("runScript finished");
}
- public void setAdblockEngineProvider(final AdblockEngineProvider adblockEngineProvider)
+ public void setProvider(final AdblockEngineProvider provider)
{
- if (this.adblockEngineProvider != null && adblockEngineProvider != null && this.adblockEngineProvider == adblockEngineProvider)
+ if (this.provider != null && provider != null && this.provider == provider)
{
return;
}
@@ -246,12 +246,12 @@ public class AdblockWebView extends WebView
@Override
public void run()
{
- AdblockWebView.this.adblockEngineProvider = adblockEngineProvider;
- AdblockWebView.this.adblockEngineProvider.retain(true); // asynchronously
+ AdblockWebView.this.provider = provider;
+ AdblockWebView.this.provider.retain(true); // asynchronously
}
};
- if (this.adblockEngineProvider != null)
+ if (this.provider != null)
{
// as adblockEngine can be busy with elemhide thread we need to use callback
this.dispose(setRunnable);
@@ -817,7 +817,7 @@ public class AdblockWebView extends WebView
boolean isXmlHttpRequest, String[] referrerChainArray)
{
// if dispose() was invoke, but the page is still loading then just let it go
- if (adblockEngineProvider.getAdblockEngine() == null)
+ if (provider.getCounter() == 0)
{
e("FilterEngine already disposed, allow loading");
@@ -835,7 +835,7 @@ public class AdblockWebView extends WebView
}
// whitelisted
- if (adblockEngineProvider.getAdblockEngine().isDomainWhitelisted(url, referrerChainArray))
+ if (provider.getEngine().isDomainWhitelisted(url, referrerChainArray))
{
w(url + " domain is whitelisted, allow loading");
@@ -843,7 +843,7 @@ public class AdblockWebView extends WebView
return null;
}
- if (adblockEngineProvider.getAdblockEngine().isDocumentWhitelisted(url, referrerChainArray))
+ if (provider.getEngine().isDocumentWhitelisted(url, referrerChainArray))
{
w(url + " document is whitelisted, allow loading");
@@ -886,7 +886,7 @@ public class AdblockWebView extends WebView
}
// check if we should block
- if (adblockEngineProvider.getAdblockEngine().matches(url, contentType, referrerChainArray))
+ if (provider.getEngine().matches(url, contentType, referrerChainArray))
{
w("Blocked loading " + url);
@@ -965,7 +965,7 @@ public class AdblockWebView extends WebView
{
try
{
- if (adblockEngineProvider.getAdblockEngine() == null)
+ if (provider.getCounter() == 0)
{
w("FilterEngine already disposed");
selectorsString = EMPTY_ELEMHIDE_ARRAY_STRING;
@@ -977,8 +977,8 @@ public class AdblockWebView extends WebView
url
};
- List<Subscription> subscriptions = adblockEngineProvider
- .getAdblockEngine()
+ List<Subscription> subscriptions = provider
+ .getEngine()
.getFilterEngine()
.getListedSubscriptions();
@@ -1004,8 +1004,8 @@ public class AdblockWebView extends WebView
}
d("Requesting elemhide selectors from AdblockEngine for " + url + " in " + this);
- List<String> selectors = adblockEngineProvider
- .getAdblockEngine()
+ List<String> selectors = provider
+ .getEngine()
.getElementHidingSelectors(url, domain, referrers);
d("Finished requesting elemhide selectors, got " + selectors.size() + " in " + this);
@@ -1081,16 +1081,16 @@ public class AdblockWebView extends WebView
{
getSettings().setJavaScriptEnabled(true);
buildInjectJs();
- initEngineProvider();
+ initProvider();
}
- private void initEngineProvider()
+ private void initProvider()
{
- // if AdblockWebView works as drop-in replacement for WebView 'adblockEngineProvider' is not set.
- // Thus AdblockWebView is using SingletonEngineProvider instance
- if (adblockEngineProvider == null)
+ // if AdblockWebView works as drop-in replacement for WebView 'provider' is not set.
+ // Thus AdblockWebView is using SingleInstanceEngineProvider instance
+ if (provider == null)
{
- setAdblockEngineProvider(new SingletonEngineProvider(
+ setProvider(new SingleInstanceEngineProvider(
getContext(), AdblockEngine.BASE_PATH_DIRECTORY, debugMode));
}
}
@@ -1109,8 +1109,10 @@ public class AdblockWebView extends WebView
{
try
{
- adblockEngineProvider.waitForReady();
- domain = adblockEngineProvider.getAdblockEngine().getFilterEngine().getHostFromURL(url);
+ d("Waiting for adblock engine");
+ provider.waitForReady();
+
+ domain = provider.getEngine().getFilterEngine().getHostFromURL(url);
if (domain == null)
{
throw new RuntimeException("Failed to extract domain from " + url);
@@ -1372,7 +1374,8 @@ public class AdblockWebView extends WebView
private void doDispose()
{
- adblockEngineProvider.release();
+ w("Disposing AdblockEngine");
+ provider.release();
}
private class DisposeRunnable implements Runnable
@@ -1406,7 +1409,7 @@ public class AdblockWebView extends WebView
{
d("Dispose invoked");
- if (adblockEngineProvider == null)
+ if (provider == null)
{
d("No internal AdblockEngineProvider created");
return;

Powered by Google App Engine
This is Rietveld