import 'dart:io'; import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'android/in_app_webview_options.dart'; import 'ios/in_app_webview_options.dart'; import '../content_blocker.dart'; import '../types.dart'; import '../util.dart'; import '../in_app_browser/in_app_browser_settings.dart'; import 'webview.dart'; class WebViewOptions { Map toMap() { return {}; } static WebViewOptions fromMap(Map map) { return WebViewOptions(); } WebViewOptions copy() { return WebViewOptions.fromMap(this.toMap()); } Map toJson() { return this.toMap(); } @override String toString() { return toMap().toString(); } } ///This class represents all the WebView settings available. class InAppWebViewSettings implements WebViewOptions, BrowserOptions, AndroidOptions, IosOptions { ///Set to `true` to be able to listen at the [WebView.shouldOverrideUrlLoading] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool useShouldOverrideUrlLoading; ///Set to `true` to be able to listen at the [WebView.onLoadResource] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool useOnLoadResource; ///Set to `true` to be able to listen at the [WebView.onDownloadStartRequest] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool useOnDownloadStart; ///Set to `true` to have all the browser's cache cleared before the new WebView is opened. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool clearCache; ///Sets the user-agent for the WebView. /// ///**NOTE**: available on iOS 9.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS String userAgent; ///Append to the existing user-agent. Setting userAgent will override this. /// ///**NOTE**: available on Android 17+ and on iOS 9.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS String applicationNameForUserAgent; ///Set to `true` to enable JavaScript. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool javaScriptEnabled; ///Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool javaScriptCanOpenWindowsAutomatically; ///Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`. /// ///**NOTE**: available on iOS 10.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool mediaPlaybackRequiresUserGesture; ///Sets the minimum font size. The default value is `8` for Android, `0` for iOS. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS int? minimumFontSize; ///Define whether the vertical scrollbar should be drawn or not. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool verticalScrollBarEnabled; ///Define whether the horizontal scrollbar should be drawn or not. The default value is `true`. /// /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool horizontalScrollBarEnabled; ///List of custom schemes that the WebView must handle. Use the [WebView.onLoadResourceCustomScheme] event to intercept resource requests with custom scheme. /// ///**NOTE**: available on iOS 11.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS List resourceCustomSchemes; ///List of [ContentBlocker] that are a set of rules used to block content in the browser window. /// ///**NOTE**: available on iOS 11.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS List contentBlockers; ///Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is [UserPreferredContentMode.RECOMMENDED]. /// ///**NOTE**: available on iOS 13.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS UserPreferredContentMode? preferredContentMode; ///Set to `true` to be able to listen at the [WebView.shouldInterceptAjaxRequest] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool useShouldInterceptAjaxRequest; ///Set to `true` to be able to listen at the [WebView.shouldInterceptFetchRequest] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool useShouldInterceptFetchRequest; ///Set to `true` to open a browser window with incognito mode. The default value is `false`. /// ///**NOTE**: available on iOS 9.0+. ///On Android, by setting this option to `true`, it will clear all the cookies of all WebView instances, ///because there isn't any way to make the website data store non-persistent for the specific WebView instance such as on iOS. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool incognito; ///Sets whether WebView should use browser caching. The default value is `true`. /// ///**NOTE**: available on iOS 9.0+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool cacheEnabled; ///Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool transparentBackground; ///Set to `true` to disable vertical scroll. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool disableVerticalScroll; ///Set to `true` to disable horizontal scroll. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool disableHorizontalScroll; ///Set to `true` to disable context menu. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool disableContextMenu; ///Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool supportZoom; ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from other file scheme URLs. ///Note that some accesses such as image HTML elements don't follow same-origin rules and aren't affected by this setting. /// ///Don't enable this setting if you open files that may be created or altered by external sources. ///Enabling this setting allows malicious scripts loaded in a `file://` context to access arbitrary local files including WebView cookies and app private data. /// ///Note that the value of this setting is ignored if the value of [allowUniversalAccessFromFileURLs] is `true`. /// ///The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool allowFileAccessFromFileURLs; ///Sets whether cross-origin requests in the context of a file scheme URL should be allowed to access content from any origin. ///This includes access to content from other file scheme URLs or web contexts. ///Note that some access such as image HTML elements doesn't follow same-origin rules and isn't affected by this setting. /// ///Don't enable this setting if you open files that may be created or altered by external sources. ///Enabling this setting allows malicious scripts loaded in a `file://` context to launch cross-site scripting attacks, ///either accessing arbitrary local files including WebView cookies, app private data or even credentials used on arbitrary web sites. /// ///The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS bool allowUniversalAccessFromFileURLs; ///Sets the text zoom of the page in percent. The default value is `100`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int textZoom; ///Set to `true` to have the session cookie cache cleared before the new window is opened. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool clearSessionCache; ///Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool builtInZoomControls; ///Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool displayZoomControls; ///Set to `true` if you want the database storage API is enabled. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool databaseEnabled; ///Set to `true` if you want the DOM storage API is enabled. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool domStorageEnabled; ///Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. ///When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. ///When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. ///If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool useWideViewPort; ///Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. ///Safe Browsing is enabled by default for devices which support it. /// ///**NOTE**: available on Android 26+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool safeBrowsingEnabled; ///Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. /// ///**NOTE**: available on Android 21+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView MixedContentMode? mixedContentMode; ///Enables or disables content URL access within WebView. Content URL access allows WebView to load content from a content provider installed in the system. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool allowContentAccess; ///Enables or disables file access within WebView. Note that this enables or disables file system access only. ///Assets and resources are still accessible using `file:///android_asset` and `file:///android_res`. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool allowFileAccess; ///Sets the path to the Application Caches files. In order for the Application Caches API to be enabled, this option must be set a path to which the application can write. ///This option is used one time: repeated calls are ignored. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String? appCachePath; ///Sets whether the WebView should not load image resources from the network (resources accessed via http and https URI schemes). The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool blockNetworkImage; ///Sets whether the WebView should not load resources from the network. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool blockNetworkLoads; ///Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed. ///When navigating back, content is not revalidated, instead the content is just retrieved from the cache. The default value is [CacheMode.LOAD_DEFAULT]. /// ///**Supported Platforms/Implementations**: ///- Android native WebView CacheMode? cacheMode; ///Sets the cursive font family name. The default value is `"cursive"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String cursiveFontFamily; ///Sets the default fixed font size. The default value is `16`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int defaultFixedFontSize; ///Sets the default font size. The default value is `16`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int defaultFontSize; ///Sets the default text encoding name to use when decoding html pages. The default value is `"UTF-8"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String defaultTextEncodingName; ///Disables the action mode menu items according to menuItems flag. /// ///**NOTE**: available on Android 24+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ActionModeMenuItem? disabledActionModeMenuItems; ///Sets the fantasy font family name. The default value is `"fantasy"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String fantasyFontFamily; ///Sets the fixed font family name. The default value is `"monospace"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String fixedFontFamily; ///Set the force dark mode for this WebView. The default value is [ForceDark.FORCE_DARK_OFF]. /// ///**NOTE**: available on Android 29+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ForceDark? forceDark; ///Sets whether Geolocation API is enabled. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool geolocationEnabled; ///Sets the underlying layout algorithm. This will cause a re-layout of the WebView. /// ///**Supported Platforms/Implementations**: ///- Android native WebView LayoutAlgorithm? layoutAlgorithm; ///Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width. ///This setting is taken into account when the content width is greater than the width of the WebView control, for example, when [useWideViewPort] is enabled. ///The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool loadWithOverviewMode; ///Sets whether the WebView should load image resources. Note that this method controls loading of all images, including those embedded using the data URI scheme. ///Note that if the value of this setting is changed from false to true, all images resources referenced by content currently displayed by the WebView are loaded automatically. ///The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool loadsImagesAutomatically; ///Sets the minimum logical font size. The default is `8`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int minimumLogicalFontSize; ///Sets the initial scale for this WebView. 0 means default. The behavior for the default scale depends on the state of [useWideViewPort] and [loadWithOverviewMode]. ///If the content fits into the WebView control by width, then the zoom is set to 100%. For wide content, the behavior depends on the state of [loadWithOverviewMode]. ///If its value is true, the content will be zoomed out to be fit by width into the WebView control, otherwise not. ///If initial scale is greater than 0, WebView starts with this value as initial scale. ///Please note that unlike the scale properties in the viewport meta tag, this method doesn't take the screen density into account. ///The default is `0`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int initialScale; ///Tells the WebView whether it needs to set a node. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool needInitialFocus; ///Sets whether this WebView should raster tiles when it is offscreen but attached to a window. ///Turning this on can avoid rendering artifacts when animating an offscreen WebView on-screen. ///Offscreen WebViews in this mode use more memory. The default value is `false`. /// ///**NOTE**: available on Android 23+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool offscreenPreRaster; ///Sets the sans-serif font family name. The default value is `"sans-serif"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String sansSerifFontFamily; ///Sets the serif font family name. The default value is `"sans-serif"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String serifFontFamily; ///Sets the standard font family name. The default value is `"sans-serif"`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String standardFontFamily; ///Sets whether the WebView should save form data. In Android O, the platform has implemented a fully functional Autofill feature to store form data. ///Therefore, the Webview form data save feature is disabled. Note that the feature will continue to be supported on older versions of Android as before. ///The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool saveFormData; ///Boolean value to enable third party cookies in the WebView. ///Used on Android Lollipop and above only as third party cookies are enabled by default on Android Kitkat and below and on iOS. ///The default value is `true`. /// ///**NOTE**: available on Android 21+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool thirdPartyCookiesEnabled; ///Boolean value to enable Hardware Acceleration in the WebView. ///The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool hardwareAcceleration; ///Sets whether the WebView supports multiple windows. ///If set to `true`, [WebView.onCreateWindow] event must be implemented by the host application. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool supportMultipleWindows; ///Regular expression used by [WebView.shouldOverrideUrlLoading] event to cancel navigation requests for frames that are not the main frame. ///If the url request of a subframe matches the regular expression, then the request of that subframe is canceled. /// ///**Supported Platforms/Implementations**: ///- Android native WebView String? regexToCancelSubFramesLoading; ///Set to `true` to enable Flutter's new Hybrid Composition. The default value is `false`. ///Hybrid Composition is supported starting with Flutter v1.20+. /// ///**NOTE**: It is recommended to use Hybrid Composition only on Android 10+ for a release app, ///as it can cause framerate drops on animations in Android 9 and lower (see [Hybrid-Composition#performance](https://github.com/flutter/flutter/wiki/Hybrid-Composition#performance)). /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool useHybridComposition; ///Set to `true` to be able to listen at the [WebView.shouldInterceptRequest] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool useShouldInterceptRequest; ///Set to `true` to be able to listen at the [WebView.onRenderProcessGone] event. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool useOnRenderProcessGone; ///Sets the WebView's over-scroll mode. ///Setting the over-scroll mode of a WebView will have an effect only if the WebView is capable of scrolling. ///The default value is [OverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS]. /// ///**Supported Platforms/Implementations**: ///- Android native WebView OverScrollMode? overScrollMode; ///Informs WebView of the network state. ///This is used to set the JavaScript property `window.navigator.isOnline` and generates the online/offline event as specified in HTML5, sec. 5.7.7. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool? networkAvailable; ///Specifies the style of the scrollbars. The scrollbars can be overlaid or inset. ///When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. ///For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, ///you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, ///then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. ///The default value is [ScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY]. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ScrollBarStyle? scrollBarStyle; ///Sets the position of the vertical scroll bar. ///The default value is [VerticalScrollbarPosition.SCROLLBAR_POSITION_DEFAULT]. /// ///**Supported Platforms/Implementations**: ///- Android native WebView VerticalScrollbarPosition? verticalScrollbarPosition; ///Defines the delay in milliseconds that a scrollbar waits before fade out. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int? scrollBarDefaultDelayBeforeFade; ///Defines whether scrollbars will fade when the view is not scrolling. ///The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool scrollbarFadingEnabled; ///Defines the scrollbar fade duration in milliseconds. /// ///**Supported Platforms/Implementations**: ///- Android native WebView int? scrollBarFadeDuration; ///Sets the renderer priority policy for this WebView. /// ///**Supported Platforms/Implementations**: ///- Android native WebView RendererPriorityPolicy? rendererPriorityPolicy; ///Sets whether the default Android error page should be disabled. ///The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- Android native WebView bool disableDefaultErrorPage; ///Sets the vertical scrollbar thumb color. /// ///**NOTE**: available on Android 29+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView Color? verticalScrollbarThumbColor; ///Sets the vertical scrollbar track color. /// ///**NOTE**: available on Android 29+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView Color? verticalScrollbarTrackColor; ///Sets the horizontal scrollbar thumb color. /// ///**NOTE**: available on Android 29+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView Color? horizontalScrollbarThumbColor; ///Sets the horizontal scrollbar track color. /// ///**NOTE**: available on Android 29+. /// ///**Supported Platforms/Implementations**: ///- Android native WebView Color? horizontalScrollbarTrackColor; ///Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- iOS bool disallowOverScroll; ///Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- iOS bool enableViewportScale; ///Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- iOS bool suppressesIncrementalRendering; ///Set to `true` to allow AirPlay. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- iOS bool allowsAirPlayForMediaPlayback; ///Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`. /// ///**Supported Platforms/Implementations**: ///- iOS bool allowsBackForwardNavigationGestures; ///Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`. /// ///**NOTE**: available on iOS 9.0+. /// ///**Supported Platforms/Implementations**: ///- iOS bool allowsLinkPreview; ///Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. ///The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`. /// ///**Supported Platforms/Implementations**: ///- iOS bool ignoresViewportScaleLimits; ///Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. ///For this to work, add the `webkit-playsinline` attribute to any `