Skip to content

Commit 0a12f2c

Browse files
[webview_flutter_wkwebview] Fixes internal enum type and adds unknown enum values (flutter#3812)
Followup from flutter/packages#3543 (comment)
1 parent 41aba5c commit 0a12f2c

File tree

11 files changed

+55
-312
lines changed

11 files changed

+55
-312
lines changed

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.4.1
2+
3+
* Fixes internal type conversion error.
4+
* Adds internal unknown enum values to handle api updates.
5+
16
## 3.4.0
27

38
* Adds support for `PlatformWebViewController.setOnPlatformPermissionRequest`.

packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,14 @@ - (void)testFWFWKMediaCaptureTypeDataFromWKMediaCaptureType API_AVAILABLE(ios(15
155155
.value,
156156
FWFWKMediaCaptureTypeCameraAndMicrophone);
157157
}
158+
159+
- (void)testNSKeyValueChangeKeyConversionReturnsUnknownIfUnrecognized {
160+
XCTAssertEqual(
161+
FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey(@"SomeUnknownValue").value,
162+
FWFNSKeyValueChangeKeyEnumUnknown);
163+
}
164+
165+
- (void)testWKNavigationTypeConversionReturnsUnknownIfUnrecognized {
166+
XCTAssertEqual(FWFWKNavigationTypeFromNativeWKNavigationType(-15), FWFWKNavigationTypeUnknown);
167+
}
158168
@end

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern FWFNSErrorData *FWFNSErrorDataFromNativeNSError(NSError *error);
137137
*
138138
* @param key The data object containing information to create a FWFNSKeyValueChangeKeyEnumData.
139139
*
140-
* @return A FWFNSKeyValueChangeKeyEnumData or nil if data could not be converted.
140+
* @return A FWFNSKeyValueChangeKeyEnumData.
141141
*/
142142
extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey(
143143
NSKeyValueChangeKey key);

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ WKNavigationActionPolicy FWFNativeWKNavigationActionPolicyFromEnumData(
210210
makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior];
211211
} else if ([key isEqualToString:NSKeyValueChangeOldKey]) {
212212
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue];
213+
} else {
214+
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumUnknown];
213215
}
214216

215217
return nil;
@@ -234,6 +236,8 @@ FWFWKNavigationType FWFWKNavigationTypeFromNativeWKNavigationType(WKNavigationTy
234236
case WKNavigationTypeOther:
235237
return FWFWKNavigationTypeOther;
236238
}
239+
240+
return FWFWKNavigationTypeUnknown;
237241
}
238242

239243
FWFWKSecurityOriginData *FWFWKSecurityOriginDataFromNativeWKSecurityOrigin(

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef NS_ENUM(NSUInteger, FWFNSKeyValueChangeKeyEnum) {
4343
FWFNSKeyValueChangeKeyEnumNewValue = 2,
4444
FWFNSKeyValueChangeKeyEnumNotificationIsPrior = 3,
4545
FWFNSKeyValueChangeKeyEnumOldValue = 4,
46+
FWFNSKeyValueChangeKeyEnumUnknown = 5,
4647
};
4748

4849
/// Mirror of WKUserScriptInjectionTime.
@@ -143,6 +144,11 @@ typedef NS_ENUM(NSUInteger, FWFWKNavigationType) {
143144
/// See
144145
/// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc.
145146
FWFWKNavigationTypeOther = 5,
147+
/// An unknown navigation type.
148+
///
149+
/// This does not represent an actual value provided by the platform and only
150+
/// indicates a value was provided that isn't currently supported.
151+
FWFWKNavigationTypeUnknown = 6,
146152
};
147153

148154
/// Possible permission decisions for device resource access.
@@ -186,6 +192,9 @@ typedef NS_ENUM(NSUInteger, FWFWKMediaCaptureType) {
186192
/// https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypemicrophone?language=objc.
187193
FWFWKMediaCaptureTypeMicrophone = 2,
188194
/// An unknown media device.
195+
///
196+
/// This does not represent an actual value provided by the platform and only
197+
/// indicates a value was provided that isn't currently supported.
189198
FWFWKMediaCaptureTypeUnknown = 3,
190199
};
191200

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (void)requestMediaCapturePermissionForDelegateWithIdentifier:(FWFUIDelegate *)
6161
webView:(WKWebView *)webView
6262
origin:(WKSecurityOrigin *)origin
6363
frame:(WKFrameInfo *)frame
64-
type:(FWFWKMediaCaptureType)type
64+
type:(WKMediaCaptureType)type
6565
completion:
6666
(void (^)(WKPermissionDecision))completion
6767
API_AVAILABLE(ios(15.0)) {

packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum NSKeyValueChangeKeyEnum {
4040
newValue,
4141
notificationIsPrior,
4242
oldValue,
43+
unknown,
4344
}
4445

4546
/// Mirror of WKUserScriptInjectionTime.
@@ -136,6 +137,12 @@ enum WKNavigationType {
136137
///
137138
/// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc.
138139
other,
140+
141+
/// An unknown navigation type.
142+
///
143+
/// This does not represent an actual value provided by the platform and only
144+
/// indicates a value was provided that isn't currently supported.
145+
unknown,
139146
}
140147

141148
/// Possible permission decisions for device resource access.
@@ -178,6 +185,9 @@ enum WKMediaCaptureType {
178185
microphone,
179186

180187
/// An unknown media device.
188+
///
189+
/// This does not represent an actual value provided by the platform and only
190+
/// indicates a value was provided that isn't currently supported.
181191
unknown,
182192
}
183193

packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ enum NSKeyValueChangeKey {
9191
///
9292
/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangeoldkey?language=objc.
9393
oldValue,
94+
95+
/// An unknown change key.
96+
///
97+
/// This does not represent an actual value provided by the platform and only
98+
/// indicates a value was provided that isn't currently supported.
99+
unknown,
94100
}
95101

96102
/// The supported keys in a cookie attributes dictionary.

packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum NSKeyValueChangeKeyEnum {
5959
newValue,
6060
notificationIsPrior,
6161
oldValue,
62+
unknown,
6263
}
6364

6465
// TODO(bparrishMines): Enums need be wrapped in a data class because thay can't
@@ -191,6 +192,12 @@ enum WKNavigationType {
191192
///
192193
/// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc.
193194
other,
195+
196+
/// An unknown navigation type.
197+
///
198+
/// This does not represent an actual value provided by the platform and only
199+
/// indicates a value was provided that isn't currently supported.
200+
unknown,
194201
}
195202

196203
/// Possible permission decisions for device resource access.
@@ -241,7 +248,7 @@ enum WKMediaCaptureType {
241248
/// An unknown media device.
242249
///
243250
/// This does not represent an actual value provided by the platform and only
244-
/// indicates a value was provided that we don't currently support.
251+
/// indicates a value was provided that isn't currently supported.
245252
unknown,
246253
}
247254

packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: webview_flutter_wkwebview
22
description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control.
33
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
5-
version: 3.4.0
5+
version: 3.4.1
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)