///Class that is used by [WebView.shouldOverrideUrlLoading] event. ///It represents the policy to pass back to the decision handler. class NavigationActionPolicy { final int _value; const NavigationActionPolicy._internal(this._value); int toValue() => _value; ///Cancel the navigation. static const CANCEL = NavigationActionPolicy._internal(0); ///Allow the navigation to continue. static const ALLOW = NavigationActionPolicy._internal(1); @override bool operator ==(value) => value == _value; @override int get hashCode => _value.hashCode; Map toMap() { return { 'action': _value, }; } } ///Class that represents the WebView context menu. It used by [WebView.contextMenu]. /// ///**NOTE**: To make it work properly on Android, JavaScript should be enabled! class ContextMenu { ///Event fired when the context menu for this WebView is being built. /// ///[hitTestResult] represents the hit result for hitting an HTML elements. final void Function(dynamic hitTestResult)? onCreateContextMenu; ///Event fired when the context menu for this WebView is being hidden. final void Function()? onHideContextMenu; ///Event fired when a context menu item has been clicked. /// ///[contextMenuItemClicked] represents the [ContextMenuItem] clicked. final void Function(ContextMenuItem contextMenuItemClicked)? onContextMenuActionItemClicked; ///Context menu options. final ContextMenuOptions? options; ///List of the custom [ContextMenuItem]. final List menuItems; ContextMenu( {this.menuItems = const [], this.onCreateContextMenu, this.onHideContextMenu, this.options, this.onContextMenuActionItemClicked}); Map toMap() { return { 'menuItems': menuItems.map((menuItem) => menuItem.toMap()).toList(), 'options': options?.toMap() }; } Map toJson() { return toMap(); } @override String toString() { return toMap().toString(); } } ///Class that represent an item of the [ContextMenu]. class ContextMenuItem { ///Android menu item ID. int? androidId; ///iOS menu item ID. String? iosId; ///Menu item title. String title; ///Menu item action that will be called when an user clicks on it. Function()? action; ContextMenuItem( {this.androidId, this.iosId, required this.title, this.action}); Map toMap() { return {'androidId': androidId, 'iosId': iosId, 'title': title}; } Map toJson() { return toMap(); } @override String toString() { return toMap().toString(); } } ///Class that represents available options used by [ContextMenu]. class ContextMenuOptions { ///Whether all the default system context menu items should be hidden or not. The default value is `false`. bool hideDefaultSystemContextMenuItems; ContextMenuOptions({this.hideDefaultSystemContextMenuItems = false}); Map toMap() { return { 'hideDefaultSystemContextMenuItems': hideDefaultSystemContextMenuItems }; } Map toJson() { return toMap(); } @override String toString() { return toMap().toString(); } } ///Class that represents contains the constants for the times at which to inject script content into a [WebView] used by an [UserScript]. class UserScriptInjectionTime { final int _value; const UserScriptInjectionTime._internal(this._value); static final Set values = { UserScriptInjectionTime.AT_DOCUMENT_START, UserScriptInjectionTime.AT_DOCUMENT_END, }; static UserScriptInjectionTime? fromValue(int? value) { if (value != null) { try { return UserScriptInjectionTime.values .firstWhere((element) => element.toValue() == value); } catch (e) { return null; } } return null; } int toValue() => _value; @override String toString() { switch (_value) { case 1: return 'AT_DOCUMENT_END'; case 0: default: return 'AT_DOCUMENT_START'; } } ///**NOTE for iOS**: A constant to inject the script after the creation of the webpage’s document element, but before loading any other content. /// ///**NOTE for Android**: A constant to try to inject the script as soon as the page starts loading. static const AT_DOCUMENT_START = UserScriptInjectionTime._internal(0); ///**NOTE for iOS**: A constant to inject the script after the document finishes loading, but before loading any other subresources. /// ///**NOTE for Android**: A constant to inject the script as soon as the page finishes loading. static const AT_DOCUMENT_END = UserScriptInjectionTime._internal(1); @override bool operator ==(value) => value == _value; @override int get hashCode => _value.hashCode; } ///Class that represents a script that the [WebView] injects into the web page. class UserScript { ///The script’s group name. String? groupName; ///The script’s source code. String source; ///The time at which to inject the script into the [WebView]. UserScriptInjectionTime injectionTime; ///A Boolean value that indicates whether to inject the script into the main frame. ///Specify true to inject the script only into the main frame, or false to inject it into all frames. ///The default value is `true`. /// ///**NOTE**: available only on iOS. bool iosForMainFrameOnly; ///A scope of execution in which to evaluate the script to prevent conflicts between different scripts. ///For more information about content worlds, see [ContentWorld]. late ContentWorld contentWorld; UserScript( {this.groupName, required this.source, required this.injectionTime, this.iosForMainFrameOnly = true, ContentWorld? contentWorld}) { this.contentWorld = contentWorld ?? ContentWorld.PAGE; } Map toMap() { return { 'groupName': groupName, 'source': source, 'injectionTime': injectionTime.toValue(), 'iosForMainFrameOnly': iosForMainFrameOnly, 'contentWorld': contentWorld.toMap() }; } Map toJson() { return toMap(); } @override String toString() { return toMap().toString(); } } final _contentWorldNameRegExp = RegExp(r'[\s]'); ///Class that represents an object that defines a scope of execution for JavaScript code and which you use to prevent conflicts between different scripts. /// ///**NOTE for iOS**: available on iOS 14.0+. This class represents the native [WKContentWorld](https://developer.apple.com/documentation/webkit/wkcontentworld) class. /// ///**NOTE for Android**: it will create and append an `