added forceDarkStrategy webview setting, updated some android checks on webview feature supported

This commit is contained in:
Lorenzo Pichilli 2022-05-02 15:08:23 +02:00
parent 706d7ee90b
commit 71c2093283
14 changed files with 372 additions and 207 deletions

View File

@ -4,7 +4,7 @@
- Added Web support - Added Web support
- Added `ProxyController` for Android - Added `ProxyController` for Android
- Added `pauseAllMediaPlayback`, `setAllMediaPlaybackSuspended`, `closeAllMediaPresentations`, `requestMediaPlaybackState`, `isInFullscreen`, `getCameraCaptureState`, `setCameraCaptureState`, `getMicrophoneCaptureState`, `setMicrophoneCaptureState` WebView controller methods - 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+ - Added support for `onPermissionRequest` event on iOS 15.0+
- Updated `getMetaThemeColor` on iOS 15.0+ - Updated `getMetaThemeColor` on iOS 15.0+
- Deprecated `onLoadError` for `onReceivedError`. `onReceivedError` will be called also for subframes. - Deprecated `onLoadError` for `onReceivedError`. `onReceivedError` will be called also for subframes.

View File

@ -57,7 +57,7 @@ public class InAppWebViewStatic implements MethodChannel.MethodCallHandler {
} else } else
result.success(null); result.success(null);
break; break;
case "setSafeBrowsingWhitelist": case "setSafeBrowsingAllowlist":
if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ALLOWLIST)) { if (WebViewFeature.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ALLOWLIST)) {
Set<String> hosts = new HashSet<>((List<String>) call.argument("hosts")); Set<String> hosts = new HashSet<>((List<String>) call.argument("hosts"));
WebViewCompat.setSafeBrowsingAllowlist(hosts, new ValueCallback<Boolean>() { WebViewCompat.setSafeBrowsingAllowlist(hosts, new ValueCallback<Boolean>() {

View File

@ -43,6 +43,7 @@ import android.webkit.WebBackForwardList;
import android.webkit.WebHistoryItem; import android.webkit.WebHistoryItem;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebStorage; import android.webkit.WebStorage;
import android.webkit.WebView;
import android.widget.HorizontalScrollView; import android.widget.HorizontalScrollView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -50,6 +51,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewCompat; import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewFeature; import androidx.webkit.WebViewFeature;
@ -229,7 +231,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
settings.setDisplayZoomControls(customSettings.displayZoomControls); settings.setDisplayZoomControls(customSettings.displayZoomControls);
settings.setSupportMultipleWindows(customSettings.supportMultipleWindows); 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.setSafeBrowsingEnabled(customSettings.safeBrowsingEnabled);
settings.setMediaPlaybackRequiresUserGesture(customSettings.mediaPlaybackRequiresUserGesture); settings.setMediaPlaybackRequiresUserGesture(customSettings.mediaPlaybackRequiresUserGesture);
@ -287,12 +291,23 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
settings.setDefaultFixedFontSize(customSettings.defaultFixedFontSize); settings.setDefaultFixedFontSize(customSettings.defaultFixedFontSize);
settings.setDefaultFontSize(customSettings.defaultFontSize); settings.setDefaultFontSize(customSettings.defaultFontSize);
settings.setDefaultTextEncodingName(customSettings.defaultTextEncodingName); settings.setDefaultTextEncodingName(customSettings.defaultTextEncodingName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && customSettings.disabledActionModeMenuItems != null) if (customSettings.disabledActionModeMenuItems != null) {
settings.setDisabledActionModeMenuItems(customSettings.disabledActionModeMenuItems); 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.setFantasyFontFamily(customSettings.fantasyFontFamily);
settings.setFixedFontFamily(customSettings.fixedFontFamily); settings.setFixedFontFamily(customSettings.fixedFontFamily);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && customSettings.forceDark != null) if (customSettings.forceDark != null) {
settings.setForceDark(customSettings.forceDark); 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); settings.setGeolocationEnabled(customSettings.geolocationEnabled);
if (customSettings.layoutAlgorithm != null) { if (customSettings.layoutAlgorithm != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && customSettings.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { 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); settings.setMinimumLogicalFontSize(customSettings.minimumLogicalFontSize);
setInitialScale(customSettings.initialScale); setInitialScale(customSettings.initialScale);
settings.setNeedInitialFocus(customSettings.needInitialFocus); 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.setOffscreenPreRaster(customSettings.offscreenPreRaster);
settings.setSansSerifFontFamily(customSettings.sansSerifFontFamily); settings.setSansSerifFontFamily(customSettings.sansSerifFontFamily);
settings.setSerifFontFamily(customSettings.serifFontFamily); settings.setSerifFontFamily(customSettings.serifFontFamily);
@ -640,94 +657,98 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
}); });
} }
public void setSettings(InAppWebViewSettings newSettings, HashMap<String, Object> newSettingsMap) { public void setSettings(InAppWebViewSettings newCustomSettings, HashMap<String, Object> newSettingsMap) {
WebSettings settings = getSettings(); WebSettings settings = getSettings();
if (newSettingsMap.get("javaScriptEnabled") != null && customSettings.javaScriptEnabled != newSettings.javaScriptEnabled) if (newSettingsMap.get("javaScriptEnabled") != null && customSettings.javaScriptEnabled != newCustomSettings.javaScriptEnabled)
settings.setJavaScriptEnabled(newSettings.javaScriptEnabled); settings.setJavaScriptEnabled(newCustomSettings.javaScriptEnabled);
if (newSettingsMap.get("useShouldInterceptAjaxRequest") != null && customSettings.useShouldInterceptAjaxRequest != newSettings.useShouldInterceptAjaxRequest) { if (newSettingsMap.get("useShouldInterceptAjaxRequest") != null && customSettings.useShouldInterceptAjaxRequest != newCustomSettings.useShouldInterceptAjaxRequest) {
enablePluginScriptAtRuntime( enablePluginScriptAtRuntime(
InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE, InterceptAjaxRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_AJAX_REQUEST_JS_SOURCE,
newSettings.useShouldInterceptAjaxRequest, newCustomSettings.useShouldInterceptAjaxRequest,
InterceptAjaxRequestJS.INTERCEPT_AJAX_REQUEST_JS_PLUGIN_SCRIPT 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( enablePluginScriptAtRuntime(
InterceptFetchRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_FETCH_REQUEST_JS_SOURCE, InterceptFetchRequestJS.FLAG_VARIABLE_FOR_SHOULD_INTERCEPT_FETCH_REQUEST_JS_SOURCE,
newSettings.useShouldInterceptFetchRequest, newCustomSettings.useShouldInterceptFetchRequest,
InterceptFetchRequestJS.INTERCEPT_FETCH_REQUEST_JS_PLUGIN_SCRIPT 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( enablePluginScriptAtRuntime(
OnLoadResourceJS.FLAG_VARIABLE_FOR_ON_LOAD_RESOURCE_JS_SOURCE, OnLoadResourceJS.FLAG_VARIABLE_FOR_ON_LOAD_RESOURCE_JS_SOURCE,
newSettings.useOnLoadResource, newCustomSettings.useOnLoadResource,
OnLoadResourceJS.ON_LOAD_RESOURCE_JS_PLUGIN_SCRIPT OnLoadResourceJS.ON_LOAD_RESOURCE_JS_PLUGIN_SCRIPT
); );
} }
if (newSettingsMap.get("javaScriptCanOpenWindowsAutomatically") != null && customSettings.javaScriptCanOpenWindowsAutomatically != newSettings.javaScriptCanOpenWindowsAutomatically) if (newSettingsMap.get("javaScriptCanOpenWindowsAutomatically") != null && customSettings.javaScriptCanOpenWindowsAutomatically != newCustomSettings.javaScriptCanOpenWindowsAutomatically)
settings.setJavaScriptCanOpenWindowsAutomatically(newSettings.javaScriptCanOpenWindowsAutomatically); settings.setJavaScriptCanOpenWindowsAutomatically(newCustomSettings.javaScriptCanOpenWindowsAutomatically);
if (newSettingsMap.get("builtInZoomControls") != null && customSettings.builtInZoomControls != newSettings.builtInZoomControls) if (newSettingsMap.get("builtInZoomControls") != null && customSettings.builtInZoomControls != newCustomSettings.builtInZoomControls)
settings.setBuiltInZoomControls(newSettings.builtInZoomControls); settings.setBuiltInZoomControls(newCustomSettings.builtInZoomControls);
if (newSettingsMap.get("displayZoomControls") != null && customSettings.displayZoomControls != newSettings.displayZoomControls) if (newSettingsMap.get("displayZoomControls") != null && customSettings.displayZoomControls != newCustomSettings.displayZoomControls)
settings.setDisplayZoomControls(newSettings.displayZoomControls); settings.setDisplayZoomControls(newCustomSettings.displayZoomControls);
if (newSettingsMap.get("safeBrowsingEnabled") != null && customSettings.safeBrowsingEnabled != newSettings.safeBrowsingEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (newSettingsMap.get("safeBrowsingEnabled") != null && customSettings.safeBrowsingEnabled != newCustomSettings.safeBrowsingEnabled) {
settings.setSafeBrowsingEnabled(newSettings.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) if (newSettingsMap.get("mediaPlaybackRequiresUserGesture") != null && customSettings.mediaPlaybackRequiresUserGesture != newCustomSettings.mediaPlaybackRequiresUserGesture)
settings.setMediaPlaybackRequiresUserGesture(newSettings.mediaPlaybackRequiresUserGesture); settings.setMediaPlaybackRequiresUserGesture(newCustomSettings.mediaPlaybackRequiresUserGesture);
if (newSettingsMap.get("databaseEnabled") != null && customSettings.databaseEnabled != newSettings.databaseEnabled) if (newSettingsMap.get("databaseEnabled") != null && customSettings.databaseEnabled != newCustomSettings.databaseEnabled)
settings.setDatabaseEnabled(newSettings.databaseEnabled); settings.setDatabaseEnabled(newCustomSettings.databaseEnabled);
if (newSettingsMap.get("domStorageEnabled") != null && customSettings.domStorageEnabled != newSettings.domStorageEnabled) if (newSettingsMap.get("domStorageEnabled") != null && customSettings.domStorageEnabled != newCustomSettings.domStorageEnabled)
settings.setDomStorageEnabled(newSettings.domStorageEnabled); settings.setDomStorageEnabled(newCustomSettings.domStorageEnabled);
if (newSettingsMap.get("userAgent") != null && !customSettings.userAgent.equals(newSettings.userAgent) && !newSettings.userAgent.isEmpty()) if (newSettingsMap.get("userAgent") != null && !customSettings.userAgent.equals(newCustomSettings.userAgent) && !newCustomSettings.userAgent.isEmpty())
settings.setUserAgentString(newSettings.userAgent); 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) { 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; String userAgentWithApplicationName = userAgent + " " + customSettings.applicationNameForUserAgent;
settings.setUserAgentString(userAgentWithApplicationName); settings.setUserAgentString(userAgentWithApplicationName);
} }
} }
if (newSettingsMap.get("clearCache") != null && newSettings.clearCache) if (newSettingsMap.get("clearCache") != null && newCustomSettings.clearCache)
clearAllCache(); clearAllCache();
else if (newSettingsMap.get("clearSessionCache") != null && newSettings.clearSessionCache) else if (newSettingsMap.get("clearSessionCache") != null && newCustomSettings.clearSessionCache)
CookieManager.getInstance().removeSessionCookie(); CookieManager.getInstance().removeSessionCookie();
if (newSettingsMap.get("thirdPartyCookiesEnabled") != null && customSettings.thirdPartyCookiesEnabled != newSettings.thirdPartyCookiesEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) if (newSettingsMap.get("thirdPartyCookiesEnabled") != null && customSettings.thirdPartyCookiesEnabled != newCustomSettings.thirdPartyCookiesEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
CookieManager.getInstance().setAcceptThirdPartyCookies(this, newSettings.thirdPartyCookiesEnabled); CookieManager.getInstance().setAcceptThirdPartyCookies(this, newCustomSettings.thirdPartyCookiesEnabled);
if (newSettingsMap.get("useWideViewPort") != null && customSettings.useWideViewPort != newSettings.useWideViewPort) if (newSettingsMap.get("useWideViewPort") != null && customSettings.useWideViewPort != newCustomSettings.useWideViewPort)
settings.setUseWideViewPort(newSettings.useWideViewPort); settings.setUseWideViewPort(newCustomSettings.useWideViewPort);
if (newSettingsMap.get("supportZoom") != null && customSettings.supportZoom != newSettings.supportZoom) if (newSettingsMap.get("supportZoom") != null && customSettings.supportZoom != newCustomSettings.supportZoom)
settings.setSupportZoom(newSettings.supportZoom); settings.setSupportZoom(newCustomSettings.supportZoom);
if (newSettingsMap.get("textZoom") != null && !customSettings.textZoom.equals(newSettings.textZoom)) if (newSettingsMap.get("textZoom") != null && !customSettings.textZoom.equals(newCustomSettings.textZoom))
settings.setTextZoom(newSettings.textZoom); settings.setTextZoom(newCustomSettings.textZoom);
if (newSettingsMap.get("verticalScrollBarEnabled") != null && customSettings.verticalScrollBarEnabled != newSettings.verticalScrollBarEnabled) if (newSettingsMap.get("verticalScrollBarEnabled") != null && customSettings.verticalScrollBarEnabled != newCustomSettings.verticalScrollBarEnabled)
setVerticalScrollBarEnabled(newSettings.verticalScrollBarEnabled); setVerticalScrollBarEnabled(newCustomSettings.verticalScrollBarEnabled);
if (newSettingsMap.get("horizontalScrollBarEnabled") != null && customSettings.horizontalScrollBarEnabled != newSettings.horizontalScrollBarEnabled) if (newSettingsMap.get("horizontalScrollBarEnabled") != null && customSettings.horizontalScrollBarEnabled != newCustomSettings.horizontalScrollBarEnabled)
setHorizontalScrollBarEnabled(newSettings.horizontalScrollBarEnabled); setHorizontalScrollBarEnabled(newCustomSettings.horizontalScrollBarEnabled);
if (newSettingsMap.get("transparentBackground") != null && customSettings.transparentBackground != newSettings.transparentBackground) { if (newSettingsMap.get("transparentBackground") != null && customSettings.transparentBackground != newCustomSettings.transparentBackground) {
if (newSettings.transparentBackground) { if (newCustomSettings.transparentBackground) {
setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.TRANSPARENT);
} else { } else {
setBackgroundColor(Color.parseColor("#FFFFFF")); 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
if (newSettingsMap.get("mixedContentMode") != null && (customSettings.mixedContentMode == null || !customSettings.mixedContentMode.equals(newSettings.mixedContentMode))) if (newSettingsMap.get("mixedContentMode") != null && (customSettings.mixedContentMode == null || !customSettings.mixedContentMode.equals(newCustomSettings.mixedContentMode)))
settings.setMixedContentMode(newSettings.mixedContentMode); settings.setMixedContentMode(newCustomSettings.mixedContentMode);
if (newSettingsMap.get("supportMultipleWindows") != null && customSettings.supportMultipleWindows != newSettings.supportMultipleWindows) if (newSettingsMap.get("supportMultipleWindows") != null && customSettings.supportMultipleWindows != newCustomSettings.supportMultipleWindows)
settings.setSupportMultipleWindows(newSettings.supportMultipleWindows); settings.setSupportMultipleWindows(newCustomSettings.supportMultipleWindows);
if (newSettingsMap.get("useOnDownloadStart") != null && customSettings.useOnDownloadStart != newSettings.useOnDownloadStart) { if (newSettingsMap.get("useOnDownloadStart") != null && customSettings.useOnDownloadStart != newCustomSettings.useOnDownloadStart) {
if (newSettings.useOnDownloadStart) { if (newCustomSettings.useOnDownloadStart) {
setDownloadListener(new DownloadStartListener()); setDownloadListener(new DownloadStartListener());
} else { } else {
setDownloadListener(null); setDownloadListener(null);
} }
} }
if (newSettingsMap.get("allowContentAccess") != null && customSettings.allowContentAccess != newSettings.allowContentAccess) if (newSettingsMap.get("allowContentAccess") != null && customSettings.allowContentAccess != newCustomSettings.allowContentAccess)
settings.setAllowContentAccess(newSettings.allowContentAccess); settings.setAllowContentAccess(newCustomSettings.allowContentAccess);
if (newSettingsMap.get("allowFileAccess") != null && customSettings.allowFileAccess != newSettings.allowFileAccess) if (newSettingsMap.get("allowFileAccess") != null && customSettings.allowFileAccess != newCustomSettings.allowFileAccess)
settings.setAllowFileAccess(newSettings.allowFileAccess); settings.setAllowFileAccess(newCustomSettings.allowFileAccess);
if (newSettingsMap.get("allowFileAccessFromFileURLs") != null && customSettings.allowFileAccessFromFileURLs != newSettings.allowFileAccessFromFileURLs) if (newSettingsMap.get("allowFileAccessFromFileURLs") != null && customSettings.allowFileAccessFromFileURLs != newCustomSettings.allowFileAccessFromFileURLs)
settings.setAllowFileAccessFromFileURLs(newSettings.allowFileAccessFromFileURLs); settings.setAllowFileAccessFromFileURLs(newCustomSettings.allowFileAccessFromFileURLs);
if (newSettingsMap.get("allowUniversalAccessFromFileURLs") != null && customSettings.allowUniversalAccessFromFileURLs != newSettings.allowUniversalAccessFromFileURLs) if (newSettingsMap.get("allowUniversalAccessFromFileURLs") != null && customSettings.allowUniversalAccessFromFileURLs != newCustomSettings.allowUniversalAccessFromFileURLs)
settings.setAllowUniversalAccessFromFileURLs(newSettings.allowUniversalAccessFromFileURLs); settings.setAllowUniversalAccessFromFileURLs(newCustomSettings.allowUniversalAccessFromFileURLs);
if (newSettingsMap.get("cacheEnabled") != null && customSettings.cacheEnabled != newSettings.cacheEnabled) if (newSettingsMap.get("cacheEnabled") != null && customSettings.cacheEnabled != newCustomSettings.cacheEnabled)
setCacheEnabled(newSettings.cacheEnabled); setCacheEnabled(newCustomSettings.cacheEnabled);
if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newSettings.appCachePath))) if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newCustomSettings.appCachePath)))
settings.setAppCachePath(newSettings.appCachePath); settings.setAppCachePath(newCustomSettings.appCachePath);
if (newSettingsMap.get("blockNetworkImage") != null && customSettings.blockNetworkImage != newSettings.blockNetworkImage) if (newSettingsMap.get("blockNetworkImage") != null && customSettings.blockNetworkImage != newCustomSettings.blockNetworkImage)
settings.setBlockNetworkImage(newSettings.blockNetworkImage); settings.setBlockNetworkImage(newCustomSettings.blockNetworkImage);
if (newSettingsMap.get("blockNetworkLoads") != null && customSettings.blockNetworkLoads != newSettings.blockNetworkLoads) if (newSettingsMap.get("blockNetworkLoads") != null && customSettings.blockNetworkLoads != newCustomSettings.blockNetworkLoads)
settings.setBlockNetworkLoads(newSettings.blockNetworkLoads); settings.setBlockNetworkLoads(newCustomSettings.blockNetworkLoads);
if (newSettingsMap.get("cacheMode") != null && !customSettings.cacheMode.equals(newSettings.cacheMode)) if (newSettingsMap.get("cacheMode") != null && !customSettings.cacheMode.equals(newCustomSettings.cacheMode))
settings.setCacheMode(newSettings.cacheMode); settings.setCacheMode(newCustomSettings.cacheMode);
if (newSettingsMap.get("cursiveFontFamily") != null && !customSettings.cursiveFontFamily.equals(newSettings.cursiveFontFamily)) if (newSettingsMap.get("cursiveFontFamily") != null && !customSettings.cursiveFontFamily.equals(newCustomSettings.cursiveFontFamily))
settings.setCursiveFontFamily(newSettings.cursiveFontFamily); settings.setCursiveFontFamily(newCustomSettings.cursiveFontFamily);
if (newSettingsMap.get("defaultFixedFontSize") != null && !customSettings.defaultFixedFontSize.equals(newSettings.defaultFixedFontSize)) if (newSettingsMap.get("defaultFixedFontSize") != null && !customSettings.defaultFixedFontSize.equals(newCustomSettings.defaultFixedFontSize))
settings.setDefaultFixedFontSize(newSettings.defaultFixedFontSize); settings.setDefaultFixedFontSize(newCustomSettings.defaultFixedFontSize);
if (newSettingsMap.get("defaultFontSize") != null && !customSettings.defaultFontSize.equals(newSettings.defaultFontSize)) if (newSettingsMap.get("defaultFontSize") != null && !customSettings.defaultFontSize.equals(newCustomSettings.defaultFontSize))
settings.setDefaultFontSize(newSettings.defaultFontSize); settings.setDefaultFontSize(newCustomSettings.defaultFontSize);
if (newSettingsMap.get("defaultTextEncodingName") != null && !customSettings.defaultTextEncodingName.equals(newSettings.defaultTextEncodingName)) if (newSettingsMap.get("defaultTextEncodingName") != null && !customSettings.defaultTextEncodingName.equals(newCustomSettings.defaultTextEncodingName))
settings.setDefaultTextEncodingName(newSettings.defaultTextEncodingName); settings.setDefaultTextEncodingName(newCustomSettings.defaultTextEncodingName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (newSettingsMap.get("disabledActionModeMenuItems") != null &&
if (newSettingsMap.get("disabledActionModeMenuItems") != null && (customSettings.disabledActionModeMenuItems == null || (customSettings.disabledActionModeMenuItems == null ||
!customSettings.disabledActionModeMenuItems.equals(newSettings.disabledActionModeMenuItems))) !customSettings.disabledActionModeMenuItems.equals(newCustomSettings.disabledActionModeMenuItems))) {
settings.setDisabledActionModeMenuItems(newSettings.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)) if (newSettingsMap.get("fantasyFontFamily") != null && !customSettings.fantasyFontFamily.equals(newCustomSettings.fantasyFontFamily))
settings.setFantasyFontFamily(newSettings.fantasyFontFamily); settings.setFantasyFontFamily(newCustomSettings.fantasyFontFamily);
if (newSettingsMap.get("fixedFontFamily") != null && !customSettings.fixedFontFamily.equals(newSettings.fixedFontFamily)) if (newSettingsMap.get("fixedFontFamily") != null && !customSettings.fixedFontFamily.equals(newCustomSettings.fixedFontFamily))
settings.setFixedFontFamily(newSettings.fixedFontFamily); settings.setFixedFontFamily(newCustomSettings.fixedFontFamily);
if (newSettingsMap.get("forceDark") != null && !customSettings.forceDark.equals(newSettings.forceDark)) if (newSettingsMap.get("forceDark") != null && !customSettings.forceDark.equals(newCustomSettings.forceDark)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK))
settings.setForceDark(newSettings.forceDark); 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) if (newSettingsMap.get("forceDarkStrategy") != null &&
settings.setGeolocationEnabled(newSettings.geolocationEnabled); !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 (newSettingsMap.get("geolocationEnabled") != null && customSettings.geolocationEnabled != newCustomSettings.geolocationEnabled)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && newSettings.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { settings.setGeolocationEnabled(newCustomSettings.geolocationEnabled);
settings.setLayoutAlgorithm(newSettings.layoutAlgorithm);
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 { } else {
settings.setLayoutAlgorithm(newSettings.layoutAlgorithm); settings.setLayoutAlgorithm(newCustomSettings.layoutAlgorithm);
} }
} }
if (newSettingsMap.get("loadWithOverviewMode") != null && customSettings.loadWithOverviewMode != newSettings.loadWithOverviewMode) if (newSettingsMap.get("loadWithOverviewMode") != null && customSettings.loadWithOverviewMode != newCustomSettings.loadWithOverviewMode)
settings.setLoadWithOverviewMode(newSettings.loadWithOverviewMode); settings.setLoadWithOverviewMode(newCustomSettings.loadWithOverviewMode);
if (newSettingsMap.get("loadsImagesAutomatically") != null && customSettings.loadsImagesAutomatically != newSettings.loadsImagesAutomatically) if (newSettingsMap.get("loadsImagesAutomatically") != null && customSettings.loadsImagesAutomatically != newCustomSettings.loadsImagesAutomatically)
settings.setLoadsImagesAutomatically(newSettings.loadsImagesAutomatically); settings.setLoadsImagesAutomatically(newCustomSettings.loadsImagesAutomatically);
if (newSettingsMap.get("minimumFontSize") != null && !customSettings.minimumFontSize.equals(newSettings.minimumFontSize)) if (newSettingsMap.get("minimumFontSize") != null && !customSettings.minimumFontSize.equals(newCustomSettings.minimumFontSize))
settings.setMinimumFontSize(newSettings.minimumFontSize); settings.setMinimumFontSize(newCustomSettings.minimumFontSize);
if (newSettingsMap.get("minimumLogicalFontSize") != null && !customSettings.minimumLogicalFontSize.equals(newSettings.minimumLogicalFontSize)) if (newSettingsMap.get("minimumLogicalFontSize") != null && !customSettings.minimumLogicalFontSize.equals(newCustomSettings.minimumLogicalFontSize))
settings.setMinimumLogicalFontSize(newSettings.minimumLogicalFontSize); settings.setMinimumLogicalFontSize(newCustomSettings.minimumLogicalFontSize);
if (newSettingsMap.get("initialScale") != null && !customSettings.initialScale.equals(newSettings.initialScale)) if (newSettingsMap.get("initialScale") != null && !customSettings.initialScale.equals(newCustomSettings.initialScale))
setInitialScale(newSettings.initialScale); setInitialScale(newCustomSettings.initialScale);
if (newSettingsMap.get("needInitialFocus") != null && customSettings.needInitialFocus != newSettings.needInitialFocus) if (newSettingsMap.get("needInitialFocus") != null && customSettings.needInitialFocus != newCustomSettings.needInitialFocus)
settings.setNeedInitialFocus(newSettings.needInitialFocus); settings.setNeedInitialFocus(newCustomSettings.needInitialFocus);
if (newSettingsMap.get("offscreenPreRaster") != null && customSettings.offscreenPreRaster != newSettings.offscreenPreRaster) if (newSettingsMap.get("offscreenPreRaster") != null && customSettings.offscreenPreRaster != newCustomSettings.offscreenPreRaster) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) if (WebViewFeature.isFeatureSupported(WebViewFeature.OFF_SCREEN_PRERASTER))
settings.setOffscreenPreRaster(newSettings.offscreenPreRaster); 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)) if (newSettingsMap.get("sansSerifFontFamily") != null && !customSettings.sansSerifFontFamily.equals(newCustomSettings.sansSerifFontFamily))
settings.setSansSerifFontFamily(newSettings.sansSerifFontFamily); settings.setSansSerifFontFamily(newCustomSettings.sansSerifFontFamily);
if (newSettingsMap.get("serifFontFamily") != null && !customSettings.serifFontFamily.equals(newSettings.serifFontFamily)) if (newSettingsMap.get("serifFontFamily") != null && !customSettings.serifFontFamily.equals(newCustomSettings.serifFontFamily))
settings.setSerifFontFamily(newSettings.serifFontFamily); settings.setSerifFontFamily(newCustomSettings.serifFontFamily);
if (newSettingsMap.get("standardFontFamily") != null && !customSettings.standardFontFamily.equals(newSettings.standardFontFamily)) if (newSettingsMap.get("standardFontFamily") != null && !customSettings.standardFontFamily.equals(newCustomSettings.standardFontFamily))
settings.setStandardFontFamily(newSettings.standardFontFamily); settings.setStandardFontFamily(newCustomSettings.standardFontFamily);
if (newSettingsMap.get("preferredContentMode") != null && !customSettings.preferredContentMode.equals(newSettings.preferredContentMode)) { if (newSettingsMap.get("preferredContentMode") != null && !customSettings.preferredContentMode.equals(newCustomSettings.preferredContentMode)) {
switch (fromValue(newSettings.preferredContentMode)) { switch (fromValue(newCustomSettings.preferredContentMode)) {
case DESKTOP: case DESKTOP:
setDesktopMode(true); setDesktopMode(true);
break; break;
@ -857,30 +894,30 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
} }
} }
if (newSettingsMap.get("saveFormData") != null && customSettings.saveFormData != newSettings.saveFormData) if (newSettingsMap.get("saveFormData") != null && customSettings.saveFormData != newCustomSettings.saveFormData)
settings.setSaveFormData(newSettings.saveFormData); settings.setSaveFormData(newCustomSettings.saveFormData);
if (newSettingsMap.get("incognito") != null && customSettings.incognito != newSettings.incognito) if (newSettingsMap.get("incognito") != null && customSettings.incognito != newCustomSettings.incognito)
setIncognito(newSettings.incognito); setIncognito(newCustomSettings.incognito);
if (newSettingsMap.get("hardwareAcceleration") != null && customSettings.hardwareAcceleration != newSettings.hardwareAcceleration) { if (newSettingsMap.get("hardwareAcceleration") != null && customSettings.hardwareAcceleration != newCustomSettings.hardwareAcceleration) {
if (newSettings.hardwareAcceleration) if (newCustomSettings.hardwareAcceleration)
setLayerType(View.LAYER_TYPE_HARDWARE, null); setLayerType(View.LAYER_TYPE_HARDWARE, null);
else else
setLayerType(View.LAYER_TYPE_SOFTWARE, null); setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} }
if (newSettingsMap.get("regexToCancelSubFramesLoading") != null && (customSettings.regexToCancelSubFramesLoading == null || if (newSettingsMap.get("regexToCancelSubFramesLoading") != null && (customSettings.regexToCancelSubFramesLoading == null ||
!customSettings.regexToCancelSubFramesLoading.equals(newSettings.regexToCancelSubFramesLoading))) { !customSettings.regexToCancelSubFramesLoading.equals(newCustomSettings.regexToCancelSubFramesLoading))) {
if (newSettings.regexToCancelSubFramesLoading == null) if (newCustomSettings.regexToCancelSubFramesLoading == null)
regexToCancelSubFramesLoadingCompiled = null; regexToCancelSubFramesLoadingCompiled = null;
else else
regexToCancelSubFramesLoadingCompiled = Pattern.compile(customSettings.regexToCancelSubFramesLoading); regexToCancelSubFramesLoadingCompiled = Pattern.compile(customSettings.regexToCancelSubFramesLoading);
} }
if (newSettings.contentBlockers != null) { if (newCustomSettings.contentBlockers != null) {
contentBlockerHandler.getRuleList().clear(); contentBlockerHandler.getRuleList().clear();
for (Map<String, Map<String, Object>> contentBlocker : newSettings.contentBlockers) { for (Map<String, Map<String, Object>> contentBlocker : newCustomSettings.contentBlockers) {
// compile ContentBlockerTrigger urlFilter // compile ContentBlockerTrigger urlFilter
ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger")); ContentBlockerTrigger trigger = ContentBlockerTrigger.fromMap(contentBlocker.get("trigger"));
ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action")); 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)) if (newSettingsMap.get("scrollBarStyle") != null && !customSettings.scrollBarStyle.equals(newCustomSettings.scrollBarStyle))
setScrollBarStyle(newSettings.scrollBarStyle); setScrollBarStyle(newCustomSettings.scrollBarStyle);
if (newSettingsMap.get("scrollBarDefaultDelayBeforeFade") != null && (customSettings.scrollBarDefaultDelayBeforeFade == null || if (newSettingsMap.get("scrollBarDefaultDelayBeforeFade") != null && (customSettings.scrollBarDefaultDelayBeforeFade == null ||
!customSettings.scrollBarDefaultDelayBeforeFade.equals(newSettings.scrollBarDefaultDelayBeforeFade))) !customSettings.scrollBarDefaultDelayBeforeFade.equals(newCustomSettings.scrollBarDefaultDelayBeforeFade)))
setScrollBarDefaultDelayBeforeFade(newSettings.scrollBarDefaultDelayBeforeFade); setScrollBarDefaultDelayBeforeFade(newCustomSettings.scrollBarDefaultDelayBeforeFade);
if (newSettingsMap.get("scrollbarFadingEnabled") != null && !customSettings.scrollbarFadingEnabled.equals(newSettings.scrollbarFadingEnabled)) if (newSettingsMap.get("scrollbarFadingEnabled") != null && !customSettings.scrollbarFadingEnabled.equals(newCustomSettings.scrollbarFadingEnabled))
setScrollbarFadingEnabled(newSettings.scrollbarFadingEnabled); setScrollbarFadingEnabled(newCustomSettings.scrollbarFadingEnabled);
if (newSettingsMap.get("scrollBarFadeDuration") != null && (customSettings.scrollBarFadeDuration == null || if (newSettingsMap.get("scrollBarFadeDuration") != null && (customSettings.scrollBarFadeDuration == null ||
!customSettings.scrollBarFadeDuration.equals(newSettings.scrollBarFadeDuration))) !customSettings.scrollBarFadeDuration.equals(newCustomSettings.scrollBarFadeDuration)))
setScrollBarFadeDuration(newSettings.scrollBarFadeDuration); setScrollBarFadeDuration(newCustomSettings.scrollBarFadeDuration);
if (newSettingsMap.get("verticalScrollbarPosition") != null && !customSettings.verticalScrollbarPosition.equals(newSettings.verticalScrollbarPosition)) if (newSettingsMap.get("verticalScrollbarPosition") != null && !customSettings.verticalScrollbarPosition.equals(newCustomSettings.verticalScrollbarPosition))
setVerticalScrollbarPosition(newSettings.verticalScrollbarPosition); setVerticalScrollbarPosition(newCustomSettings.verticalScrollbarPosition);
if (newSettingsMap.get("disableVerticalScroll") != null && customSettings.disableVerticalScroll != newSettings.disableVerticalScroll) if (newSettingsMap.get("disableVerticalScroll") != null && customSettings.disableVerticalScroll != newCustomSettings.disableVerticalScroll)
setVerticalScrollBarEnabled(!newSettings.disableVerticalScroll && newSettings.verticalScrollBarEnabled); setVerticalScrollBarEnabled(!newCustomSettings.disableVerticalScroll && newCustomSettings.verticalScrollBarEnabled);
if (newSettingsMap.get("disableHorizontalScroll") != null && customSettings.disableHorizontalScroll != newSettings.disableHorizontalScroll) if (newSettingsMap.get("disableHorizontalScroll") != null && customSettings.disableHorizontalScroll != newCustomSettings.disableHorizontalScroll)
setHorizontalScrollBarEnabled(!newSettings.disableHorizontalScroll && newSettings.horizontalScrollBarEnabled); setHorizontalScrollBarEnabled(!newCustomSettings.disableHorizontalScroll && newCustomSettings.horizontalScrollBarEnabled);
if (newSettingsMap.get("overScrollMode") != null && !customSettings.overScrollMode.equals(newSettings.overScrollMode)) if (newSettingsMap.get("overScrollMode") != null && !customSettings.overScrollMode.equals(newCustomSettings.overScrollMode))
setOverScrollMode(newSettings.overScrollMode); setOverScrollMode(newCustomSettings.overScrollMode);
if (newSettingsMap.get("networkAvailable") != null && customSettings.networkAvailable != newSettings.networkAvailable) if (newSettingsMap.get("networkAvailable") != null && customSettings.networkAvailable != newCustomSettings.networkAvailable)
setNetworkAvailable(newSettings.networkAvailable); setNetworkAvailable(newCustomSettings.networkAvailable);
if (newSettingsMap.get("rendererPriorityPolicy") != null && if (newSettingsMap.get("rendererPriorityPolicy") != null &&
(customSettings.rendererPriorityPolicy.get("rendererRequestedPriority") != newSettings.rendererPriorityPolicy.get("rendererRequestedPriority") || (customSettings.rendererPriorityPolicy.get("rendererRequestedPriority") != newCustomSettings.rendererPriorityPolicy.get("rendererRequestedPriority") ||
customSettings.rendererPriorityPolicy.get("waivedWhenNotVisible") != newSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")) && customSettings.rendererPriorityPolicy.get("waivedWhenNotVisible") != newCustomSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setRendererPriorityPolicy( setRendererPriorityPolicy(
(int) newSettings.rendererPriorityPolicy.get("rendererRequestedPriority"), (int) newCustomSettings.rendererPriorityPolicy.get("rendererRequestedPriority"),
(boolean) newSettings.rendererPriorityPolicy.get("waivedWhenNotVisible")); (boolean) newCustomSettings.rendererPriorityPolicy.get("waivedWhenNotVisible"));
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (newSettingsMap.get("verticalScrollbarThumbColor") != null && !Util.objEquals(customSettings.verticalScrollbarThumbColor, newSettings.verticalScrollbarThumbColor)) if (newSettingsMap.get("verticalScrollbarThumbColor") != null && !Util.objEquals(customSettings.verticalScrollbarThumbColor, newCustomSettings.verticalScrollbarThumbColor))
setVerticalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newSettings.verticalScrollbarThumbColor))); setVerticalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.verticalScrollbarThumbColor)));
if (newSettingsMap.get("verticalScrollbarTrackColor") != null && !Util.objEquals(customSettings.verticalScrollbarTrackColor, newSettings.verticalScrollbarTrackColor)) if (newSettingsMap.get("verticalScrollbarTrackColor") != null && !Util.objEquals(customSettings.verticalScrollbarTrackColor, newCustomSettings.verticalScrollbarTrackColor))
setVerticalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newSettings.verticalScrollbarTrackColor))); setVerticalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.verticalScrollbarTrackColor)));
if (newSettingsMap.get("horizontalScrollbarThumbColor") != null && !Util.objEquals(customSettings.horizontalScrollbarThumbColor, newSettings.horizontalScrollbarThumbColor)) if (newSettingsMap.get("horizontalScrollbarThumbColor") != null && !Util.objEquals(customSettings.horizontalScrollbarThumbColor, newCustomSettings.horizontalScrollbarThumbColor))
setHorizontalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newSettings.horizontalScrollbarThumbColor))); setHorizontalScrollbarThumbDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.horizontalScrollbarThumbColor)));
if (newSettingsMap.get("horizontalScrollbarTrackColor") != null && !Util.objEquals(customSettings.horizontalScrollbarTrackColor, newSettings.horizontalScrollbarTrackColor)) if (newSettingsMap.get("horizontalScrollbarTrackColor") != null && !Util.objEquals(customSettings.horizontalScrollbarTrackColor, newCustomSettings.horizontalScrollbarTrackColor))
setHorizontalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newSettings.horizontalScrollbarTrackColor))); setHorizontalScrollbarTrackDrawable(new ColorDrawable(Color.parseColor(newCustomSettings.horizontalScrollbarTrackColor)));
} }
customSettings = newSettings; customSettings = newCustomSettings;
} }
public Map<String, Object> getCustomSettings() { public Map<String, Object> getCustomSettings() {
@ -1666,8 +1703,10 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
} }
public void addWebMessageListener(@NonNull WebMessageListener webMessageListener) throws Exception { public void addWebMessageListener(@NonNull WebMessageListener webMessageListener) throws Exception {
WebViewCompat.addWebMessageListener(this, webMessageListener.jsObjectName, webMessageListener.allowedOriginRules, webMessageListener.listener); if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
webMessageListeners.add(webMessageListener); WebViewCompat.addWebMessageListener(this, webMessageListener.jsObjectName, webMessageListener.allowedOriginRules, webMessageListener.listener);
webMessageListeners.add(webMessageListener);
}
} }
public void disposeWebMessageChannels() { public void disposeWebMessageChannels() {

View File

@ -25,6 +25,9 @@ import android.webkit.WebViewClient;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; 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.Util;
import com.pichillilorenzo.flutter_inappwebview.credential_database.CredentialDatabase; import com.pichillilorenzo.flutter_inappwebview.credential_database.CredentialDatabase;
@ -74,7 +77,9 @@ public class InAppWebViewClient extends WebViewClient {
InAppWebView webView = (InAppWebView) view; InAppWebView webView = (InAppWebView) view;
if (webView.customSettings.useShouldOverrideUrlLoading) { if (webView.customSettings.useShouldOverrideUrlLoading) {
boolean isRedirect = false; 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(); isRedirect = request.isRedirect();
} }
onShouldOverrideUrlLoading( onShouldOverrideUrlLoading(
@ -705,7 +710,9 @@ public class InAppWebViewClient extends WebViewClient {
headers = webResourceRequest.getRequestHeaders(); headers = webResourceRequest.getRequestHeaders();
hasGesture = webResourceRequest.hasGesture(); hasGesture = webResourceRequest.hasGesture();
isForMainFrame = webResourceRequest.isForMainFrame(); 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(); isRedirect = webResourceRequest.isRedirect();
} }
} }

View File

@ -5,6 +5,8 @@ import android.view.View;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import com.pichillilorenzo.flutter_inappwebview.ISettings; import com.pichillilorenzo.flutter_inappwebview.ISettings;
import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface; import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface;
@ -71,7 +73,8 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
public Integer disabledActionModeMenuItems; public Integer disabledActionModeMenuItems;
public String fantasyFontFamily = "fantasy"; public String fantasyFontFamily = "fantasy";
public String fixedFontFamily = "monospace"; 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 Boolean geolocationEnabled = true;
public WebSettings.LayoutAlgorithm layoutAlgorithm; public WebSettings.LayoutAlgorithm layoutAlgorithm;
public Boolean loadWithOverviewMode = true; public Boolean loadWithOverviewMode = true;
@ -266,6 +269,9 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
case "forceDark": case "forceDark":
forceDark = (Integer) value; forceDark = (Integer) value;
break; break;
case "forceDarkStrategy":
forceDarkStrategy = (Integer) value;
break;
case "geolocationEnabled": case "geolocationEnabled":
geolocationEnabled = (Boolean) value; geolocationEnabled = (Boolean) value;
break; break;
@ -420,6 +426,7 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
settings.put("fantasyFontFamily", fantasyFontFamily); settings.put("fantasyFontFamily", fantasyFontFamily);
settings.put("fixedFontFamily", fixedFontFamily); settings.put("fixedFontFamily", fixedFontFamily);
settings.put("forceDark", forceDark); settings.put("forceDark", forceDark);
settings.put("forceDarkStrategy", forceDarkStrategy);
settings.put("geolocationEnabled", geolocationEnabled); settings.put("geolocationEnabled", geolocationEnabled);
settings.put("layoutAlgorithm", getLayoutAlgorithm()); settings.put("layoutAlgorithm", getLayoutAlgorithm());
settings.put("loadWithOverviewMode", loadWithOverviewMode); settings.put("loadWithOverviewMode", loadWithOverviewMode);
@ -475,7 +482,9 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
realSettings.put("databaseEnabled", settings.getDatabaseEnabled()); realSettings.put("databaseEnabled", settings.getDatabaseEnabled());
realSettings.put("domStorageEnabled", settings.getDomStorageEnabled()); realSettings.put("domStorageEnabled", settings.getDomStorageEnabled());
realSettings.put("useWideViewPort", settings.getUseWideViewPort()); 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()); realSettings.put("safeBrowsingEnabled", settings.getSafeBrowsingEnabled());
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@ -492,19 +501,28 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
realSettings.put("defaultFixedFontSize", settings.getDefaultFixedFontSize()); realSettings.put("defaultFixedFontSize", settings.getDefaultFixedFontSize());
realSettings.put("defaultFontSize", settings.getDefaultFontSize()); realSettings.put("defaultFontSize", settings.getDefaultFontSize());
realSettings.put("defaultTextEncodingName", settings.getDefaultTextEncodingName()); 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("disabledActionModeMenuItems", settings.getDisabledActionModeMenuItems());
} }
realSettings.put("fantasyFontFamily", settings.getFantasyFontFamily()); realSettings.put("fantasyFontFamily", settings.getFantasyFontFamily());
realSettings.put("fixedFontFamily", settings.getFixedFontFamily()); 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()); 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("layoutAlgorithm", settings.getLayoutAlgorithm().name());
realSettings.put("loadWithOverviewMode", settings.getLoadWithOverviewMode()); realSettings.put("loadWithOverviewMode", settings.getLoadWithOverviewMode());
realSettings.put("loadsImagesAutomatically", settings.getLoadsImagesAutomatically()); realSettings.put("loadsImagesAutomatically", settings.getLoadsImagesAutomatically());
realSettings.put("minimumLogicalFontSize", settings.getMinimumLogicalFontSize()); 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("offscreenPreRaster", settings.getOffscreenPreRaster());
} }
realSettings.put("sansSerifFontFamily", settings.getSansSerifFontFamily()); realSettings.put("sansSerifFontFamily", settings.getSansSerifFontFamily());

