From 71c20932838d4cf8c52bc4979dd0ed3c5b2ffa91 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Mon, 2 May 2022 15:08:23 +0200 Subject: [PATCH] added forceDarkStrategy webview setting, updated some android checks on webview feature supported --- CHANGELOG.md | 2 +- .../InAppWebViewStatic.java | 2 +- .../in_app_webview/InAppWebView.java | 367 ++++++++++-------- .../in_app_webview/InAppWebViewClient.java | 11 +- .../in_app_webview/InAppWebViewSettings.java | 28 +- .../types/WebResourceRequestExt.java | 12 +- .../in_app_webview/safe_browsing.dart | 2 +- lib/src/android/webview_feature.dart | 33 +- .../android/in_app_webview_controller.dart | 4 +- .../in_app_webview_controller.dart | 11 +- .../in_app_webview_settings.dart | 17 +- lib/src/types/force_dark.dart | 18 +- lib/src/types/force_dark_strategy.dart | 69 ++++ lib/src/types/main.dart | 3 +- 14 files changed, 372 insertions(+), 207 deletions(-) create mode 100644 lib/src/types/force_dark_strategy.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 44672141..813a388f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Added Web support - Added `ProxyController` for Android - Added `pauseAllMediaPlayback`, `setAllMediaPlaybackSuspended`, `closeAllMediaPresentations`, `requestMediaPlaybackState`, `isInFullscreen`, `getCameraCaptureState`, `setCameraCaptureState`, `getMicrophoneCaptureState`, `setMicrophoneCaptureState` WebView controller methods -- Added `underPageBackgroundColor`, `isTextInteractionEnabled`, `isSiteSpecificQuirksModeEnabled`, `upgradeKnownHostsToHTTPS` WebView settings +- Added `underPageBackgroundColor`, `isTextInteractionEnabled`, `isSiteSpecificQuirksModeEnabled`, `upgradeKnownHostsToHTTPS`, `forceDarkStrategy` WebView settings - Added support for `onPermissionRequest` event on iOS 15.0+ - Updated `getMetaThemeColor` on iOS 15.0+ - Deprecated `onLoadError` for `onReceivedError`. `onReceivedError` will be called also for subframes. diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java index 646eda39..c57d21ca 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java @@ -57,7 +57,7 @@ public class InAppWebViewStatic implements MethodChannel.MethodCallHandler { } else result.success(null); break; - case "setSafeBrowsingWhitelist": + case "setSafeBrowsingAllowlist": if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ALLOWLIST)) { Set hosts = new HashSet<>((List) call.argument("hosts")); WebViewCompat.setSafeBrowsingAllowlist(hosts, new ValueCallback() { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java index f4f222af..a0e86c39 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java @@ -43,6 +43,7 @@ import android.webkit.WebBackForwardList; import android.webkit.WebHistoryItem; import android.webkit.WebSettings; import android.webkit.WebStorage; +import android.webkit.WebView; import android.widget.HorizontalScrollView; import android.widget.LinearLayout; import android.widget.TextView; @@ -50,6 +51,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.webkit.WebSettingsCompat; import androidx.webkit.WebViewCompat; import androidx.webkit.WebViewFeature; @@ -229,7 +231,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie settings.setDisplayZoomControls(customSettings.displayZoomControls); settings.setSupportMultipleWindows(customSettings.supportMultipleWindows); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)) + WebSettingsCompat.setSafeBrowsingEnabled(settings, customSettings.safeBrowsingEnabled); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) settings.setSafeBrowsingEnabled(customSettings.safeBrowsingEnabled); settings.setMediaPlaybackRequiresUserGesture(customSettings.mediaPlaybackRequiresUserGesture); @@ -287,12 +291,23 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie settings.setDefaultFixedFontSize(customSettings.defaultFixedFontSize); settings.setDefaultFontSize(customSettings.defaultFontSize); settings.setDefaultTextEncodingName(customSettings.defaultTextEncodingName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && customSettings.disabledActionModeMenuItems != null) - settings.setDisabledActionModeMenuItems(customSettings.disabledActionModeMenuItems); + if (customSettings.disabledActionModeMenuItems != null) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS)) + WebSettingsCompat.setDisabledActionModeMenuItems(settings, customSettings.disabledActionModeMenuItems); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + settings.setDisabledActionModeMenuItems(customSettings.disabledActionModeMenuItems); + } settings.setFantasyFontFamily(customSettings.fantasyFontFamily); settings.setFixedFontFamily(customSettings.fixedFontFamily); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && customSettings.forceDark != null) - settings.setForceDark(customSettings.forceDark); + if (customSettings.forceDark != null) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) + WebSettingsCompat.setForceDark(settings, customSettings.forceDark); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + settings.setForceDark(customSettings.forceDark); + } + if (customSettings.forceDarkStrategy != null && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) { + WebSettingsCompat.setForceDarkStrategy(settings, customSettings.forceDarkStrategy); + } settings.setGeolocationEnabled(customSettings.geolocationEnabled); if (customSettings.layoutAlgorithm != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && customSettings.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { @@ -306,7 +321,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie settings.setMinimumLogicalFontSize(customSettings.minimumLogicalFontSize); setInitialScale(customSettings.initialScale); settings.setNeedInitialFocus(customSettings.needInitialFocus); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + if (WebViewFeature.isFeatureSupported(WebViewFeature.OFF_SCREEN_PRERASTER)) + WebSettingsCompat.setOffscreenPreRaster(settings, customSettings.offscreenPreRaster); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) settings.setOffscreenPreRaster(customSettings.offscreenPreRaster); settings.setSansSerifFontFamily(customSettings.sansSerifFontFamily); settings.setSerifFontFamily(customSettings.serifFontFamily); @@ -640,94 +657,98 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie }); } - public void setSettings(InAppWebViewSettings newSettings, HashMap newSettingsMap) { + public void setSettings(InAppWebViewSettings newCustomSettings, HashMap newSettingsMap) { WebSettings settings = getSettings(); - if (newSettingsMap.get("javaScriptEnabled") != null && customSettings.javaScriptEnabled != newSettings.javaScriptEnabled) - settings.setJavaScriptEnabled(newSettings.javaScriptEnabled); + if (newSettingsMap.get("javaScriptEnabled") != null && customSettings.javaScriptEnabled != newCustomSettings.javaScriptEnabled) + settings.setJavaScriptEnabled(newCustomSettings.javaScriptEnabled); - if (newSettingsMap.get("useShouldInterceptAjaxRequest") != null && customSettings.useShouldInterceptAjaxRequest != newSettings.useShouldInterceptAjaxRequest) { + if (newSettingsMap.get("useShouldInterceptAjaxRequest") != null && customSettings.useShouldInterceptAjaxRequest != newCustomSettings.useShouldInterceptAjaxRequest) { enablePluginScriptAtRuntime( InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE, - newSettings.useShouldInterceptAjaxRequest, + newCustomSettings.useShouldInterceptAjaxRequest, InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT ); } - if (newSettingsMap.get("useShouldInterceptFetchRequest") != null && customSettings.useShouldInterceptFetchRequest != newSettings.useShouldInterceptFetchRequest) { + if (newSettingsMap.get("useShouldInterceptFetchRequest") != null && customSettings.useShouldInterceptFetchRequest != newCustomSettings.useShouldInterceptFetchRequest) { enablePluginScriptAtRuntime( InterceptFetchRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_FETCH_REQUEST_JS_SOURCE, - newSettings.useShouldInterceptFetchRequest, + newCustomSettings.useShouldInterceptFetchRequest, InterceptFetchRequestJS.INTERCEPT_FETCH_REQUEST_JS_PLUGIN_SCRIPT ); } - if (newSettingsMap.get("useOnLoadResource") != null && customSettings.useOnLoadResource != newSettings.useOnLoadResource) { + if (newSettingsMap.get("useOnLoadResource") != null && customSettings.useOnLoadResource != newCustomSettings.useOnLoadResource) { enablePluginScriptAtRuntime( OnLoadResourceJS.FLAG_VARIABLE_FOR_ON_LOAD_RESOURCE_JS_SOURCE, - newSettings.useOnLoadResource, + newCustomSettings.useOnLoadResource, OnLoadResourceJS.ON_LOAD_RESOURCE_JS_PLUGIN_SCRIPT ); } - if (newSettingsMap.get("javaScriptCanOpenWindowsAutomatically") != null && customSettings.javaScriptCanOpenWindowsAutomatically != newSettings.javaScriptCanOpenWindowsAutomatically) - settings.setJavaScriptCanOpenWindowsAutomatically(newSettings.javaScriptCanOpenWindowsAutomatically); + if (newSettingsMap.get("javaScriptCanOpenWindowsAutomatically") != null && customSettings.javaScriptCanOpenWindowsAutomatically != newCustomSettings.javaScriptCanOpenWindowsAutomatically) + settings.setJavaScriptCanOpenWindowsAutomatically(newCustomSettings.javaScriptCanOpenWindowsAutomatically); - if (newSettingsMap.get("builtInZoomControls") != null && customSettings.builtInZoomControls != newSettings.builtInZoomControls) - settings.setBuiltInZoomControls(newSettings.builtInZoomControls); + if (newSettingsMap.get("builtInZoomControls") != null && customSettings.builtInZoomControls != newCustomSettings.builtInZoomControls) + settings.setBuiltInZoomControls(newCustomSettings.builtInZoomControls); - if (newSettingsMap.get("displayZoomControls") != null && customSettings.displayZoomControls != newSettings.displayZoomControls) - settings.setDisplayZoomControls(newSettings.displayZoomControls); + if (newSettingsMap.get("displayZoomControls") != null && customSettings.displayZoomControls != newCustomSettings.displayZoomControls) + settings.setDisplayZoomControls(newCustomSettings.displayZoomControls); - if (newSettingsMap.get("safeBrowsingEnabled") != null && customSettings.safeBrowsingEnabled != newSettings.safeBrowsingEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - settings.setSafeBrowsingEnabled(newSettings.safeBrowsingEnabled); + if (newSettingsMap.get("safeBrowsingEnabled") != null && customSettings.safeBrowsingEnabled != newCustomSettings.safeBrowsingEnabled) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)) + WebSettingsCompat.setSafeBrowsingEnabled(settings, newCustomSettings.safeBrowsingEnabled); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + settings.setSafeBrowsingEnabled(newCustomSettings.safeBrowsingEnabled); + } - if (newSettingsMap.get("mediaPlaybackRequiresUserGesture") != null && customSettings.mediaPlaybackRequiresUserGesture != newSettings.mediaPlaybackRequiresUserGesture) - settings.setMediaPlaybackRequiresUserGesture(newSettings.mediaPlaybackRequiresUserGesture); + if (newSettingsMap.get("mediaPlaybackRequiresUserGesture") != null && customSettings.mediaPlaybackRequiresUserGesture != newCustomSettings.mediaPlaybackRequiresUserGesture) + settings.setMediaPlaybackRequiresUserGesture(newCustomSettings.mediaPlaybackRequiresUserGesture); - if (newSettingsMap.get("databaseEnabled") != null && customSettings.databaseEnabled != newSettings.databaseEnabled) - settings.setDatabaseEnabled(newSettings.databaseEnabled); + if (newSettingsMap.get("databaseEnabled") != null && customSettings.databaseEnabled != newCustomSettings.databaseEnabled) + settings.setDatabaseEnabled(newCustomSettings.databaseEnabled); - if (newSettingsMap.get("domStorageEnabled") != null && customSettings.domStorageEnabled != newSettings.domStorageEnabled) - settings.setDomStorageEnabled(newSettings.domStorageEnabled); + if (newSettingsMap.get("domStorageEnabled") != null && customSettings.domStorageEnabled != newCustomSettings.domStorageEnabled) + settings.setDomStorageEnabled(newCustomSettings.domStorageEnabled); - if (newSettingsMap.get("userAgent") != null && !customSettings.userAgent.equals(newSettings.userAgent) && !newSettings.userAgent.isEmpty()) - settings.setUserAgentString(newSettings.userAgent); + if (newSettingsMap.get("userAgent") != null && !customSettings.userAgent.equals(newCustomSettings.userAgent) && !newCustomSettings.userAgent.isEmpty()) + settings.setUserAgentString(newCustomSettings.userAgent); - if (newSettingsMap.get("applicationNameForUserAgent") != null && !customSettings.applicationNameForUserAgent.equals(newSettings.applicationNameForUserAgent) && !newSettings.applicationNameForUserAgent.isEmpty()) { + if (newSettingsMap.get("applicationNameForUserAgent") != null && !customSettings.applicationNameForUserAgent.equals(newCustomSettings.applicationNameForUserAgent) && !newCustomSettings.applicationNameForUserAgent.isEmpty()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - String userAgent = (newSettings.userAgent != null && !newSettings.userAgent.isEmpty()) ? newSettings.userAgent : WebSettings.getDefaultUserAgent(getContext()); + String userAgent = (newCustomSettings.userAgent != null && !newCustomSettings.userAgent.isEmpty()) ? newCustomSettings.userAgent : WebSettings.getDefaultUserAgent(getContext()); String userAgentWithApplicationName = userAgent + " " + customSettings.applicationNameForUserAgent; settings.setUserAgentString(userAgentWithApplicationName); } } - if (newSettingsMap.get("clearCache") != null && newSettings.clearCache) + if (newSettingsMap.get("clearCache") != null && newCustomSettings.clearCache) clearAllCache(); - else if (newSettingsMap.get("clearSessionCache") != null && newSettings.clearSessionCache) + else if (newSettingsMap.get("clearSessionCache") != null && newCustomSettings.clearSessionCache) CookieManager.getInstance().removeSessionCookie(); - if (newSettingsMap.get("thirdPartyCookiesEnabled") != null && customSettings.thirdPartyCookiesEnabled != newSettings.thirdPartyCookiesEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - CookieManager.getInstance().setAcceptThirdPartyCookies(this, newSettings.thirdPartyCookiesEnabled); + if (newSettingsMap.get("thirdPartyCookiesEnabled") != null && customSettings.thirdPartyCookiesEnabled != newCustomSettings.thirdPartyCookiesEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + CookieManager.getInstance().setAcceptThirdPartyCookies(this, newCustomSettings.thirdPartyCookiesEnabled); - if (newSettingsMap.get("useWideViewPort") != null && customSettings.useWideViewPort != newSettings.useWideViewPort) - settings.setUseWideViewPort(newSettings.useWideViewPort); + if (newSettingsMap.get("useWideViewPort") != null && customSettings.useWideViewPort != newCustomSettings.useWideViewPort) + settings.setUseWideViewPort(newCustomSettings.useWideViewPort); - if (newSettingsMap.get("supportZoom") != null && customSettings.supportZoom != newSettings.supportZoom) - settings.setSupportZoom(newSettings.supportZoom); + if (newSettingsMap.get("supportZoom") != null && customSettings.supportZoom != newCustomSettings.supportZoom) + settings.setSupportZoom(newCustomSettings.supportZoom); - if (newSettingsMap.get("textZoom") != null && !customSettings.textZoom.equals(newSettings.textZoom)) - settings.setTextZoom(newSettings.textZoom); + if (newSettingsMap.get("textZoom") != null && !customSettings.textZoom.equals(newCustomSettings.textZoom)) + settings.setTextZoom(newCustomSettings.textZoom); - if (newSettingsMap.get("verticalScrollBarEnabled") != null && customSettings.verticalScrollBarEnabled != newSettings.verticalScrollBarEnabled) - setVerticalScrollBarEnabled(newSettings.verticalScrollBarEnabled); + if (newSettingsMap.get("verticalScrollBarEnabled") != null && customSettings.verticalScrollBarEnabled != newCustomSettings.verticalScrollBarEnabled) + setVerticalScrollBarEnabled(newCustomSettings.verticalScrollBarEnabled); - if (newSettingsMap.get("horizontalScrollBarEnabled") != null && customSettings.horizontalScrollBarEnabled != newSettings.horizontalScrollBarEnabled) - setHorizontalScrollBarEnabled(newSettings.horizontalScrollBarEnabled); + if (newSettingsMap.get("horizontalScrollBarEnabled") != null && customSettings.horizontalScrollBarEnabled != newCustomSettings.horizontalScrollBarEnabled) + setHorizontalScrollBarEnabled(newCustomSettings.horizontalScrollBarEnabled); - if (newSettingsMap.get("transparentBackground") != null && customSettings.transparentBackground != newSettings.transparentBackground) { - if (newSettings.transparentBackground) { + if (newSettingsMap.get("transparentBackground") != null && customSettings.transparentBackground != newCustomSettings.transparentBackground) { + if (newCustomSettings.transparentBackground) { setBackgroundColor(Color.TRANSPARENT); } else { setBackgroundColor(Color.parseColor("#FFFFFF")); @@ -735,118 +756,134 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - if (newSettingsMap.get("mixedContentMode") != null && (customSettings.mixedContentMode == null || !customSettings.mixedContentMode.equals(newSettings.mixedContentMode))) - settings.setMixedContentMode(newSettings.mixedContentMode); + if (newSettingsMap.get("mixedContentMode") != null && (customSettings.mixedContentMode == null || !customSettings.mixedContentMode.equals(newCustomSettings.mixedContentMode))) + settings.setMixedContentMode(newCustomSettings.mixedContentMode); - if (newSettingsMap.get("supportMultipleWindows") != null && customSettings.supportMultipleWindows != newSettings.supportMultipleWindows) - settings.setSupportMultipleWindows(newSettings.supportMultipleWindows); + if (newSettingsMap.get("supportMultipleWindows") != null && customSettings.supportMultipleWindows != newCustomSettings.supportMultipleWindows) + settings.setSupportMultipleWindows(newCustomSettings.supportMultipleWindows); - if (newSettingsMap.get("useOnDownloadStart") != null && customSettings.useOnDownloadStart != newSettings.useOnDownloadStart) { - if (newSettings.useOnDownloadStart) { + if (newSettingsMap.get("useOnDownloadStart") != null && customSettings.useOnDownloadStart != newCustomSettings.useOnDownloadStart) { + if (newCustomSettings.useOnDownloadStart) { setDownloadListener(new DownloadStartListener()); } else { setDownloadListener(null); } } - if (newSettingsMap.get("allowContentAccess") != null && customSettings.allowContentAccess != newSettings.allowContentAccess) - settings.setAllowContentAccess(newSettings.allowContentAccess); + if (newSettingsMap.get("allowContentAccess") != null && customSettings.allowContentAccess != newCustomSettings.allowContentAccess) + settings.setAllowContentAccess(newCustomSettings.allowContentAccess); - if (newSettingsMap.get("allowFileAccess") != null && customSettings.allowFileAccess != newSettings.allowFileAccess) - settings.setAllowFileAccess(newSettings.allowFileAccess); + if (newSettingsMap.get("allowFileAccess") != null && customSettings.allowFileAccess != newCustomSettings.allowFileAccess) + settings.setAllowFileAccess(newCustomSettings.allowFileAccess); - if (newSettingsMap.get("allowFileAccessFromFileURLs") != null && customSettings.allowFileAccessFromFileURLs != newSettings.allowFileAccessFromFileURLs) - settings.setAllowFileAccessFromFileURLs(newSettings.allowFileAccessFromFileURLs); + if (newSettingsMap.get("allowFileAccessFromFileURLs") != null && customSettings.allowFileAccessFromFileURLs != newCustomSettings.allowFileAccessFromFileURLs) + settings.setAllowFileAccessFromFileURLs(newCustomSettings.allowFileAccessFromFileURLs); - if (newSettingsMap.get("allowUniversalAccessFromFileURLs") != null && customSettings.allowUniversalAccessFromFileURLs != newSettings.allowUniversalAccessFromFileURLs) - settings.setAllowUniversalAccessFromFileURLs(newSettings.allowUniversalAccessFromFileURLs); + if (newSettingsMap.get("allowUniversalAccessFromFileURLs") != null && customSettings.allowUniversalAccessFromFileURLs != newCustomSettings.allowUniversalAccessFromFileURLs) + settings.setAllowUniversalAccessFromFileURLs(newCustomSettings.allowUniversalAccessFromFileURLs); - if (newSettingsMap.get("cacheEnabled") != null && customSettings.cacheEnabled != newSettings.cacheEnabled) - setCacheEnabled(newSettings.cacheEnabled); + if (newSettingsMap.get("cacheEnabled") != null && customSettings.cacheEnabled != newCustomSettings.cacheEnabled) + setCacheEnabled(newCustomSettings.cacheEnabled); - if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newSettings.appCachePath))) - settings.setAppCachePath(newSettings.appCachePath); + if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newCustomSettings.appCachePath))) + settings.setAppCachePath(newCustomSettings.appCachePath); - if (newSettingsMap.get("blockNetworkImage") != null && customSettings.blockNetworkImage != newSettings.blockNetworkImage) - settings.setBlockNetworkImage(newSettings.blockNetworkImage); + if (newSettingsMap.get("blockNetworkImage") != null && customSettings.blockNetworkImage != newCustomSettings.blockNetworkImage) + settings.setBlockNetworkImage(newCustomSettings.blockNetworkImage); - if (newSettingsMap.get("blockNetworkLoads") != null && customSettings.blockNetworkLoads != newSettings.blockNetworkLoads) - settings.setBlockNetworkLoads(newSettings.blockNetworkLoads); + if (newSettingsMap.get("blockNetworkLoads") != null && customSettings.blockNetworkLoads != newCustomSettings.blockNetworkLoads) + settings.setBlockNetworkLoads(newCustomSettings.blockNetworkLoads); - if (newSettingsMap.get("cacheMode") != null && !customSettings.cacheMode.equals(newSettings.cacheMode)) - settings.setCacheMode(newSettings.cacheMode); + if (newSettingsMap.get("cacheMode") != null && !customSettings.cacheMode.equals(newCustomSettings.cacheMode)) + settings.setCacheMode(newCustomSettings.cacheMode); - if (newSettingsMap.get("cursiveFontFamily") != null && !customSettings.cursiveFontFamily.equals(newSettings.cursiveFontFamily)) - settings.setCursiveFontFamily(newSettings.cursiveFontFamily); + if (newSettingsMap.get("cursiveFontFamily") != null && !customSettings.cursiveFontFamily.equals(newCustomSettings.cursiveFontFamily)) + settings.setCursiveFontFamily(newCustomSettings.cursiveFontFamily); - if (newSettingsMap.get("defaultFixedFontSize") != null && !customSettings.defaultFixedFontSize.equals(newSettings.defaultFixedFontSize)) - settings.setDefaultFixedFontSize(newSettings.defaultFixedFontSize); + if (newSettingsMap.get("defaultFixedFontSize") != null && !customSettings.defaultFixedFontSize.equals(newCustomSettings.defaultFixedFontSize)) + settings.setDefaultFixedFontSize(newCustomSettings.defaultFixedFontSize); - if (newSettingsMap.get("defaultFontSize") != null && !customSettings.defaultFontSize.equals(newSettings.defaultFontSize)) - settings.setDefaultFontSize(newSettings.defaultFontSize); + if (newSettingsMap.get("defaultFontSize") != null && !customSettings.defaultFontSize.equals(newCustomSettings.defaultFontSize)) + settings.setDefaultFontSize(newCustomSettings.defaultFontSize); - if (newSettingsMap.get("defaultTextEncodingName") != null && !customSettings.defaultTextEncodingName.equals(newSettings.defaultTextEncodingName)) - settings.setDefaultTextEncodingName(newSettings.defaultTextEncodingName); + if (newSettingsMap.get("defaultTextEncodingName") != null && !customSettings.defaultTextEncodingName.equals(newCustomSettings.defaultTextEncodingName)) + settings.setDefaultTextEncodingName(newCustomSettings.defaultTextEncodingName); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - if (newSettingsMap.get("disabledActionModeMenuItems") != null && (customSettings.disabledActionModeMenuItems == null || - !customSettings.disabledActionModeMenuItems.equals(newSettings.disabledActionModeMenuItems))) - settings.setDisabledActionModeMenuItems(newSettings.disabledActionModeMenuItems); + if (newSettingsMap.get("disabledActionModeMenuItems") != null && + (customSettings.disabledActionModeMenuItems == null || + !customSettings.disabledActionModeMenuItems.equals(newCustomSettings.disabledActionModeMenuItems))) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS)) + WebSettingsCompat.setDisabledActionModeMenuItems(settings, newCustomSettings.disabledActionModeMenuItems); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + settings.setDisabledActionModeMenuItems(newCustomSettings.disabledActionModeMenuItems); + } - if (newSettingsMap.get("fantasyFontFamily") != null && !customSettings.fantasyFontFamily.equals(newSettings.fantasyFontFamily)) - settings.setFantasyFontFamily(newSettings.fantasyFontFamily); + if (newSettingsMap.get("fantasyFontFamily") != null && !customSettings.fantasyFontFamily.equals(newCustomSettings.fantasyFontFamily)) + settings.setFantasyFontFamily(newCustomSettings.fantasyFontFamily); - if (newSettingsMap.get("fixedFontFamily") != null && !customSettings.fixedFontFamily.equals(newSettings.fixedFontFamily)) - settings.setFixedFontFamily(newSettings.fixedFontFamily); + if (newSettingsMap.get("fixedFontFamily") != null && !customSettings.fixedFontFamily.equals(newCustomSettings.fixedFontFamily)) + settings.setFixedFontFamily(newCustomSettings.fixedFontFamily); - if (newSettingsMap.get("forceDark") != null && !customSettings.forceDark.equals(newSettings.forceDark)) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - settings.setForceDark(newSettings.forceDark); + if (newSettingsMap.get("forceDark") != null && !customSettings.forceDark.equals(newCustomSettings.forceDark)) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) + WebSettingsCompat.setForceDark(settings, newCustomSettings.forceDark); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + settings.setForceDark(newCustomSettings.forceDark); + } - if (newSettingsMap.get("geolocationEnabled") != null && customSettings.geolocationEnabled != newSettings.geolocationEnabled) - settings.setGeolocationEnabled(newSettings.geolocationEnabled); + if (newSettingsMap.get("forceDarkStrategy") != null && + !customSettings.forceDarkStrategy.equals(newCustomSettings.forceDarkStrategy) && + WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) { + WebSettingsCompat.setForceDarkStrategy(settings, newCustomSettings.forceDarkStrategy); + } - if (newSettingsMap.get("layoutAlgorithm") != null && customSettings.layoutAlgorithm != newSettings.layoutAlgorithm) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && newSettings.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { - settings.setLayoutAlgorithm(newSettings.layoutAlgorithm); + if (newSettingsMap.get("geolocationEnabled") != null && customSettings.geolocationEnabled != newCustomSettings.geolocationEnabled) + settings.setGeolocationEnabled(newCustomSettings.geolocationEnabled); + + if (newSettingsMap.get("layoutAlgorithm") != null && customSettings.layoutAlgorithm != newCustomSettings.layoutAlgorithm) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && newCustomSettings.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { + settings.setLayoutAlgorithm(newCustomSettings.layoutAlgorithm); } else { - settings.setLayoutAlgorithm(newSettings.layoutAlgorithm); + settings.setLayoutAlgorithm(newCustomSettings.layoutAlgorithm); } } - if (newSettingsMap.get("loadWithOverviewMode") != null && customSettings.loadWithOverviewMode != newSettings.loadWithOverviewMode) - settings.setLoadWithOverviewMode(newSettings.loadWithOverviewMode); + if (newSettingsMap.get("loadWithOverviewMode") != null && customSettings.loadWithOverviewMode != newCustomSettings.loadWithOverviewMode) + settings.setLoadWithOverviewMode(newCustomSettings.loadWithOverviewMode); - if (newSettingsMap.get("loadsImagesAutomatically") != null && customSettings.loadsImagesAutomatically != newSettings.loadsImagesAutomatically) - settings.setLoadsImagesAutomatically(newSettings.loadsImagesAutomatically); + if (newSettingsMap.get("loadsImagesAutomatically") != null && customSettings.loadsImagesAutomatically != newCustomSettings.loadsImagesAutomatically) + settings.setLoadsImagesAutomatically(newCustomSettings.loadsImagesAutomatically); - if (newSettingsMap.get("minimumFontSize") != null && !customSettings.minimumFontSize.equals(newSettings.minimumFontSize)) - settings.setMinimumFontSize(newSettings.minimumFontSize); + if (newSettingsMap.get("minimumFontSize") != null && !customSettings.minimumFontSize.equals(newCustomSettings.minimumFontSize)) + settings.setMinimumFontSize(newCustomSettings.minimumFontSize); - if (newSettingsMap.get("minimumLogicalFontSize") != null && !customSettings.minimumLogicalFontSize.equals(newSettings.minimumLogicalFontSize)) - settings.setMinimumLogicalFontSize(newSettings.minimumLogicalFontSize); + if (newSettingsMap.get("minimumLogicalFontSize") != null && !customSettings.minimumLogicalFontSize.equals(newCustomSettings.minimumLogicalFontSize)) + settings.setMinimumLogicalFontSize(newCustomSettings.minimumLogicalFontSize); - if (newSettingsMap.get("initialScale") != null && !customSettings.initialScale.equals(newSettings.initialScale)) - setInitialScale(newSettings.initialScale); + if (newSettingsMap.get("initialScale") != null && !customSettings.initialScale.equals(newCustomSettings.initialScale)) + setInitialScale(newCustomSettings.initialScale); - if (newSettingsMap.get("needInitialFocus") != null && customSettings.needInitialFocus != newSettings.needInitialFocus) - settings.setNeedInitialFocus(newSettings.needInitialFocus); + if (newSettingsMap.get("needInitialFocus") != null && customSettings.needInitialFocus != newCustomSettings.needInitialFocus) + settings.setNeedInitialFocus(newCustomSettings.needInitialFocus); - if (newSettingsMap.get("offscreenPreRaster") != null && customSettings.offscreenPreRaster != newSettings.offscreenPreRaster) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - settings.setOffscreenPreRaster(newSettings.offscreenPreRaster); + if (newSettingsMap.get("offscreenPreRaster") != null && customSettings.offscreenPreRaster != newCustomSettings.offscreenPreRaster) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.OFF_SCREEN_PRERASTER)) + WebSettingsCompat.setOffscreenPreRaster(settings, newCustomSettings.offscreenPreRaster); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + settings.setOffscreenPreRaster(newCustomSettings.offscreenPreRaster); + } - if (newSettingsMap.get("sansSerifFontFamily") != null && !customSettings.sansSerifFontFamily.equals(newSettings.sansSerifFontFamily)) - settings.setSansSerifFontFamily(newSettings.sansSerifFontFamily); + if (newSettingsMap.get("sansSerifFontFamily") != null && !customSettings.sansSerifFontFamily.equals(newCustomSettings.sansSerifFontFamily)) + settings.setSansSerifFontFamily(newCustomSettings.sansSerifFontFamily); - if (newSettingsMap.get("serifFontFamily") != null && !customSettings.serifFontFamily.equals(newSettings.serifFontFamily)) - settings.setSerifFontFamily(newSettings.serifFontFamily); + if (newSettingsMap.get("serifFontFamily") != null && !customSettings.serifFontFamily.equals(newCustomSettings.serifFontFamily)) + settings.setSerifFontFamily(newCustomSettings.serifFontFamily); - if (newSettingsMap.get("standardFontFamily") != null && !customSettings.standardFontFamily.equals(newSettings.standardFontFamily)) - settings.setStandardFontFamily(newSettings.standardFontFamily); + if (newSettingsMap.get("standardFontFamily") != null && !customSettings.standardFontFamily.equals(newCustomSettings.standardFontFamily)) + settings.setStandardFontFamily(newCustomSettings.standardFontFamily); - if (newSettingsMap.get("preferredContentMode") != null && !customSettings.preferredContentMode.equals(newSettings.preferredContentMode)) { - switch (fromValue(newSettings.preferredContentMode)) { + if (newSettingsMap.get("preferredContentMode") != null && !customSettings.preferredContentMode.equals(newCustomSettings.preferredContentMode)) { + switch (fromValue(newCustomSettings.preferredContentMode)) { case DESKTOP: setDesktopMode(true); break; @@ -857,30 +894,30 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } } - if (newSettingsMap.get("saveFormData") != null && customSettings.saveFormData != newSettings.saveFormData) - settings.setSaveFormData(newSettings.saveFormData); + if (newSettingsMap.get("saveFormData") != null && customSettings.saveFormData != newCustomSettings.saveFormData) + settings.setSaveFormData(newCustomSettings.saveFormData); - if (newSettingsMap.get("incognito") != null && customSettings.incognito != newSettings.incognito) - setIncognito(newSettings.incognito); + if (newSettingsMap.get("incognito") != null && customSettings.incognito != newCustomSettings.incognito) + setIncognito(newCustomSettings.incognito); - if (newSettingsMap.get("hardwareAcceleration") != null && customSettings.hardwareAcceleration != newSettings.hardwareAcceleration) { - if (newSettings.hardwareAcceleration) + if (newSettingsMap.get("hardwareAcceleration") != null && customSettings.hardwareAcceleration != newCustomSettings.hardwareAcceleration) { + if (newCustomSettings.hardwareAcceleration) setLayerType(View.LAYER_TYPE_HARDWARE, null); else setLayerType(View.LAYER_TYPE_SOFTWARE, null); } if (newSettingsMap.get("regexToCancelSubFramesLoading") != null && (customSettings.regexToCancelSubFramesLoading == null || - !customSettings.regexToCancelSubFramesLoading.equals(newSettings.regexToCancelSubFramesLoading))) { - if (newSettings.regexToCancelSubFramesLoading == null) + !customSettings.regexToCancelSubFramesLoading.equals(newCustomSettings.regexToCancelSubFramesLoading))) { + if (newCustomSettings.regexToCancelSubFramesLoading == null) regexToCancelSubFramesLoadingCompiled = null; else regexToCancelSubFramesLoadingCompiled = Pattern.compile(customSettings.regexToCancelSubFramesLoading); } - if (newSettings.contentBlockers != null) { + if (newCustomSettings.contentBlockers != null) { contentBlockerHandler.getRuleList().clear(); - for (Map> contentBlocker : newSettings.contentBlockers) { + for (Map> contentBlocker : newCustomSettings.contentBlockers) { // compile ContentBlockerTrigger urlFilter ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger")); ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action")); @@ -888,59 +925,59 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } } - if (newSettingsMap.get("scrollBarStyle") != null && !customSettings.scrollBarStyle.equals(newSettings.scrollBarStyle)) - setScrollBarStyle(newSettings.scrollBarStyle); + if (newSettingsMap.get("scrollBarStyle") != null && !customSettings.scrollBarStyle.equals(newCustomSettings.scrollBarStyle)) + setScrollBarStyle(newCustomSettings.scrollBarStyle); if (newSettingsMap.get("scrollBarDefaultDelayBeforeFade") != null && (customSettings.scrollBarDefaultDelayBeforeFade == null || - !customSettings.scrollBarDefaultDelayBeforeFade.equals(newSettings.scrollBarDefaultDelayBeforeFade))) - setScrollBarDefaultDelayBeforeFade(newSettings.scrollBarDefaultDelayBeforeFade); + !customSettings.scrollBarDefaultDelayBeforeFade.equals(newCustomSettings.scrollBarDefaultDelayBeforeFade))) + setScrollBarDefaultDelayBeforeFade(newCustomSettings.scrollBarDefaultDelayBeforeFade); - if (newSettingsMap.get("scrollbarFadingEnabled") != null && !customSettings.scrollbarFadingEnabled.equals(newSettings.scrollbarFadingEnabled)) - setScrollbarFadingEnabled(newSettings.scrollbarFadingEnabled); + if (newSettingsMap.get("scrollbarFadingEnabled") != null && !customSettings.scrollbarFadingEnabled.equals(newCustomSettings.scrollbarFadingEnabled)) + setScrollbarFadingEnabled(newCustomSettings.scrollbarFadingEnabled); if (newSettingsMap.get("scrollBarFadeDuration") != null && (customSettings.scrollBarFadeDuration == null || - !customSettings.scrollBarFadeDuration.equals(newSettings.scrollBarFadeDuration))) - setScrollBarFadeDuration(newSettings.scrollBarFadeDuration); + !customSettings.scrollBarFadeDuration.equals(newCustomSettings.scrollBarFadeDuration))) + setScrollBarFadeDuration(newCustomSettings.scrollBarFadeDuration); - if (newSettingsMap.get("verticalScrollbarPosition") != null && !customSettings.verticalScrollbarPosition.equals(newSettings.verticalScrollbarPosition)) - setVerticalScrollbarPosition(newSettings.verticalScrollbarPosition); + if (newSettingsMap.get("verticalScrollbarPosition") != null && !customSettings.verticalScrollbarPosition.equals(newCustomSettings.verticalScrollbarPosition)) + setVerticalScrollbarPosition(newCustomSettings.verticalScrollbarPosition); - if (newSettingsMap.get("disableVerticalScroll") != null && customSettings.disableVerticalScroll != newSettings.disableVerticalScroll) - setVerticalScrollBarEnabled(!newSettings.disableVerticalScroll && newSettings.verticalScrollBarEnabled); + if (newSettingsMap.get("disableVerticalScroll") != null && customSettings.disableVerticalScroll != newCustomSettings.disableVerticalScroll) + setVerticalScrollBarEnabled(!newCustomSettings.disableVerticalScroll && newCustomSettings.verticalScrollBarEnabled); - if (newSettingsMap.get("disableHorizontalScroll") != null && customSettings.disableHorizontalScroll != newSettings.disableHorizontalScroll) - setHorizontalScrollBarEnabled(!newSettings.disableHorizontalScroll && newSettings.horizontalScrollBarEnabled); + if (newSettingsMap.get("disableHorizontalScroll") != null && customSettings.disableHorizontalScroll != newCustomSettings.disableHorizontalScroll) + setHorizontalScrollBarEnabled(!newCustomSettings.disableHorizontalScroll && newCustomSettings.horizontalScrollBarEnabled); - if (newSettingsMap.get("overScrollMode") != null && !customSettings.overScrollMode.equals(newSettings.overScrollMode)) - setOverScrollMode(newSettings.overScrollMode); + if (newSettingsMap.get("overScrollMode") != null && !customSettings.overScrollMode.equals(newCustomSettings.overScrollMode)) + setOverScrollMode(newCustomSettings.overScrollMode); - if (newSettingsMap.get("networkAvailable") != null && customSettings.networkAvailable != newSettings.networkAvailable) - setNetworkAvailable(newSettings.networkAvailable); + if (newSettingsMap.get("networkAvailable") != null && customSettings.networkAvailable != newCustomSettings.networkAvailable) + setNetworkAvailable(newCustomSettings.networkAvailable); if (newSettingsMap.get("rendererPriorityPolicy") != null && - (customSettings.rendererPriorityPolicy.get("rendererRequestedPriority") != newSettings.rendererPriorityPolicy.get("rendererRequestedPriority") || - customSettings.rendererPriorityPolicy.get("waivedWhenNotVisible") != newSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")) && + (customSettings.rendererPriorityPolicy.get("rendererRequestedPriority") != newCustomSettings.rendererPriorityPolicy.get("rendererRequestedPriority") || + customSettings.rendererPriorityPolicy.get("waivedWhenNotVisible") != newCustomSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setRendererPriorityPolicy( - (int) newSettings.rendererPriorityPolicy.get("rendererRequestedPriority"), - (boolean) newSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")); + (int) newCustomSettings.rendererPriorityPolicy.get("rendererRequestedPriority"), + (boolean) newCustomSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - if (newSettingsMap.get("verticalScrollbarThumbColor") != null && !Util.objEquals(customSettings.verticalScrollbarThumbColor, newSettings.verticalScrollbarThumbColor)) - setVerticalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newSettings.verticalScrollbarThumbColor))); + if (newSettingsMap.get("verticalScrollbarThumbColor") != null && !Util.objEquals(customSettings.verticalScrollbarThumbColor, newCustomSettings.verticalScrollbarThumbColor)) + setVerticalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.verticalScrollbarThumbColor))); - if (newSettingsMap.get("verticalScrollbarTrackColor") != null && !Util.objEquals(customSettings.verticalScrollbarTrackColor, newSettings.verticalScrollbarTrackColor)) - setVerticalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newSettings.verticalScrollbarTrackColor))); + if (newSettingsMap.get("verticalScrollbarTrackColor") != null && !Util.objEquals(customSettings.verticalScrollbarTrackColor, newCustomSettings.verticalScrollbarTrackColor)) + setVerticalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.verticalScrollbarTrackColor))); - if (newSettingsMap.get("horizontalScrollbarThumbColor") != null && !Util.objEquals(customSettings.horizontalScrollbarThumbColor, newSettings.horizontalScrollbarThumbColor)) - setHorizontalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newSettings.horizontalScrollbarThumbColor))); + if (newSettingsMap.get("horizontalScrollbarThumbColor") != null && !Util.objEquals(customSettings.horizontalScrollbarThumbColor, newCustomSettings.horizontalScrollbarThumbColor)) + setHorizontalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.horizontalScrollbarThumbColor))); - if (newSettingsMap.get("horizontalScrollbarTrackColor") != null && !Util.objEquals(customSettings.horizontalScrollbarTrackColor, newSettings.horizontalScrollbarTrackColor)) - setHorizontalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newSettings.horizontalScrollbarTrackColor))); + if (newSettingsMap.get("horizontalScrollbarTrackColor") != null && !Util.objEquals(customSettings.horizontalScrollbarTrackColor, newCustomSettings.horizontalScrollbarTrackColor)) + setHorizontalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.horizontalScrollbarTrackColor))); } - customSettings = newSettings; + customSettings = newCustomSettings; } public Map getCustomSettings() { @@ -1666,8 +1703,10 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie } public void addWebMessageListener(@NonNull WebMessageListener webMessageListener) throws Exception { - WebViewCompat.addWebMessageListener(this, webMessageListener.jsObjectName, webMessageListener.allowedOriginRules, webMessageListener.listener); - webMessageListeners.add(webMessageListener); + if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) { + WebViewCompat.addWebMessageListener(this, webMessageListener.jsObjectName, webMessageListener.allowedOriginRules, webMessageListener.listener); + webMessageListeners.add(webMessageListener); + } } public void disposeWebMessageChannels() { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewClient.java index 13b4628e..3ba1a47d 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewClient.java @@ -25,6 +25,9 @@ import android.webkit.WebViewClient; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.webkit.WebResourceRequestCompat; +import androidx.webkit.WebViewCompat; +import androidx.webkit.WebViewFeature; import com.pichillilorenzo.flutter_inappwebview.Util; import com.pichillilorenzo.flutter_inappwebview.credential_database.CredentialDatabase; @@ -74,7 +77,9 @@ public class InAppWebViewClient extends WebViewClient { InAppWebView webView = (InAppWebView) view; if (webView.customSettings.useShouldOverrideUrlLoading) { boolean isRedirect = false; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT)) { + isRedirect = WebResourceRequestCompat.isRedirect(request); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { isRedirect = request.isRedirect(); } onShouldOverrideUrlLoading( @@ -705,7 +710,9 @@ public class InAppWebViewClient extends WebViewClient { headers = webResourceRequest.getRequestHeaders(); hasGesture = webResourceRequest.hasGesture(); isForMainFrame = webResourceRequest.isForMainFrame(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT)) { + isRedirect = WebResourceRequestCompat.isRedirect(webResourceRequest); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { isRedirect = webResourceRequest.isRedirect(); } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java index 58ad704f..8d0c2fef 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewSettings.java @@ -5,6 +5,8 @@ import android.view.View; import android.webkit.WebSettings; import androidx.annotation.Nullable; +import androidx.webkit.WebSettingsCompat; +import androidx.webkit.WebViewFeature; import com.pichillilorenzo.flutter_inappwebview.ISettings; import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; @@ -71,7 +73,8 @@ public class InAppWebViewSettings implements ISettings { public Integer disabledActionModeMenuItems; public String fantasyFontFamily = "fantasy"; public String fixedFontFamily = "monospace"; - public Integer forceDark = 0; // WebSettings.FORCE_DARK_OFF + public Integer forceDark = 0; // WebSettingsCompat.FORCE_DARK_OFF + public Integer forceDarkStrategy = WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING; public Boolean geolocationEnabled = true; public WebSettings.LayoutAlgorithm layoutAlgorithm; public Boolean loadWithOverviewMode = true; @@ -266,6 +269,9 @@ public class InAppWebViewSettings implements ISettings { case "forceDark": forceDark = (Integer) value; break; + case "forceDarkStrategy": + forceDarkStrategy = (Integer) value; + break; case "geolocationEnabled": geolocationEnabled = (Boolean) value; break; @@ -420,6 +426,7 @@ public class InAppWebViewSettings implements ISettings { settings.put("fantasyFontFamily", fantasyFontFamily); settings.put("fixedFontFamily", fixedFontFamily); settings.put("forceDark", forceDark); + settings.put("forceDarkStrategy", forceDarkStrategy); settings.put("geolocationEnabled", geolocationEnabled); settings.put("layoutAlgorithm", getLayoutAlgorithm()); settings.put("loadWithOverviewMode", loadWithOverviewMode); @@ -475,7 +482,9 @@ public class InAppWebViewSettings implements ISettings { realSettings.put("databaseEnabled", settings.getDatabaseEnabled()); realSettings.put("domStorageEnabled", settings.getDomStorageEnabled()); realSettings.put("useWideViewPort", settings.getUseWideViewPort()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE)) { + realSettings.put("safeBrowsingEnabled", WebSettingsCompat.getSafeBrowsingEnabled(settings)); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { realSettings.put("safeBrowsingEnabled", settings.getSafeBrowsingEnabled()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -492,19 +501,28 @@ public class InAppWebViewSettings implements ISettings { realSettings.put("defaultFixedFontSize", settings.getDefaultFixedFontSize()); realSettings.put("defaultFontSize", settings.getDefaultFontSize()); realSettings.put("defaultTextEncodingName", settings.getDefaultTextEncodingName()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS)) { + realSettings.put("disabledActionModeMenuItems", WebSettingsCompat.getDisabledActionModeMenuItems(settings)); + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { realSettings.put("disabledActionModeMenuItems", settings.getDisabledActionModeMenuItems()); } realSettings.put("fantasyFontFamily", settings.getFantasyFontFamily()); realSettings.put("fixedFontFamily", settings.getFixedFontFamily()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + realSettings.put("forceDark", WebSettingsCompat.getForceDark(settings)); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { realSettings.put("forceDark", settings.getForceDark()); } + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) { + realSettings.put("forceDarkStrategy", WebSettingsCompat.getForceDarkStrategy(settings)); + } realSettings.put("layoutAlgorithm", settings.getLayoutAlgorithm().name()); realSettings.put("loadWithOverviewMode", settings.getLoadWithOverviewMode()); realSettings.put("loadsImagesAutomatically", settings.getLoadsImagesAutomatically()); realSettings.put("minimumLogicalFontSize", settings.getMinimumLogicalFontSize()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (WebViewFeature.isFeatureSupported(WebViewFeature.OFF_SCREEN_PRERASTER)) { + realSettings.put("offscreenPreRaster", WebSettingsCompat.getOffscreenPreRaster(settings)); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { realSettings.put("offscreenPreRaster", settings.getOffscreenPreRaster()); } realSettings.put("sansSerifFontFamily", settings.getSansSerifFontFamily()); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java index 720c7037..f0a41d40 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java @@ -6,6 +6,8 @@ import android.webkit.WebResourceRequest; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; +import androidx.webkit.WebResourceRequestCompat; +import androidx.webkit.WebViewFeature; import java.util.HashMap; import java.util.Map; @@ -29,10 +31,16 @@ public class WebResourceRequestExt { } @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - static public WebResourceRequestExt fromWebResourceRequest(@NonNull WebResourceRequest request) { + static public WebResourceRequestExt fromWebResourceRequest(@NonNull WebResourceRequest request) { + boolean isRedirect = false; + if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT)) { + isRedirect = WebResourceRequestCompat.isRedirect(request); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + isRedirect = request.isRedirect(); + } return new WebResourceRequestExt(request.getUrl(), request.getRequestHeaders(), - Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && request.isRedirect(), + isRedirect, request.hasGesture(), request.isForMainFrame(), request.getMethod() diff --git a/example/integration_test/in_app_webview/safe_browsing.dart b/example/integration_test/in_app_webview/safe_browsing.dart index 2ddfafd8..ae0593e3 100644 --- a/example/integration_test/in_app_webview/safe_browsing.dart +++ b/example/integration_test/in_app_webview/safe_browsing.dart @@ -55,7 +55,7 @@ void safeBrowsing() { test('setSafeBrowsingWhitelist', () async { expect( - await InAppWebViewController.setSafeBrowsingWhitelist( + await InAppWebViewController.setSafeBrowsingAllowlist( hosts: ["flutter.dev", "github.com"]), true); }); diff --git a/lib/src/android/webview_feature.dart b/lib/src/android/webview_feature.dart index e6dac690..4c7f398a 100644 --- a/lib/src/android/webview_feature.dart +++ b/lib/src/android/webview_feature.dart @@ -2,6 +2,9 @@ import 'dart:async'; import 'package:flutter/services.dart'; import '../in_app_webview/in_app_webview_controller.dart'; import '../in_app_webview/in_app_webview_settings.dart'; +import 'proxy_controller.dart'; +import 'service_worker_controller.dart'; +import '../web_message/main.dart'; ///Class that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device. class WebViewFeature { @@ -83,7 +86,7 @@ class WebViewFeature { ///This feature covers [InAppWebViewSettings.forceDark]. static const FORCE_DARK = const WebViewFeature._internal("FORCE_DARK"); - /// + ///This feature covers [InAppWebViewSettings.forceDarkStrategy]. static const FORCE_DARK_STRATEGY = const WebViewFeature._internal("FORCE_DARK_STRATEGY"); @@ -102,15 +105,15 @@ class WebViewFeature { /// static const MULTI_PROCESS = const WebViewFeature._internal("MULTI_PROCESS"); - /// + ///This feature covers [InAppWebViewSettings.offscreenPreRaster]. static const OFF_SCREEN_PRERASTER = const WebViewFeature._internal("OFF_SCREEN_PRERASTER"); - /// + ///This feature covers [InAppWebViewController.postWebMessage]. static const POST_WEB_MESSAGE = const WebViewFeature._internal("POST_WEB_MESSAGE"); - /// + ///This feature covers [ProxyController.setProxyOverride] and [ProxyController.clearProxyOverride]. static const PROXY_OVERRIDE = const WebViewFeature._internal("PROXY_OVERRIDE"); @@ -122,11 +125,11 @@ class WebViewFeature { static const RECEIVE_WEB_RESOURCE_ERROR = const WebViewFeature._internal("RECEIVE_WEB_RESOURCE_ERROR"); - /// + ///This feature covers [InAppWebViewController.setSafeBrowsingAllowlist]. static const SAFE_BROWSING_ALLOWLIST = const WebViewFeature._internal("SAFE_BROWSING_ALLOWLIST"); - /// + ///This feature covers [InAppWebViewSettings.safeBrowsingEnabled]. static const SAFE_BROWSING_ENABLE = const WebViewFeature._internal("SAFE_BROWSING_ENABLE"); @@ -134,7 +137,7 @@ class WebViewFeature { static const SAFE_BROWSING_HIT = const WebViewFeature._internal("SAFE_BROWSING_HIT"); - /// + ///This feature covers [InAppWebViewController.getSafeBrowsingPrivacyPolicyUrl]. static const SAFE_BROWSING_PRIVACY_POLICY_URL = const WebViewFeature._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); @@ -156,27 +159,27 @@ class WebViewFeature { static const SAFE_BROWSING_WHITELIST = const WebViewFeature._internal("SAFE_BROWSING_WHITELIST"); - /// + ///This feature covers [ServiceWorkerController]. static const SERVICE_WORKER_BASIC_USAGE = const WebViewFeature._internal("SERVICE_WORKER_BASIC_USAGE"); - /// + ///This feature covers [ServiceWorkerController.setBlockNetworkLoads] and [ServiceWorkerController.getBlockNetworkLoads]. static const SERVICE_WORKER_BLOCK_NETWORK_LOADS = const WebViewFeature._internal("SERVICE_WORKER_BLOCK_NETWORK_LOADS"); - /// + ///This feature covers [ServiceWorkerController.setCacheMode] and [ServiceWorkerController.getCacheMode]. static const SERVICE_WORKER_CACHE_MODE = const WebViewFeature._internal("SERVICE_WORKER_CACHE_MODE"); - /// + ///This feature covers [ServiceWorkerController.setAllowContentAccess] and [ServiceWorkerController.getAllowContentAccess]. static const SERVICE_WORKER_CONTENT_ACCESS = const WebViewFeature._internal("SERVICE_WORKER_CONTENT_ACCESS"); - /// + ///This feature covers [ServiceWorkerController.setAllowFileAccess] and [ServiceWorkerController.getAllowFileAccess]. static const SERVICE_WORKER_FILE_ACCESS = const WebViewFeature._internal("SERVICE_WORKER_FILE_ACCESS"); - /// + ///This feature covers [ServiceWorkerClient.shouldInterceptRequest]. static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = const WebViewFeature._internal("SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST"); @@ -184,7 +187,7 @@ class WebViewFeature { static const SHOULD_OVERRIDE_WITH_REDIRECTS = const WebViewFeature._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); - /// + ///This feature covers [InAppWebViewController.startSafeBrowsing]. static const START_SAFE_BROWSING = const WebViewFeature._internal("START_SAFE_BROWSING"); @@ -200,7 +203,7 @@ class WebViewFeature { static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = const WebViewFeature._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); - /// + ///This feature covers [WebMessageListener]. static const WEB_MESSAGE_LISTENER = const WebViewFeature._internal("WEB_MESSAGE_LISTENER"); diff --git a/lib/src/in_app_webview/android/in_app_webview_controller.dart b/lib/src/in_app_webview/android/in_app_webview_controller.dart index 3f700e02..39e69e21 100644 --- a/lib/src/in_app_webview/android/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/android/in_app_webview_controller.dart @@ -93,10 +93,10 @@ class AndroidInAppWebViewController { } ///Use [InAppWebViewController.setSafeBrowsingWhitelist] instead. - @Deprecated("Use InAppWebViewController.setSafeBrowsingWhitelist instead") + @Deprecated("Use InAppWebViewController.setSafeBrowsingAllowlist instead") static Future setSafeBrowsingWhitelist( {required List hosts}) async { - return await InAppWebViewController.setSafeBrowsingWhitelist(hosts: hosts); + return await InAppWebViewController.setSafeBrowsingAllowlist(hosts: hosts); } ///Use [InAppWebViewController.getCurrentWebViewPackage] instead. diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 9f6795db..7eed780a 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -3341,6 +3341,13 @@ class InAppWebViewController { return url != null ? Uri.parse(url) : null; } + ///Use [setSafeBrowsingAllowlist] instead. + @Deprecated("Use setSafeBrowsingAllowlist instead") + static Future setSafeBrowsingWhitelist( + {required List hosts}) async { + return await InAppWebViewController.setSafeBrowsingAllowlist(hosts: hosts); + } + ///Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks. The list is global for all the WebViews. /// /// Each rule should take one of these: @@ -3359,11 +3366,11 @@ class InAppWebViewController { /// ///**Supported Platforms/Implementations**: ///- Android native WebView ([Official API - WebViewCompat.setSafeBrowsingAllowlist](https://developer.android.com/reference/androidx/webkit/WebViewCompat#setSafeBrowsingAllowlist(java.util.Set%3Cjava.lang.String%3E,%20android.webkit.ValueCallback%3Cjava.lang.Boolean%3E))) - static Future setSafeBrowsingWhitelist( + static Future setSafeBrowsingAllowlist( {required List hosts}) async { Map args = {}; args.putIfAbsent('hosts', () => hosts); - return await _staticChannel.invokeMethod('setSafeBrowsingWhitelist', args); + return await _staticChannel.invokeMethod('setSafeBrowsingAllowlist', args); } ///If WebView has already been loaded into the current process this method will return the package that was used to load it. diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart index b1874a81..e3d01c17 100755 --- a/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; +import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'android/in_app_webview_options.dart'; import 'apple/in_app_webview_options.dart'; @@ -418,7 +419,7 @@ class InAppWebViewSettings ///- Android native WebView String fixedFontFamily; - ///Set the force dark mode for this WebView. The default value is [ForceDark.FORCE_DARK_OFF]. + ///Set the force dark mode for this WebView. The default value is [ForceDark.OFF]. /// ///**NOTE**: available on Android 29+. /// @@ -426,6 +427,15 @@ class InAppWebViewSettings ///- Android native WebView ForceDark? forceDark; + ///Set how WebView content should be darkened. + ///The default value is [ForceDarkStrategy.PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING]. + /// + ///**NOTE on Android**: it will take effect only if [WebViewFeature.isFeatureSupported] returns `true` for [WebViewFeature.FORCE_DARK_STRATEGY]. + /// + ///**Supported Platforms/Implementations**: + ///- Android native WebView + ForceDarkStrategy? forceDarkStrategy; + ///Sets whether Geolocation API is enabled. The default value is `true`. /// ///**Supported Platforms/Implementations**: @@ -1102,7 +1112,8 @@ class InAppWebViewSettings this.disabledActionModeMenuItems, this.fantasyFontFamily = "fantasy", this.fixedFontFamily = "monospace", - this.forceDark = ForceDark.FORCE_DARK_OFF, + this.forceDark = ForceDark.OFF, + this.forceDarkStrategy = ForceDarkStrategy.PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING, this.geolocationEnabled = true, this.layoutAlgorithm, this.loadWithOverviewMode = true, @@ -1250,6 +1261,7 @@ class InAppWebViewSettings "fantasyFontFamily": fantasyFontFamily, "fixedFontFamily": fixedFontFamily, "forceDark": forceDark?.toValue(), + "forceDarkStrategy": forceDarkStrategy?.toValue(), "geolocationEnabled": geolocationEnabled, "layoutAlgorithm": layoutAlgorithm?.toValue(), "loadWithOverviewMode": loadWithOverviewMode, @@ -1422,6 +1434,7 @@ class InAppWebViewSettings settings.fantasyFontFamily = map["fantasyFontFamily"]; settings.fixedFontFamily = map["fixedFontFamily"]; settings.forceDark = ForceDark.fromValue(map["forceDark"]); + settings.forceDarkStrategy = ForceDarkStrategy.fromValue(map["forceDarkStrategy"]); settings.geolocationEnabled = map["geolocationEnabled"]; settings.layoutAlgorithm = LayoutAlgorithm.fromValue(map["layoutAlgorithm"]); diff --git a/lib/src/types/force_dark.dart b/lib/src/types/force_dark.dart index 726a0f82..6236dfcb 100644 --- a/lib/src/types/force_dark.dart +++ b/lib/src/types/force_dark.dart @@ -6,9 +6,9 @@ class ForceDark { ///Set of all values of [ForceDark]. static final Set values = [ - ForceDark.FORCE_DARK_OFF, - ForceDark.FORCE_DARK_AUTO, - ForceDark.FORCE_DARK_ON, + ForceDark.OFF, + ForceDark.AUTO, + ForceDark.ON, ].toSet(); ///Gets a possible [ForceDark] instance from an [int] value. @@ -31,24 +31,24 @@ class ForceDark { String toString() { switch (_value) { case 1: - return "FORCE_DARK_AUTO"; + return "AUTO"; case 2: - return "FORCE_DARK_ON"; + return "ON"; case 0: default: - return "FORCE_DARK_OFF"; + return "OFF"; } } ///Disable force dark, irrespective of the force dark mode of the WebView parent. ///In this mode, WebView content will always be rendered as-is, regardless of whether native views are being automatically darkened. - static const FORCE_DARK_OFF = const ForceDark._internal(0); + static const OFF = const ForceDark._internal(0); ///Enable force dark dependent on the state of the WebView parent view. - static const FORCE_DARK_AUTO = const ForceDark._internal(1); + static const AUTO = const ForceDark._internal(1); ///Unconditionally enable force dark. In this mode WebView content will always be rendered so as to emulate a dark theme. - static const FORCE_DARK_ON = const ForceDark._internal(2); + static const ON = const ForceDark._internal(2); bool operator ==(value) => value == _value; diff --git a/lib/src/types/force_dark_strategy.dart b/lib/src/types/force_dark_strategy.dart new file mode 100644 index 00000000..700caf1b --- /dev/null +++ b/lib/src/types/force_dark_strategy.dart @@ -0,0 +1,69 @@ +import '../in_app_webview/webview.dart'; + +///Class used to indicate how [WebView] content should be darkened. +class ForceDarkStrategy { + final int _value; + + const ForceDarkStrategy._internal(this._value); + + ///Set of all values of [ForceDarkStrategy]. + static final Set values = [ + ForceDarkStrategy.USER_AGENT_DARKENING_ONLY, + ForceDarkStrategy.WEB_THEME_DARKENING_ONLY, + ForceDarkStrategy.PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING, + ].toSet(); + + ///Gets a possible [ForceDarkStrategy] instance from an [int] value. + static ForceDarkStrategy? fromValue(int? value) { + if (value != null) { + try { + return ForceDarkStrategy.values + .firstWhere((element) => element.toValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + ///Gets [int] value. + int toValue() => _value; + + @override + String toString() { + switch (_value) { + case 1: + return "WEB_THEME_DARKENING_ONLY"; + case 2: + return "PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING"; + case 0: + default: + return "USER_AGENT_DARKENING_ONLY"; + } + } + + ///In this mode [WebView] content will be darkened by a user agent and it will ignore the web page's dark theme if it exists. + ///To avoid mixing two different darkening strategies, the `prefers-color-scheme` media query will evaluate to light. + /// + ///See [specification](https://drafts.csswg.org/css-color-adjust-1/) for more information. + static const USER_AGENT_DARKENING_ONLY = const ForceDarkStrategy._internal(0); + + ///In this mode [WebView] content will always be darkened using dark theme provided by web page. + ///If web page does not provide dark theme support [WebView] content will be rendered with a default theme. + /// + ///See [specification](https://drafts.csswg.org/css-color-adjust-1/) for more information. + static const WEB_THEME_DARKENING_ONLY = const ForceDarkStrategy._internal(1); + + ///In this mode [WebView] content will be darkened by a user agent unless web page supports dark theme. + ///[WebView] determines whether web pages supports dark theme by the presence of `color-scheme` metadata containing `"dark"` value. + ///For example, ``. + ///If the metadata is not presented [WebView] content will be darkened by a user agent and `prefers-color-scheme` media query will evaluate to light. + /// + ///See [specification](https://drafts.csswg.org/css-color-adjust-1/) for more information. + static const PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING = const ForceDarkStrategy._internal(2); + + bool operator ==(value) => value == _value; + + @override + int get hashCode => _value.hashCode; +} diff --git a/lib/src/types/main.dart b/lib/src/types/main.dart index f399a2d8..ef46d869 100644 --- a/lib/src/types/main.dart +++ b/lib/src/types/main.dart @@ -146,4 +146,5 @@ export 'web_resource_error.dart'; export 'web_resource_error_type.dart'; export 'media_capture_state.dart'; export 'proxy_rule.dart'; -export 'proxy_scheme_filter.dart'; \ No newline at end of file +export 'proxy_scheme_filter.dart'; +export 'force_dark_strategy.dart'; \ No newline at end of file