Skip to content

[webview_flutter_wkwebview] Fixes internal enum type and adds unknown enum values #3812

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

Merged
merged 6 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,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
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code now.

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
Copy link
Contributor Author

@bparrishMines bparrishMines Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not causing an crash since all enums are represented by an NSInteger and the correct WKMediaCaptureType was still being passed. But this was causing the lint error:

error: implicit conversion from enumeration type 'FWFWKMediaCaptureType' (aka 'enum FWFWKMediaCaptureType') to different enumeration type 'WKMediaCaptureType' (aka 'enum WKMediaCaptureType') [-Werror,-Wenum-conversion]

completion:
(void (^)(WKPermissionDecision))completion
API_AVAILABLE(ios(15.0)) {
Expand Down
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
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
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
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