View File

@ -6,6 +6,8 @@ import android.webkit.WebResourceRequest;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.webkit.WebResourceRequestCompat;
import androidx.webkit.WebViewFeature;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -30,9 +32,15 @@ public class WebResourceRequestExt {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) @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(), return new WebResourceRequestExt(request.getUrl(),
request.getRequestHeaders(), request.getRequestHeaders(),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && request.isRedirect(), isRedirect,
request.hasGesture(), request.hasGesture(),
request.isForMainFrame(), request.isForMainFrame(),
request.getMethod() request.getMethod()

View File

@ -55,7 +55,7 @@ void safeBrowsing() {
test('setSafeBrowsingWhitelist', () async { test('setSafeBrowsingWhitelist', () async {
expect( expect(
await InAppWebViewController.setSafeBrowsingWhitelist( await InAppWebViewController.setSafeBrowsingAllowlist(
hosts: ["flutter.dev", "github.com"]), hosts: ["flutter.dev", "github.com"]),
true); true);
}); });

View File

@ -2,6 +2,9 @@ import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../in_app_webview/in_app_webview_controller.dart'; import '../in_app_webview/in_app_webview_controller.dart';
import '../in_app_webview/in_app_webview_settings.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 that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device.
class WebViewFeature { class WebViewFeature {
@ -83,7 +86,7 @@ class WebViewFeature {
///This feature covers [InAppWebViewSettings.forceDark]. ///This feature covers [InAppWebViewSettings.forceDark].
static const FORCE_DARK = const WebViewFeature._internal("FORCE_DARK"); static const FORCE_DARK = const WebViewFeature._internal("FORCE_DARK");
/// ///This feature covers [InAppWebViewSettings.forceDarkStrategy].
static const FORCE_DARK_STRATEGY = static const FORCE_DARK_STRATEGY =
const WebViewFeature._internal("FORCE_DARK_STRATEGY"); const WebViewFeature._internal("FORCE_DARK_STRATEGY");
@ -102,15 +105,15 @@ class WebViewFeature {
/// ///
static const MULTI_PROCESS = const WebViewFeature._internal("MULTI_PROCESS"); static const MULTI_PROCESS = const WebViewFeature._internal("MULTI_PROCESS");
/// ///This feature covers [InAppWebViewSettings.offscreenPreRaster].
static const OFF_SCREEN_PRERASTER = static const OFF_SCREEN_PRERASTER =
const WebViewFeature._internal("OFF_SCREEN_PRERASTER"); const WebViewFeature._internal("OFF_SCREEN_PRERASTER");
/// ///This feature covers [InAppWebViewController.postWebMessage].
static const POST_WEB_MESSAGE = static const POST_WEB_MESSAGE =
const WebViewFeature._internal("POST_WEB_MESSAGE"); const WebViewFeature._internal("POST_WEB_MESSAGE");
/// ///This feature covers [ProxyController.setProxyOverride] and [ProxyController.clearProxyOverride].
static const PROXY_OVERRIDE = static const PROXY_OVERRIDE =
const WebViewFeature._internal("PROXY_OVERRIDE"); const WebViewFeature._internal("PROXY_OVERRIDE");
@ -122,11 +125,11 @@ class WebViewFeature {
static const RECEIVE_WEB_RESOURCE_ERROR = static const RECEIVE_WEB_RESOURCE_ERROR =
const WebViewFeature._internal("RECEIVE_WEB_RESOURCE_ERROR"); const WebViewFeature._internal("RECEIVE_WEB_RESOURCE_ERROR");
/// ///This feature covers [InAppWebViewController.setSafeBrowsingAllowlist].
static const SAFE_BROWSING_ALLOWLIST = static const SAFE_BROWSING_ALLOWLIST =
const WebViewFeature._internal("SAFE_BROWSING_ALLOWLIST"); const WebViewFeature._internal("SAFE_BROWSING_ALLOWLIST");
/// ///This feature covers [InAppWebViewSettings.safeBrowsingEnabled].
static const SAFE_BROWSING_ENABLE = static const SAFE_BROWSING_ENABLE =
const WebViewFeature._internal("SAFE_BROWSING_ENABLE"); const WebViewFeature._internal("SAFE_BROWSING_ENABLE");
@ -134,7 +137,7 @@ class WebViewFeature {
static const SAFE_BROWSING_HIT = static const SAFE_BROWSING_HIT =
const WebViewFeature._internal("SAFE_BROWSING_HIT"); const WebViewFeature._internal("SAFE_BROWSING_HIT");
/// ///This feature covers [InAppWebViewController.getSafeBrowsingPrivacyPolicyUrl].
static const SAFE_BROWSING_PRIVACY_POLICY_URL = static const SAFE_BROWSING_PRIVACY_POLICY_URL =
const WebViewFeature._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); const WebViewFeature._internal("SAFE_BROWSING_PRIVACY_POLICY_URL");
@ -156,27 +159,27 @@ class WebViewFeature {
static const SAFE_BROWSING_WHITELIST = static const SAFE_BROWSING_WHITELIST =
const WebViewFeature._internal("SAFE_BROWSING_WHITELIST"); const WebViewFeature._internal("SAFE_BROWSING_WHITELIST");
/// ///This feature covers [ServiceWorkerController].
static const SERVICE_WORKER_BASIC_USAGE = static const SERVICE_WORKER_BASIC_USAGE =
const WebViewFeature._internal("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 = static const SERVICE_WORKER_BLOCK_NETWORK_LOADS =
const WebViewFeature._internal("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 = static const SERVICE_WORKER_CACHE_MODE =
const WebViewFeature._internal("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 = static const SERVICE_WORKER_CONTENT_ACCESS =
const WebViewFeature._internal("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 = static const SERVICE_WORKER_FILE_ACCESS =
const WebViewFeature._internal("SERVICE_WORKER_FILE_ACCESS"); const WebViewFeature._internal("SERVICE_WORKER_FILE_ACCESS");
/// ///This feature covers [ServiceWorkerClient.shouldInterceptRequest].
static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST =
const WebViewFeature._internal("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 = static const SHOULD_OVERRIDE_WITH_REDIRECTS =
const WebViewFeature._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); const WebViewFeature._internal("SHOULD_OVERRIDE_WITH_REDIRECTS");
/// ///This feature covers [InAppWebViewController.startSafeBrowsing].
static const START_SAFE_BROWSING = static const START_SAFE_BROWSING =
const WebViewFeature._internal("START_SAFE_BROWSING"); const WebViewFeature._internal("START_SAFE_BROWSING");
@ -200,7 +203,7 @@ class WebViewFeature {
static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = static const WEB_MESSAGE_CALLBACK_ON_MESSAGE =
const WebViewFeature._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); const WebViewFeature._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE");
/// ///This feature covers [WebMessageListener].
static const WEB_MESSAGE_LISTENER = static const WEB_MESSAGE_LISTENER =
const WebViewFeature._internal("WEB_MESSAGE_LISTENER"); const WebViewFeature._internal("WEB_MESSAGE_LISTENER");

View File

@ -93,10 +93,10 @@ class AndroidInAppWebViewController {
} }
///Use [InAppWebViewController.setSafeBrowsingWhitelist] instead. ///Use [InAppWebViewController.setSafeBrowsingWhitelist] instead.
@Deprecated("Use InAppWebViewController.setSafeBrowsingWhitelist instead") @Deprecated("Use InAppWebViewController.setSafeBrowsingAllowlist instead")
static Future<bool> setSafeBrowsingWhitelist( static Future<bool> setSafeBrowsingWhitelist(
{required List<String> hosts}) async { {required List<String> hosts}) async {
return await InAppWebViewController.setSafeBrowsingWhitelist(hosts: hosts); return await InAppWebViewController.setSafeBrowsingAllowlist(hosts: hosts);
} }
///Use [InAppWebViewController.getCurrentWebViewPackage] instead. ///Use [InAppWebViewController.getCurrentWebViewPackage] instead.

View File

@ -3341,6 +3341,13 @@ class InAppWebViewController {
return url != null ? Uri.parse(url) : null; return url != null ? Uri.parse(url) : null;
} }
///Use [setSafeBrowsingAllowlist] instead.
@Deprecated("Use setSafeBrowsingAllowlist instead")
static Future<bool> setSafeBrowsingWhitelist(
{required List<String> 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. ///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: /// Each rule should take one of these:
@ -3359,11 +3366,11 @@ class InAppWebViewController {
/// ///
///**Supported Platforms/Implementations**: ///**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))) ///- 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<bool> setSafeBrowsingWhitelist( static Future<bool> setSafeBrowsingAllowlist(
{required List<String> hosts}) async { {required List<String> hosts}) async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('hosts', () => hosts); 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. ///If WebView has already been loaded into the current process this method will return the package that was used to load it.

View File

@ -1,6 +1,7 @@
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'android/in_app_webview_options.dart'; import 'android/in_app_webview_options.dart';
import 'apple/in_app_webview_options.dart'; import 'apple/in_app_webview_options.dart';
@ -418,7 +419,7 @@ class InAppWebViewSettings
///- Android native WebView ///- Android native WebView
String fixedFontFamily; 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+. ///**NOTE**: available on Android 29+.
/// ///
@ -426,6 +427,15 @@ class InAppWebViewSettings
///- Android native WebView ///- Android native WebView
ForceDark? forceDark; 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`. ///Sets whether Geolocation API is enabled. The default value is `true`.
/// ///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
@ -1102,7 +1112,8 @@ class InAppWebViewSettings
this.disabledActionModeMenuItems, this.disabledActionModeMenuItems,
this.fantasyFontFamily = "fantasy", this.fantasyFontFamily = "fantasy",
this.fixedFontFamily = "monospace", 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.geolocationEnabled = true,
this.layoutAlgorithm, this.layoutAlgorithm,
this.loadWithOverviewMode = true, this.loadWithOverviewMode = true,
@ -1250,6 +1261,7 @@ class InAppWebViewSettings
"fantasyFontFamily": fantasyFontFamily, "fantasyFontFamily": fantasyFontFamily,
"fixedFontFamily": fixedFontFamily, "fixedFontFamily": fixedFontFamily,
"forceDark": forceDark?.toValue(), "forceDark": forceDark?.toValue(),
"forceDarkStrategy": forceDarkStrategy?.toValue(),
"geolocationEnabled": geolocationEnabled, "geolocationEnabled": geolocationEnabled,
"layoutAlgorithm": layoutAlgorithm?.toValue(), "layoutAlgorithm": layoutAlgorithm?.toValue(),
"loadWithOverviewMode": loadWithOverviewMode, "loadWithOverviewMode": loadWithOverviewMode,
@ -1422,6 +1434,7 @@ class InAppWebViewSettings
settings.fantasyFontFamily = map["fantasyFontFamily"]; settings.fantasyFontFamily = map["fantasyFontFamily"];
settings.fixedFontFamily = map["fixedFontFamily"]; settings.fixedFontFamily = map["fixedFontFamily"];
settings.forceDark = ForceDark.fromValue(map["forceDark"]); settings.forceDark = ForceDark.fromValue(map["forceDark"]);
settings.forceDarkStrategy = ForceDarkStrategy.fromValue(map["forceDarkStrategy"]);
settings.geolocationEnabled = map["geolocationEnabled"]; settings.geolocationEnabled = map["geolocationEnabled"];
settings.layoutAlgorithm = settings.layoutAlgorithm =
LayoutAlgorithm.fromValue(map["layoutAlgorithm"]); LayoutAlgorithm.fromValue(map["layoutAlgorithm"]);

View File

@ -6,9 +6,9 @@ class ForceDark {
///Set of all values of [ForceDark]. ///Set of all values of [ForceDark].
static final Set<ForceDark> values = [ static final Set<ForceDark> values = [
ForceDark.FORCE_DARK_OFF, ForceDark.OFF,
ForceDark.FORCE_DARK_AUTO, ForceDark.AUTO,
ForceDark.FORCE_DARK_ON, ForceDark.ON,
].toSet(); ].toSet();
///Gets a possible [ForceDark] instance from an [int] value. ///Gets a possible [ForceDark] instance from an [int] value.
@ -31,24 +31,24 @@ class ForceDark {
String toString() { String toString() {
switch (_value) { switch (_value) {
case 1: case 1:
return "FORCE_DARK_AUTO"; return "AUTO";
case 2: case 2:
return "FORCE_DARK_ON"; return "ON";
case 0: case 0:
default: default:
return "FORCE_DARK_OFF"; return "OFF";
} }
} }
///Disable force dark, irrespective of the force dark mode of the WebView parent. ///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. ///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. ///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. ///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; bool operator ==(value) => value == _value;

View File

@ -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<ForceDarkStrategy> 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, `<meta name="color-scheme" content="dark light">`.
///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;
}

View File

@ -147,3 +147,4 @@ export 'web_resource_error_type.dart';
export 'media_capture_state.dart'; export 'media_capture_state.dart';
export 'proxy_rule.dart'; export 'proxy_rule.dart';
export 'proxy_scheme_filter.dart'; export 'proxy_scheme_filter.dart';
export 'force_dark_strategy.dart';