From e2afcea98645521fba3f4120d651d508841ab47b Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Mon, 25 Apr 2022 17:41:14 +0200 Subject: [PATCH 1/3] updated pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2bfc1296..941da3eb 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 5.4.1+2 +version: 5.4.2 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: From f885a0537fcaf858c2ef38f1de0ce677354dfa8c Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Mon, 25 Apr 2022 18:00:10 +0200 Subject: [PATCH 2/3] fixed code example --- example/lib/in_app_webiew_example.screen.dart | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index a92baa96..b656d6fe 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -169,20 +169,6 @@ class _InAppWebViewExampleScreenState extends State { this.url = url.toString(); urlController.text = this.url; }); - if (url?.host == 'github.com') { - await controller.loadUrl( - urlRequest: URLRequest( - url: Uri.parse('https://flutter-header-echo.herokuapp.com/'), - headers: { - 'test_header': 'flutter_test_header' - })); - final String? currentUrl = (await controller.getUrl())?.toString(); - print(currentUrl); - await Future.delayed(Duration(seconds: 2)); - final String? content = await controller.evaluateJavascript( - source: 'document.documentElement.innerText'); - print(content); - } }, onLoadError: (controller, url, code, message) { pullToRefreshController.endRefreshing(); From 442b51db0f0d9995f8f0fe24c9e26b8d9f06bba1 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 26 Apr 2022 13:55:24 +0200 Subject: [PATCH 3/3] fix #1155 --- CHANGELOG.md | 4 + .../InAppWebViewFlutterPlugin.java | 4 + .../InAppWebViewStatic.java | 2 +- .../ChromeCustomTabsActivity.java | 13 +-- .../ChromeSafariBrowserManager.java | 4 +- .../HeadlessInAppWebView.java | 32 +++---- .../in_app_browser/InAppBrowserManager.java | 12 ++- .../in_app_webview/FlutterWebView.java | 2 +- .../in_app_webview/InAppWebView.java | 28 +++--- .../InAppWebViewChromeClient.java | 86 ++++++++++++++++--- .../webview_flutter_test.dart | 27 ++++-- pubspec.yaml | 2 +- 12 files changed, 157 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 624ee67c..bf0e210b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.4.2+1 + +- Fixed "Latest version 5.4.2 crashes on Android - HeadlessInAppWebView.dispose" [#1155](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1155) + ## 5.4.2 - Added `setActionButton` method to `ChromeSafariBrowser` class diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java index ceff965b..ee5b2cb6 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java @@ -6,6 +6,8 @@ import android.net.Uri; import android.os.Build; import android.webkit.ValueCallback; +import androidx.annotation.Nullable; + import com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager; import com.pichillilorenzo.flutter_inappwebview.credential_database.CredentialDatabaseHandler; import com.pichillilorenzo.flutter_inappwebview.in_app_browser.InAppBrowserManager; @@ -41,7 +43,9 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { public PluginRegistry.Registrar registrar; public BinaryMessenger messenger; public FlutterPlugin.FlutterAssets flutterAssets; + @Nullable public ActivityPluginBinding activityPluginBinding; + @Nullable public Activity activity; @SuppressWarnings("deprecation") public FlutterView flutterView; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java index eb1731c4..646eda39 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java @@ -79,7 +79,7 @@ public class InAppWebViewStatic implements MethodChannel.MethodCallHandler { result.success(false); break; case "getCurrentWebViewPackage": - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && plugin != null && plugin.activity != null) { result.success(convertWebViewPackageToMap(WebViewCompat.getCurrentWebViewPackage(plugin.activity))); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //with Android Lollipop (API 21) they started to update the WebView diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java index e62072b7..ff0a38b0 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java @@ -41,6 +41,7 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel. protected final int CHROME_CUSTOM_TAB_REQUEST_CODE = 100; protected boolean onChromeSafariBrowserOpened = false; protected boolean onChromeSafariBrowserCompletedInitialLoad = false; + @Nullable public ChromeSafariBrowserManager manager; public String initialUrl; public List menuItems = new ArrayList<>(); @@ -137,11 +138,13 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel. this.onDestroy(); this.close(); - // https://stackoverflow.com/a/41596629/4637638 - Intent myIntent = new Intent(manager.plugin.activity, manager.plugin.activity.getClass()); - myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - manager.plugin.activity.startActivity(myIntent); + if (manager != null && manager.plugin != null && manager.plugin.activity != null) { + // https://stackoverflow.com/a/41596629/4637638 + Intent myIntent = new Intent(manager.plugin.activity, manager.plugin.activity.getClass()); + myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + manager.plugin.activity.startActivity(myIntent); + } dispose(); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java index 0516e86c..d5b3ae83 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java @@ -41,7 +41,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl switch (call.method) { case "open": - if (plugin != null) { + if (plugin != null && plugin.activity != null) { String url = (String) call.argument("url"); HashMap options = (HashMap) call.argument("options"); HashMap actionButton = (HashMap) call.argument("actionButton"); @@ -52,7 +52,7 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl } break; case "isAvailable": - if (plugin != null) { + if (plugin != null && plugin.activity != null) { result.success(CustomTabActivityHelper.isAvailable(plugin.activity)); } else { result.success(false); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java index bcf68b5e..c53cec8a 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java @@ -70,21 +70,23 @@ public class HeadlessInAppWebView implements MethodChannel.MethodCallHandler { } public void prepare(Map params) { - // Add the headless WebView to the view hierarchy. - // This way is also possible to take screenshots. - ViewGroup contentView = (ViewGroup) plugin.activity.findViewById(android.R.id.content); - ViewGroup mainView = (ViewGroup) (contentView).getChildAt(0); - if (mainView != null) { - View view = flutterWebView.getView(); - final Map initialSize = (Map) params.get("initialSize"); - Size2D size = Size2D.fromMap(initialSize); - if (size != null) { - setSize(size); - } else { - view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + if (plugin != null && plugin.activity != null) { + // Add the headless WebView to the view hierarchy. + // This way is also possible to take screenshots. + ViewGroup contentView = (ViewGroup) plugin.activity.findViewById(android.R.id.content); + ViewGroup mainView = (ViewGroup) (contentView).getChildAt(0); + if (mainView != null && flutterWebView != null) { + View view = flutterWebView.getView(); + final Map initialSize = (Map) params.get("initialSize"); + Size2D size = Size2D.fromMap(initialSize); + if (size != null) { + setSize(size); + } else { + view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + } + mainView.addView(view, 0); + view.setVisibility(View.INVISIBLE); } - mainView.addView(view, 0); - view.setVisibility(View.INVISIBLE); } } @@ -110,7 +112,7 @@ public class HeadlessInAppWebView implements MethodChannel.MethodCallHandler { public void dispose() { channel.setMethodCallHandler(null); HeadlessInAppWebViewManager.webViews.remove(id); - if (plugin != null) { + if (plugin != null && plugin.activity != null) { ViewGroup contentView = (ViewGroup) plugin.activity.findViewById(android.R.id.content); ViewGroup mainView = (ViewGroup) (contentView).getChildAt(0); if (mainView != null && flutterWebView != null) { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserManager.java index 26a82615..a72187eb 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserManager.java @@ -72,13 +72,19 @@ public class InAppBrowserManager implements MethodChannel.MethodCallHandler { public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { switch (call.method) { case "open": - open(plugin.activity, (Map) call.arguments()); - result.success(true); + if (plugin != null && plugin.activity != null) { + open(plugin.activity, (Map) call.arguments()); + result.success(true); + } else { + result.success(false); + } break; case "openWithSystemBrowser": - { + if (plugin != null && plugin.activity != null) { String url = (String) call.argument("url"); openWithSystemBrowser(plugin.activity, url, result); + } else { + result.success(false); } break; default: diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java index 4f226493..f3f762cd 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java @@ -60,7 +60,7 @@ public class FlutterWebView implements PlatformWebView { InAppWebViewOptions options = new InAppWebViewOptions(); options.parse(initialOptions); - if (plugin.activity == null) { + if (plugin == null || plugin.activity == null) { Log.e(LOG_TAG, "\n\n\nERROR: You need to upgrade your Flutter project to use the new Java Embedding API:\n\n" + "- Take a look at the \"IMPORTANT Note for Android\" section here: https://github.com/pichillilorenzo/flutter_inappwebview#important-note-for-android\n" + "- See the official wiki here: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects\n\n\n"); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java index 3ae40f08..a1951e6b 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java @@ -175,7 +175,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie this.options = options; this.contextMenu = contextMenu; this.userContentController.addUserOnlyScripts(userScripts); - plugin.activity.registerForContextMenu(this); + if (plugin != null && plugin.activity != null) { + plugin.activity.registerForContextMenu(this); + } } public void prepare() { @@ -1216,20 +1218,22 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void printCurrentPage() { - // Get a PrintManager instance - PrintManager printManager = (PrintManager) plugin.activity.getSystemService(Context.PRINT_SERVICE); + if (plugin != null && plugin.activity != null) { + // Get a PrintManager instance + PrintManager printManager = (PrintManager) plugin.activity.getSystemService(Context.PRINT_SERVICE); - if (printManager != null) { - String jobName = getTitle() + " Document"; + if (printManager != null) { + String jobName = getTitle() + " Document"; - // Get a printCurrentPage adapter instance - PrintDocumentAdapter printAdapter = createPrintDocumentAdapter(jobName); + // Get a printCurrentPage adapter instance + PrintDocumentAdapter printAdapter = createPrintDocumentAdapter(jobName); - // Create a printCurrentPage job with name and adapter instance - printManager.print(jobName, printAdapter, - new PrintAttributes.Builder().build()); - } else { - Log.e(LOG_TAG, "No PrintManager available"); + // Create a printCurrentPage job with name and adapter instance + printManager.print(jobName, printAdapter, + new PrintAttributes.Builder().build()); + } else { + Log.e(LOG_TAG, "No PrintManager available"); + } } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java index b49f07f1..0cb92643 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java @@ -113,7 +113,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR if (plugin.registrar != null) plugin.registrar.addActivityResultListener(this); - else + else if (plugin.activityPluginBinding != null) plugin.activityPluginBinding.addActivityResultListener(this); } @@ -124,9 +124,15 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR @Override public void onHideCustomView() { - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } View decorView = getRootView(); + if (decorView == null) { + return; + } ((FrameLayout) decorView).removeView(this.mCustomView); this.mCustomView = null; decorView.setSystemUiVisibility(this.mOriginalSystemUiVisibility); @@ -145,9 +151,15 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR return; } - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } View decorView = getRootView(); + if (decorView == null) { + return; + } this.mCustomView = paramView; this.mOriginalSystemUiVisibility = decorView.getSystemUiVisibility(); this.mOriginalOrientation = activity.getRequestedOrientation(); @@ -229,7 +241,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } }; - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_Dialog_Alert); alertDialogBuilder.setMessage(alertMessage); @@ -322,7 +337,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } }; - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_Dialog_Alert); alertDialogBuilder.setMessage(alertMessage); @@ -441,7 +459,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } }; - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_Dialog_Alert); alertDialogBuilder.setMessage(alertMessage); @@ -539,7 +560,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } }; - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity, R.style.Theme_AppCompat_Dialog_Alert); alertDialogBuilder.setMessage(alertMessage); @@ -746,8 +770,12 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR channel.invokeMethod("onReceivedTouchIconUrl", obj); } + @Nullable protected ViewGroup getRootView() { - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return null; + } return (ViewGroup) activity.findViewById(android.R.id.content); } @@ -841,7 +869,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } private boolean isFileNotEmpty(Uri uri) { - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return false; + } long length; try { @@ -882,7 +913,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Parcelable[]{})); - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return; + } if (chooserIntent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivityForResult(chooserIntent, PICKER_LEGACY); } else { @@ -910,7 +944,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR chooserIntent.putExtra(Intent.EXTRA_INTENT, fileSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Parcelable[]{})); - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return true; + } if (chooserIntent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivityForResult(chooserIntent, PICKER); } else { @@ -923,7 +960,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR protected boolean needsCameraPermission() { boolean needed = false; - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return true; + } PackageManager packageManager = activity.getPackageManager(); try { String[] requestedPermissions = packageManager.getPackageInfo(activity.getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions; @@ -1051,6 +1091,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR return type; } + @Nullable private Uri getOutputUri(String intentType) { File capturedFile = null; try { @@ -1065,12 +1106,16 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR return Uri.fromFile(capturedFile); } - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return null; + } // for versions 6.0+ (23) we use the FileProvider to avoid runtime permissions String packageName = activity.getApplicationContext().getPackageName(); return FileProvider.getUriForFile(activity.getApplicationContext(), packageName + "." + fileProviderAuthorityExtension, capturedFile); } + @Nullable private File getCapturedFile(String intentType) throws IOException { String prefix = ""; String suffix = ""; @@ -1095,7 +1140,10 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR return new File(storageDir, filename); } - Activity activity = inAppBrowserDelegate != null ? inAppBrowserDelegate.getActivity() : plugin.activity; + Activity activity = getActivity(); + if (activity == null) { + return null; + } File storageDir = activity.getApplicationContext().getExternalFilesDir(null); return File.createTempFile(prefix, suffix, storageDir); } @@ -1153,6 +1201,16 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } } + @Nullable + private Activity getActivity() { + if (inAppBrowserDelegate != null) { + return inAppBrowserDelegate.getActivity(); + } else if (plugin != null) { + return plugin.activity; + } + return null; + } + public void dispose() { if (plugin != null && plugin.activityPluginBinding != null) { plugin.activityPluginBinding.removeActivityResultListener(this); diff --git a/example/integration_test/webview_flutter_test.dart b/example/integration_test/webview_flutter_test.dart index 31b6e369..9b62063f 100644 --- a/example/integration_test/webview_flutter_test.dart +++ b/example/integration_test/webview_flutter_test.dart @@ -15,6 +15,21 @@ import 'package:path_provider/path_provider.dart'; import '.env.dart'; +/// Returns a matcher that matches the isNullOrEmpty property. +const Matcher isNullOrEmpty = _NullOrEmpty(); + +class _NullOrEmpty extends Matcher { + const _NullOrEmpty(); + + @override + bool matches(Object? item, Map matchState) => + item == null || (item as dynamic).isEmpty; + + @override + Description describe(Description description) => + description.add('null or empty'); +} + class Foo { String? bar; String? baz; @@ -4148,7 +4163,7 @@ setTimeout(function() { if (Platform.isAndroid) { await pageLoaded.future; expect(await controller.evaluateJavascript(source: "document.body"), - isEmpty); + isNullOrEmpty); } else if (Platform.isIOS) { expect(pageLoaded.future, doesNotComplete); } @@ -5498,7 +5513,7 @@ setTimeout(function() { if (swAvailable && swInterceptAvailable) { AndroidServiceWorkerController serviceWorkerController = - AndroidServiceWorkerController.instance(); + AndroidServiceWorkerController.instance(); await serviceWorkerController.setServiceWorkerClient(null); } @@ -5509,7 +5524,7 @@ setTimeout(function() { child: InAppWebView( key: GlobalKey(), initialUrlRequest: - URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')), + URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')), onLoadStop: (controller, url) { pageLoaded.complete(url!.toString()); }, @@ -5874,7 +5889,8 @@ setTimeout(function() { group('Android Custom Tabs', () { test('add custom action button', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); - var actionButtonIcon = await rootBundle.load('test_assets/images/flutter-logo.png'); + var actionButtonIcon = + await rootBundle.load('test_assets/images/flutter-logo.png'); chromeSafariBrowser.setActionButton(ChromeSafariBrowserActionButton( id: 1, description: 'Action Button description', @@ -5892,7 +5908,8 @@ setTimeout(function() { await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev")); }, throwsA(isInstanceOf())); - await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes); + await expectLater( + chromeSafariBrowser.firstPageLoaded.future, completes); await chromeSafariBrowser.close(); await chromeSafariBrowser.browserClosed.future; expect(chromeSafariBrowser.isOpened(), false); diff --git a/pubspec.yaml b/pubspec.yaml index 941da3eb..320956f4 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 5.4.2 +version: 5.4.2+1 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: