2020-05-11 00:48:41 +00:00
import ' dart:io ' ;
import ' dart:async ' ;
import ' dart:collection ' ;
import ' dart:typed_data ' ;
import ' dart:convert ' ;
2020-06-12 02:04:41 +00:00
import ' dart:core ' ;
2020-05-11 00:48:41 +00:00
import ' package:flutter/foundation.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/services.dart ' ;
import ' package:flutter/widgets.dart ' ;
2020-06-15 00:08:23 +00:00
import ' X509Certificate/asn1_distinguished_names.dart ' ;
import ' X509Certificate/x509_certificate.dart ' ;
2020-05-11 00:48:41 +00:00
2020-05-29 12:51:26 +00:00
import ' context_menu.dart ' ;
2020-05-11 00:48:41 +00:00
import ' types.dart ' ;
import ' in_app_browser.dart ' ;
import ' webview_options.dart ' ;
2020-05-29 12:51:26 +00:00
import ' headless_in_app_webview.dart ' ;
import ' webview.dart ' ;
import ' in_app_webview.dart ' ;
2020-06-12 02:04:41 +00:00
import ' web_storage.dart ' ;
import ' util.dart ' ;
2020-05-29 12:51:26 +00:00
///List of forbidden names for JavaScript handlers.
const javaScriptHandlerForbiddenNames = [
" onLoadResource " ,
" shouldInterceptAjaxRequest " ,
" onAjaxReadyStateChange " ,
" onAjaxProgress " ,
" shouldInterceptFetchRequest " ,
" onPrint " ,
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
" onWindowFocus " ,
" onWindowBlur " ,
2021-02-07 15:05:39 +00:00
" callAsyncJavaScript "
2020-05-29 12:51:26 +00:00
] ;
2020-05-11 00:48:41 +00:00
///Controls a WebView, such as an [InAppWebView] widget instance, a [HeadlessInAppWebView] instance or [InAppBrowser] WebView instance.
///
///If you are using the [InAppWebView] widget, an [InAppWebViewController] instance can be obtained by setting the [InAppWebView.onWebViewCreated]
///callback. Instead, if you are using an [InAppBrowser] instance, you can get it through the [InAppBrowser.webViewController] attribute.
class InAppWebViewController {
2021-01-28 16:10:15 +00:00
WebView ? _webview ;
late MethodChannel _channel ;
2020-05-11 00:48:41 +00:00
static MethodChannel _staticChannel =
2020-05-28 23:03:45 +00:00
MethodChannel ( ' com.pichillilorenzo/flutter_inappwebview_static ' ) ;
2020-05-11 00:48:41 +00:00
Map < String , JavaScriptHandlerCallback > javaScriptHandlersMap =
2020-05-28 23:03:45 +00:00
HashMap < String , JavaScriptHandlerCallback > ( ) ;
2021-02-01 14:55:27 +00:00
List < UserScript > _userScripts = [ ] ;
2020-05-11 00:48:41 +00:00
// ignore: unused_field
bool _isOpened = false ;
// ignore: unused_field
dynamic _id ;
2020-06-21 23:17:35 +00:00
// ignore: unused_field
2021-01-28 16:10:15 +00:00
String ? _inAppBrowserUuid ;
2020-06-21 23:17:35 +00:00
2021-01-28 16:10:15 +00:00
InAppBrowser ? _inAppBrowser ;
2020-05-11 00:48:41 +00:00
///Android controller that contains only android-specific methods
2021-01-28 16:10:15 +00:00
late AndroidInAppWebViewController android ;
2020-05-11 00:48:41 +00:00
///iOS controller that contains only ios-specific methods
2021-01-28 16:10:15 +00:00
late IOSInAppWebViewController ios ;
2020-05-11 00:48:41 +00:00
2020-06-21 23:17:35 +00:00
///Provides access to the JavaScript [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API): `window.sessionStorage` and `window.localStorage`.
2021-01-28 16:10:15 +00:00
late WebStorage webStorage ;
2020-06-12 02:04:41 +00:00
2020-05-11 00:48:41 +00:00
InAppWebViewController ( dynamic id , WebView webview ) {
this . _id = id ;
this . _channel =
MethodChannel ( ' com.pichillilorenzo/flutter_inappwebview_ $ id ' ) ;
this . _channel . setMethodCallHandler ( handleMethod ) ;
this . _webview = webview ;
2021-02-01 14:55:27 +00:00
this . _userScripts = List < UserScript > . from ( webview . initialUserScripts ? ? [ ] ) ;
2021-01-28 16:10:15 +00:00
this . _init ( ) ;
2020-05-11 00:48:41 +00:00
}
InAppWebViewController . fromInAppBrowser (
2021-02-01 14:55:27 +00:00
String uuid , MethodChannel channel , InAppBrowser inAppBrowser , UnmodifiableListView < UserScript > ? initialUserScripts ) {
2020-05-11 00:48:41 +00:00
this . _inAppBrowserUuid = uuid ;
this . _channel = channel ;
this . _inAppBrowser = inAppBrowser ;
2021-02-01 14:55:27 +00:00
this . _userScripts = List < UserScript > . from ( initialUserScripts ? ? [ ] ) ;
2021-01-28 16:10:15 +00:00
this . _init ( ) ;
}
void _init ( ) {
this . android = AndroidInAppWebViewController ( this ) ;
this . ios = IOSInAppWebViewController ( this ) ;
this . webStorage = WebStorage (
localStorage: LocalStorage ( this ) , sessionStorage: SessionStorage ( this ) ) ;
2020-05-11 00:48:41 +00:00
}
Future < dynamic > handleMethod ( MethodCall call ) async {
switch ( call . method ) {
case " onHeadlessWebViewCreated " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview is HeadlessInAppWebView & & _webview ! . onWebViewCreated ! = null )
_webview ! . onWebViewCreated ! ( this ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onLoadStart " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
if ( _webview ! = null & & _webview ! . onLoadStart ! = null )
_webview ! . onLoadStart ! ( this , url ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onLoadStart ( url ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onLoadStop " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
if ( _webview ! = null & & _webview ! . onLoadStop ! = null )
_webview ! . onLoadStop ! ( this , url ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onLoadStop ( url ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onLoadError " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
2020-05-11 00:48:41 +00:00
int code = call . arguments [ " code " ] ;
String message = call . arguments [ " message " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onLoadError ! = null )
_webview ! . onLoadError ! ( this , url , code , message ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onLoadError ( url , code , message ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onLoadHttpError " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
2020-05-11 00:48:41 +00:00
int statusCode = call . arguments [ " statusCode " ] ;
String description = call . arguments [ " description " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onLoadHttpError ! = null )
_webview ! . onLoadHttpError ! ( this , url , statusCode , description ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onLoadHttpError ( url , statusCode , description ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onProgressChanged " :
int progress = call . arguments [ " progress " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onProgressChanged ! = null )
_webview ! . onProgressChanged ! ( this , progress ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onProgressChanged ( progress ) ;
2020-05-11 00:48:41 +00:00
break ;
case " shouldOverrideUrlLoading " :
String url = call . arguments [ " url " ] ;
2021-01-28 16:10:15 +00:00
String ? method = call . arguments [ " method " ] ;
Map < String , String > ? headers =
2020-05-28 23:03:45 +00:00
call . arguments [ " headers " ] ? . cast < String , String > ( ) ;
2020-05-11 00:48:41 +00:00
bool isForMainFrame = call . arguments [ " isForMainFrame " ] ;
2021-01-28 16:10:15 +00:00
bool ? androidHasGesture = call . arguments [ " androidHasGesture " ] ;
bool ? androidIsRedirect = call . arguments [ " androidIsRedirect " ] ;
int ? iosWKNavigationType = call . arguments [ " iosWKNavigationType " ] ;
2020-05-11 00:48:41 +00:00
ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest =
2020-05-28 23:03:45 +00:00
ShouldOverrideUrlLoadingRequest (
url: url ,
method: method ,
headers: headers ,
isForMainFrame: isForMainFrame ,
androidHasGesture: androidHasGesture ,
androidIsRedirect: androidIsRedirect ,
iosWKNavigationType:
IOSWKNavigationType . fromValue ( iosWKNavigationType ) ) ;
2020-05-11 00:48:41 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . shouldOverrideUrlLoading ! = null )
return ( await _webview ! . shouldOverrideUrlLoading ! (
2020-05-28 23:03:45 +00:00
this , shouldOverrideUrlLoadingRequest ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser !
2020-05-28 23:03:45 +00:00
. shouldOverrideUrlLoading ( shouldOverrideUrlLoadingRequest ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onConsoleMessage " :
String message = call . arguments [ " message " ] ;
2021-01-28 16:10:15 +00:00
ConsoleMessageLevel ? messageLevel =
2020-05-28 23:03:45 +00:00
ConsoleMessageLevel . fromValue ( call . arguments [ " messageLevel " ] ) ;
2020-05-11 00:48:41 +00:00
ConsoleMessage consoleMessage =
2020-05-28 23:03:45 +00:00
ConsoleMessage ( message: message , messageLevel: messageLevel ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onConsoleMessage ! = null )
_webview ! . onConsoleMessage ! ( this , consoleMessage ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onConsoleMessage ( consoleMessage ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onScrollChanged " :
int x = call . arguments [ " x " ] ;
int y = call . arguments [ " y " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onScrollChanged ! = null )
_webview ! . onScrollChanged ! ( this , x , y ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onScrollChanged ( x , y ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onDownloadStart " :
String url = call . arguments [ " url " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onDownloadStart ! = null )
_webview ! . onDownloadStart ! ( this , url ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onDownloadStart ( url ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onLoadResourceCustomScheme " :
String scheme = call . arguments [ " scheme " ] ;
String url = call . arguments [ " url " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onLoadResourceCustomScheme ! = null ) {
2020-05-11 00:48:41 +00:00
try {
var response =
2021-01-28 16:10:15 +00:00
await _webview ! . onLoadResourceCustomScheme ! ( this , scheme , url ) ;
2020-05-11 00:48:41 +00:00
return ( response ! = null ) ? response . toJson ( ) : null ;
} catch ( error ) {
print ( error ) ;
return null ;
}
} else if ( _inAppBrowser ! = null ) {
try {
var response =
2021-01-28 16:10:15 +00:00
await _inAppBrowser ! . onLoadResourceCustomScheme ( scheme , url ) ;
2020-05-11 00:48:41 +00:00
return ( response ! = null ) ? response . toJson ( ) : null ;
} catch ( error ) {
print ( error ) ;
return null ;
}
}
break ;
case " onCreateWindow " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
int windowId = call . arguments [ " windowId " ] ;
2021-01-28 16:10:15 +00:00
bool ? androidIsDialog = call . arguments [ " androidIsDialog " ] ;
bool ? androidIsUserGesture = call . arguments [ " androidIsUserGesture " ] ;
int ? iosWKNavigationType = call . arguments [ " iosWKNavigationType " ] ;
bool ? iosIsForMainFrame = call . arguments [ " iosIsForMainFrame " ] ;
2020-05-11 00:48:41 +00:00
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
CreateWindowRequest createWindowRequest = CreateWindowRequest (
2020-05-11 00:48:41 +00:00
url: url ,
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
windowId: windowId ,
2020-05-11 00:48:41 +00:00
androidIsDialog: androidIsDialog ,
androidIsUserGesture: androidIsUserGesture ,
iosWKNavigationType:
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
IOSWKNavigationType . fromValue ( iosWKNavigationType ) ,
iosIsForMainFrame: iosIsForMainFrame ) ;
2021-01-28 16:10:15 +00:00
bool ? result = false ;
2020-05-11 00:48:41 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onCreateWindow ! = null )
result = await _webview ! . onCreateWindow ! ( this , createWindowRequest ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
else if ( _inAppBrowser ! = null ) {
2021-01-28 16:10:15 +00:00
result = await _inAppBrowser ! . onCreateWindow ( createWindowRequest ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
}
2020-06-30 08:58:59 +00:00
return result ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
case " onCloseWindow " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onCloseWindow ! = null )
_webview ! . onCloseWindow ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onCloseWindow ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
case " onTitleChanged " :
2021-01-28 16:10:15 +00:00
String ? title = call . arguments [ " title " ] ;
if ( _webview ! = null & & _webview ! . onTitleChanged ! = null )
_webview ! . onTitleChanged ! ( this , title ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onTitleChanged ( title ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onGeolocationPermissionsShowPrompt " :
String origin = call . arguments [ " origin " ] ;
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . androidOnGeolocationPermissionsShowPrompt ! = null )
return ( await _webview ! . androidOnGeolocationPermissionsShowPrompt ! (
2020-05-28 23:03:45 +00:00
this , origin ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser !
2020-05-28 23:03:45 +00:00
. androidOnGeolocationPermissionsShowPrompt ( origin ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onGeolocationPermissionsHidePrompt " :
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . androidOnGeolocationPermissionsHidePrompt ! = null )
_webview ! . androidOnGeolocationPermissionsHidePrompt ! ( this ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnGeolocationPermissionsHidePrompt ( ) ;
2020-05-11 00:48:41 +00:00
break ;
2020-05-28 23:03:45 +00:00
case " shouldInterceptRequest " :
String url = call . arguments [ " url " ] ;
String method = call . arguments [ " method " ] ;
2021-01-28 16:10:15 +00:00
Map < String , String > ? headers =
2020-05-28 23:03:45 +00:00
call . arguments [ " headers " ] ? . cast < String , String > ( ) ;
bool isForMainFrame = call . arguments [ " isForMainFrame " ] ;
bool hasGesture = call . arguments [ " hasGesture " ] ;
bool isRedirect = call . arguments [ " isRedirect " ] ;
var request = new WebResourceRequest (
url: url ,
method: method ,
headers: headers ,
isForMainFrame: isForMainFrame ,
hasGesture: hasGesture ,
isRedirect: isRedirect ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidShouldInterceptRequest ! = null )
return ( await _webview ! . androidShouldInterceptRequest ! ( this , request ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidShouldInterceptRequest ( request ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
break ;
case " onRenderProcessUnresponsive " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
2020-05-28 23:03:45 +00:00
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . androidOnRenderProcessUnresponsive ! = null )
return ( await _webview ! . androidOnRenderProcessUnresponsive ! ( this , url ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidOnRenderProcessUnresponsive ( url ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
break ;
case " onRenderProcessResponsive " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
2020-05-28 23:03:45 +00:00
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . androidOnRenderProcessResponsive ! = null )
return ( await _webview ! . androidOnRenderProcessResponsive ! ( this , url ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidOnRenderProcessResponsive ( url ) )
2020-05-28 23:03:45 +00:00
? . toMap ( ) ;
break ;
case " onRenderProcessGone " :
bool didCrash = call . arguments [ " didCrash " ] ;
2021-01-28 16:10:15 +00:00
RendererPriority ? rendererPriorityAtExit = RendererPriority . fromValue (
2020-05-28 23:03:45 +00:00
call . arguments [ " rendererPriorityAtExit " ] ) ;
var detail = RenderProcessGoneDetail (
didCrash: didCrash , rendererPriorityAtExit: rendererPriorityAtExit ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnRenderProcessGone ! = null )
_webview ! . androidOnRenderProcessGone ! ( this , detail ) ;
2020-05-28 23:03:45 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnRenderProcessGone ( detail ) ;
2020-05-28 23:03:45 +00:00
break ;
case " onFormResubmission " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
if ( _webview ! = null & & _webview ! . androidOnFormResubmission ! = null )
return ( await _webview ! . androidOnFormResubmission ! ( this , url ) ) ? . toMap ( ) ;
2020-05-28 23:03:45 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidOnFormResubmission ( url ) ) ? . toMap ( ) ;
2020-05-28 23:03:45 +00:00
break ;
case " onScaleChanged " :
double oldScale = call . arguments [ " oldScale " ] ;
double newScale = call . arguments [ " newScale " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnScaleChanged ! = null )
_webview ! . androidOnScaleChanged ! ( this , oldScale , newScale ) ;
2020-05-28 23:03:45 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnScaleChanged ( oldScale , newScale ) ;
2020-05-28 23:03:45 +00:00
break ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
case " onRequestFocus " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnRequestFocus ! = null )
_webview ! . androidOnRequestFocus ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . androidOnRequestFocus ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
case " onReceivedIcon " :
Uint8List icon = Uint8List . fromList ( call . arguments [ " icon " ] . cast < int > ( ) ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnReceivedIcon ! = null )
_webview ! . androidOnReceivedIcon ! ( this , icon ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnReceivedIcon ( icon ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
case " onReceivedTouchIconUrl " :
String url = call . arguments [ " url " ] ;
bool precomposed = call . arguments [ " precomposed " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnReceivedTouchIconUrl ! = null )
_webview ! . androidOnReceivedTouchIconUrl ! ( this , url , precomposed ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnReceivedTouchIconUrl ( url , precomposed ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onJsAlert " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
String ? message = call . arguments [ " message " ] ;
bool ? iosIsMainFrame = call . arguments [ " iosIsMainFrame " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
JsAlertRequest jsAlertRequest = JsAlertRequest (
2020-06-29 14:37:36 +00:00
url: url , message: message , iosIsMainFrame: iosIsMainFrame ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onJsAlert ! = null )
return ( await _webview ! . onJsAlert ! ( this , jsAlertRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . onJsAlert ( jsAlertRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onJsConfirm " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
String ? message = call . arguments [ " message " ] ;
bool ? iosIsMainFrame = call . arguments [ " iosIsMainFrame " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
JsConfirmRequest jsConfirmRequest = JsConfirmRequest (
2020-06-29 14:37:36 +00:00
url: url , message: message , iosIsMainFrame: iosIsMainFrame ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onJsConfirm ! = null )
return ( await _webview ! . onJsConfirm ! ( this , jsConfirmRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . onJsConfirm ( jsConfirmRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
break ;
case " onJsPrompt " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
String ? message = call . arguments [ " message " ] ;
String ? defaultValue = call . arguments [ " defaultValue " ] ;
bool ? iosIsMainFrame = call . arguments [ " iosIsMainFrame " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
JsPromptRequest jsPromptRequest = JsPromptRequest (
url: url ,
message: message ,
defaultValue: defaultValue ,
2020-06-29 14:37:36 +00:00
iosIsMainFrame: iosIsMainFrame ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onJsPrompt ! = null )
return ( await _webview ! . onJsPrompt ! ( this , jsPromptRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . onJsPrompt ( jsPromptRequest ) ) ? . toMap ( ) ;
2020-05-11 00:48:41 +00:00
break ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
case " onJsBeforeUnload " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
String ? message = call . arguments [ " message " ] ;
bool ? iosIsMainFrame = call . arguments [ " iosIsMainFrame " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
JsBeforeUnloadRequest jsBeforeUnloadRequest = JsBeforeUnloadRequest (
2020-06-29 14:37:36 +00:00
url: url , message: message , iosIsMainFrame: iosIsMainFrame ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
print ( jsBeforeUnloadRequest ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnJsBeforeUnload ! = null )
return ( await _webview ! . androidOnJsBeforeUnload ! (
2020-06-29 14:37:36 +00:00
this , jsBeforeUnloadRequest ) )
? . toMap ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser !
2020-06-29 14:37:36 +00:00
. androidOnJsBeforeUnload ( jsBeforeUnloadRequest ) )
? . toMap ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onSafeBrowsingHit " :
String url = call . arguments [ " url " ] ;
2021-01-28 16:10:15 +00:00
SafeBrowsingThreat ? threatType =
2020-05-28 23:03:45 +00:00
SafeBrowsingThreat . fromValue ( call . arguments [ " threatType " ] ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnSafeBrowsingHit ! = null )
return ( await _webview ! . androidOnSafeBrowsingHit ! (
2020-05-28 23:03:45 +00:00
this , url , threatType ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidOnSafeBrowsingHit ( url , threatType ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
case " onReceivedLoginRequest " :
String realm = call . arguments [ " realm " ] ;
2021-01-28 16:10:15 +00:00
String ? account = call . arguments [ " account " ] ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
String args = call . arguments [ " args " ] ;
2020-06-29 14:37:36 +00:00
LoginRequest loginRequest =
LoginRequest ( realm: realm , account: account , args: args ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnReceivedLoginRequest ! = null )
_webview ! . androidOnReceivedLoginRequest ! ( this , loginRequest ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . androidOnReceivedLoginRequest ( loginRequest ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onReceivedHttpAuthRequest " :
String host = call . arguments [ " host " ] ;
String protocol = call . arguments [ " protocol " ] ;
2021-01-28 16:10:15 +00:00
String ? realm = call . arguments [ " realm " ] ;
int ? port = call . arguments [ " port " ] ;
2020-05-11 00:48:41 +00:00
int previousFailureCount = call . arguments [ " previousFailureCount " ] ;
var protectionSpace = ProtectionSpace (
host: host , protocol: protocol , realm: realm , port: port ) ;
var challenge = HttpAuthChallenge (
previousFailureCount: previousFailureCount ,
protectionSpace: protectionSpace ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onReceivedHttpAuthRequest ! = null )
return ( await _webview ! . onReceivedHttpAuthRequest ! ( this , challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . onReceivedHttpAuthRequest ( challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onReceivedServerTrustAuthRequest " :
String host = call . arguments [ " host " ] ;
String protocol = call . arguments [ " protocol " ] ;
2021-01-28 16:10:15 +00:00
String ? realm = call . arguments [ " realm " ] ;
int ? port = call . arguments [ " port " ] ;
int ? androidError = call . arguments [ " androidError " ] ;
int ? iosError = call . arguments [ " iosError " ] ;
String ? message = call . arguments [ " message " ] ;
Map < String , dynamic > ? sslCertificateMap =
2020-06-21 22:09:35 +00:00
call . arguments [ " sslCertificate " ] ? . cast < String , dynamic > ( ) ;
2020-06-15 00:08:23 +00:00
2021-01-28 16:10:15 +00:00
SslCertificate ? sslCertificate ;
2020-06-15 00:08:23 +00:00
if ( sslCertificateMap ! = null ) {
2020-09-07 08:32:24 +00:00
if ( defaultTargetPlatform = = TargetPlatform . iOS ) {
2020-06-15 00:08:23 +00:00
try {
2020-06-21 22:09:35 +00:00
X509Certificate x509certificate = X509Certificate . fromData (
data: sslCertificateMap [ " x509Certificate " ] ) ;
2020-06-15 00:08:23 +00:00
sslCertificate = SslCertificate (
issuedBy: SslCertificateDName (
2020-06-21 22:09:35 +00:00
CName: x509certificate . issuer (
dn: ASN1DistinguishedNames . COMMON_NAME ) ? ?
" " ,
2020-06-15 00:08:23 +00:00
DName: x509certificate . issuerDistinguishedName ? ? " " ,
2020-06-21 22:09:35 +00:00
OName: x509certificate . issuer (
dn: ASN1DistinguishedNames . ORGANIZATION_NAME ) ? ?
" " ,
UName: x509certificate . issuer (
dn: ASN1DistinguishedNames
. ORGANIZATIONAL_UNIT_NAME ) ? ?
" " ) ,
2020-06-15 00:08:23 +00:00
issuedTo: SslCertificateDName (
2020-06-21 22:09:35 +00:00
CName: x509certificate . subject (
dn: ASN1DistinguishedNames . COMMON_NAME ) ? ?
" " ,
2020-06-15 00:08:23 +00:00
DName: x509certificate . subjectDistinguishedName ? ? " " ,
2020-06-21 22:09:35 +00:00
OName: x509certificate . subject (
dn: ASN1DistinguishedNames . ORGANIZATION_NAME ) ? ?
" " ,
UName: x509certificate . subject (
dn: ASN1DistinguishedNames
. ORGANIZATIONAL_UNIT_NAME ) ? ?
" " ) ,
2020-06-15 00:08:23 +00:00
validNotAfterDate: x509certificate . notAfter ,
validNotBeforeDate: x509certificate . notBefore ,
x509Certificate: x509certificate ,
) ;
2020-06-21 22:09:35 +00:00
} catch ( e , stacktrace ) {
2020-06-15 00:08:23 +00:00
print ( e ) ;
print ( stacktrace ) ;
return null ;
}
} else {
sslCertificate = SslCertificate . fromMap ( sslCertificateMap ) ;
}
}
2020-06-13 01:50:19 +00:00
2021-01-28 16:10:15 +00:00
AndroidSslError ? androidSslError = androidError ! = null
2020-06-21 22:09:35 +00:00
? AndroidSslError . fromValue ( androidError )
: null ;
2021-01-28 16:10:15 +00:00
IOSSslError ? iosSslError =
2020-06-21 22:09:35 +00:00
iosError ! = null ? IOSSslError . fromValue ( iosError ) : null ;
2020-06-13 01:50:19 +00:00
2020-05-11 00:48:41 +00:00
var protectionSpace = ProtectionSpace (
host: host , protocol: protocol , realm: realm , port: port ) ;
var challenge = ServerTrustChallenge (
protectionSpace: protectionSpace ,
2020-06-13 01:50:19 +00:00
androidError: androidSslError ,
iosError: iosSslError ,
2020-05-11 00:48:41 +00:00
message: message ,
2020-06-15 00:08:23 +00:00
sslCertificate: sslCertificate ) ;
2020-05-28 23:03:45 +00:00
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . onReceivedServerTrustAuthRequest ! = null )
return ( await _webview ! . onReceivedServerTrustAuthRequest ! (
2020-05-28 23:03:45 +00:00
this , challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser !
2020-05-28 23:03:45 +00:00
. onReceivedServerTrustAuthRequest ( challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onReceivedClientCertRequest " :
String host = call . arguments [ " host " ] ;
String protocol = call . arguments [ " protocol " ] ;
2021-01-28 16:10:15 +00:00
String ? realm = call . arguments [ " realm " ] ;
int ? port = call . arguments [ " port " ] ;
2020-05-11 00:48:41 +00:00
var protectionSpace = ProtectionSpace (
host: host , protocol: protocol , realm: realm , port: port ) ;
var challenge = ClientCertChallenge ( protectionSpace: protectionSpace ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onReceivedClientCertRequest ! = null )
return ( await _webview ! . onReceivedClientCertRequest ! ( this , challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . onReceivedClientCertRequest ( challenge ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onFindResultReceived " :
int activeMatchOrdinal = call . arguments [ " activeMatchOrdinal " ] ;
int numberOfMatches = call . arguments [ " numberOfMatches " ] ;
bool isDoneCounting = call . arguments [ " isDoneCounting " ] ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onFindResultReceived ! = null )
_webview ! . onFindResultReceived ! (
2020-05-11 00:48:41 +00:00
this , activeMatchOrdinal , numberOfMatches , isDoneCounting ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onFindResultReceived (
2020-05-11 00:48:41 +00:00
activeMatchOrdinal , numberOfMatches , isDoneCounting ) ;
break ;
case " onPermissionRequest " :
String origin = call . arguments [ " origin " ] ;
List < String > resources = call . arguments [ " resources " ] . cast < String > ( ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . androidOnPermissionRequest ! = null )
return ( await _webview ! . androidOnPermissionRequest ! (
2020-05-28 23:03:45 +00:00
this , origin , resources ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return ( await _inAppBrowser ! . androidOnPermissionRequest (
2020-05-28 23:03:45 +00:00
origin , resources ) )
2020-05-11 00:48:41 +00:00
? . toMap ( ) ;
break ;
case " onUpdateVisitedHistory " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
bool ? androidIsReload = call . arguments [ " androidIsReload " ] ;
if ( _webview ! = null & & _webview ! . onUpdateVisitedHistory ! = null )
_webview ! . onUpdateVisitedHistory ! ( this , url , androidIsReload ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onUpdateVisitedHistory ( url , androidIsReload ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " onWebContentProcessDidTerminate " :
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . iosOnWebContentProcessDidTerminate ! = null )
_webview ! . iosOnWebContentProcessDidTerminate ! ( this ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . iosOnWebContentProcessDidTerminate ( ) ;
2020-05-21 01:34:39 +00:00
break ;
2020-05-28 23:03:45 +00:00
case " onPageCommitVisible " :
2021-01-28 16:10:15 +00:00
String ? url = call . arguments [ " url " ] ;
if ( _webview ! = null & & _webview ! . onPageCommitVisible ! = null )
_webview ! . onPageCommitVisible ! ( this , url ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onPageCommitVisible ( url ) ;
2020-05-21 01:34:39 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onDidReceiveServerRedirectForProvisionalNavigation " :
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . iosOnDidReceiveServerRedirectForProvisionalNavigation ! =
2020-05-11 00:48:41 +00:00
null )
2021-01-28 16:10:15 +00:00
_webview ! . iosOnDidReceiveServerRedirectForProvisionalNavigation ! ( this ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . iosOnDidReceiveServerRedirectForProvisionalNavigation ( ) ;
2020-05-21 01:34:39 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onLongPressHitTestResult " :
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? hitTestResultMap =
2020-05-28 23:03:45 +00:00
call . arguments [ " hitTestResult " ] ;
2021-01-28 16:10:15 +00:00
InAppWebViewHitTestResultType ? type =
2020-05-28 23:03:45 +00:00
InAppWebViewHitTestResultType . fromValue (
2021-01-28 16:10:15 +00:00
hitTestResultMap ? [ " type " ] . toInt ( ) ) ;
String ? extra = hitTestResultMap ? [ " extra " ] ;
2020-05-28 23:03:45 +00:00
InAppWebViewHitTestResult hitTestResult =
InAppWebViewHitTestResult ( type: type , extra: extra ) ;
2020-05-11 00:48:41 +00:00
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onLongPressHitTestResult ! = null )
_webview ! . onLongPressHitTestResult ! ( this , hitTestResult ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onLongPressHitTestResult ( hitTestResult ) ;
2020-05-11 00:48:41 +00:00
break ;
2020-05-21 01:34:39 +00:00
case " onCreateContextMenu " :
2021-01-28 16:10:15 +00:00
ContextMenu ? contextMenu ;
if ( _webview ! = null & & _webview ! . contextMenu ! = null ) {
contextMenu = _webview ! . contextMenu ;
} else if ( _inAppBrowser ! = null & & _inAppBrowser ! . contextMenu ! = null ) {
contextMenu = _inAppBrowser ! . contextMenu ;
2020-05-21 01:34:39 +00:00
}
if ( contextMenu ! = null & & contextMenu . onCreateContextMenu ! = null ) {
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? hitTestResultMap =
2020-05-28 23:03:45 +00:00
call . arguments [ " hitTestResult " ] ;
2021-01-28 16:10:15 +00:00
InAppWebViewHitTestResultType ? type =
2020-05-28 23:03:45 +00:00
InAppWebViewHitTestResultType . fromValue (
2021-01-28 16:10:15 +00:00
hitTestResultMap ? [ " type " ] . toInt ( ) ) ;
String ? extra = hitTestResultMap ? [ " extra " ] ;
2020-05-28 23:03:45 +00:00
InAppWebViewHitTestResult hitTestResult =
InAppWebViewHitTestResult ( type: type , extra: extra ) ;
2020-05-21 01:34:39 +00:00
2021-01-28 16:10:15 +00:00
contextMenu . onCreateContextMenu ! ( hitTestResult ) ;
2020-05-21 01:34:39 +00:00
}
break ;
case " onHideContextMenu " :
2021-01-28 16:10:15 +00:00
ContextMenu ? contextMenu ;
if ( _webview ! = null & & _webview ! . contextMenu ! = null ) {
contextMenu = _webview ! . contextMenu ;
} else if ( _inAppBrowser ! = null & & _inAppBrowser ! . contextMenu ! = null ) {
contextMenu = _inAppBrowser ! . contextMenu ;
2020-05-21 01:34:39 +00:00
}
if ( contextMenu ! = null & & contextMenu . onHideContextMenu ! = null ) {
2021-01-28 16:10:15 +00:00
contextMenu . onHideContextMenu ! ( ) ;
2020-05-21 01:34:39 +00:00
}
break ;
case " onContextMenuActionItemClicked " :
2021-01-28 16:10:15 +00:00
ContextMenu ? contextMenu ;
if ( _webview ! = null & & _webview ! . contextMenu ! = null ) {
contextMenu = _webview ! . contextMenu ;
} else if ( _inAppBrowser ! = null & & _inAppBrowser ! . contextMenu ! = null ) {
contextMenu = _inAppBrowser ! . contextMenu ;
2020-05-21 01:34:39 +00:00
}
if ( contextMenu ! = null ) {
2021-01-28 16:10:15 +00:00
int ? androidId = call . arguments [ " androidId " ] ;
String ? iosId = call . arguments [ " iosId " ] ;
2020-05-21 01:34:39 +00:00
String title = call . arguments [ " title " ] ;
2020-05-28 23:03:45 +00:00
ContextMenuItem menuItemClicked = ContextMenuItem (
androidId: androidId , iosId: iosId , title: title , action: null ) ;
2020-05-21 01:34:39 +00:00
for ( var menuItem in contextMenu . menuItems ) {
2020-09-07 08:32:24 +00:00
if ( ( defaultTargetPlatform = = TargetPlatform . android & & menuItem . androidId = = androidId ) | |
( defaultTargetPlatform = = TargetPlatform . iOS & & menuItem . iosId = = iosId ) ) {
2020-05-21 01:34:39 +00:00
menuItemClicked = menuItem ;
2021-01-28 16:10:15 +00:00
if ( menuItem . action ! = null ) {
menuItem . action ! ( ) ;
}
2020-05-21 01:34:39 +00:00
break ;
}
}
if ( contextMenu . onContextMenuActionItemClicked ! = null ) {
2021-01-28 16:10:15 +00:00
contextMenu . onContextMenuActionItemClicked ! ( menuItemClicked ) ;
2020-05-21 01:34:39 +00:00
}
}
break ;
2020-05-23 17:33:54 +00:00
case " onEnterFullscreen " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onEnterFullscreen ! = null )
_webview ! . onEnterFullscreen ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onEnterFullscreen ( ) ;
2020-05-23 17:33:54 +00:00
break ;
case " onExitFullscreen " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onExitFullscreen ! = null )
_webview ! . onExitFullscreen ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onExitFullscreen ( ) ;
2020-05-23 17:33:54 +00:00
break ;
2020-05-11 00:48:41 +00:00
case " onCallJsHandler " :
String handlerName = call . arguments [ " handlerName " ] ;
// decode args to json
List < dynamic > args = jsonDecode ( call . arguments [ " args " ] ) ;
switch ( handlerName ) {
case " onLoadResource " :
Map < dynamic , dynamic > argMap = args [ 0 ] ;
2021-01-28 16:10:15 +00:00
String ? initiatorType = argMap [ " initiatorType " ] ;
String ? url = argMap [ " name " ] ;
double ? startTime = argMap [ " startTime " ] is int
2020-05-11 00:48:41 +00:00
? argMap [ " startTime " ] . toDouble ( )
: argMap [ " startTime " ] ;
2021-01-28 16:10:15 +00:00
double ? duration = argMap [ " duration " ] is int
2020-05-11 00:48:41 +00:00
? argMap [ " duration " ] . toDouble ( )
: argMap [ " duration " ] ;
var response = new LoadedResource (
initiatorType: initiatorType ,
url: url ,
startTime: startTime ,
duration: duration ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onLoadResource ! = null )
_webview ! . onLoadResource ! ( this , response ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
_inAppBrowser ! . onLoadResource ( response ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " shouldInterceptAjaxRequest " :
Map < dynamic , dynamic > argMap = args [ 0 ] ;
dynamic data = argMap [ " data " ] ;
2021-01-28 16:10:15 +00:00
String ? method = argMap [ " method " ] ;
String ? url = argMap [ " url " ] ;
bool ? isAsync = argMap [ " isAsync " ] ;
String ? user = argMap [ " user " ] ;
String ? password = argMap [ " password " ] ;
bool ? withCredentials = argMap [ " withCredentials " ] ;
AjaxRequestHeaders headers = AjaxRequestHeaders ( argMap [ " headers " ] ? ? { } ) ;
String ? responseType = argMap [ " responseType " ] ;
2020-05-11 00:48:41 +00:00
var request = new AjaxRequest (
data: data ,
method: method ,
url: url ,
isAsync: isAsync ,
user: user ,
password: password ,
withCredentials: withCredentials ,
headers: headers ,
responseType: responseType ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . shouldInterceptAjaxRequest ! = null )
2020-05-11 00:48:41 +00:00
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _webview ! . shouldInterceptAjaxRequest ! ( this , request ) ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _inAppBrowser ! . shouldInterceptAjaxRequest ( request ) ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " onAjaxReadyStateChange " :
Map < dynamic , dynamic > argMap = args [ 0 ] ;
dynamic data = argMap [ " data " ] ;
2021-01-28 16:10:15 +00:00
String ? method = argMap [ " method " ] ;
String ? url = argMap [ " url " ] ;
bool ? isAsync = argMap [ " isAsync " ] ;
String ? user = argMap [ " user " ] ;
String ? password = argMap [ " password " ] ;
bool ? withCredentials = argMap [ " withCredentials " ] ;
AjaxRequestHeaders headers = AjaxRequestHeaders ( argMap [ " headers " ] ? ? { } ) ;
int ? readyState = argMap [ " readyState " ] ;
int ? status = argMap [ " status " ] ;
String ? responseURL = argMap [ " responseURL " ] ;
String ? responseType = argMap [ " responseType " ] ;
2020-05-11 00:48:41 +00:00
dynamic response = argMap [ " response " ] ;
2021-01-28 16:10:15 +00:00
String ? responseText = argMap [ " responseText " ] ;
String ? responseXML = argMap [ " responseXML " ] ;
String ? statusText = argMap [ " statusText " ] ;
Map < dynamic , dynamic > ? responseHeaders = argMap [ " responseHeaders " ] ;
2020-05-11 00:48:41 +00:00
var request = new AjaxRequest (
data: data ,
method: method ,
url: url ,
isAsync: isAsync ,
user: user ,
password: password ,
withCredentials: withCredentials ,
headers: headers ,
readyState: AjaxRequestReadyState . fromValue ( readyState ) ,
status: status ,
responseURL: responseURL ,
responseType: responseType ,
response: response ,
responseText: responseText ,
responseXML: responseXML ,
statusText: statusText ,
responseHeaders: responseHeaders ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onAjaxReadyStateChange ! = null )
2020-05-11 00:48:41 +00:00
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _webview ! . onAjaxReadyStateChange ! ( this , request ) ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _inAppBrowser ! . onAjaxReadyStateChange ( request ) ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " onAjaxProgress " :
Map < dynamic , dynamic > argMap = args [ 0 ] ;
dynamic data = argMap [ " data " ] ;
2021-01-28 16:10:15 +00:00
String ? method = argMap [ " method " ] ;
String ? url = argMap [ " url " ] ;
bool ? isAsync = argMap [ " isAsync " ] ;
String ? user = argMap [ " user " ] ;
String ? password = argMap [ " password " ] ;
bool ? withCredentials = argMap [ " withCredentials " ] ;
AjaxRequestHeaders headers = AjaxRequestHeaders ( argMap [ " headers " ] ? ? { } ) ;
int ? readyState = argMap [ " readyState " ] ;
int ? status = argMap [ " status " ] ;
String ? responseURL = argMap [ " responseURL " ] ;
String ? responseType = argMap [ " responseType " ] ;
2020-05-11 00:48:41 +00:00
dynamic response = argMap [ " response " ] ;
2021-01-28 16:10:15 +00:00
String ? responseText = argMap [ " responseText " ] ;
String ? responseXML = argMap [ " responseXML " ] ;
String ? statusText = argMap [ " statusText " ] ;
Map < dynamic , dynamic > ? responseHeaders = argMap [ " responseHeaders " ] ;
Map < dynamic , dynamic > ? eventMap = argMap [ " event " ] ;
2020-05-11 00:48:41 +00:00
AjaxRequestEvent event = AjaxRequestEvent (
2021-01-28 16:10:15 +00:00
lengthComputable: eventMap ? [ " lengthComputable " ] ,
loaded: eventMap ? [ " loaded " ] ,
total: eventMap ? [ " total " ] ,
type: AjaxRequestEventType . fromValue ( eventMap ? [ " type " ] ) ) ;
2020-05-11 00:48:41 +00:00
var request = new AjaxRequest (
data: data ,
method: method ,
url: url ,
isAsync: isAsync ,
user: user ,
password: password ,
withCredentials: withCredentials ,
headers: headers ,
readyState: AjaxRequestReadyState . fromValue ( readyState ) ,
status: status ,
responseURL: responseURL ,
responseType: responseType ,
response: response ,
responseText: responseText ,
responseXML: responseXML ,
statusText: statusText ,
responseHeaders: responseHeaders ,
event: event ) ;
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onAjaxProgress ! = null )
return jsonEncode ( await _webview ! . onAjaxProgress ! ( this , request ) ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
2021-01-28 16:10:15 +00:00
return jsonEncode ( await _inAppBrowser ! . onAjaxProgress ( request ) ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " shouldInterceptFetchRequest " :
Map < dynamic , dynamic > argMap = args [ 0 ] ;
2021-01-28 16:10:15 +00:00
String ? url = argMap [ " url " ] ;
String ? method = argMap [ " method " ] ;
Map < dynamic , dynamic > ? headers = argMap [ " headers " ] ;
headers = headers ? . cast < String , dynamic > ( ) ;
Uint8List ? body = argMap [ " body " ] ! = null ? Uint8List . fromList ( argMap [ " body " ] . cast < int > ( ) ) : null ;
String ? mode = argMap [ " mode " ] ;
FetchRequestCredential ? credentials =
2020-05-30 21:13:28 +00:00
FetchRequest . fromMap ( argMap [ " credentials " ] ) ;
2021-01-28 16:10:15 +00:00
String ? cache = argMap [ " cache " ] ;
String ? redirect = argMap [ " redirect " ] ;
String ? referrer = argMap [ " referrer " ] ;
String ? referrerPolicy = argMap [ " referrerPolicy " ] ;
String ? integrity = argMap [ " integrity " ] ;
bool ? keepalive = argMap [ " keepalive " ] ;
2020-05-11 00:48:41 +00:00
var request = new FetchRequest (
url: url ,
method: method ,
2021-01-28 16:10:15 +00:00
headers: headers as Map < String , dynamic > ? ,
2020-05-11 00:48:41 +00:00
body: body ,
mode: mode ,
credentials: credentials ,
cache: cache ,
redirect: redirect ,
referrer: referrer ,
referrerPolicy: referrerPolicy ,
integrity: integrity ,
keepalive: keepalive ) ;
2020-05-28 23:03:45 +00:00
if ( _webview ! = null & &
2021-01-28 16:10:15 +00:00
_webview ! . shouldInterceptFetchRequest ! = null )
2020-05-11 00:48:41 +00:00
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _webview ! . shouldInterceptFetchRequest ! ( this , request ) ) ;
2020-05-11 00:48:41 +00:00
else if ( _inAppBrowser ! = null )
return jsonEncode (
2021-01-28 16:10:15 +00:00
await _inAppBrowser ! . shouldInterceptFetchRequest ( request ) ) ;
2020-05-11 00:48:41 +00:00
return null ;
case " onPrint " :
2021-01-28 16:10:15 +00:00
String ? url = args [ 0 ] ;
if ( _webview ! = null & & _webview ! . onPrint ! = null )
_webview ! . onPrint ! ( this , url ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onPrint ( url ) ;
2020-05-11 00:48:41 +00:00
return null ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
case " onWindowFocus " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onWindowFocus ! = null )
_webview ! . onWindowFocus ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onWindowFocus ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
return null ;
case " onWindowBlur " :
2021-01-28 16:10:15 +00:00
if ( _webview ! = null & & _webview ! . onWindowBlur ! = null )
_webview ! . onWindowBlur ! ( this ) ;
else if ( _inAppBrowser ! = null ) _inAppBrowser ! . onWindowBlur ( ) ;
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
return null ;
2020-05-11 00:48:41 +00:00
}
if ( javaScriptHandlersMap . containsKey ( handlerName ) ) {
// convert result to json
try {
2021-01-28 16:10:15 +00:00
return jsonEncode ( await javaScriptHandlersMap [ handlerName ] ! ( args ) ) ;
2020-05-11 00:48:41 +00:00
} catch ( error ) {
print ( error ) ;
return null ;
}
}
break ;
default :
throw UnimplementedError ( " Unimplemented ${ call . method } method " ) ;
}
2021-02-04 20:54:09 +00:00
return null ;
2020-05-11 00:48:41 +00:00
}
///Gets the URL for the current page.
2020-05-29 12:51:26 +00:00
///This is not always the same as the URL passed to [WebView.onLoadStart] because although the load for that URL has begun, the current page may not have changed.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getUrl()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415005-url
2021-01-28 16:10:15 +00:00
Future < String ? > getUrl ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getUrl ' , args ) ;
}
///Gets the title for the current page.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getTitle()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415015-title
2021-01-28 16:10:15 +00:00
Future < String ? > getTitle ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getTitle ' , args ) ;
}
///Gets the progress for the current page. The progress value is between 0 and 100.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getProgress()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415007-estimatedprogress
2021-01-28 16:10:15 +00:00
Future < int ? > getProgress ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getProgress ' , args ) ;
}
///Gets the content html of the page. It first tries to get the content through javascript.
///If this doesn't work, it tries to get the content reading the file:
///- checking if it is an asset (`file:///`) or
///- downloading it using an `HttpClient` through the WebView's current url.
2020-06-12 02:04:41 +00:00
///
///Returns `null` if it was unable to get it.
2021-01-28 16:10:15 +00:00
Future < String ? > getHtml ( ) async {
String ? html ;
2020-06-12 02:04:41 +00:00
2021-01-28 16:10:15 +00:00
InAppWebViewGroupOptions ? options = await getOptions ( ) ;
if ( options ! = null & & options . crossPlatform ! = null & &
options . crossPlatform ! . javaScriptEnabled = = true ) {
2020-05-11 00:48:41 +00:00
html = await evaluateJavascript (
source : " window.document.getElementsByTagName('html')[0].outerHTML; " ) ;
if ( html ! = null & & html . isNotEmpty ) return html ;
}
var webviewUrl = await getUrl ( ) ;
2021-01-28 16:10:15 +00:00
if ( webviewUrl = = null ) {
return html ;
}
2020-05-11 00:48:41 +00:00
if ( webviewUrl . startsWith ( " file:/// " ) ) {
var assetPathSplitted = webviewUrl . split ( " /flutter_assets/ " ) ;
var assetPath = assetPathSplitted [ assetPathSplitted . length - 1 ] ;
2020-06-13 01:50:19 +00:00
try {
var bytes = await rootBundle . load ( assetPath ) ;
html = utf8 . decode ( bytes . buffer . asUint8List ( ) ) ;
} catch ( e ) { }
2020-05-11 00:48:41 +00:00
} else {
HttpClient client = new HttpClient ( ) ;
var url = Uri . parse ( webviewUrl ) ;
try {
var htmlRequest = await client . getUrl ( url ) ;
html =
2021-01-28 16:10:15 +00:00
await ( await htmlRequest . close ( ) ) . transform ( Utf8Decoder ( ) ) . join ( ) ;
2020-05-11 00:48:41 +00:00
} catch ( e ) {
print ( e ) ;
}
}
2021-01-28 16:10:15 +00:00
2020-05-11 00:48:41 +00:00
return html ;
}
///Gets the list of all favicons for the current page.
Future < List < Favicon > > getFavicons ( ) async {
List < Favicon > favicons = [ ] ;
HttpClient client = new HttpClient ( ) ;
var webviewUrl = await getUrl ( ) ;
2021-01-28 16:10:15 +00:00
if ( webviewUrl = = null ) {
return favicons ;
}
2020-05-11 00:48:41 +00:00
var url = ( webviewUrl . startsWith ( " file:/// " ) )
? Uri . file ( webviewUrl )
: Uri . parse ( webviewUrl ) ;
2021-01-28 16:10:15 +00:00
String ? manifestUrl ;
2020-05-11 00:48:41 +00:00
var html = await getHtml ( ) ;
2021-01-28 16:10:15 +00:00
if ( html = = null | | html . isEmpty ) {
2020-05-11 00:48:41 +00:00
return favicons ;
}
var assetPathBase ;
if ( webviewUrl . startsWith ( " file:/// " ) ) {
var assetPathSplitted = webviewUrl . split ( " /flutter_assets/ " ) ;
assetPathBase = assetPathSplitted [ 0 ] + " /flutter_assets/ " ;
}
2021-01-28 16:10:15 +00:00
InAppWebViewGroupOptions ? options = await getOptions ( ) ;
if ( options ! = null & & options . crossPlatform ! = null & &
options . crossPlatform ! . javaScriptEnabled = = true ) {
2020-06-21 22:09:35 +00:00
List < Map < dynamic , dynamic > > links = ( await evaluateJavascript ( source : """
2020-06-19 19:59:43 +00:00
( function ( ) {
var linkNodes = document . head . getElementsByTagName ( " link " ) ;
var links = [ ] ;
for ( var i = 0 ; i < linkNodes . length ; i + + ) {
var linkNode = linkNodes [ i ] ;
if ( linkNode . rel = = = ' manifest ' ) {
links . push (
{
rel: linkNode . rel ,
href: linkNode . href ,
sizes: null
}
) ;
} else if ( linkNode . rel ! = null & & linkNode . rel . indexOf ( ' icon ' ) > = 0 ) {
links . push (
{
rel: linkNode . rel ,
href: linkNode . href ,
sizes: linkNode . sizes ! = null & & linkNode . sizes . value ! = " " ? linkNode . sizes . value : null
}
) ;
}
}
return links ;
} ) ( ) ;
""" ))?.cast<Map<dynamic, dynamic>>() ?? [];
for ( var link in links ) {
if ( link [ " rel " ] = = " manifest " ) {
manifestUrl = link [ " href " ] ;
2021-01-28 16:10:15 +00:00
if ( ! _isUrlAbsolute ( manifestUrl ! ) ) {
2020-06-19 19:59:43 +00:00
if ( manifestUrl . startsWith ( " / " ) ) {
manifestUrl = manifestUrl . substring ( 1 ) ;
}
manifestUrl = ( ( assetPathBase = = null )
2020-06-21 22:09:35 +00:00
? url . scheme + " :// " + url . host + " / "
: assetPathBase ) +
2020-06-19 19:59:43 +00:00
manifestUrl ;
2020-05-11 00:48:41 +00:00
}
2020-06-19 19:59:43 +00:00
continue ;
2020-05-11 00:48:41 +00:00
}
2020-06-19 19:59:43 +00:00
favicons . addAll ( _createFavicons ( url , assetPathBase , link [ " href " ] ,
link [ " rel " ] , link [ " sizes " ] , false ) ) ;
2020-05-11 00:48:41 +00:00
}
}
// try to get /favicon.ico
try {
var faviconUrl = url . scheme + " :// " + url . host + " /favicon.ico " ;
await client . headUrl ( Uri . parse ( faviconUrl ) ) ;
favicons . add ( Favicon ( url: faviconUrl , rel: " shortcut icon " ) ) ;
2020-06-21 23:17:35 +00:00
} catch ( e ) {
2020-05-11 00:48:41 +00:00
print ( " /favicon.ico file not found: " + e . toString ( ) ) ;
2020-06-19 19:59:43 +00:00
// print(stacktrace);
2020-05-11 00:48:41 +00:00
}
// try to get the manifest file
2021-01-28 16:10:15 +00:00
HttpClientRequest ? manifestRequest ;
HttpClientResponse ? manifestResponse ;
2020-05-11 00:48:41 +00:00
bool manifestFound = false ;
if ( manifestUrl = = null ) {
manifestUrl = url . scheme + " :// " + url . host + " /manifest.json " ;
}
try {
manifestRequest = await client . getUrl ( Uri . parse ( manifestUrl ) ) ;
manifestResponse = await manifestRequest . close ( ) ;
manifestFound = manifestResponse . statusCode = = 200 & &
manifestResponse . headers . contentType ? . mimeType = = " application/json " ;
2020-06-21 23:17:35 +00:00
} catch ( e ) {
2020-05-11 00:48:41 +00:00
print ( " Manifest file not found: " + e . toString ( ) ) ;
2020-06-19 19:59:43 +00:00
// print(stacktrace);
2020-05-11 00:48:41 +00:00
}
if ( manifestFound ) {
Map < String , dynamic > manifest =
2021-01-28 16:10:15 +00:00
json . decode ( await manifestResponse ! . transform ( Utf8Decoder ( ) ) . join ( ) ) ;
2020-05-11 00:48:41 +00:00
if ( manifest . containsKey ( " icons " ) ) {
for ( Map < String , dynamic > icon in manifest [ " icons " ] ) {
favicons . addAll ( _createFavicons ( url , assetPathBase , icon [ " src " ] ,
icon [ " rel " ] , icon [ " sizes " ] , true ) ) ;
}
}
}
return favicons ;
}
bool _isUrlAbsolute ( String url ) {
return url . startsWith ( " http:// " ) | | url . startsWith ( " https:// " ) ;
}
2021-01-28 16:10:15 +00:00
List < Favicon > _createFavicons ( Uri url , String ? assetPathBase , String urlIcon ,
String ? rel , String ? sizes , bool isManifest ) {
2020-05-11 00:48:41 +00:00
List < Favicon > favicons = [ ] ;
List < String > urlSplitted = urlIcon . split ( " / " ) ;
if ( ! _isUrlAbsolute ( urlIcon ) ) {
if ( urlIcon . startsWith ( " / " ) ) {
urlIcon = urlIcon . substring ( 1 ) ;
}
urlIcon = ( ( assetPathBase = = null )
2020-05-28 23:03:45 +00:00
? url . scheme + " :// " + url . host + " / "
: assetPathBase ) +
2020-05-11 00:48:41 +00:00
urlIcon ;
}
if ( isManifest ) {
rel = ( sizes ! = null )
? urlSplitted [ urlSplitted . length - 1 ]
2020-05-28 23:03:45 +00:00
. replaceFirst ( " - " + sizes , " " )
. split ( " " ) [ 0 ]
. split ( " . " ) [ 0 ]
2020-05-11 00:48:41 +00:00
: null ;
}
if ( sizes ! = null & & sizes . isNotEmpty & & sizes ! = " any " ) {
List < String > sizesSplitted = sizes . split ( " " ) ;
for ( String size in sizesSplitted ) {
int width = int . parse ( size . split ( " x " ) [ 0 ] ) ;
int height = int . parse ( size . split ( " x " ) [ 1 ] ) ;
favicons
. add ( Favicon ( url: urlIcon , rel: rel , width: width , height: height ) ) ;
}
} else {
favicons . add ( Favicon ( url: urlIcon , rel: rel , width: null , height: null ) ) ;
}
return favicons ;
}
///Loads the given [url] with optional [headers] specified as a map from name to value.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414954-load
2020-05-11 00:48:41 +00:00
Future < void > loadUrl (
2021-01-28 16:10:15 +00:00
{ required String url , Map < String , String > headers = const { } } ) async {
assert ( url . isNotEmpty ) ;
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' url ' , ( ) = > url ) ;
args . putIfAbsent ( ' headers ' , ( ) = > headers ) ;
await _channel . invokeMethod ( ' loadUrl ' , args ) ;
}
///Loads the given [url] with [postData] using `POST` method into this WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#postUrl(java.lang.String,%20byte[])
2020-05-11 00:48:41 +00:00
Future < void > postUrl (
2021-01-28 16:10:15 +00:00
{ required String url , required Uint8List postData } ) async {
assert ( url . isNotEmpty ) ;
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' url ' , ( ) = > url ) ;
args . putIfAbsent ( ' postData ' , ( ) = > postData ) ;
await _channel . invokeMethod ( ' postUrl ' , args ) ;
}
///Loads the given [data] into this WebView, using [baseUrl] as the base URL for the content.
///
///The [mimeType] parameter specifies the format of the data. The default value is `"text/html"`.
///
///The [encoding] parameter specifies the encoding of the data. The default value is `"utf8"`.
///
///The [androidHistoryUrl] parameter is the URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**:
///- https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring
///- https://developer.apple.com/documentation/webkit/wkwebview/1415011-load
2020-05-11 00:48:41 +00:00
Future < void > loadData (
2021-01-28 16:10:15 +00:00
{ required String data ,
2020-05-28 23:03:45 +00:00
String mimeType = " text/html " ,
String encoding = " utf8 " ,
String baseUrl = " about:blank " ,
String androidHistoryUrl = " about:blank " } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' data ' , ( ) = > data ) ;
args . putIfAbsent ( ' mimeType ' , ( ) = > mimeType ) ;
args . putIfAbsent ( ' encoding ' , ( ) = > encoding ) ;
args . putIfAbsent ( ' baseUrl ' , ( ) = > baseUrl ) ;
args . putIfAbsent ( ' historyUrl ' , ( ) = > androidHistoryUrl ) ;
await _channel . invokeMethod ( ' loadData ' , args ) ;
}
///Loads the given [assetFilePath] with optional [headers] specified as a map from name to value.
///
///To be able to load your local files (assets, js, css, etc.), you need to add them in the `assets` section of the `pubspec.yaml` file, otherwise they cannot be found!
///
///Example of a `pubspec.yaml` file:
///```yaml
///...
///
///# The following section is specific to Flutter.
///flutter:
///
/// # The following line ensures that the Material Icons font is
/// # included with your application, so that you can use the icons in
/// # the material Icons class.
/// uses-material-design: true
///
/// assets:
/// - assets/index.html
/// - assets/css/
/// - assets/images/
///
///...
///```
///Example of a `main.dart` file:
///```dart
///...
///inAppBrowser.loadFile("assets/index.html");
///...
///```
Future < void > loadFile (
2021-01-28 16:10:15 +00:00
{ required String assetFilePath ,
2020-05-28 23:03:45 +00:00
Map < String , String > headers = const { } } ) async {
2021-01-28 16:10:15 +00:00
assert ( assetFilePath . isNotEmpty ) ;
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' url ' , ( ) = > assetFilePath ) ;
args . putIfAbsent ( ' headers ' , ( ) = > headers ) ;
await _channel . invokeMethod ( ' loadFile ' , args ) ;
}
///Reloads the WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#reload()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414969-reload
2020-05-11 00:48:41 +00:00
Future < void > reload ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' reload ' , args ) ;
}
///Goes back in the history of the WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goBack()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414952-goback
2020-05-11 00:48:41 +00:00
Future < void > goBack ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' goBack ' , args ) ;
}
///Returns a boolean value indicating whether the WebView can move backward.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoBack()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback
2020-05-11 00:48:41 +00:00
Future < bool > canGoBack ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' canGoBack ' , args ) ;
}
///Goes forward in the history of the WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goForward()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414993-goforward
2020-05-11 00:48:41 +00:00
Future < void > goForward ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' goForward ' , args ) ;
}
///Returns a boolean value indicating whether the WebView can move forward.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoForward()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward
2020-05-11 00:48:41 +00:00
Future < bool > canGoForward ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' canGoForward ' , args ) ;
}
///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goBackOrForward(int)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414991-go
2021-01-28 16:10:15 +00:00
Future < void > goBackOrForward ( { required int steps } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' steps ' , ( ) = > steps ) ;
await _channel . invokeMethod ( ' goBackOrForward ' , args ) ;
}
///Returns a boolean value indicating whether the WebView can go back or forward the given number of steps. Steps is negative if backward and positive if forward.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoBackOrForward(int)
2021-01-28 16:10:15 +00:00
Future < bool > canGoBackOrForward ( { required int steps } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' steps ' , ( ) = > steps ) ;
return await _channel . invokeMethod ( ' canGoBackOrForward ' , args ) ;
}
///Navigates to a [WebHistoryItem] from the back-forward [WebHistory.list] and sets it as the current item.
2021-01-28 16:10:15 +00:00
Future < void > goTo ( { required WebHistoryItem historyItem } ) async {
if ( historyItem . offset ! = null ) {
await goBackOrForward ( steps: historyItem . offset ! ) ;
}
2020-05-11 00:48:41 +00:00
}
///Check if the WebView instance is in a loading state.
Future < bool > isLoading ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' isLoading ' , args ) ;
}
///Stops the WebView from loading.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#stopLoading()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414981-stoploading
2020-05-11 00:48:41 +00:00
Future < void > stopLoading ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' stopLoading ' , args ) ;
}
2021-02-06 01:30:15 +00:00
///Evaluates JavaScript [source] code into the WebView and returns the result of the evaluation.
///
///[contentWorld], on iOS, it represents the namespace in which to evaluate the JavaScript [source] code.
///Instead, on Android, it will run the [source] code into an iframe.
///This parameter doesn’ t apply to changes you make to the underlying web content, such as the document’ s DOM structure.
///Those changes remain visible to all scripts, regardless of which content world you specify.
///For more information about content worlds, see [ContentWorld].
///Available on iOS 14.0+.
2020-05-29 12:51:26 +00:00
///
2020-06-19 19:59:43 +00:00
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
///
2020-05-29 12:51:26 +00:00
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2021-02-06 01:30:15 +00:00
///**Official iOS API**:
///- https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript
///- https://developer.apple.com/documentation/webkit/wkwebview/3656442-evaluatejavascript
Future < dynamic > evaluateJavascript ( { required String source , ContentWorld ? contentWorld } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' source ' , ( ) = > source ) ;
2021-02-06 01:30:15 +00:00
args . putIfAbsent ( ' contentWorld ' , ( ) = > contentWorld ? . name ) ;
2020-05-11 00:48:41 +00:00
var data = await _channel . invokeMethod ( ' evaluateJavascript ' , args ) ;
2020-09-07 08:32:24 +00:00
if ( data ! = null & & defaultTargetPlatform = = TargetPlatform . android ) data = json . decode ( data ) ;
2020-05-11 00:48:41 +00:00
return data ;
}
///Injects an external JavaScript file into the WebView from a defined url.
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
2021-01-28 16:10:15 +00:00
Future < void > injectJavascriptFileFromUrl ( { required String urlFile } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' urlFile ' , ( ) = > urlFile ) ;
await _channel . invokeMethod ( ' injectJavascriptFileFromUrl ' , args ) ;
}
///Injects a JavaScript file into the WebView from the flutter assets directory.
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
2020-05-11 00:48:41 +00:00
Future < void > injectJavascriptFileFromAsset (
2021-01-28 16:10:15 +00:00
{ required String assetFilePath } ) async {
2020-05-11 00:48:41 +00:00
String source = await rootBundle . loadString ( assetFilePath ) ;
await evaluateJavascript ( source : source ) ;
}
///Injects CSS into the WebView.
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
2021-01-28 16:10:15 +00:00
Future < void > injectCSSCode ( { required String source } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' source ' , ( ) = > source ) ;
await _channel . invokeMethod ( ' injectCSSCode ' , args ) ;
}
///Injects an external CSS file into the WebView from a defined url.
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
2021-01-28 16:10:15 +00:00
Future < void > injectCSSFileFromUrl ( { required String urlFile } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' urlFile ' , ( ) = > urlFile ) ;
2021-01-18 14:08:26 +00:00
await _channel . invokeMethod ( ' injectCSSFileFromUrl ' , args ) ;
2020-05-11 00:48:41 +00:00
}
///Injects a CSS file into the WebView from the flutter assets directory.
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method shouldn't be called in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events,
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
2021-01-28 16:10:15 +00:00
Future < void > injectCSSFileFromAsset ( { required String assetFilePath } ) async {
2020-05-11 00:48:41 +00:00
String source = await rootBundle . loadString ( assetFilePath ) ;
await injectCSSCode ( source : source ) ;
}
///Adds a JavaScript message handler [callback] ([JavaScriptHandlerCallback]) that listen to post messages sent from JavaScript by the handler with name [handlerName].
///
///The Android implementation uses [addJavascriptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)).
///The iOS implementation uses [addScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537172-addscriptmessagehandler?language=objc)
///
///The JavaScript function that can be used to call the handler is `window.flutter_inappwebview.callHandler(handlerName <String>, ...args)`, where `args` are [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
///The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
///
///In order to call `window.flutter_inappwebview.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppWebViewPlatformReady`.
///This event will be dispatched as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
///```javascript
/// window.addEventListener("flutterInAppWebViewPlatformReady", function(event) {
/// console.log("ready");
/// });
///```
///
///`window.flutter_inappwebview.callHandler` returns a JavaScript [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
///that can be used to get the json result returned by [JavaScriptHandlerCallback].
///In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library.
///
///So, on the JavaScript side, to get data coming from the Dart side, you will use:
///```html
///<script>
/// window.addEventListener("flutterInAppWebViewPlatformReady", function(event) {
/// window.flutter_inappwebview.callHandler('handlerFoo').then(function(result) {
/// console.log(result);
/// });
///
/// window.flutter_inappwebview.callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}).then(function(result) {
/// console.log(result);
/// });
/// });
///</script>
///```
///
///Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
///```dart
/// // Inject JavaScript that will receive data back from Flutter
/// inAppWebViewController.evaluateJavascript(source: """
/// window.flutter_inappwebview.callHandler('test', 'Text from Javascript').then(function(result) {
/// console.log(result);
/// });
/// """);
///```
///
///Forbidden names for JavaScript handlers are defined in [javaScriptHandlerForbiddenNames].
2020-06-19 19:59:43 +00:00
///
///**NOTE**: This method should be called, for example, in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events or, at least,
///before you know that your JavaScript code will call the `window.flutter_inappwebview.callHandler` method,
///otherwise you won't be able to intercept the JavaScript message.
2020-05-11 00:48:41 +00:00
void addJavaScriptHandler (
2021-01-28 16:10:15 +00:00
{ required String handlerName ,
required JavaScriptHandlerCallback callback } ) {
2020-05-11 00:48:41 +00:00
assert ( ! javaScriptHandlerForbiddenNames . contains ( handlerName ) ) ;
this . javaScriptHandlersMap [ handlerName ] = ( callback ) ;
}
///Removes a JavaScript message handler previously added with the [addJavaScriptHandler()] associated to [handlerName] key.
///Returns the value associated with [handlerName] before it was removed.
///Returns `null` if [handlerName] was not found.
2021-01-28 16:10:15 +00:00
JavaScriptHandlerCallback ? removeJavaScriptHandler (
{ required String handlerName } ) {
2020-05-11 00:48:41 +00:00
return this . javaScriptHandlersMap . remove ( handlerName ) ;
}
2021-02-08 00:17:12 +00:00
///Takes a screenshot (in PNG format) of the WebView's visible viewport and returns a [Uint8List]. Returns `null` if it wasn't be able to take it.
///
///[screenshotConfiguration] represents the configuration data to use when generating an image from a web view’ s contents.
2020-05-11 00:48:41 +00:00
///
2021-02-09 00:39:35 +00:00
///**NOTE for iOS**: available on iOS 11.0+.
2020-05-29 12:51:26 +00:00
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/2873260-takesnapshot
2021-02-08 00:17:12 +00:00
Future < Uint8List ? > takeScreenshot ( { ScreenshotConfiguration ? screenshotConfiguration } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-02-08 00:17:12 +00:00
args . putIfAbsent ( ' screenshotConfiguration ' , ( ) = > screenshotConfiguration ? . toMap ( ) ) ;
2020-05-11 00:48:41 +00:00
return await _channel . invokeMethod ( ' takeScreenshot ' , args ) ;
}
///Sets the WebView options with the new [options] and evaluates them.
2021-01-28 16:10:15 +00:00
Future < void > setOptions ( { required InAppWebViewGroupOptions options } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
args . putIfAbsent ( ' options ' , ( ) = > options . toMap ( ) ) ;
2020-05-11 00:48:41 +00:00
await _channel . invokeMethod ( ' setOptions ' , args ) ;
}
2020-06-13 01:50:19 +00:00
///Gets the current WebView options. Returns `null` if it wasn't able to get them.
2021-01-28 16:10:15 +00:00
Future < InAppWebViewGroupOptions ? > getOptions ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? options =
2020-05-28 23:03:45 +00:00
await _channel . invokeMethod ( ' getOptions ' , args ) ;
2020-05-11 00:48:41 +00:00
if ( options ! = null ) {
options = options . cast < String , dynamic > ( ) ;
2021-01-28 16:10:15 +00:00
return InAppWebViewGroupOptions . fromMap ( options as Map < String , dynamic > ) ;
2020-05-11 00:48:41 +00:00
}
2020-06-13 01:50:19 +00:00
return null ;
2020-05-11 00:48:41 +00:00
}
///Gets the WebHistory for this WebView. This contains the back/forward list for use in querying each item in the history stack.
///This contains only a snapshot of the current state.
///Multiple calls to this method may return different objects.
///The object returned from this method will not be updated to reflect any new state.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#copyBackForwardList()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414977-backforwardlist
2021-01-28 16:10:15 +00:00
Future < WebHistory ? > getCopyBackForwardList ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? result =
2020-05-28 23:03:45 +00:00
await _channel . invokeMethod ( ' getCopyBackForwardList ' , args ) ;
2021-01-28 16:10:15 +00:00
if ( result = = null ) {
return null ;
}
2020-05-11 00:48:41 +00:00
result = result . cast < String , dynamic > ( ) ;
List < dynamic > historyListMap = result [ " history " ] ;
historyListMap = historyListMap . cast < LinkedHashMap < dynamic , dynamic > > ( ) ;
int currentIndex = result [ " currentIndex " ] ;
2021-01-28 16:10:15 +00:00
List < WebHistoryItem > historyList = [ ] as List < WebHistoryItem > ;
2020-05-11 00:48:41 +00:00
for ( var i = 0 ; i < historyListMap . length ; i + + ) {
LinkedHashMap < dynamic , dynamic > historyItem = historyListMap [ i ] ;
historyList . add ( WebHistoryItem (
originalUrl: historyItem [ " originalUrl " ] ,
title: historyItem [ " title " ] ,
url: historyItem [ " url " ] ,
index: i ,
offset: i - currentIndex ) ) ;
}
return WebHistory ( list: historyList , currentIndex: currentIndex ) ;
}
///Clears all the webview's cache.
Future < void > clearCache ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' clearCache ' , args ) ;
}
///Finds all instances of find on the page and highlights them. Notifies [onFindResultReceived] listener.
///
///[find] represents the string to find.
///
///**NOTE**: on Android, it finds all instances asynchronously. Successive calls to this will cancel any pending searches.
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#findAllAsync(java.lang.String)
2021-01-28 16:10:15 +00:00
Future < void > findAllAsync ( { required String find } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' find ' , ( ) = > find ) ;
await _channel . invokeMethod ( ' findAllAsync ' , args ) ;
}
///Highlights and scrolls to the next match found by [findAllAsync()]. Notifies [onFindResultReceived] listener.
///
///[forward] represents the direction to search.
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#findNext(boolean)
2021-01-28 16:10:15 +00:00
Future < void > findNext ( { required bool forward } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' forward ' , ( ) = > forward ) ;
await _channel . invokeMethod ( ' findNext ' , args ) ;
}
///Clears the highlighting surrounding text matches created by [findAllAsync()].
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearMatches()
2020-05-11 00:48:41 +00:00
Future < void > clearMatches ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' clearMatches ' , args ) ;
}
///Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerCss()].
Future < String > getTRexRunnerHtml ( ) async {
return await rootBundle
. loadString ( " packages/flutter_inappwebview/t_rex_runner/t-rex.html " ) ;
}
///Gets the css of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerHtml()].
Future < String > getTRexRunnerCss ( ) async {
return await rootBundle
. loadString ( " packages/flutter_inappwebview/t_rex_runner/t-rex.css " ) ;
}
///Scrolls the WebView to the position.
///
///[x] represents the x position to scroll to.
///
///[y] represents the y position to scroll to.
2020-05-29 12:51:26 +00:00
///
2020-06-13 01:50:19 +00:00
///[animated] `true` to animate the scroll transition, `false` to make the scoll transition immediate.
///
2020-05-29 12:51:26 +00:00
///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollTo(int,%20int)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
2020-06-21 22:09:35 +00:00
Future < void > scrollTo (
2021-01-28 16:10:15 +00:00
{ required int x , required int y , bool animated = false } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' x ' , ( ) = > x ) ;
args . putIfAbsent ( ' y ' , ( ) = > y ) ;
2021-01-28 16:10:15 +00:00
args . putIfAbsent ( ' animated ' , ( ) = > animated ) ;
2020-05-11 00:48:41 +00:00
await _channel . invokeMethod ( ' scrollTo ' , args ) ;
}
///Moves the scrolled position of the WebView.
///
///[x] represents the amount of pixels to scroll by horizontally.
///
///[y] represents the amount of pixels to scroll by vertically.
2020-05-29 12:51:26 +00:00
///
2020-06-13 01:50:19 +00:00
///[animated] `true` to animate the scroll transition, `false` to make the scoll transition immediate.
///
2020-05-29 12:51:26 +00:00
///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollBy(int,%20int)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
2020-06-21 22:09:35 +00:00
Future < void > scrollBy (
2021-01-28 16:10:15 +00:00
{ required int x , required int y , bool animated = false } ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' x ' , ( ) = > x ) ;
args . putIfAbsent ( ' y ' , ( ) = > y ) ;
2021-01-28 16:10:15 +00:00
args . putIfAbsent ( ' animated ' , ( ) = > animated ) ;
2020-05-11 00:48:41 +00:00
await _channel . invokeMethod ( ' scrollBy ' , args ) ;
}
///On Android, it pauses all layout, parsing, and JavaScript timers for all WebViews.
///This is a global requests, not restricted to just this WebView. This can be useful if the application has been paused.
///
///On iOS, it is restricted to just this WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#pauseTimers()
2020-05-11 00:48:41 +00:00
Future < void > pauseTimers ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' pauseTimers ' , args ) ;
}
///On Android, it resumes all layout, parsing, and JavaScript timers for all WebViews. This will resume dispatching all timers.
///
///On iOS, it resumes all layout, parsing, and JavaScript timers to just this WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#resumeTimers()
2020-05-11 00:48:41 +00:00
Future < void > resumeTimers ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' resumeTimers ' , args ) ;
}
///Prints the current page.
///
///**NOTE**: available on Android 21+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/print/PrintManager
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiprintinteractioncontroller
2020-05-11 00:48:41 +00:00
Future < void > printCurrentPage ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' printCurrentPage ' , args ) ;
}
///Gets the height of the HTML content.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getContentHeight()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619399-contentsize
2021-01-28 16:10:15 +00:00
Future < int ? > getContentHeight ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getContentHeight ' , args ) ;
}
2020-05-21 01:34:39 +00:00
///Performs a zoom operation in this WebView.
2020-05-11 00:48:41 +00:00
///
2020-06-13 01:50:19 +00:00
///[zoomFactor] represents the zoom factor to apply. On Android, the zoom factor will be clamped to the Webview's zoom limits and, also, this value must be in the range 0.01 (excluded) to 100.0 (included).
2020-05-11 00:48:41 +00:00
///
2021-02-08 00:17:12 +00:00
///[iosAnimated] `true` to animate the transition to the new scale, `false` to make the transition immediate.
///**NOTE**: available only on iOS.
2021-02-07 15:37:01 +00:00
///
2020-05-11 00:48:41 +00:00
///**NOTE**: available on Android 21+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#zoomBy(float)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619412-setzoomscale
2021-02-07 15:37:01 +00:00
Future < void > zoomBy ( { required double zoomFactor , bool iosAnimated = false } ) async {
2020-09-07 08:32:24 +00:00
assert ( defaultTargetPlatform ! = TargetPlatform . android | |
( defaultTargetPlatform = = TargetPlatform . android & & zoomFactor > 0.01 & & zoomFactor < = 100.0 ) ) ;
2020-06-13 01:50:19 +00:00
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' zoomFactor ' , ( ) = > zoomFactor ) ;
2021-02-07 15:37:01 +00:00
args . putIfAbsent ( ' iosAnimated ' , ( ) = > iosAnimated ) ;
2020-05-11 00:48:41 +00:00
return await _channel . invokeMethod ( ' zoomBy ' , args ) ;
}
///Gets the current scale of this WebView.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**:
///- https://developer.android.com/reference/android/util/DisplayMetrics#density
///- https://developer.android.com/reference/android/webkit/WebViewClient#onScaleChanged(android.webkit.WebView,%20float,%20float)
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-29 12:51:26 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619419-zoomscale
2021-01-28 16:10:15 +00:00
Future < double ? > getScale ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getScale ' , args ) ;
}
2020-05-21 01:34:39 +00:00
///Gets the selected text.
///
///**NOTE**: This method is implemented with using JavaScript.
2021-02-08 00:17:12 +00:00
///
///**NOTE for Android**: available only on Android 19+.
2021-01-28 16:10:15 +00:00
Future < String ? > getSelectedText ( ) async {
2020-05-21 01:34:39 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getSelectedText ' , args ) ;
}
///Gets the hit result for hitting an HTML elements.
///
///**NOTE**: On iOS it is implemented using JavaScript.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getHitTestResult()
2021-01-28 16:10:15 +00:00
Future < InAppWebViewHitTestResult ? > getHitTestResult ( ) async {
2020-05-21 01:34:39 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? hitTestResultMap =
2020-05-28 23:03:45 +00:00
await _channel . invokeMethod ( ' getHitTestResult ' , args ) ;
2021-01-28 16:10:15 +00:00
if ( hitTestResultMap = = null ) {
return null ;
}
hitTestResultMap = hitTestResultMap . cast < String , dynamic > ( ) ;
InAppWebViewHitTestResultType ? type =
2020-05-28 23:03:45 +00:00
InAppWebViewHitTestResultType . fromValue (
hitTestResultMap [ " type " ] . toInt ( ) ) ;
2020-05-21 01:34:39 +00:00
String extra = hitTestResultMap [ " extra " ] ;
return InAppWebViewHitTestResult ( type: type , extra: extra ) ;
}
2020-05-30 18:23:33 +00:00
///Clears the current focus. It will clear also, for example, the current text selection.
///
///**Official Android API**: https://developer.android.com/reference/android/view/ViewGroup#clearFocus()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-05-30 18:23:33 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiresponder/1621097-resignfirstresponder
Future < void > clearFocus ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' clearFocus ' , args ) ;
}
///Sets or updates the WebView context menu to be used next time it will appear.
2021-01-28 16:10:15 +00:00
Future < void > setContextMenu ( ContextMenu ? contextMenu ) async {
2020-05-30 18:23:33 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( " contextMenu " , ( ) = > contextMenu ? . toMap ( ) ) ;
await _channel . invokeMethod ( ' setContextMenu ' , args ) ;
_inAppBrowser ? . contextMenu = contextMenu ;
}
2020-06-12 02:04:41 +00:00
///Requests the anchor or image element URL at the last tapped point.
///
///**NOTE**: On iOS it is implemented using JavaScript.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#requestFocusNodeHref(android.os.Message)
2021-01-28 16:10:15 +00:00
Future < RequestFocusNodeHrefResult ? > requestFocusNodeHref ( ) async {
2020-06-12 02:04:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? result =
2020-06-21 22:09:35 +00:00
await _channel . invokeMethod ( ' requestFocusNodeHref ' , args ) ;
return result ! = null
? RequestFocusNodeHrefResult (
url: result [ ' url ' ] ,
title: result [ ' title ' ] ,
src: result [ ' src ' ] ,
)
: null ;
2020-06-12 02:04:41 +00:00
}
///Requests the URL of the image last touched by the user.
///
///**NOTE**: On iOS it is implemented using JavaScript.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#requestImageRef(android.os.Message)
2021-01-28 16:10:15 +00:00
Future < RequestImageRefResult ? > requestImageRef ( ) async {
2020-06-12 02:04:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < dynamic , dynamic > ? result =
2020-06-21 22:09:35 +00:00
await _channel . invokeMethod ( ' requestImageRef ' , args ) ;
return result ! = null
? RequestImageRefResult (
url: result [ ' url ' ] ,
)
: null ;
2020-06-12 02:04:41 +00:00
}
///Returns the list of `<meta>` tags of the current WebView.
///
///**NOTE**: It is implemented using JavaScript.
Future < List < MetaTag > > getMetaTags ( ) async {
List < MetaTag > metaTags = [ ] ;
2021-01-28 16:10:15 +00:00
List < Map < dynamic , dynamic > > ? metaTagList =
2020-06-21 22:09:35 +00:00
( await evaluateJavascript ( source : """
2020-06-12 02:04:41 +00:00
( function ( ) {
var metaTags = [ ] ;
var metaTagNodes = document . head . getElementsByTagName ( ' meta ' ) ;
for ( var i = 0 ; i < metaTagNodes . length ; i + + ) {
var metaTagNode = metaTagNodes [ i ] ;
var otherAttributes = metaTagNode . getAttributeNames ( ) ;
var nameIndex = otherAttributes . indexOf ( " name " ) ;
if ( nameIndex ! = = - 1 ) otherAttributes . splice ( nameIndex , 1 ) ;
var contentIndex = otherAttributes . indexOf ( " content " ) ;
if ( contentIndex ! = = - 1 ) otherAttributes . splice ( contentIndex , 1 ) ;
var attrs = [ ] ;
for ( var j = 0 ; j < otherAttributes . length ; j + + ) {
var otherAttribute = otherAttributes [ j ] ;
attrs . push (
{
name: otherAttribute ,
value: metaTagNode . getAttribute ( otherAttribute )
}
) ;
}
metaTags . push (
{
name: metaTagNode . name ,
content: metaTagNode . content ,
attrs: attrs
}
) ;
}
return metaTags ;
} ) ( ) ;
""" ))?.cast<Map<dynamic, dynamic>>();
if ( metaTagList = = null ) {
return metaTags ;
}
for ( var metaTag in metaTagList ) {
var attrs = < MetaTagAttribute > [ ] ;
for ( var metaTagAttr in metaTag [ " attrs " ] ) {
2020-06-21 22:09:35 +00:00
attrs . add ( MetaTagAttribute (
name: metaTagAttr [ " name " ] , value: metaTagAttr [ " value " ] ) ) ;
2020-06-12 02:04:41 +00:00
}
2020-06-21 22:09:35 +00:00
metaTags . add ( MetaTag (
name: metaTag [ " name " ] , content: metaTag [ " content " ] , attrs: attrs ) ) ;
2020-06-12 02:04:41 +00:00
}
return metaTags ;
}
///Returns an instance of [Color] representing the `content` value of the
///`<meta name="theme-color" content="">` tag of the current WebView, if available, otherwise `null`.
///
///**NOTE**: It is implemented using JavaScript.
2021-01-28 16:10:15 +00:00
Future < Color ? > getMetaThemeColor ( ) async {
2020-06-12 02:04:41 +00:00
var metaTags = await getMetaTags ( ) ;
2021-01-28 16:10:15 +00:00
MetaTag ? metaTagThemeColor ;
2020-06-12 02:04:41 +00:00
for ( var metaTag in metaTags ) {
if ( metaTag . name = = " theme-color " ) {
metaTagThemeColor = metaTag ;
break ;
}
}
if ( metaTagThemeColor = = null ) {
return null ;
}
var colorValue = metaTagThemeColor . content ;
2021-01-28 16:10:15 +00:00
return colorValue ! = null ? Util . convertColorFromStringRepresentation ( colorValue ) : null ;
2020-06-12 02:04:41 +00:00
}
2020-06-13 01:50:19 +00:00
///Returns the scrolled left position of the current WebView.
///
///**Official Android API**: https://developer.android.com/reference/android/view/View#getScrollX()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-06-13 01:50:19 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset
2021-01-28 16:10:15 +00:00
Future < int ? > getScrollX ( ) async {
2020-06-13 01:50:19 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getScrollX ' , args ) ;
}
///Returns the scrolled top position of the current WebView.
///
///**Official Android API**: https://developer.android.com/reference/android/view/View#getScrollY()
Updated onCreateWindow, onJsAlert, onJsConfirm, and onJsPrompt webview events, added onCloseWindow, onTitleChanged, onWindowFocus, and onWindowBlur webview events, added androidOnRequestFocus, androidOnReceivedIcon, androidOnReceivedTouchIconUrl, androidOnJsBeforeUnload, and androidOnReceivedLoginRequest Android-specific webview events, fix #403
2020-06-29 14:34:08 +00:00
///
2020-06-13 01:50:19 +00:00
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset
2021-01-28 16:10:15 +00:00
Future < int ? > getScrollY ( ) async {
2020-06-13 01:50:19 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _channel . invokeMethod ( ' getScrollY ' , args ) ;
}
2020-06-15 00:08:23 +00:00
///Gets the SSL certificate for the main top-level page or null if there is no certificate (the site is not secure).
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getCertificate()
2021-01-28 16:10:15 +00:00
Future < SslCertificate ? > getCertificate ( ) async {
2020-06-15 00:08:23 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < String , dynamic > ? sslCertificateMap =
2020-06-21 22:09:35 +00:00
( await _channel . invokeMethod ( ' getCertificate ' , args ) )
? . cast < String , dynamic > ( ) ;
2020-06-15 00:08:23 +00:00
if ( sslCertificateMap ! = null ) {
2020-09-07 08:32:24 +00:00
if ( defaultTargetPlatform = = TargetPlatform . iOS ) {
2020-06-15 00:08:23 +00:00
try {
2020-06-21 22:09:35 +00:00
X509Certificate x509certificate = X509Certificate . fromData (
data: sslCertificateMap [ " x509Certificate " ] ) ;
2020-06-15 00:08:23 +00:00
return SslCertificate (
issuedBy: SslCertificateDName (
2020-06-21 22:09:35 +00:00
CName: x509certificate . issuer (
dn: ASN1DistinguishedNames . COMMON_NAME ) ? ?
" " ,
2020-06-15 00:08:23 +00:00
DName: x509certificate . issuerDistinguishedName ? ? " " ,
2020-06-21 22:09:35 +00:00
OName: x509certificate . issuer (
dn: ASN1DistinguishedNames . ORGANIZATION_NAME ) ? ?
" " ,
UName: x509certificate . issuer (
dn: ASN1DistinguishedNames . ORGANIZATIONAL_UNIT_NAME ) ? ?
" " ) ,
2020-06-15 00:08:23 +00:00
issuedTo: SslCertificateDName (
2020-06-21 22:09:35 +00:00
CName: x509certificate . subject (
dn: ASN1DistinguishedNames . COMMON_NAME ) ? ?
" " ,
2020-06-15 00:08:23 +00:00
DName: x509certificate . subjectDistinguishedName ? ? " " ,
2020-06-21 22:09:35 +00:00
OName: x509certificate . subject (
dn: ASN1DistinguishedNames . ORGANIZATION_NAME ) ? ?
" " ,
UName: x509certificate . subject (
dn: ASN1DistinguishedNames . ORGANIZATIONAL_UNIT_NAME ) ? ?
" " ) ,
2020-06-15 00:08:23 +00:00
validNotAfterDate: x509certificate . notAfter ,
validNotBeforeDate: x509certificate . notBefore ,
x509Certificate: x509certificate ,
) ;
2020-06-21 22:09:35 +00:00
} catch ( e , stacktrace ) {
2020-06-15 00:08:23 +00:00
print ( e ) ;
print ( stacktrace ) ;
return null ;
}
} else {
return SslCertificate . fromMap ( sslCertificateMap ) ;
}
}
return null ;
}
2021-02-01 14:55:27 +00:00
///Injects the specified [userScript] into the webpage’ s content.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537448-adduserscript
Future < void > addUserScript ( UserScript userScript ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' userScript ' , ( ) = > userScript . toMap ( ) ) ;
if ( ! _userScripts . contains ( userScript ) ) {
_userScripts . add ( userScript ) ;
await _channel . invokeMethod ( ' addUserScript ' , args ) ;
}
}
///Injects the [userScripts] into the webpage’ s content.
Future < void > addUserScripts ( List < UserScript > userScripts ) async {
for ( var i = 0 ; i < userScripts . length ; i + + ) {
await addUserScript ( userScripts [ i ] ) ;
}
}
///Removes the specified [userScript] from the webpage’ s content.
///User scripts already loaded into the webpage's content cannot be removed. This will have effect only on the next page load.
///Returns `true` if [userScript] was in the list, `false` otherwise.
Future < bool > removeUserScript ( UserScript userScript ) async {
var index = _userScripts . indexOf ( userScript ) ;
if ( index = = - 1 ) {
return false ;
}
_userScripts . remove ( userScript ) ;
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' index ' , ( ) = > index ) ;
await _channel . invokeMethod ( ' removeUserScript ' , args ) ;
return true ;
}
///Removes the [userScripts] from the webpage’ s content.
///User scripts already loaded into the webpage's content cannot be removed. This will have effect only on the next page load.
Future < void > removeUserScripts ( List < UserScript > userScripts ) async {
for ( var i = 0 ; i < userScripts . length ; i + + ) {
await removeUserScript ( userScripts [ i ] ) ;
}
}
///Removes all the user scripts from the webpage’ s content.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1536540-removealluserscripts
Future < void > removeAllUserScripts ( ) async {
_userScripts . clear ( ) ;
Map < String , dynamic > args = < String , dynamic > { } ;
await _channel . invokeMethod ( ' removeAllUserScripts ' , args ) ;
}
2021-02-07 15:05:39 +00:00
///Executes the specified string as an asynchronous JavaScript function.
///
///[functionBody] is the JavaScript string to use as the function body.
///This method treats the string as an anonymous JavaScript function body and calls it with the named arguments in the arguments parameter.
///
///[arguments] is a dictionary of the arguments to pass to the function call.
///Each key in the dictionary corresponds to the name of an argument in the [functionBody] string,
///and the value of that key is the value to use during the evaluation of the code.
///Supported value types can be found in the official Flutter docs:
///[Platform channel data types support and codecs](https://flutter.dev/docs/development/platform-integration/platform-channels#codec),
///except for [Uint8List], [Int32List], [Int64List], and [Float64List] that should be converted into a [List].
///All items in an array or dictionary must also be one of the supported types.
///
///[contentWorld], on iOS, it represents the namespace in which to evaluate the JavaScript [source] code.
///Instead, on Android, it will run the [source] code into an iframe.
///This parameter doesn’ t apply to changes you make to the underlying web content, such as the document’ s DOM structure.
///Those changes remain visible to all scripts, regardless of which content world you specify.
///For more information about content worlds, see [ContentWorld].
///Available on iOS 14.0+.
///
///**NOTE for iOS**: available only on iOS 10.3+.
///
///**NOTE for Android**: available only on Android 21+.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/3656441-callasyncjavascript
Future < CallAsyncJavaScriptResult ? > callAsyncJavaScript ( { required String functionBody , Map < String , dynamic > arguments = const < String , dynamic > { } , ContentWorld ? contentWorld } ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' functionBody ' , ( ) = > functionBody ) ;
args . putIfAbsent ( ' arguments ' , ( ) = > arguments ) ;
args . putIfAbsent ( ' contentWorld ' , ( ) = > contentWorld ? . name ) ;
var data = await _channel . invokeMethod ( ' callAsyncJavaScript ' , args ) ;
if ( data = = null ) {
return null ;
}
if ( defaultTargetPlatform = = TargetPlatform . android ) {
data = json . decode ( data ) ;
}
return CallAsyncJavaScriptResult ( value: data [ " value " ] , error: data [ " error " ] ) ;
}
2021-02-09 00:39:35 +00:00
///Saves the current WebView as a web archive.
///Returns the file path under which the web archive file was saved, or `null` if saving the file failed.
///
///[filePath] represents the file path where the archive should be placed. This value cannot be `null`.
///
///[autoname] if `false`, takes [filePath] to be a file.
///If `true`, [filePath] is assumed to be a directory in which a filename will be chosen according to the URL of the current page.
///
///**NOTE for iOS**: Available on iOS 14.0+. If [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.WEBARCHIVE] file extension.
///
///**NOTE for Android**: if [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.MHT] file extension.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#saveWebArchive(java.lang.String,%20boolean,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)
Future < String ? > saveWebArchive (
{ required String filePath , bool autoname = false } ) async {
if ( ! autoname ) {
if ( Platform . isAndroid ) {
assert ( filePath . endsWith ( " . " + WebArchiveFormat . MHT . toValue ( ) ) ) ;
} else if ( Platform . isIOS ) {
assert ( filePath . endsWith ( " . " + WebArchiveFormat . WEBARCHIVE . toValue ( ) ) ) ;
}
}
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( " filePath " , ( ) = > filePath ) ;
args . putIfAbsent ( " autoname " , ( ) = > autoname ) ;
return await _channel . invokeMethod ( ' saveWebArchive ' , args ) ;
}
2020-05-11 00:48:41 +00:00
///Gets the default user agent.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebSettings#getDefaultUserAgent(android.content.Context)
2020-05-11 00:48:41 +00:00
static Future < String > getDefaultUserAgent ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _staticChannel . invokeMethod ( ' getDefaultUserAgent ' , args ) ;
}
}
2021-01-31 21:08:20 +00:00
///Class represents the Android controller that contains only android-specific methods for the WebView.
2020-05-11 00:48:41 +00:00
class AndroidInAppWebViewController {
2021-01-28 16:10:15 +00:00
late InAppWebViewController _controller ;
2020-05-11 00:48:41 +00:00
AndroidInAppWebViewController ( InAppWebViewController controller ) {
this . _controller = controller ;
}
///Starts Safe Browsing initialization.
///
///URL loads are not guaranteed to be protected by Safe Browsing until after the this method returns true.
///Safe Browsing is not fully supported on all devices. For those devices this method will returns false.
///
///This should not be called if Safe Browsing has been disabled by manifest tag
///or [AndroidInAppWebViewOptions.safeBrowsingEnabled]. This prepares resources used for Safe Browsing.
///
///**NOTE**: available only on Android 27+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#startSafeBrowsing(android.content.Context,%20android.webkit.ValueCallback%3Cjava.lang.Boolean%3E)
2020-05-11 00:48:41 +00:00
Future < bool > startSafeBrowsing ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' startSafeBrowsing ' , args ) ;
}
///Clears the SSL preferences table stored in response to proceeding with SSL certificate errors.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearSslPreferences()
2020-05-11 00:48:41 +00:00
Future < void > clearSslPreferences ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _controller . _channel . invokeMethod ( ' clearSslPreferences ' , args ) ;
}
///Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript.
///To pause JavaScript globally, use [pauseTimers()]. To resume WebView, call [resume()].
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#onPause()
2020-05-11 00:48:41 +00:00
Future < void > pause ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _controller . _channel . invokeMethod ( ' pause ' , args ) ;
}
///Resumes a WebView after a previous call to [pause()].
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#onResume()
2020-05-11 00:48:41 +00:00
Future < void > resume ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _controller . _channel . invokeMethod ( ' resume ' , args ) ;
}
///Gets the URL that was originally requested for the current page.
///This is not always the same as the URL passed to [InAppWebView.onLoadStarted] because although the load for that URL has begun,
///the current page may not have changed. Also, there may have been redirects resulting in a different URL to that originally requested.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getOriginalUrl()
2021-01-28 16:10:15 +00:00
Future < String ? > getOriginalUrl ( ) async {
2020-05-11 00:48:41 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' getOriginalUrl ' , args ) ;
}
2020-05-25 22:26:32 +00:00
2020-05-28 23:03:45 +00:00
///Scrolls the contents of this WebView down by half the page size.
///Returns `true` if the page was scrolled.
///
2020-05-29 12:51:26 +00:00
///[bottom] `true` to jump to bottom of page.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#pageDown(boolean)
2021-01-28 16:10:15 +00:00
Future < bool > pageDown ( { required bool bottom } ) async {
2020-05-28 23:03:45 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( " bottom " , ( ) = > bottom ) ;
return await _controller . _channel . invokeMethod ( ' pageDown ' , args ) ;
}
///Scrolls the contents of this WebView up by half the view size.
///Returns `true` if the page was scrolled.
///
2020-05-29 12:51:26 +00:00
///[bottom] `true` to jump to the top of the page.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#pageUp(boolean)
2021-01-28 16:10:15 +00:00
Future < bool > pageUp ( { required bool top } ) async {
2020-05-28 23:03:45 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( " top " , ( ) = > top ) ;
return await _controller . _channel . invokeMethod ( ' pageUp ' , args ) ;
}
///Performs zoom in in this WebView.
///Returns `true` if zoom in succeeds, `false` if no zoom changes.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#zoomIn()
2020-05-28 23:03:45 +00:00
Future < bool > zoomIn ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' zoomIn ' , args ) ;
}
///Performs zoom out in this WebView.
///Returns `true` if zoom out succeeds, `false` if no zoom changes.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#zoomOut()
2020-05-28 23:03:45 +00:00
Future < bool > zoomOut ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' zoomOut ' , args ) ;
}
2020-05-30 18:23:33 +00:00
///Clears the internal back/forward list.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearHistory()
Future < void > clearHistory ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' clearHistory ' , args ) ;
}
2020-05-25 22:26:32 +00:00
///Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests.
///Note that WebView automatically clears these preferences when the system keychain is updated.
///The preferences are shared by all the WebViews that are created by the embedder application.
///
///**NOTE**: On iOS certificate-based credentials are never stored permanently.
///
///**NOTE**: available on Android 21+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearClientCertPreferences(java.lang.Runnable)
2020-05-25 22:26:32 +00:00
static Future < void > clearClientCertPreferences ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
2020-05-28 23:03:45 +00:00
await InAppWebViewController . _staticChannel
. invokeMethod ( ' clearClientCertPreferences ' , args ) ;
2020-05-25 22:26:32 +00:00
}
///Returns a URL pointing to the privacy policy for Safe Browsing reporting. This value will never be `null`.
///
///**NOTE**: available only on Android 27+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewCompat#getSafeBrowsingPrivacyPolicyUrl()
2021-01-28 16:10:15 +00:00
static Future < String ? > getSafeBrowsingPrivacyPolicyUrl ( ) async {
2020-05-25 22:26:32 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
return await InAppWebViewController . _staticChannel
. invokeMethod ( ' getSafeBrowsingPrivacyPolicyUrl ' , args ) ;
}
///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:
///| Rule | Example | Matches Subdomain |
///| -- | -- | -- |
///| HOSTNAME | example.com | Yes |
///| .HOSTNAME | .example.com | No |
///| IPV4_LITERAL | 192.168.1.1 | No |
///| IPV6_LITERAL_WITH_BRACKETS | [10:20:30:40:50:60:70:80] | No |
///
///All other rules, including wildcards, are invalid. The correct syntax for hosts is defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3.2.2).
///
2021-01-28 16:10:15 +00:00
///[hosts] represents the list of hosts. This value must never be `null`.
2020-05-25 22:26:32 +00:00
///
///**NOTE**: available only on Android 27+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewCompat#getSafeBrowsingPrivacyPolicyUrl()
2020-05-28 23:03:45 +00:00
static Future < bool > setSafeBrowsingWhitelist (
2021-01-28 16:10:15 +00:00
{ required List < String > hosts } ) async {
2020-05-25 22:26:32 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' hosts ' , ( ) = > hosts ) ;
return await InAppWebViewController . _staticChannel
. invokeMethod ( ' setSafeBrowsingWhitelist ' , args ) ;
}
2020-05-28 23:03:45 +00:00
///If WebView has already been loaded into the current process this method will return the package that was used to load it.
///Otherwise, the package that would be used if the WebView was loaded right now will be returned;
///this does not cause WebView to be loaded, so this information may become outdated at any time.
///The WebView package changes either when the current WebView package is updated, disabled, or uninstalled.
///It can also be changed through a Developer Setting. If the WebView package changes, any app process that
///has loaded WebView will be killed.
///The next time the app starts and loads WebView it will use the new WebView package instead.
///
///**NOTE**: available only on Android 26+.
2020-05-29 12:51:26 +00:00
///
///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewCompat#getCurrentWebViewPackage(android.content.Context)
2021-01-28 16:10:15 +00:00
static Future < AndroidWebViewPackageInfo ? > getCurrentWebViewPackage ( ) async {
2020-05-28 23:03:45 +00:00
Map < String , dynamic > args = < String , dynamic > { } ;
2021-01-28 16:10:15 +00:00
Map < String , dynamic > ? packageInfo = ( await InAppWebViewController
2020-05-29 17:56:03 +00:00
. _staticChannel
. invokeMethod ( ' getCurrentWebViewPackage ' , args ) )
? . cast < String , dynamic > ( ) ;
2020-05-28 23:03:45 +00:00
return AndroidWebViewPackageInfo . fromMap ( packageInfo ) ;
}
2021-01-28 16:10:15 +00:00
///Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.
///This flag can be enabled in order to facilitate debugging of web layouts and JavaScript code running inside WebViews.
///Please refer to WebView documentation for the debugging guide. The default is `false`.
///
///[debuggingEnabled] whether to enable web contents debugging.
///
///**NOTE**: available only on Android 19+.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setWebContentsDebuggingEnabled(boolean)
static Future < void > setWebContentsDebuggingEnabled ( bool debuggingEnabled ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' debuggingEnabled ' , ( ) = > debuggingEnabled ) ;
return await InAppWebViewController . _staticChannel
. invokeMethod ( ' setWebContentsDebuggingEnabled ' , args ) ;
}
2020-05-11 00:48:41 +00:00
}
2021-01-31 21:08:20 +00:00
///Class represents the iOS controller that contains only iOS-specific methods for the WebView.
2020-05-11 00:48:41 +00:00
class IOSInAppWebViewController {
2021-01-28 16:10:15 +00:00
late InAppWebViewController _controller ;
2020-05-11 00:48:41 +00:00
IOSInAppWebViewController ( InAppWebViewController controller ) {
this . _controller = controller ;
}
///Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.
2020-05-29 12:51:26 +00:00
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414956-reloadfromorigin
2020-05-11 00:48:41 +00:00
Future < void > reloadFromOrigin ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
await _controller . _channel . invokeMethod ( ' reloadFromOrigin ' , args ) ;
}
///A Boolean value indicating whether all resources on the page have been loaded over securely encrypted connections.
2020-05-29 12:51:26 +00:00
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415002-hasonlysecurecontent
2020-05-11 00:48:41 +00:00
Future < bool > hasOnlySecureContent ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel
. invokeMethod ( ' hasOnlySecureContent ' , args ) ;
}
2021-02-04 00:43:55 +00:00
2021-02-08 17:28:35 +00:00
///Generates PDF data from the web view’ s contents asynchronously.
2021-02-09 00:39:35 +00:00
///Returns `null` if a problem occurred.
2021-02-08 17:28:35 +00:00
///
///[iosWKPdfConfiguration] represents the object that specifies the portion of the web view to capture as PDF data.
2021-02-09 00:39:35 +00:00
///
///**NOTE**: available only on iOS 14.0+.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/3650490-createpdf
2021-02-08 17:28:35 +00:00
Future < Uint8List ? > createPdf ( { IOSWKPDFConfiguration ? iosWKPdfConfiguration } ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' iosWKPdfConfiguration ' , ( ) = > iosWKPdfConfiguration ? . toMap ( ) ) ;
return await _controller . _channel . invokeMethod ( ' createPdf ' , args ) ;
}
2021-02-09 00:39:35 +00:00
///Creates a web archive of the web view’ s current contents asynchronously.
///Returns `null` if a problem occurred.
///
///**NOTE**: available only on iOS 14.0+.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/3650491-createwebarchivedata
Future < Uint8List ? > createWebArchiveData ( ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
return await _controller . _channel . invokeMethod ( ' createWebArchiveData ' , args ) ;
}
2021-02-04 00:43:55 +00:00
///Returns a Boolean value that indicates whether WebKit natively supports resources with the specified URL scheme.
///
///[urlScheme] represents the URL scheme associated with the resource.
///
///**NOTE**: available only on iOS 11.0+.
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/2875370-handlesurlscheme
static Future < bool > handlesURLScheme ( String urlScheme ) async {
Map < String , dynamic > args = < String , dynamic > { } ;
args . putIfAbsent ( ' urlScheme ' , ( ) = > urlScheme ) ;
return await InAppWebViewController . _staticChannel
. invokeMethod ( ' handlesURLScheme ' , args ) ;
}
2020-05-11 00:48:41 +00:00
}