Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_wkwebview] Fixes an exception caused by the onUrlChange callback returning a null url #3848

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.4.2

* Fixes an exception caused by the `onUrlChange` callback passing a null `NSUrl`.

## 3.4.1

* Fixes internal type conversion error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class WebKitWebViewController extends PlatformWebViewController {
final UrlChangeCallback? urlChangeCallback =
controller._currentNavigationDelegate?._onUrlChange;
if (urlChangeCallback != null) {
final NSUrl url = change[NSKeyValueChangeKey.newValue]! as NSUrl;
urlChangeCallback(UrlChange(url: await url.getAbsoluteString()));
final NSUrl? url = change[NSKeyValueChangeKey.newValue] as NSUrl?;
urlChangeCallback(UrlChange(url: await url?.getAbsoluteString()));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.1
version: 3.4.2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,56 @@ void main() {
expect(urlChange.url, 'https://www.google.com');
});

test('setPlatformNavigationDelegate onUrlChange to null NSUrl', () async {
final MockWKWebView mockWebView = MockWKWebView();

late final void Function(
String keyPath,
NSObject object,
Map<NSKeyValueChangeKey, Object?> change,
) webViewObserveValue;

final WebKitWebViewController controller = createControllerWithMocks(
createMockWebView: (
_, {
void Function(
String keyPath,
NSObject object,
Map<NSKeyValueChangeKey, Object?> change,
)? observeValue,
}) {
webViewObserveValue = observeValue!;
return mockWebView;
},
);

final WebKitNavigationDelegate navigationDelegate =
WebKitNavigationDelegate(
const WebKitNavigationDelegateCreationParams(
webKitProxy: WebKitProxy(
createNavigationDelegate: CapturingNavigationDelegate.new,
createUIDelegate: WKUIDelegate.detached,
),
),
);

final Completer<UrlChange> urlChangeCompleter = Completer<UrlChange>();
navigationDelegate.setOnUrlChange(
(UrlChange change) => urlChangeCompleter.complete(change),
);

await controller.setPlatformNavigationDelegate(navigationDelegate);

webViewObserveValue(
'URL',
mockWebView,
<NSKeyValueChangeKey, Object?>{NSKeyValueChangeKey.newValue: null},
);

final UrlChange urlChange = await urlChangeCompleter.future;
expect(urlChange.url, isNull);
});

test('webViewIdentifier', () {
final InstanceManager instanceManager = InstanceManager(
onWeakReferenceRemoved: (_) {},
Expand Down