This commit is contained in:
Lorenzo Pichilli 2022-04-25 12:55:35 +02:00
parent f511e4d1f5
commit 951b974dd3
4 changed files with 53 additions and 4 deletions

View File

@ -1,3 +1,7 @@
## 5.4.1+2
- Fixed "Android ServiceWorkerControllerCompat.setServiceWorkerClient(null) makes Webivew Plugin Crashes" [#1151](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1151)
## 5.4.1+1
- Fixed Android default context menu over custom context menu on API Level 31+

View File

@ -118,7 +118,9 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler {
private void setServiceWorkerClient(Boolean isNull) {
if (serviceWorkerController != null) {
serviceWorkerController.setServiceWorkerClient(isNull ? null : new ServiceWorkerClientCompat() {
// set ServiceWorkerClient as null makes the app crashes, so just set a dummy ServiceWorkerClientCompat.
// https://github.com/pichillilorenzo/flutter_inappwebview/issues/1151
serviceWorkerController.setServiceWorkerClient(isNull ? dummyServiceWorkerClientCompat() : new ServiceWorkerClientCompat() {
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) {
@ -165,10 +167,20 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler {
}
}
private ServiceWorkerClientCompat dummyServiceWorkerClientCompat() {
return new ServiceWorkerClientCompat() {
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) {
return null;
}
};
}
public void dispose() {
channel.setMethodCallHandler(null);
if (serviceWorkerController != null) {
serviceWorkerController.setServiceWorkerClient(null);
serviceWorkerController.setServiceWorkerClient(dummyServiceWorkerClientCompat());
serviceWorkerController = null;
}
plugin = null;

View File

@ -5449,7 +5449,7 @@ setTimeout(function() {
});
group('Service Worker', () {
testWidgets('AndroidInAppWebViewController', (WidgetTester tester) async {
testWidgets('shouldInterceptRequest', (WidgetTester tester) async {
final Completer completer = Completer();
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
@ -5487,6 +5487,39 @@ setTimeout(function() {
expect(completer.future, completes);
}, skip: !Platform.isAndroid);
testWidgets('setServiceWorkerClient to null', (WidgetTester tester) async {
final Completer<String> pageLoaded = Completer<String>();
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
if (swAvailable && swInterceptAvailable) {
AndroidServiceWorkerController serviceWorkerController =
AndroidServiceWorkerController.instance();
await serviceWorkerController.setServiceWorkerClient(null);
}
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')),
onLoadStop: (controller, url) {
pageLoaded.complete(url!.toString());
},
),
),
);
final String url = await pageLoaded.future;
expect(url, "https://mdn.github.io/sw-test/");
}, skip: !Platform.isAndroid);
});
group('Cookie Manager', () {

View File

@ -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+1
version: 5.4.1+2
homepage: https://github.com/pichillilorenzo/flutter_inappwebview
environment: