This commit is contained in:
Lorenzo Pichilli 2022-04-25 13:01:17 +02:00
commit b5935e9304
3 changed files with 52 additions and 3 deletions

View File

@ -6,6 +6,10 @@
- Added support for `onPermissionRequest` event on iOS 15.0+
- Updated `getMetaThemeColor` on iOS 15.0+
## 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', () {