From 3b7e0693ddd7f6ba919e2c1af7ffec1a46c9c2df Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 2 May 2023 12:39:00 -0400 Subject: [PATCH] [webview_flutter_wkwebview] Fixes internal enum type and adds unknown enum values (#3812) Followup from https://github.com/flutter/packages/pull/3543#discussion_r1170129830 --- webview_flutter_wkwebview/CHANGELOG.md | 5 + .../ios/RunnerTests/FWFDataConvertersTests.m | 10 + .../ios/Classes/FWFDataConverters.h | 2 +- .../ios/Classes/FWFDataConverters.m | 4 + .../ios/Classes/FWFGeneratedWebKitApis.h | 9 + .../ios/Classes/FWFUIDelegateHostApi.m | 2 +- .../lib/src/common/web_kit.g.dart | 10 + .../lib/src/foundation/foundation.dart | 6 + .../pigeons/web_kit.dart | 9 +- webview_flutter_wkwebview/pubspec.yaml | 2 +- ...webkit_navigation_delegate_test.mocks.dart | 308 ------------------ 11 files changed, 55 insertions(+), 312 deletions(-) delete mode 100644 webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart diff --git a/webview_flutter_wkwebview/CHANGELOG.md b/webview_flutter_wkwebview/CHANGELOG.md index 1041b12..c43051a 100644 --- a/webview_flutter_wkwebview/CHANGELOG.md +++ b/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.4.1 + +* Fixes internal type conversion error. +* Adds internal unknown enum values to handle api updates. + ## 3.4.0 * Adds support for `PlatformWebViewController.setOnPlatformPermissionRequest`. diff --git a/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m b/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m index 82bf99c..f580b60 100644 --- a/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m +++ b/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m @@ -155,4 +155,14 @@ - (void)testFWFWKMediaCaptureTypeDataFromWKMediaCaptureType API_AVAILABLE(ios(15 .value, FWFWKMediaCaptureTypeCameraAndMicrophone); } + +- (void)testNSKeyValueChangeKeyConversionReturnsUnknownIfUnrecognized { + XCTAssertEqual( + FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey(@"SomeUnknownValue").value, + FWFNSKeyValueChangeKeyEnumUnknown); +} + +- (void)testWKNavigationTypeConversionReturnsUnknownIfUnrecognized { + XCTAssertEqual(FWFWKNavigationTypeFromNativeWKNavigationType(-15), FWFWKNavigationTypeUnknown); +} @end diff --git a/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h b/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h index d66767b..005cecb 100644 --- a/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h +++ b/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h @@ -137,7 +137,7 @@ extern FWFNSErrorData *FWFNSErrorDataFromNativeNSError(NSError *error); * * @param key The data object containing information to create a FWFNSKeyValueChangeKeyEnumData. * - * @return A FWFNSKeyValueChangeKeyEnumData or nil if data could not be converted. + * @return A FWFNSKeyValueChangeKeyEnumData. */ extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey( NSKeyValueChangeKey key); diff --git a/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 8b63d83..20607da 100644 --- a/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -210,6 +210,8 @@ WKNavigationActionPolicy FWFNativeWKNavigationActionPolicyFromEnumData( makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior]; } else if ([key isEqualToString:NSKeyValueChangeOldKey]) { return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue]; + } else { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumUnknown]; } return nil; @@ -234,6 +236,8 @@ FWFWKNavigationType FWFWKNavigationTypeFromNativeWKNavigationType(WKNavigationTy case WKNavigationTypeOther: return FWFWKNavigationTypeOther; } + + return FWFWKNavigationTypeUnknown; } FWFWKSecurityOriginData *FWFWKSecurityOriginDataFromNativeWKSecurityOrigin( diff --git a/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h b/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h index a5c7601..45b1e42 100644 --- a/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h +++ b/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h @@ -43,6 +43,7 @@ typedef NS_ENUM(NSUInteger, FWFNSKeyValueChangeKeyEnum) { FWFNSKeyValueChangeKeyEnumNewValue = 2, FWFNSKeyValueChangeKeyEnumNotificationIsPrior = 3, FWFNSKeyValueChangeKeyEnumOldValue = 4, + FWFNSKeyValueChangeKeyEnumUnknown = 5, }; /// Mirror of WKUserScriptInjectionTime. @@ -143,6 +144,11 @@ typedef NS_ENUM(NSUInteger, FWFWKNavigationType) { /// See /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. FWFWKNavigationTypeOther = 5, + /// An unknown navigation type. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + FWFWKNavigationTypeUnknown = 6, }; /// Possible permission decisions for device resource access. @@ -186,6 +192,9 @@ typedef NS_ENUM(NSUInteger, FWFWKMediaCaptureType) { /// https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypemicrophone?language=objc. FWFWKMediaCaptureTypeMicrophone = 2, /// An unknown media device. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. FWFWKMediaCaptureTypeUnknown = 3, }; diff --git a/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 9615e7f..a701050 100644 --- a/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -61,7 +61,7 @@ - (void)requestMediaCapturePermissionForDelegateWithIdentifier:(FWFUIDelegate *) webView:(WKWebView *)webView origin:(WKSecurityOrigin *)origin frame:(WKFrameInfo *)frame - type:(FWFWKMediaCaptureType)type + type:(WKMediaCaptureType)type completion: (void (^)(WKPermissionDecision))completion API_AVAILABLE(ios(15.0)) { diff --git a/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart b/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart index 92372f2..2ce5055 100644 --- a/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart +++ b/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart @@ -40,6 +40,7 @@ enum NSKeyValueChangeKeyEnum { newValue, notificationIsPrior, oldValue, + unknown, } /// Mirror of WKUserScriptInjectionTime. @@ -136,6 +137,12 @@ enum WKNavigationType { /// /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. other, + + /// An unknown navigation type. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, } /// Possible permission decisions for device resource access. @@ -178,6 +185,9 @@ enum WKMediaCaptureType { microphone, /// An unknown media device. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. unknown, } diff --git a/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index a9bbdc5..1c87b8b 100644 --- a/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -91,6 +91,12 @@ enum NSKeyValueChangeKey { /// /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangeoldkey?language=objc. oldValue, + + /// An unknown change key. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, } /// The supported keys in a cookie attributes dictionary. diff --git a/webview_flutter_wkwebview/pigeons/web_kit.dart b/webview_flutter_wkwebview/pigeons/web_kit.dart index bb588bd..20d4ee4 100644 --- a/webview_flutter_wkwebview/pigeons/web_kit.dart +++ b/webview_flutter_wkwebview/pigeons/web_kit.dart @@ -59,6 +59,7 @@ enum NSKeyValueChangeKeyEnum { newValue, notificationIsPrior, oldValue, + unknown, } // TODO(bparrishMines): Enums need be wrapped in a data class because thay can't @@ -191,6 +192,12 @@ enum WKNavigationType { /// /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. other, + + /// An unknown navigation type. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, } /// Possible permission decisions for device resource access. @@ -241,7 +248,7 @@ enum WKMediaCaptureType { /// An unknown media device. /// /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that we don't currently support. + /// indicates a value was provided that isn't currently supported. unknown, } diff --git a/webview_flutter_wkwebview/pubspec.yaml b/webview_flutter_wkwebview/pubspec.yaml index 915be55..e1f2e31 100644 --- a/webview_flutter_wkwebview/pubspec.yaml +++ b/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.4.0 +version: 3.4.1 environment: sdk: ">=2.18.0 <4.0.0" diff --git a/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart b/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart deleted file mode 100644 index e445f99..0000000 --- a/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart +++ /dev/null @@ -1,308 +0,0 @@ -// Mocks generated by Mockito 5.4.0 from annotations -// in webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; -import 'dart:ui' as _i6; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i5; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart' as _i3; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -class _FakeWKWebViewConfiguration_0 extends _i1.SmartFake - implements _i2.WKWebViewConfiguration { - _FakeWKWebViewConfiguration_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeUIScrollView_1 extends _i1.SmartFake implements _i3.UIScrollView { - _FakeUIScrollView_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWKWebView_2 extends _i1.SmartFake implements _i2.WKWebView { - _FakeWKWebView_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [WKWebView]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKWebView extends _i1.Mock implements _i2.WKWebView { - MockWKWebView() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.WKWebViewConfiguration get configuration => (super.noSuchMethod( - Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_0( - this, - Invocation.getter(#configuration), - ), - ) as _i2.WKWebViewConfiguration); - @override - _i3.UIScrollView get scrollView => (super.noSuchMethod( - Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_1( - this, - Invocation.getter(#scrollView), - ), - ) as _i3.UIScrollView); - @override - _i4.Future setUIDelegate(_i2.WKUIDelegate? delegate) => - (super.noSuchMethod( - Invocation.method( - #setUIDelegate, - [delegate], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setNavigationDelegate(_i2.WKNavigationDelegate? delegate) => - (super.noSuchMethod( - Invocation.method( - #setNavigationDelegate, - [delegate], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future getUrl() => (super.noSuchMethod( - Invocation.method( - #getUrl, - [], - ), - returnValue: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future getEstimatedProgress() => (super.noSuchMethod( - Invocation.method( - #getEstimatedProgress, - [], - ), - returnValue: _i4.Future.value(0.0), - ) as _i4.Future); - @override - _i4.Future loadRequest(_i5.NSUrlRequest? request) => - (super.noSuchMethod( - Invocation.method( - #loadRequest, - [request], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future loadHtmlString( - String? string, { - String? baseUrl, - }) => - (super.noSuchMethod( - Invocation.method( - #loadHtmlString, - [string], - {#baseUrl: baseUrl}, - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future loadFileUrl( - String? url, { - required String? readAccessUrl, - }) => - (super.noSuchMethod( - Invocation.method( - #loadFileUrl, - [url], - {#readAccessUrl: readAccessUrl}, - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future loadFlutterAsset(String? key) => (super.noSuchMethod( - Invocation.method( - #loadFlutterAsset, - [key], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future canGoBack() => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [], - ), - returnValue: _i4.Future.value(false), - ) as _i4.Future); - @override - _i4.Future canGoForward() => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [], - ), - returnValue: _i4.Future.value(false), - ) as _i4.Future); - @override - _i4.Future goBack() => (super.noSuchMethod( - Invocation.method( - #goBack, - [], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future goForward() => (super.noSuchMethod( - Invocation.method( - #goForward, - [], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future reload() => (super.noSuchMethod( - Invocation.method( - #reload, - [], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future getTitle() => (super.noSuchMethod( - Invocation.method( - #getTitle, - [], - ), - returnValue: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setAllowsBackForwardNavigationGestures(bool? allow) => - (super.noSuchMethod( - Invocation.method( - #setAllowsBackForwardNavigationGestures, - [allow], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( - Invocation.method( - #setCustomUserAgent, - [userAgent], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future evaluateJavaScript(String? javaScriptString) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavaScript, - [javaScriptString], - ), - returnValue: _i4.Future.value(), - ) as _i4.Future); - @override - _i2.WKWebView copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWKWebView_2( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WKWebView); - @override - _i4.Future setBackgroundColor(_i6.Color? color) => (super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [color], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setOpaque(bool? opaque) => (super.noSuchMethod( - Invocation.method( - #setOpaque, - [opaque], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future addObserver( - _i5.NSObject? observer, { - required String? keyPath, - required Set<_i5.NSKeyValueObservingOptions>? options, - }) => - (super.noSuchMethod( - Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future removeObserver( - _i5.NSObject? observer, { - required String? keyPath, - }) => - (super.noSuchMethod( - Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); -}