added disableDefaultErrorPage Android-specific webview option, updated onCreateWindow event implementation
This commit is contained in:
parent
0c71edf8a6
commit
710be67894
|
@ -3,6 +3,7 @@
|
||||||
- Updated `onCreateWindow`, `onJsAlert`, `onJsConfirm`, `onJsPrompt` webview events
|
- Updated `onCreateWindow`, `onJsAlert`, `onJsConfirm`, `onJsPrompt` webview events
|
||||||
- Added `onCloseWindow`, `onTitleChanged`, `onWindowFocus`, `onWindowBlur` webview events
|
- Added `onCloseWindow`, `onTitleChanged`, `onWindowFocus`, `onWindowBlur` webview events
|
||||||
- Added `androidOnRequestFocus`, `androidOnReceivedIcon`, `androidOnReceivedTouchIconUrl`, `androidOnJsBeforeUnload`, `androidOnReceivedLoginRequest` Android-specific webview events
|
- Added `androidOnRequestFocus`, `androidOnReceivedIcon`, `androidOnReceivedTouchIconUrl`, `androidOnJsBeforeUnload`, `androidOnReceivedLoginRequest` Android-specific webview events
|
||||||
|
- Added `disableDefaultErrorPage` Android-specific webview option
|
||||||
- Fixed "SFSafariViewController doesn't open like a native iOS modal" [#403](https://github.com/pichillilorenzo/flutter_inappwebview/issues/403)
|
- Fixed "SFSafariViewController doesn't open like a native iOS modal" [#403](https://github.com/pichillilorenzo/flutter_inappwebview/issues/403)
|
||||||
|
|
||||||
### BREAKING CHANGES
|
### BREAKING CHANGES
|
||||||
|
|
|
@ -583,6 +583,7 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
|
||||||
* `scrollbarFadingEnabled`: Define whether scrollbars will fade when the view is not scrolling. The default value is `true`.
|
* `scrollbarFadingEnabled`: Define whether scrollbars will fade when the view is not scrolling. The default value is `true`.
|
||||||
* `scrollBarFadeDuration`: Define the scrollbar fade duration in milliseconds.
|
* `scrollBarFadeDuration`: Define the scrollbar fade duration in milliseconds.
|
||||||
* `rendererPriorityPolicy`: Set the renderer priority policy for this WebView.
|
* `rendererPriorityPolicy`: Set the renderer priority policy for this WebView.
|
||||||
|
* `disableDefaultErrorPage`: Sets whether the default Android error page should be disabled. The default value is `false`.
|
||||||
|
|
||||||
##### `InAppWebView` iOS-specific options
|
##### `InAppWebView` iOS-specific options
|
||||||
|
|
||||||
|
|
|
@ -518,9 +518,9 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
channel.setMethodCallHandler(null);
|
channel.setMethodCallHandler(null);
|
||||||
if (webView != null) {
|
if (webView != null) {
|
||||||
if (Shared.activityPluginBinding != null) {
|
webView.inAppWebViewChromeClient.dispose();
|
||||||
Shared.activityPluginBinding.removeActivityResultListener(webView.inAppWebViewChromeClient);
|
webView.inAppWebViewClient.dispose();
|
||||||
}
|
webView.javaScriptBridgeInterface.dispose();
|
||||||
webView.setWebChromeClient(new WebChromeClient());
|
webView.setWebChromeClient(new WebChromeClient());
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -602,7 +602,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
|
||||||
channel.invokeMethod("onCreateWindow", obj, new MethodChannel.Result() {
|
channel.invokeMethod("onCreateWindow", obj, new MethodChannel.Result() {
|
||||||
@Override
|
@Override
|
||||||
public void success(@Nullable Object result) {
|
public void success(@Nullable Object result) {
|
||||||
if (result == null && InAppWebViewChromeClient.windowWebViewMessages.containsKey(windowId)) {
|
boolean handledByClient = false;
|
||||||
|
if (result instanceof Boolean) {
|
||||||
|
handledByClient = (boolean) result;
|
||||||
|
}
|
||||||
|
if (!handledByClient && InAppWebViewChromeClient.windowWebViewMessages.containsKey(windowId)) {
|
||||||
InAppWebViewChromeClient.windowWebViewMessages.remove(windowId);
|
InAppWebViewChromeClient.windowWebViewMessages.remove(windowId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1132,4 +1136,17 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
channel.setMethodCallHandler(null);
|
||||||
|
if (Shared.activityPluginBinding != null) {
|
||||||
|
Shared.activityPluginBinding.removeActivityResultListener(this);
|
||||||
|
}
|
||||||
|
if (inAppBrowserActivity != null) {
|
||||||
|
inAppBrowserActivity = null;
|
||||||
|
}
|
||||||
|
if (flutterWebView != null) {
|
||||||
|
flutterWebView = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
if (webView.options.useShouldOverrideUrlLoading) {
|
if (webView.options.useShouldOverrideUrlLoading) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
onShouldOverrideUrlLoading(
|
onShouldOverrideUrlLoading(
|
||||||
|
webView,
|
||||||
request.getUrl().toString(),
|
request.getUrl().toString(),
|
||||||
request.getMethod(),
|
request.getMethod(),
|
||||||
request.getRequestHeaders(),
|
request.getRequestHeaders(),
|
||||||
|
@ -74,6 +75,7 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
request.isRedirect());
|
request.isRedirect());
|
||||||
} else {
|
} else {
|
||||||
onShouldOverrideUrlLoading(
|
onShouldOverrideUrlLoading(
|
||||||
|
webView,
|
||||||
request.getUrl().toString(),
|
request.getUrl().toString(),
|
||||||
request.getMethod(),
|
request.getMethod(),
|
||||||
request.getRequestHeaders(),
|
request.getRequestHeaders(),
|
||||||
|
@ -102,14 +104,16 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
|
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
|
||||||
if (((inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView).options.useShouldOverrideUrlLoading) {
|
InAppWebView inAppWebView = (InAppWebView) webView;
|
||||||
onShouldOverrideUrlLoading(url, "GET", null,true, false, false);
|
if (inAppWebView.options.useShouldOverrideUrlLoading) {
|
||||||
|
onShouldOverrideUrlLoading(inAppWebView, url, "GET", null,true, false, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onShouldOverrideUrlLoading(final String url, final String method, final Map<String, String> headers, final boolean isForMainFrame, boolean hasGesture, boolean isRedirect) {
|
public void onShouldOverrideUrlLoading(final InAppWebView webView, final String url, final String method, final Map<String, String> headers,
|
||||||
|
final boolean isForMainFrame, boolean hasGesture, boolean isRedirect) {
|
||||||
Map<String, Object> obj = new HashMap<>();
|
Map<String, Object> obj = new HashMap<>();
|
||||||
if (inAppBrowserActivity != null)
|
if (inAppBrowserActivity != null)
|
||||||
obj.put("uuid", inAppBrowserActivity.uuid);
|
obj.put("uuid", inAppBrowserActivity.uuid);
|
||||||
|
@ -132,7 +136,6 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
if (isForMainFrame) {
|
if (isForMainFrame) {
|
||||||
// There isn't any way to load an URL for a frame that is not the main frame,
|
// There isn't any way to load an URL for a frame that is not the main frame,
|
||||||
// so call this only on main frame.
|
// so call this only on main frame.
|
||||||
InAppWebView webView = ((inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||||
webView.loadUrl(url, headers);
|
webView.loadUrl(url, headers);
|
||||||
else
|
else
|
||||||
|
@ -250,11 +253,15 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
// // Used to show instantly a custom error page
|
|
||||||
// view.stopLoading();
|
|
||||||
// view.loadUrl("about:blank");
|
|
||||||
|
|
||||||
((inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView).isLoading = false;
|
final InAppWebView webView = (InAppWebView) view;
|
||||||
|
|
||||||
|
if (webView.options.disableDefaultErrorPage) {
|
||||||
|
webView.stopLoading();
|
||||||
|
webView.loadUrl("about:blank");
|
||||||
|
}
|
||||||
|
|
||||||
|
webView.isLoading = false;
|
||||||
previousAuthRequestFailureCount = 0;
|
previousAuthRequestFailureCount = 0;
|
||||||
credentialsProposed = null;
|
credentialsProposed = null;
|
||||||
|
|
||||||
|
@ -830,4 +837,14 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
|
public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
channel.setMethodCallHandler(null);
|
||||||
|
if (inAppBrowserActivity != null) {
|
||||||
|
inAppBrowserActivity = null;
|
||||||
|
}
|
||||||
|
if (flutterWebView != null) {
|
||||||
|
flutterWebView = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class InAppWebViewOptions implements Options<InAppWebView> {
|
||||||
public Map<String, Object> rendererPriorityPolicy = new HashMap<>();
|
public Map<String, Object> rendererPriorityPolicy = new HashMap<>();
|
||||||
public Boolean useShouldInterceptRequest = false;
|
public Boolean useShouldInterceptRequest = false;
|
||||||
public Boolean useOnRenderProcessGone = false;
|
public Boolean useOnRenderProcessGone = false;
|
||||||
|
public Boolean disableDefaultErrorPage = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InAppWebViewOptions parse(Map<String, Object> options) {
|
public InAppWebViewOptions parse(Map<String, Object> options) {
|
||||||
|
@ -335,6 +336,9 @@ public class InAppWebViewOptions implements Options<InAppWebView> {
|
||||||
case "useOnRenderProcessGone":
|
case "useOnRenderProcessGone":
|
||||||
useOnRenderProcessGone = (Boolean) value;
|
useOnRenderProcessGone = (Boolean) value;
|
||||||
break;
|
break;
|
||||||
|
case "disableDefaultErrorPage":
|
||||||
|
disableDefaultErrorPage = (Boolean) value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,6 +424,7 @@ public class InAppWebViewOptions implements Options<InAppWebView> {
|
||||||
options.put("rendererPriorityPolicy", rendererPriorityPolicy);
|
options.put("rendererPriorityPolicy", rendererPriorityPolicy);
|
||||||
options.put("useShouldInterceptRequest", useShouldInterceptRequest);
|
options.put("useShouldInterceptRequest", useShouldInterceptRequest);
|
||||||
options.put("useOnRenderProcessGone", useOnRenderProcessGone);
|
options.put("useOnRenderProcessGone", useOnRenderProcessGone);
|
||||||
|
options.put("disableDefaultErrorPage", disableDefaultErrorPage);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ public class JavaScriptBridgeInterface {
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void _hideContextMenu() {
|
public void _hideContextMenu() {
|
||||||
|
if (flutterWebView == null && inAppBrowserActivity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
|
final InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
|
||||||
|
|
||||||
final Handler handler = new Handler(Looper.getMainLooper());
|
final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
@ -61,6 +65,10 @@ public class JavaScriptBridgeInterface {
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void _callHandler(final String handlerName, final String _callHandlerID, final String args) {
|
public void _callHandler(final String handlerName, final String _callHandlerID, final String args) {
|
||||||
|
if (flutterWebView == null && inAppBrowserActivity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
|
final InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
|
||||||
|
|
||||||
final Map<String, Object> obj = new HashMap<>();
|
final Map<String, Object> obj = new HashMap<>();
|
||||||
|
@ -108,4 +116,14 @@ public class JavaScriptBridgeInterface {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
channel.setMethodCallHandler(null);
|
||||||
|
if (inAppBrowserActivity != null) {
|
||||||
|
inAppBrowserActivity = null;
|
||||||
|
}
|
||||||
|
if (flutterWebView != null) {
|
||||||
|
flutterWebView = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-06-29 16:24:39.876196","version":"1.17.4"}
|
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.4.4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.10/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-06-29 17:43:40.301350","version":"1.17.4"}
|
|
@ -1906,7 +1906,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
||||||
|
|
||||||
if (options?.useOnDownloadStart)! {
|
if (options?.useOnDownloadStart)! {
|
||||||
let mimeType = navigationResponse.response.mimeType
|
let mimeType = navigationResponse.response.mimeType
|
||||||
if let url = navigationResponse.response.url {
|
if let url = navigationResponse.response.url, navigationResponse.isForMainFrame {
|
||||||
if mimeType != nil && !mimeType!.starts(with: "text/") {
|
if mimeType != nil && !mimeType!.starts(with: "text/") {
|
||||||
onDownloadStart(url: url.absoluteString)
|
onDownloadStart(url: url.absoluteString)
|
||||||
decisionHandler(.cancel)
|
decisionHandler(.cancel)
|
||||||
|
@ -1959,7 +1959,17 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
||||||
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
||||||
InAppWebView.credentialsProposed = []
|
InAppWebView.credentialsProposed = []
|
||||||
|
|
||||||
onLoadError(url: url?.absoluteString, error: error)
|
var urlError = url?.absoluteString
|
||||||
|
if let info = error._userInfo as? [String: Any] {
|
||||||
|
if let failingUrl = info[NSURLErrorFailingURLErrorKey] as? URL {
|
||||||
|
urlError = failingUrl.absoluteString
|
||||||
|
}
|
||||||
|
if let failingUrlString = info[NSURLErrorFailingURLStringErrorKey] as? String {
|
||||||
|
urlError = failingUrlString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoadError(url: urlError, error: error)
|
||||||
|
|
||||||
if IABController != nil {
|
if IABController != nil {
|
||||||
IABController!.backButton.isEnabled = canGoBack
|
IABController!.backButton.isEnabled = canGoBack
|
||||||
|
@ -2439,7 +2449,11 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if result == nil, InAppWebView.windowWebViews[windowId] != nil {
|
var handledByClient = false
|
||||||
|
if result != nil, result is Bool {
|
||||||
|
handledByClient = result as! Bool
|
||||||
|
}
|
||||||
|
if !handledByClient, InAppWebView.windowWebViews[windowId] != nil {
|
||||||
InAppWebView.windowWebViews.removeValue(forKey: windowId)
|
InAppWebView.windowWebViews.removeValue(forKey: windowId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ class HeadlessInAppWebView implements WebView {
|
||||||
onConsoleMessage;
|
onConsoleMessage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final Future<WebView> Function(InAppWebViewController controller,
|
final Future<bool> Function(InAppWebViewController controller,
|
||||||
CreateWindowRequest onCreateWindowRequest) onCreateWindow;
|
CreateWindowRequest onCreateWindowRequest) onCreateWindow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -341,10 +341,9 @@ class InAppBrowser {
|
||||||
|
|
||||||
///Event fired when the [InAppBrowser] webview requests the host application to create a new window,
|
///Event fired when the [InAppBrowser] webview requests the host application to create a new window,
|
||||||
///for example when trying to open a link with `target="_blank"` or when `window.open()` is called by JavaScript side.
|
///for example when trying to open a link with `target="_blank"` or when `window.open()` is called by JavaScript side.
|
||||||
///The return type should be an [InAppBrowser] instance, a [HeadlessInAppWebView] instance or `null`. If it returns `null`, then nothing will happen.
|
///If the host application chooses to honor this request, it should return `true` from this method, create a new WebView to host the window.
|
||||||
///If it returns an [InAppBrowser] instance, the new [InAppBrowser] will be immediately opened.
|
///If the host application chooses not to honor the request, it should return `false` from this method.
|
||||||
///If it returns a [HeadlessInAppWebView] instance, the [HeadlessInAppWebView.run] method will be immediately called.
|
///The default implementation of this method does nothing and hence returns `false`.
|
||||||
///Remember to use the [CreateWindowRequest.windowId] to create the new WebView instance.
|
|
||||||
///
|
///
|
||||||
///[createWindowRequest] represents the request.
|
///[createWindowRequest] represents the request.
|
||||||
///
|
///
|
||||||
|
@ -369,7 +368,7 @@ class InAppBrowser {
|
||||||
///
|
///
|
||||||
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview
|
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview
|
||||||
// ignore: missing_return
|
// ignore: missing_return
|
||||||
Future<dynamic> onCreateWindow(CreateWindowRequest createWindowRequest) {}
|
Future<bool> onCreateWindow(CreateWindowRequest createWindowRequest) {}
|
||||||
|
|
||||||
///Event fired when the host application should close the given WebView and remove it from the view system if necessary.
|
///Event fired when the host application should close the given WebView and remove it from the view system if necessary.
|
||||||
///At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.
|
///At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.
|
||||||
|
|
|
@ -161,7 +161,7 @@ class InAppWebView extends StatefulWidget implements WebView {
|
||||||
onConsoleMessage;
|
onConsoleMessage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final Future<WebView> Function(InAppWebViewController controller,
|
final Future<bool> Function(InAppWebViewController controller,
|
||||||
CreateWindowRequest onCreateWindowRequest) onCreateWindow;
|
CreateWindowRequest onCreateWindowRequest) onCreateWindow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -222,50 +222,15 @@ class InAppWebViewController {
|
||||||
IOSWKNavigationType.fromValue(iosWKNavigationType),
|
IOSWKNavigationType.fromValue(iosWKNavigationType),
|
||||||
iosIsForMainFrame: iosIsForMainFrame);
|
iosIsForMainFrame: iosIsForMainFrame);
|
||||||
|
|
||||||
WebView webView;
|
bool result = false;
|
||||||
dynamic inAppBrowserWindow;
|
|
||||||
|
|
||||||
if (_webview != null && _webview.onCreateWindow != null)
|
if (_webview != null && _webview.onCreateWindow != null)
|
||||||
webView = await _webview.onCreateWindow(this, createWindowRequest);
|
result = await _webview.onCreateWindow(this, createWindowRequest);
|
||||||
else if (_inAppBrowser != null) {
|
else if (_inAppBrowser != null) {
|
||||||
inAppBrowserWindow =
|
result = await _inAppBrowser.onCreateWindow(createWindowRequest);
|
||||||
await _inAppBrowser.onCreateWindow(createWindowRequest);
|
|
||||||
assert(
|
|
||||||
inAppBrowserWindow is InAppBrowser ||
|
|
||||||
inAppBrowserWindow is HeadlessInAppWebView,
|
|
||||||
"InAppBrowser.onCreateWindow should return an \"InAppBrowser\" instance or a \"HeadlessInAppWebView\" instance.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int webViewWindowId;
|
return result;
|
||||||
|
|
||||||
if (webView != null) {
|
|
||||||
webViewWindowId = webView.windowId;
|
|
||||||
assert(
|
|
||||||
webViewWindowId != null,
|
|
||||||
"If you are returning a WebView, then WebView.windowId should be not null. To set the " +
|
|
||||||
"WebView.windowId property, you should use the CreateWindowRequest.windowId property.");
|
|
||||||
if (webView is HeadlessInAppWebView) {
|
|
||||||
webView.run();
|
|
||||||
}
|
|
||||||
} else if (inAppBrowserWindow != null) {
|
|
||||||
if (inAppBrowserWindow is InAppBrowser) {
|
|
||||||
webViewWindowId = inAppBrowserWindow.windowId;
|
|
||||||
assert(
|
|
||||||
webViewWindowId != null,
|
|
||||||
"If you are returning an InAppBrowser, then InAppBrowser.windowId should be not null. To set the " +
|
|
||||||
"InAppBrowser.windowId property, you should use the CreateWindowRequest.windowId property.");
|
|
||||||
inAppBrowserWindow.openUrl(url: "about:blank");
|
|
||||||
} else if (inAppBrowserWindow is HeadlessInAppWebView) {
|
|
||||||
webViewWindowId = inAppBrowserWindow.windowId;
|
|
||||||
assert(
|
|
||||||
webViewWindowId != null,
|
|
||||||
"If you are returning a HeadlessInAppWebView, then HeadlessInAppWebView.windowId should be not null. To set the " +
|
|
||||||
"HeadlessInAppWebView.windowId property, you should use the CreateWindowRequest.windowId property.");
|
|
||||||
inAppBrowserWindow.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return webViewWindowId;
|
|
||||||
case "onCloseWindow":
|
case "onCloseWindow":
|
||||||
if (_webview != null && _webview.onCloseWindow != null)
|
if (_webview != null && _webview.onCloseWindow != null)
|
||||||
_webview.onCloseWindow(this);
|
_webview.onCloseWindow(this);
|
||||||
|
@ -1222,7 +1187,10 @@ class InAppWebViewController {
|
||||||
String encoding = "utf8",
|
String encoding = "utf8",
|
||||||
String baseUrl = "about:blank",
|
String baseUrl = "about:blank",
|
||||||
String androidHistoryUrl = "about:blank"}) async {
|
String androidHistoryUrl = "about:blank"}) async {
|
||||||
assert(data != null);
|
assert(data != null &&
|
||||||
|
mimeType != null &&
|
||||||
|
encoding != null &&
|
||||||
|
baseUrl != null);
|
||||||
Map<String, dynamic> args = <String, dynamic>{};
|
Map<String, dynamic> args = <String, dynamic>{};
|
||||||
args.putIfAbsent('data', () => data);
|
args.putIfAbsent('data', () => data);
|
||||||
args.putIfAbsent('mimeType', () => mimeType);
|
args.putIfAbsent('mimeType', () => mimeType);
|
||||||
|
|
|
@ -132,10 +132,9 @@ abstract class WebView {
|
||||||
|
|
||||||
///Event fired when the [WebView] requests the host application to create a new window,
|
///Event fired when the [WebView] requests the host application to create a new window,
|
||||||
///for example when trying to open a link with `target="_blank"` or when `window.open()` is called by JavaScript side.
|
///for example when trying to open a link with `target="_blank"` or when `window.open()` is called by JavaScript side.
|
||||||
///The return value should be a [WebView] instance or `null`. If it returns `null`, then nothing will happen.
|
///If the host application chooses to honor this request, it should return `true` from this method, create a new WebView to host the window.
|
||||||
///If it returns an [InAppWebView] instance, when it will be added to the widget tree, it will load the request.
|
///If the host application chooses not to honor the request, it should return `false` from this method.
|
||||||
///If it returns a [HeadlessInAppWebView] instance, the [HeadlessInAppWebView.run] method will be immediately called.
|
///The default implementation of this method does nothing and hence returns `false`.
|
||||||
///Remember to use the [CreateWindowRequest.windowId] to create the new WebView instance.
|
|
||||||
///
|
///
|
||||||
///[createWindowRequest] represents the request.
|
///[createWindowRequest] represents the request.
|
||||||
///
|
///
|
||||||
|
@ -150,7 +149,7 @@ abstract class WebView {
|
||||||
///[IOSInAppWebViewOptions.allowsPictureInPictureMediaPlayback], [IOSInAppWebViewOptions.isFraudulentWebsiteWarningEnabled],
|
///[IOSInAppWebViewOptions.allowsPictureInPictureMediaPlayback], [IOSInAppWebViewOptions.isFraudulentWebsiteWarningEnabled],
|
||||||
///[IOSInAppWebViewOptions.allowsInlineMediaPlayback], [IOSInAppWebViewOptions.suppressesIncrementalRendering], [IOSInAppWebViewOptions.selectionGranularity],
|
///[IOSInAppWebViewOptions.allowsInlineMediaPlayback], [IOSInAppWebViewOptions.suppressesIncrementalRendering], [IOSInAppWebViewOptions.selectionGranularity],
|
||||||
///[IOSInAppWebViewOptions.ignoresViewportScaleLimits],
|
///[IOSInAppWebViewOptions.ignoresViewportScaleLimits],
|
||||||
///will have no effect due to a `WKWebView` limitation when creating a new window WebView: it's impossible to return a new `WKWebView`
|
///will have no effect due to a `WKWebView` limitation when creating the new window WebView: it's impossible to return the new `WKWebView`
|
||||||
///with a different `WKWebViewConfiguration` instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview).
|
///with a different `WKWebViewConfiguration` instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview).
|
||||||
///So, these options will be inherited from the caller WebView.
|
///So, these options will be inherited from the caller WebView.
|
||||||
///Also, note that calling [InAppWebViewController.setOptions] method using the controller of the new created WebView,
|
///Also, note that calling [InAppWebViewController.setOptions] method using the controller of the new created WebView,
|
||||||
|
@ -159,7 +158,7 @@ abstract class WebView {
|
||||||
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebChromeClient#onCreateWindow(android.webkit.WebView,%20boolean,%20boolean,%20android.os.Message)
|
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebChromeClient#onCreateWindow(android.webkit.WebView,%20boolean,%20boolean,%20android.os.Message)
|
||||||
///
|
///
|
||||||
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview
|
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview
|
||||||
final Future<WebView> Function(InAppWebViewController controller,
|
final Future<bool> Function(InAppWebViewController controller,
|
||||||
CreateWindowRequest createWindowRequest) onCreateWindow;
|
CreateWindowRequest createWindowRequest) onCreateWindow;
|
||||||
|
|
||||||
///Event fired when the host application should close the given WebView and remove it from the view system if necessary.
|
///Event fired when the host application should close the given WebView and remove it from the view system if necessary.
|
||||||
|
|
|
@ -462,7 +462,7 @@ class AndroidInAppWebViewOptions
|
||||||
///The default value is `true`.
|
///The default value is `true`.
|
||||||
bool hardwareAcceleration;
|
bool hardwareAcceleration;
|
||||||
|
|
||||||
///Sets whether the WebView whether supports multiple windows.
|
///Sets whether the WebView supports multiple windows.
|
||||||
///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`.
|
///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`.
|
||||||
bool supportMultipleWindows;
|
bool supportMultipleWindows;
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ class AndroidInAppWebViewOptions
|
||||||
///This is used to set the JavaScript property `window.navigator.isOnline` and generates the online/offline event as specified in HTML5, sec. 5.7.7.
|
///This is used to set the JavaScript property `window.navigator.isOnline` and generates the online/offline event as specified in HTML5, sec. 5.7.7.
|
||||||
bool networkAvailable;
|
bool networkAvailable;
|
||||||
|
|
||||||
///Specify the style of the scrollbars. The scrollbars can be overlaid or inset.
|
///Specifies the style of the scrollbars. The scrollbars can be overlaid or inset.
|
||||||
///When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view.
|
///When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view.
|
||||||
///For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable,
|
///For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable,
|
||||||
///you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding,
|
///you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding,
|
||||||
|
@ -493,23 +493,27 @@ class AndroidInAppWebViewOptions
|
||||||
///The default value is [AndroidScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY].
|
///The default value is [AndroidScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY].
|
||||||
AndroidScrollBarStyle scrollBarStyle;
|
AndroidScrollBarStyle scrollBarStyle;
|
||||||
|
|
||||||
///Set the position of the vertical scroll bar.
|
///Sets the position of the vertical scroll bar.
|
||||||
///The default value is [AndroidVerticalScrollbarPosition.SCROLLBAR_POSITION_DEFAULT].
|
///The default value is [AndroidVerticalScrollbarPosition.SCROLLBAR_POSITION_DEFAULT].
|
||||||
AndroidVerticalScrollbarPosition verticalScrollbarPosition;
|
AndroidVerticalScrollbarPosition verticalScrollbarPosition;
|
||||||
|
|
||||||
///Defines the delay in milliseconds that a scrollbar waits before fade out.
|
///Defines the delay in milliseconds that a scrollbar waits before fade out.
|
||||||
int scrollBarDefaultDelayBeforeFade;
|
int scrollBarDefaultDelayBeforeFade;
|
||||||
|
|
||||||
///Define whether scrollbars will fade when the view is not scrolling.
|
///Defines whether scrollbars will fade when the view is not scrolling.
|
||||||
///The default value is `true`.
|
///The default value is `true`.
|
||||||
bool scrollbarFadingEnabled;
|
bool scrollbarFadingEnabled;
|
||||||
|
|
||||||
///Define the scrollbar fade duration in milliseconds.
|
///Defines the scrollbar fade duration in milliseconds.
|
||||||
int scrollBarFadeDuration;
|
int scrollBarFadeDuration;
|
||||||
|
|
||||||
///Set the renderer priority policy for this WebView.
|
///Sets the renderer priority policy for this WebView.
|
||||||
RendererPriorityPolicy rendererPriorityPolicy;
|
RendererPriorityPolicy rendererPriorityPolicy;
|
||||||
|
|
||||||
|
///Sets whether the default Android error page should be disabled.
|
||||||
|
///The default value is `false`.
|
||||||
|
bool disableDefaultErrorPage;
|
||||||
|
|
||||||
AndroidInAppWebViewOptions({
|
AndroidInAppWebViewOptions({
|
||||||
this.textZoom = 100,
|
this.textZoom = 100,
|
||||||
this.clearSessionCache = false,
|
this.clearSessionCache = false,
|
||||||
|
@ -563,6 +567,7 @@ class AndroidInAppWebViewOptions
|
||||||
this.scrollbarFadingEnabled = true,
|
this.scrollbarFadingEnabled = true,
|
||||||
this.scrollBarFadeDuration,
|
this.scrollBarFadeDuration,
|
||||||
this.rendererPriorityPolicy,
|
this.rendererPriorityPolicy,
|
||||||
|
this.disableDefaultErrorPage,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -618,7 +623,8 @@ class AndroidInAppWebViewOptions
|
||||||
"scrollBarDefaultDelayBeforeFade": scrollBarDefaultDelayBeforeFade,
|
"scrollBarDefaultDelayBeforeFade": scrollBarDefaultDelayBeforeFade,
|
||||||
"scrollbarFadingEnabled": scrollbarFadingEnabled,
|
"scrollbarFadingEnabled": scrollbarFadingEnabled,
|
||||||
"scrollBarFadeDuration": scrollBarFadeDuration,
|
"scrollBarFadeDuration": scrollBarFadeDuration,
|
||||||
"rendererPriorityPolicy": rendererPriorityPolicy?.toMap()
|
"rendererPriorityPolicy": rendererPriorityPolicy?.toMap(),
|
||||||
|
"disableDefaultErrorPage": disableDefaultErrorPage
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,6 +692,7 @@ class AndroidInAppWebViewOptions
|
||||||
options.scrollBarFadeDuration = map["scrollBarFadeDuration"];
|
options.scrollBarFadeDuration = map["scrollBarFadeDuration"];
|
||||||
options.rendererPriorityPolicy = RendererPriorityPolicy.fromMap(
|
options.rendererPriorityPolicy = RendererPriorityPolicy.fromMap(
|
||||||
map["rendererPriorityPolicy"]?.cast<String, dynamic>());
|
map["rendererPriorityPolicy"]?.cast<String, dynamic>());
|
||||||
|
options.disableDefaultErrorPage = map["disableDefaultErrorPage"];
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue