From f22ff3640547b3524fc6d2e6eb1f83b6cd24c6e3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:43:54 -0400 Subject: [PATCH] [webview_flutter_wkwebview] Only set `limitsNavigationsToAppBoundDomains` when it is set to true (#5137) This changes the flag to only flag to only call the method if it sets it to `true`. Fixes https://github.com/flutter/flutter/issues/136449 --- .../webview_flutter_wkwebview/CHANGELOG.md | 5 +++++ .../lib/src/webkit_webview_controller.dart | 10 ++++++++-- .../webview_flutter_wkwebview/pubspec.yaml | 2 +- .../test/webkit_webview_controller_test.dart | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index 4de08406bba1..197c5d70784f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.9.2 + +* Fixes error caused by calling `WKWebViewConfiguration.limitsNavigationsToAppBoundDomains` on + versions below 14. + ## 3.9.1 * Fixes bug where `WebkitWebViewController.getUserAgent` was incorrectly returning an empty String. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart index a02ed61069e7..d15b28251828 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart @@ -70,8 +70,14 @@ class WebKitWebViewControllerCreationParams ); } _configuration.setAllowsInlineMediaPlayback(allowsInlineMediaPlayback); - _configuration.setLimitsNavigationsToAppBoundDomains( - limitsNavigationsToAppBoundDomains); + // `WKWebViewConfiguration.limitsNavigationsToAppBoundDomains` is only + // supported on iOS versions 14+. So this only calls it if the value is set + // to true. + if (limitsNavigationsToAppBoundDomains) { + _configuration.setLimitsNavigationsToAppBoundDomains( + limitsNavigationsToAppBoundDomains, + ); + } } /// Constructs a [WebKitWebViewControllerCreationParams] using a diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 63ed6e4db5f0..2d469bd83825 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_wkwebview description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.9.1 +version: 3.9.2 environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart index d1854df4bce0..46badc069058 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart @@ -160,6 +160,25 @@ void main() { ); }); + test( + 'limitsNavigationsToAppBoundDomains is not called if it uses default value (false)', + () { + final MockWKWebViewConfiguration mockConfiguration = + MockWKWebViewConfiguration(); + + WebKitWebViewControllerCreationParams( + webKitProxy: WebKitProxy( + createWebViewConfiguration: ({InstanceManager? instanceManager}) { + return mockConfiguration; + }, + ), + ); + + verifyNever( + mockConfiguration.setLimitsNavigationsToAppBoundDomains(any), + ); + }); + test('mediaTypesRequiringUserAction', () { final MockWKWebViewConfiguration mockConfiguration = MockWKWebViewConfiguration();