Skip to content

Commit

Permalink
[webview_flutter_wkwebview] Fixes internal enum type and adds unknown…
Browse files Browse the repository at this point in the history
… enum values (#3812)

Followup from flutter/packages#3543 (comment)
  • Loading branch information
bparrishMines authored May 2, 2023
1 parent 4fcd99f commit 3b7e069
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 312 deletions.
5 changes: 5 additions & 0 deletions webview_flutter_wkwebview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ WKNavigationActionPolicy FWFNativeWKNavigationActionPolicyFromEnumData(
makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior];
} else if ([key isEqualToString:NSKeyValueChangeOldKey]) {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue];
} else {
return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumUnknown];
}

return nil;
Expand All @@ -234,6 +236,8 @@ FWFWKNavigationType FWFWKNavigationTypeFromNativeWKNavigationType(WKNavigationTy
case WKNavigationTypeOther:
return FWFWKNavigationTypeOther;
}

return FWFWKNavigationTypeUnknown;
}

FWFWKSecurityOriginData *FWFWKSecurityOriginDataFromNativeWKSecurityOrigin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef NS_ENUM(NSUInteger, FWFNSKeyValueChangeKeyEnum) {
FWFNSKeyValueChangeKeyEnumNewValue = 2,
FWFNSKeyValueChangeKeyEnumNotificationIsPrior = 3,
FWFNSKeyValueChangeKeyEnumOldValue = 4,
FWFNSKeyValueChangeKeyEnumUnknown = 5,
};

/// Mirror of WKUserScriptInjectionTime.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
10 changes: 10 additions & 0 deletions webview_flutter_wkwebview/lib/src/common/web_kit.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum NSKeyValueChangeKeyEnum {
newValue,
notificationIsPrior,
oldValue,
unknown,
}

/// Mirror of WKUserScriptInjectionTime.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}

Expand Down
6 changes: 6 additions & 0 deletions webview_flutter_wkwebview/lib/src/foundation/foundation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion webview_flutter_wkwebview/pigeons/web_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum NSKeyValueChangeKeyEnum {
newValue,
notificationIsPrior,
oldValue,
unknown,
}

// TODO(bparrishMines): Enums need be wrapped in a data class because thay can't
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion webview_flutter_wkwebview/pubspec.yaml
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.0
version: 3.4.1

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Loading

0 comments on commit 3b7e069

Please sign in to comment.