diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b80552a6..dc97bd14 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -15,22 +15,39 @@
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
-
+
+
+
+
@@ -50,20 +67,20 @@
-
-
+
+
-
-
+
+
-
+
-
-
+
+
@@ -71,17 +88,8 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -90,22 +98,31 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -116,8 +133,8 @@
-
-
+
+
@@ -125,8 +142,8 @@
-
-
+
+
@@ -134,8 +151,8 @@
-
-
+
+
@@ -144,10 +161,10 @@
-
+
-
-
+
+
@@ -167,36 +184,36 @@
- initialUrl
- InAppBrowser
- onCustomScheme
- print
- onTargetBlank
- customSchemes
- customSchemes__
- toJson
- onCustom
- schemes
- schemes_
- onDownload
- resourceCustomSchemes
- onLoadResourceCustomScheme
- and return a [Cu
- encoded in `base64`
- _
- _throwIsNotOpened(
- _throwIsNotOpened
- _hand
- _ChannelManager
- onDo
- initialData
- assert
- Level
- options
- options = const {}
- List<WebViewOptions> options = const []
options)
WebViewOptions
+ websiteDataStore
+ CacheMode
+ toStr
+ cacheMode
+ disabledActionModeMenuItems
+ AndroidInAppWebViewModeMenuItem
+ fantasyFontFamily
+ AndroidInAppWebViewLayoutAlgorithm
+ loadWithOverviewMode
+ AndroidInAppWebViewCacheMode
+ mixedContentMode
+ disable
+ appCachePath
+ List<Con
+ appCacheEnabled
+ List<Content
+ NOTE
+ onGeolocationPermissionsShowPrompt
+ "onGeolocationPermissionsShowPrompt"
+ databaseEnabled
+ RequestPermission
+ geolocation
+ userInterfaceDirectionPolicy
+ WKSelectionGranularityDynamic
+ minimumFontSize
+ defaultWebpagePreferences
+ contentBlockers
+ preferredContentMode
activity.getPreferences(0)
@@ -232,7 +249,6 @@
-
@@ -246,27 +262,28 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -281,6 +298,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -310,61 +388,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -515,11 +539,11 @@
-
+
-
-
+
+
@@ -529,15 +553,15 @@
-
+
-
+
-
+
@@ -565,22 +589,12 @@
-
-
-
-
-
-
-
-
-
-
@@ -588,13 +602,6 @@
-
-
-
-
-
-
-
@@ -716,23 +723,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -787,27 +777,10 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -818,81 +791,136 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
-
-
-
-
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22a157d5..288ee685 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-## 1.3.0
+## 2.0.0
- Merge "Avoid null pointer exception after webview is disposed" [#116](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/116) (thanks to [robsonfingo](https://github.com/robsonfingo))
- Merge "Remove async call in close" [#119](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/119) (thanks to [benfingo](https://github.com/benfingo))
@@ -13,6 +13,10 @@
- Added `onLoadResourceCustomScheme` event and `resourceCustomSchemes` option to set custom schemes that WebView must handle to load resources
- Added `onTargetBlank` event and `useOnTargetBlank` option to manage links with `target="_blank"`
- Added `ContentBlocker`, `ContentBlockerTrigger` and `ContentBlockerAction` classes and the `contentBlockers` option that allows to define a set of rules to use to block content in the WebView
+- Added new WebView option `minimumFontSize`
+- Added new Android WebView options: `allowContentAccess`, `allowFileAccess`, `allowFileAccessFromFileURLs`, `allowUniversalAccessFromFileURLs`, `appCacheEnabled`, `appCachePath`, `blockNetworkImage`, `blockNetworkLoads`, `cacheMode`, `cursiveFontFamily`, `defaultFixedFontSize`, `defaultFontSize`, `defaultTextEncodingName`, `disabledActionModeMenuItems`, `fantasyFontFamily`, `fixedFontFamily`, `forceDark`, `geolocationEnabled`, `layoutAlgorithm`, `loadWithOverviewMode`, `loadsImagesAutomatically`, `minimumLogicalFontSize`, `needInitialFocus`, `offscreenPreRaster`, `sansSerifFontFamily`, `serifFontFamily`, `standardFontFamily`
+- Added new iOS WebView options: `applicationNameForUserAgent`, `isFraudulentWebsiteWarningEnabled`, `selectionGranularity`, `dataDetectorTypes`, `preferredContentMode`
+- Added `onGeolocationPermissionsShowPrompt` event and `GeolocationPermissionShowPromptResponse` class (available only for Android)
### BREAKING CHANGES
- Deleted `WebResourceRequest` class
@@ -20,7 +24,6 @@
- Updated `onLoadResource` event
- WebView options are now available with the new corresponding classes: `InAppWebViewOptions`, `AndroidInAppWebViewOptions`, `iOSInAppWebViewOptions`, `InAppBrowserOptions`, `AndroidInAppBrowserOptions`, `iOSInAppBrowserOptions`, `AndroidChromeCustomTabsOptions` and `iOSChromeCustomTabsOptions`
-
## 1.2.1
- Merge "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
diff --git a/android/build.gradle b/android/build.gradle
index 2933abdf..fc587565 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -35,7 +35,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'
android {
- compileSdkVersion 28
+ compileSdkVersion 29
defaultConfig {
minSdkVersion 17
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlocker.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlocker.java
index 1f40e8dd..c8265741 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlocker.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlocker.java
@@ -1,235 +1,11 @@
package com.pichillilorenzo.flutter_inappbrowser.ContentBlocker;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Looper;
-import android.util.Log;
-import android.webkit.WebResourceResponse;
-
-import com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebView;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import okhttp3.Request;
-import okhttp3.Response;
-
public class ContentBlocker {
- protected static final String LOG_TAG = "ContentBlocker";
+ public ContentBlockerTrigger trigger;
+ public ContentBlockerAction action;
- public static WebResourceResponse checkUrl(final InAppWebView webView, String url, ContentBlockerTriggerResourceType responseResourceType) throws URISyntaxException, InterruptedException {
- if (webView.options.contentBlockers == null)
- return null;
-
- URI u = new URI(url);
- String host = u.getHost();
- int port = u.getPort();
- String scheme = u.getScheme();
-
- for (Map> contentBlocker : webView.options.contentBlockers) {
- ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger"));
- List resourceTypes = trigger.resourceType;
-
- ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action"));
-
- Pattern mPattern = Pattern.compile(trigger.urlFilter);
- Matcher m = mPattern.matcher(url);
-
- if (m.matches()) {
-
- if (!resourceTypes.isEmpty() && !resourceTypes.contains(responseResourceType)) {
- return null;
- }
- if (!trigger.ifDomain.isEmpty()) {
- boolean matchFound = false;
- for (String domain : trigger.ifDomain) {
- if ((domain.startsWith("*") && host.endsWith(domain.replace("*", ""))) || domain.equals(host)) {
- matchFound = true;
- break;
- }
- }
- if (!matchFound)
- return null;
- }
- if (!trigger.unlessDomain.isEmpty()) {
- for (String domain : trigger.unlessDomain)
- if ((domain.startsWith("*") && host.endsWith(domain.replace("*", ""))) || domain.equals(host))
- return null;
- }
-
- final String[] webViewUrl = new String[1];
- if (!trigger.loadType.isEmpty() || !trigger.ifTopUrl.isEmpty() || !trigger.unlessTopUrl.isEmpty()) {
- final CountDownLatch latch = new CountDownLatch(1);
- Handler handler = new Handler(Looper.getMainLooper());
- handler.post(new Runnable() {
- @Override
- public void run() {
- webViewUrl[0] = webView.getUrl();
- latch.countDown();
- }
- });
- latch.await();
- }
-
- if (!trigger.loadType.isEmpty()) {
- URI cUrl = new URI(webViewUrl[0]);
- String cHost = cUrl.getHost();
- int cPort = cUrl.getPort();
- String cScheme = cUrl.getScheme();
-
- if ( (trigger.loadType.contains("first-party") && cHost != null && !(cScheme.equals(scheme) && cHost.equals(host) && cPort == port)) ||
- (trigger.loadType.contains("third-party") && cHost != null && cHost.equals(host)) )
- return null;
- }
- if (!trigger.ifTopUrl.isEmpty()) {
- boolean matchFound = false;
- for (String topUrl : trigger.ifTopUrl) {
- if (webViewUrl[0].equals(topUrl)) {
- matchFound = true;
- break;
- }
- }
- if (!matchFound)
- return null;
- }
- if (!trigger.unlessTopUrl.isEmpty()) {
- for (String topUrl : trigger.unlessTopUrl)
- if (webViewUrl[0].equals(topUrl))
- return null;
- }
-
- switch (action.type) {
-
- case BLOCK:
- return new WebResourceResponse("", "", null);
-
- case CSS_DISPLAY_NONE:
- final String jsScript = "function hide () { document.querySelectorAll('" + action.selector + "').forEach(function (item, index) { item.style.display = \"none\"; }); }; hide(); document.addEventListener(\"DOMContentLoaded\", function(event) { hide(); });";
- final Handler handler = new Handler(Looper.getMainLooper());
- Log.d(LOG_TAG, jsScript);
- handler.post(new Runnable() {
- @Override
- public void run() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- webView.evaluateJavascript(jsScript, null);
- } else {
- webView.loadUrl("javascript:" + jsScript);
- }
- }
- });
- break;
-
- case MAKE_HTTPS:
- if (url.startsWith("http://")) {
- String urlHttps = url.replace("http://", "https://");
-
- Request mRequest = new Request.Builder().url(urlHttps).build();
- Response response = null;
-
- try {
-
- response = webView.httpClient.newCall(mRequest).execute();
- byte[] dataBytes = response.body().bytes();
- InputStream dataStream = new ByteArrayInputStream(dataBytes);
-
- String[] contentTypeSplitted = response.header("content-type", "text/plain").split(";");
-
- String contentType = contentTypeSplitted[0].trim();
- String encoding = (contentTypeSplitted.length > 1 && contentTypeSplitted[1].contains("charset="))
- ? contentTypeSplitted[1].replace("charset=", "").trim()
- : "utf-8";
-
- response.close();
-
- return new WebResourceResponse(contentType, encoding, dataStream);
-
- } catch (IOException e) {
- e.printStackTrace();
- if (response != null) {
- response.close();
- }
- Log.e(LOG_TAG, e.getMessage());
- }
- }
- break;
- }
- }
- }
- return null;
- }
-
- public static WebResourceResponse checkUrl(final InAppWebView webView, String url) throws URISyntaxException, InterruptedException {
- ContentBlockerTriggerResourceType responseResourceType = getResourceTypeFromUrl(webView, url);
- return checkUrl(webView, url, responseResourceType);
- }
-
- public static WebResourceResponse checkUrl(final InAppWebView webView, String url, String contentType) throws URISyntaxException, InterruptedException {
- ContentBlockerTriggerResourceType responseResourceType = getResourceTypeFromContentType(contentType);
- return checkUrl(webView, url, responseResourceType);
- }
-
-
- public static ContentBlockerTriggerResourceType getResourceTypeFromUrl(InAppWebView webView, String url) {
- ContentBlockerTriggerResourceType responseResourceType = ContentBlockerTriggerResourceType.RAW;
-
- // make an HTTP "HEAD" request to the server for that URL. This will not return the full content of the URL.
- if (url.startsWith("http://") || url.startsWith("https://")) {
- Request mRequest = new Request.Builder().url(url).head().build();
- Response response = null;
- try {
- response = webView.httpClient.newCall(mRequest).execute();
-
- if (response.header("content-type") != null) {
- String[] contentTypeSplitted = response.header("content-type").split(";");
-
- String contentType = contentTypeSplitted[0].trim();
- String encoding = (contentTypeSplitted.length > 1 && contentTypeSplitted[1].contains("charset="))
- ? contentTypeSplitted[1].replace("charset=", "").trim()
- : "utf-8";
-
- response.close();
- responseResourceType = getResourceTypeFromContentType(contentType);
- }
-
- } catch (IOException e) {
- if (response != null) {
- response.close();
- }
- e.printStackTrace();
- Log.e(LOG_TAG, e.getMessage());
- }
- }
- return responseResourceType;
- }
-
- public static ContentBlockerTriggerResourceType getResourceTypeFromContentType(String contentType) {
- ContentBlockerTriggerResourceType responseResourceType = ContentBlockerTriggerResourceType.RAW;
-
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
- if (contentType.equals("text/css")) {
- responseResourceType = ContentBlockerTriggerResourceType.STYLE_SHEET;
- } else if (contentType.equals("image/svg+xml")) {
- responseResourceType = ContentBlockerTriggerResourceType.SVG_DOCUMENT;
- } else if (contentType.startsWith("image/")) {
- responseResourceType = ContentBlockerTriggerResourceType.IMAGE;
- } else if (contentType.startsWith("font/")) {
- responseResourceType = ContentBlockerTriggerResourceType.FONT;
- } else if (contentType.startsWith("audio/") || contentType.startsWith("video/") || contentType.equals("application/ogg")) {
- responseResourceType = ContentBlockerTriggerResourceType.MEDIA;
- } else if (contentType.endsWith("javascript")) {
- responseResourceType = ContentBlockerTriggerResourceType.SCRIPT;
- } else if (contentType.startsWith("text/")) {
- responseResourceType = ContentBlockerTriggerResourceType.DOCUMENT;
- }
-
- return responseResourceType;
+ public ContentBlocker (ContentBlockerTrigger trigger, ContentBlockerAction action) {
+ this.trigger = trigger;
+ this.action = action;
}
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerHandler.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerHandler.java
new file mode 100644
index 00000000..ef45be8e
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerHandler.java
@@ -0,0 +1,251 @@
+package com.pichillilorenzo.flutter_inappbrowser.ContentBlocker;
+
+import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+import android.webkit.WebResourceResponse;
+
+import com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebView;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.regex.Matcher;
+
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class ContentBlockerHandler {
+ protected static final String LOG_TAG = "ContentBlockerHandler";
+
+ protected List ruleList = new ArrayList<>();
+
+ public ContentBlockerHandler() {}
+
+ public ContentBlockerHandler(List ruleList) {
+ this.ruleList = ruleList;
+ }
+
+ public List getRuleList() {
+ return this.ruleList;
+ }
+
+ public void setRuleList(List newRuleList) {
+ this.ruleList = newRuleList;
+ }
+
+ public WebResourceResponse checkUrl(final InAppWebView webView, String url, ContentBlockerTriggerResourceType responseResourceType) throws URISyntaxException, InterruptedException {
+ if (webView.options.contentBlockers == null)
+ return null;
+
+ URI u = new URI(url);
+ String host = u.getHost();
+ int port = u.getPort();
+ String scheme = u.getScheme();
+ // thread safe copy list
+ List ruleListCopy = new CopyOnWriteArrayList(ruleList);
+
+ for (ContentBlocker contentBlocker : ruleListCopy) {
+ ContentBlockerTrigger trigger = contentBlocker.trigger;
+ List resourceTypes = trigger.resourceType;
+
+ ContentBlockerAction action = contentBlocker.action;
+
+ Matcher m = trigger.urlFilterPatternCompiled.matcher(url);
+ if (m.matches()) {
+
+ if (!resourceTypes.isEmpty() && !resourceTypes.contains(responseResourceType)) {
+ return null;
+ }
+ if (!trigger.ifDomain.isEmpty()) {
+ boolean matchFound = false;
+ for (String domain : trigger.ifDomain) {
+ if ((domain.startsWith("*") && host.endsWith(domain.replace("*", ""))) || domain.equals(host)) {
+ matchFound = true;
+ break;
+ }
+ }
+ if (!matchFound)
+ return null;
+ }
+ if (!trigger.unlessDomain.isEmpty()) {
+ for (String domain : trigger.unlessDomain)
+ if ((domain.startsWith("*") && host.endsWith(domain.replace("*", ""))) || domain.equals(host))
+ return null;
+ }
+
+ final String[] webViewUrl = new String[1];
+ if (!trigger.loadType.isEmpty() || !trigger.ifTopUrl.isEmpty() || !trigger.unlessTopUrl.isEmpty()) {
+ final CountDownLatch latch = new CountDownLatch(1);
+ Handler handler = new Handler(Looper.getMainLooper());
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ webViewUrl[0] = webView.getUrl();
+ latch.countDown();
+ }
+ });
+ latch.await();
+ }
+
+ if (!trigger.loadType.isEmpty()) {
+ URI cUrl = new URI(webViewUrl[0]);
+ String cHost = cUrl.getHost();
+ int cPort = cUrl.getPort();
+ String cScheme = cUrl.getScheme();
+
+ if ( (trigger.loadType.contains("first-party") && cHost != null && !(cScheme.equals(scheme) && cHost.equals(host) && cPort == port)) ||
+ (trigger.loadType.contains("third-party") && cHost != null && cHost.equals(host)) )
+ return null;
+ }
+ if (!trigger.ifTopUrl.isEmpty()) {
+ boolean matchFound = false;
+ for (String topUrl : trigger.ifTopUrl) {
+ if (webViewUrl[0].equals(topUrl)) {
+ matchFound = true;
+ break;
+ }
+ }
+ if (!matchFound)
+ return null;
+ }
+ if (!trigger.unlessTopUrl.isEmpty()) {
+ for (String topUrl : trigger.unlessTopUrl)
+ if (webViewUrl[0].equals(topUrl))
+ return null;
+ }
+
+ switch (action.type) {
+
+ case BLOCK:
+ return new WebResourceResponse("", "", null);
+
+ case CSS_DISPLAY_NONE:
+ final String jsScript = "function hide () { document.querySelectorAll('" + action.selector + "').forEach(function (item, index) { item.style.display = \"none\"; }); }; hide(); document.addEventListener(\"DOMContentLoaded\", function(event) { hide(); });";
+ final Handler handler = new Handler(Looper.getMainLooper());
+ Log.d(LOG_TAG, jsScript);
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ webView.evaluateJavascript(jsScript, null);
+ } else {
+ webView.loadUrl("javascript:" + jsScript);
+ }
+ }
+ });
+ break;
+
+ case MAKE_HTTPS:
+ if (url.startsWith("http://")) {
+ String urlHttps = url.replace("http://", "https://");
+
+ Request mRequest = new Request.Builder().url(urlHttps).build();
+ Response response = null;
+
+ try {
+
+ response = webView.httpClient.newCall(mRequest).execute();
+ byte[] dataBytes = response.body().bytes();
+ InputStream dataStream = new ByteArrayInputStream(dataBytes);
+
+ String[] contentTypeSplitted = response.header("content-type", "text/plain").split(";");
+
+ String contentType = contentTypeSplitted[0].trim();
+ String encoding = (contentTypeSplitted.length > 1 && contentTypeSplitted[1].contains("charset="))
+ ? contentTypeSplitted[1].replace("charset=", "").trim()
+ : "utf-8";
+
+ response.close();
+
+ return new WebResourceResponse(contentType, encoding, dataStream);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ if (response != null) {
+ response.close();
+ }
+ Log.e(LOG_TAG, e.getMessage());
+ }
+ }
+ break;
+ }
+ }
+ }
+ return null;
+ }
+
+ public WebResourceResponse checkUrl(final InAppWebView webView, String url) throws URISyntaxException, InterruptedException {
+ ContentBlockerTriggerResourceType responseResourceType = getResourceTypeFromUrl(webView, url);
+ return checkUrl(webView, url, responseResourceType);
+ }
+
+ public WebResourceResponse checkUrl(final InAppWebView webView, String url, String contentType) throws URISyntaxException, InterruptedException {
+ ContentBlockerTriggerResourceType responseResourceType = getResourceTypeFromContentType(contentType);
+ return checkUrl(webView, url, responseResourceType);
+ }
+
+
+ public ContentBlockerTriggerResourceType getResourceTypeFromUrl(InAppWebView webView, String url) {
+ ContentBlockerTriggerResourceType responseResourceType = ContentBlockerTriggerResourceType.RAW;
+
+ // make an HTTP "HEAD" request to the server for that URL. This will not return the full content of the URL.
+ if (url.startsWith("http://") || url.startsWith("https://")) {
+ Request mRequest = new Request.Builder().url(url).head().build();
+ Response response = null;
+ try {
+ response = webView.httpClient.newCall(mRequest).execute();
+
+ if (response.header("content-type") != null) {
+ String[] contentTypeSplitted = response.header("content-type").split(";");
+
+ String contentType = contentTypeSplitted[0].trim();
+ String encoding = (contentTypeSplitted.length > 1 && contentTypeSplitted[1].contains("charset="))
+ ? contentTypeSplitted[1].replace("charset=", "").trim()
+ : "utf-8";
+
+ response.close();
+ responseResourceType = getResourceTypeFromContentType(contentType);
+ }
+
+ } catch (Exception e) {
+ if (response != null) {
+ response.close();
+ }
+ e.printStackTrace();
+ Log.e(LOG_TAG, e.getMessage());
+ }
+ }
+ return responseResourceType;
+ }
+
+ public ContentBlockerTriggerResourceType getResourceTypeFromContentType(String contentType) {
+ ContentBlockerTriggerResourceType responseResourceType = ContentBlockerTriggerResourceType.RAW;
+
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
+ if (contentType.equals("text/css")) {
+ responseResourceType = ContentBlockerTriggerResourceType.STYLE_SHEET;
+ } else if (contentType.equals("image/svg+xml")) {
+ responseResourceType = ContentBlockerTriggerResourceType.SVG_DOCUMENT;
+ } else if (contentType.startsWith("image/")) {
+ responseResourceType = ContentBlockerTriggerResourceType.IMAGE;
+ } else if (contentType.startsWith("font/")) {
+ responseResourceType = ContentBlockerTriggerResourceType.FONT;
+ } else if (contentType.startsWith("audio/") || contentType.startsWith("video/") || contentType.equals("application/ogg")) {
+ responseResourceType = ContentBlockerTriggerResourceType.MEDIA;
+ } else if (contentType.endsWith("javascript")) {
+ responseResourceType = ContentBlockerTriggerResourceType.SCRIPT;
+ } else if (contentType.startsWith("text/")) {
+ responseResourceType = ContentBlockerTriggerResourceType.DOCUMENT;
+ }
+
+ return responseResourceType;
+ }
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerTrigger.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerTrigger.java
index d1f94853..26f95996 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerTrigger.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerTrigger.java
@@ -3,10 +3,12 @@ package com.pichillilorenzo.flutter_inappbrowser.ContentBlocker;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
public class ContentBlockerTrigger {
public String urlFilter;
+ public Pattern urlFilterPatternCompiled;
public Boolean urlFilterIsCaseSensitive;
public List resourceType = new ArrayList<>();
public List ifDomain = new ArrayList<>();
@@ -18,6 +20,8 @@ public class ContentBlockerTrigger {
public ContentBlockerTrigger(String urlFilter, Boolean urlFilterIsCaseSensitive, List resourceType, List ifDomain,
List unlessDomain, List loadType, List ifTopUrl, List unlessTopUrl) {
this.urlFilter = urlFilter;
+ this.urlFilterPatternCompiled = Pattern.compile(this.urlFilter);
+
this.resourceType = resourceType != null ? resourceType : this.resourceType;
this.urlFilterIsCaseSensitive = urlFilterIsCaseSensitive != null ? urlFilterIsCaseSensitive : false;
this.ifDomain = ifDomain != null ? ifDomain : this.ifDomain;
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
index f05e73de..294034aa 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java
@@ -1,5 +1,6 @@
package com.pichillilorenzo.flutter_inappbrowser;
+import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
@@ -191,7 +192,10 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
result.success((webView != null) && webView.isLoading());
break;
case "takeScreenshot":
- result.success((webView != null) ? webView.takeScreenshot() : null);
+ if (webView != null)
+ webView.takeScreenshot(result);
+ else
+ result.error(LOG_TAG, "webView is null", null);
break;
case "setOptions":
if (webView != null) {
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
index 063adbc5..0181a369 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
@@ -1,5 +1,7 @@
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
+import android.Manifest;
+import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -9,6 +11,7 @@ import android.os.Build;
import android.util.Log;
import android.view.View;
import android.webkit.ConsoleMessage;
+import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
@@ -17,6 +20,7 @@ import android.widget.FrameLayout;
import com.pichillilorenzo.flutter_inappbrowser.FlutterWebView;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserActivity;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin;
+import com.pichillilorenzo.flutter_inappbrowser.RequestPermissionHandler;
import java.util.HashMap;
import java.util.Map;
@@ -98,6 +102,34 @@ public class InAppWebChromeClient extends WebChromeClient {
return false;
}
+ @Override
+ public void onGeolocationPermissionsShowPrompt (final String origin, final GeolocationPermissions.Callback callback) {
+ Map obj = new HashMap<>();
+ if (inAppBrowserActivity != null)
+ obj.put("uuid", inAppBrowserActivity.uuid);
+ obj.put("origin", origin);
+ getChannel().invokeMethod("onGeolocationPermissionsShowPrompt", obj, new MethodChannel.Result() {
+ @Override
+ public void success(Object o) {
+ Map response = (Map) o;
+ if (response != null)
+ callback.invoke((String) response.get("origin"),(Boolean) response.get("allow"),(Boolean) response.get("retain"));
+ else
+ callback.invoke(origin,false,false);
+ }
+
+ @Override
+ public void error(String s, String s1, Object o) {
+ callback.invoke(origin,false,false);
+ }
+
+ @Override
+ public void notImplemented() {
+ callback.invoke(origin,false,false);
+ }
+ });
+ }
+
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Map obj = new HashMap<>();
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
index dc5e78f0..f6c62d6a 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java
@@ -18,6 +18,10 @@ import android.webkit.WebHistoryItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
+import com.pichillilorenzo.flutter_inappbrowser.ContentBlocker.ContentBlocker;
+import com.pichillilorenzo.flutter_inappbrowser.ContentBlocker.ContentBlockerAction;
+import com.pichillilorenzo.flutter_inappbrowser.ContentBlocker.ContentBlockerHandler;
+import com.pichillilorenzo.flutter_inappbrowser.ContentBlocker.ContentBlockerTrigger;
import com.pichillilorenzo.flutter_inappbrowser.FlutterWebView;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserActivity;
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin;
@@ -34,7 +38,6 @@ import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
-import okhttp3.Cache;
import okhttp3.OkHttpClient;
public class InAppWebView extends WebView {
@@ -51,6 +54,7 @@ public class InAppWebView extends WebView {
public boolean isLoading = false;
public OkHttpClient httpClient;
int okHttpClientCacheSize = 10 * 1024 * 1024; // 10MB
+ public ContentBlockerHandler contentBlockerHandler = new ContentBlockerHandler();
static final String consoleLogJS = "(function() {" +
" var oldLogs = {" +
@@ -115,12 +119,11 @@ public class InAppWebView extends WebView {
@Override
public void reload() {
super.reload();
- Log.d(LOG_TAG, "RELOAD");
}
public void prepare() {
- final Activity activity = (inAppBrowserActivity != null) ? inAppBrowserActivity : registrar.activity();
+ final Activity activity = (inAppBrowserActivity != null) ? inAppBrowserActivity : registrar.activity().getParent();
boolean isFromInAppBrowserActivity = inAppBrowserActivity != null;
@@ -173,24 +176,53 @@ public class InAppWebView extends WebView {
setVerticalScrollBarEnabled(options.verticalScrollBarEnabled);
setHorizontalScrollBarEnabled(options.horizontalScrollBarEnabled);
- if (options.transparentBackground) {
+ if (options.transparentBackground)
setBackgroundColor(Color.TRANSPARENT);
- }
- if (!options.mixedContentMode.isEmpty()) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- switch (options.mixedContentMode) {
- case "MIXED_CONTENT_COMPATIBILITY_MODE":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
- break;
- case "MIXED_CONTENT_ALWAYS_ALLOW":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
- break;
- case "MIXED_CONTENT_NEVER_ALLOW":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
- break;
- }
- }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && options.mixedContentMode != null)
+ settings.setMixedContentMode(options.mixedContentMode);
+
+ settings.setAllowContentAccess(options.allowContentAccess);
+ settings.setAllowFileAccess(options.allowFileAccess);
+ settings.setAllowFileAccessFromFileURLs(options.allowFileAccessFromFileURLs);
+ settings.setAllowUniversalAccessFromFileURLs(options.allowUniversalAccessFromFileURLs);
+ settings.setAppCacheEnabled(options.appCacheEnabled);
+ if (options.appCachePath != null && !options.appCachePath.isEmpty() && options.appCacheEnabled)
+ settings.setAppCachePath(options.appCachePath);
+ settings.setBlockNetworkImage(options.blockNetworkImage);
+ settings.setBlockNetworkLoads(options.blockNetworkLoads);
+ if (options.cacheMode != null)
+ settings.setCacheMode(options.cacheMode);
+ settings.setCursiveFontFamily(options.cursiveFontFamily);
+ settings.setDefaultFixedFontSize(options.defaultFixedFontSize);
+ settings.setDefaultFontSize(options.defaultFontSize);
+ settings.setDefaultTextEncodingName(options.defaultTextEncodingName);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && options.disabledActionModeMenuItems != null)
+ settings.setDisabledActionModeMenuItems(options.disabledActionModeMenuItems);
+ settings.setFantasyFontFamily(options.fantasyFontFamily);
+ settings.setFixedFontFamily(options.fixedFontFamily);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.forceDark != null)
+ settings.setForceDark(options.forceDark);
+ settings.setGeolocationEnabled(options.geolocationEnabled);
+ if (options.layoutAlgorithm != null)
+ settings.setLayoutAlgorithm(options.layoutAlgorithm);
+ settings.setLoadWithOverviewMode(options.loadWithOverviewMode);
+ settings.setLoadsImagesAutomatically(options.loadsImagesAutomatically);
+ settings.setMinimumFontSize(options.minimumFontSize);
+ settings.setMinimumLogicalFontSize(options.minimumLogicalFontSize);
+ settings.setNeedInitialFocus(options.needInitialFocus);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+ settings.setOffscreenPreRaster(options.offscreenPreRaster);
+ settings.setSansSerifFontFamily(options.sansSerifFontFamily);
+ settings.setSerifFontFamily(options.serifFontFamily);
+ settings.setStandardFontFamily(options.standardFontFamily);
+
+ contentBlockerHandler.getRuleList().clear();
+ for (Map> contentBlocker : options.contentBlockers) {
+ // compile ContentBlockerTrigger urlFilter
+ ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger"));
+ ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action"));
+ contentBlockerHandler.getRuleList().add(new ContentBlocker(trigger, action));
}
}
@@ -286,29 +318,36 @@ public class InAppWebView extends WebView {
clearFormData();
}
- public byte[] takeScreenshot() {
- float scale = getResources().getDisplayMetrics().density; // getScale();
- int height = (int) (getContentHeight() * scale + 0.5);
+ public void takeScreenshot(final MethodChannel.Result result) {
+ post(new Runnable() {
+ @Override
+ public void run() {
+ float scale = getResources().getDisplayMetrics().density; // getScale();
+ int height = (int) (getContentHeight() * scale + 0.5);
- Bitmap b = Bitmap.createBitmap( getWidth(),
- height, Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
+ Bitmap b = Bitmap.createBitmap( getWidth(),
+ height, Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(b);
- draw(c);
- int scrollOffset = (getScrollY() + getMeasuredHeight() > b.getHeight())
- ? b.getHeight() : getScrollY();
- Bitmap resized = Bitmap.createBitmap(
- b, 0, scrollOffset, b.getWidth(), getMeasuredHeight());
+ draw(c);
+ int scrollOffset = (getScrollY() + getMeasuredHeight() > b.getHeight())
+ ? b.getHeight() : getScrollY();
+ Bitmap resized = Bitmap.createBitmap(
+ b, 0, scrollOffset, b.getWidth(), getMeasuredHeight());
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- resized.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
- try {
- byteArrayOutputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- resized.recycle();
- return byteArrayOutputStream.toByteArray();
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ resized.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
+ try {
+ byteArrayOutputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ Log.e(LOG_TAG, e.getMessage());
+ }
+ resized.recycle();
+ result.success(byteArrayOutputStream.toByteArray());
+ }
+ });
}
public void setOptions(InAppWebViewOptions newOptions, HashMap newOptionsMap) {
@@ -353,7 +392,7 @@ public class InAppWebView extends WebView {
if (newOptionsMap.get("supportZoom") != null && options.supportZoom != newOptions.supportZoom)
settings.setSupportZoom(newOptions.supportZoom);
- if (newOptionsMap.get("textZoom") != null && options.textZoom != newOptions.textZoom)
+ if (newOptionsMap.get("textZoom") != null && !options.textZoom.equals(newOptions.textZoom))
settings.setTextZoom(newOptions.textZoom);
if (newOptionsMap.get("verticalScrollBarEnabled") != null && options.verticalScrollBarEnabled != newOptions.verticalScrollBarEnabled)
@@ -370,21 +409,9 @@ public class InAppWebView extends WebView {
}
}
- if (newOptionsMap.get("mixedContentMode") != null && !options.mixedContentMode.equals(newOptions.mixedContentMode)) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- switch (newOptions.mixedContentMode) {
- case "MIXED_CONTENT_COMPATIBILITY_MODE":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
- break;
- case "MIXED_CONTENT_ALWAYS_ALLOW":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
- break;
- case "MIXED_CONTENT_NEVER_ALLOW":
- settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
- break;
- }
- }
- }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ if (newOptionsMap.get("mixedContentMode") != null && !options.mixedContentMode.equals(newOptions.mixedContentMode))
+ settings.setMixedContentMode(newOptions.mixedContentMode);
if (newOptionsMap.get("useOnTargetBlank") != null && options.useOnTargetBlank != newOptions.useOnTargetBlank)
settings.setSupportMultipleWindows(newOptions.useOnTargetBlank);
@@ -397,6 +424,104 @@ public class InAppWebView extends WebView {
}
}
+ if (newOptionsMap.get("allowContentAccess") != null && options.allowContentAccess != newOptions.allowContentAccess)
+ settings.setAllowContentAccess(newOptions.allowContentAccess);
+
+ if (newOptionsMap.get("allowFileAccess") != null && options.allowFileAccess != newOptions.allowFileAccess)
+ settings.setAllowFileAccess(newOptions.allowFileAccess);
+
+ if (newOptionsMap.get("allowFileAccessFromFileURLs") != null && options.allowFileAccessFromFileURLs != newOptions.allowFileAccessFromFileURLs)
+ settings.setAllowFileAccessFromFileURLs(newOptions.allowFileAccessFromFileURLs);
+
+ if (newOptionsMap.get("allowUniversalAccessFromFileURLs") != null && options.allowUniversalAccessFromFileURLs != newOptions.allowUniversalAccessFromFileURLs)
+ settings.setAllowUniversalAccessFromFileURLs(newOptions.allowUniversalAccessFromFileURLs);
+
+ if (newOptionsMap.get("appCacheEnabled") != null && options.appCacheEnabled != newOptions.appCacheEnabled)
+ settings.setAppCacheEnabled(newOptions.appCacheEnabled);
+
+ if (newOptionsMap.get("appCachePath") != null && !options.appCachePath.equals(newOptions.appCachePath))
+ if (newOptions.appCacheEnabled)
+ settings.setAppCachePath(newOptions.appCachePath);
+
+ if (newOptionsMap.get("blockNetworkImage") != null && options.blockNetworkImage != newOptions.blockNetworkImage)
+ settings.setBlockNetworkImage(newOptions.blockNetworkImage);
+
+ if (newOptionsMap.get("blockNetworkLoads") != null && options.blockNetworkLoads != newOptions.blockNetworkLoads)
+ settings.setBlockNetworkLoads(newOptions.blockNetworkLoads);
+
+ if (newOptionsMap.get("cacheMode") != null && !options.cacheMode.equals(newOptions.cacheMode))
+ settings.setCacheMode(newOptions.cacheMode);
+
+ if (newOptionsMap.get("cursiveFontFamily") != null && !options.cursiveFontFamily.equals(newOptions.cursiveFontFamily))
+ settings.setCursiveFontFamily(newOptions.cursiveFontFamily);
+
+ if (newOptionsMap.get("defaultFixedFontSize") != null && !options.defaultFixedFontSize.equals(newOptions.defaultFixedFontSize))
+ settings.setDefaultFixedFontSize(newOptions.defaultFixedFontSize);
+
+ if (newOptionsMap.get("defaultFontSize") != null && !options.defaultFontSize.equals(newOptions.defaultFontSize))
+ settings.setDefaultFontSize(newOptions.defaultFontSize);
+
+ if (newOptionsMap.get("defaultTextEncodingName") != null && !options.defaultTextEncodingName.equals(newOptions.defaultTextEncodingName))
+ settings.setDefaultTextEncodingName(newOptions.defaultTextEncodingName);
+
+ if (newOptionsMap.get("disabledActionModeMenuItems") != null && !options.disabledActionModeMenuItems.equals(newOptions.disabledActionModeMenuItems))
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ settings.setDisabledActionModeMenuItems(newOptions.disabledActionModeMenuItems);
+
+ if (newOptionsMap.get("fantasyFontFamily") != null && !options.fantasyFontFamily.equals(newOptions.fantasyFontFamily))
+ settings.setFantasyFontFamily(newOptions.fantasyFontFamily);
+
+ if (newOptionsMap.get("fixedFontFamily") != null && !options.fixedFontFamily.equals(newOptions.fixedFontFamily))
+ settings.setFixedFontFamily(newOptions.fixedFontFamily);
+
+ if (newOptionsMap.get("forceDark") != null && !options.forceDark.equals(newOptions.forceDark))
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ settings.setForceDark(newOptions.forceDark);
+
+ if (newOptionsMap.get("geolocationEnabled") != null && options.geolocationEnabled != newOptions.geolocationEnabled)
+ settings.setGeolocationEnabled(newOptions.geolocationEnabled);
+
+ if (newOptionsMap.get("layoutAlgorithm") != null && options.layoutAlgorithm != newOptions.layoutAlgorithm)
+ settings.setLayoutAlgorithm(newOptions.layoutAlgorithm);
+
+ if (newOptionsMap.get("loadWithOverviewMode") != null && options.loadWithOverviewMode != newOptions.loadWithOverviewMode)
+ settings.setLoadWithOverviewMode(newOptions.loadWithOverviewMode);
+
+ if (newOptionsMap.get("loadsImagesAutomatically") != null && options.loadsImagesAutomatically != newOptions.loadsImagesAutomatically)
+ settings.setLoadsImagesAutomatically(newOptions.loadsImagesAutomatically);
+
+ if (newOptionsMap.get("minimumFontSize") != null && !options.minimumFontSize.equals(newOptions.minimumFontSize))
+ settings.setMinimumFontSize(newOptions.minimumFontSize);
+
+ if (newOptionsMap.get("minimumLogicalFontSize") != null && !options.minimumLogicalFontSize.equals(newOptions.minimumLogicalFontSize))
+ settings.setMinimumLogicalFontSize(newOptions.minimumLogicalFontSize);
+
+ if (newOptionsMap.get("needInitialFocus") != null && options.needInitialFocus != newOptions.needInitialFocus)
+ settings.setNeedInitialFocus(newOptions.needInitialFocus);
+
+ if (newOptionsMap.get("offscreenPreRaster") != null && options.offscreenPreRaster != newOptions.offscreenPreRaster)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+ settings.setOffscreenPreRaster(newOptions.offscreenPreRaster);
+
+ if (newOptionsMap.get("sansSerifFontFamily") != null && !options.sansSerifFontFamily.equals(newOptions.sansSerifFontFamily))
+ settings.setSansSerifFontFamily(newOptions.sansSerifFontFamily);
+
+ if (newOptionsMap.get("serifFontFamily") != null && !options.serifFontFamily.equals(newOptions.serifFontFamily))
+ settings.setSerifFontFamily(newOptions.serifFontFamily);
+
+ if (newOptionsMap.get("standardFontFamily") != null && !options.standardFontFamily.equals(newOptions.standardFontFamily))
+ settings.setStandardFontFamily(newOptions.standardFontFamily);
+
+ if (newOptions.contentBlockers != null) {
+ contentBlockerHandler.getRuleList().clear();
+ for (Map> contentBlocker : newOptions.contentBlockers) {
+ // compile ContentBlockerTrigger urlFilter
+ ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger"));
+ ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action"));
+ contentBlockerHandler.getRuleList().add(new ContentBlocker(trigger, action));
+ }
+ }
+
options = newOptions;
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
index 03589d13..24566dab 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java
@@ -335,7 +335,7 @@ public class InAppWebViewClient extends WebViewClient {
Map res = (Map) flutterResult.result;
WebResourceResponse response = null;
try {
- response = ContentBlocker.checkUrl(webView, url, res.get("content-type"));
+ response = webView.contentBlockerHandler.checkUrl(webView, url, res.get("content-type"));
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
@@ -349,7 +349,7 @@ public class InAppWebViewClient extends WebViewClient {
WebResourceResponse response = null;
try {
- response = ContentBlocker.checkUrl(webView, url);
+ response = webView.contentBlockerHandler.checkUrl(webView, url);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
index 0aac1f38..e240cedf 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java
@@ -1,5 +1,7 @@
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
+import android.webkit.WebSettings;
+
import com.pichillilorenzo.flutter_inappbrowser.Options;
import java.util.ArrayList;
@@ -19,11 +21,12 @@ public class InAppWebViewOptions extends Options {
public boolean javaScriptEnabled = true;
public boolean javaScriptCanOpenWindowsAutomatically = false;
public boolean mediaPlaybackRequiresUserGesture = true;
- public int textZoom = 100;
+ public Integer textZoom = 100;
public boolean verticalScrollBarEnabled = true;
public boolean horizontalScrollBarEnabled = true;
public List resourceCustomSchemes = new ArrayList<>();
public List