Skip to content

Commit

Permalink
[iOS 17.4] Blink crashes on launch due to an unrecognized selector on…
Browse files Browse the repository at this point in the history
… WKExtendedTextInputTraits

https://bugs.webkit.org/show_bug.cgi?id=268667
rdar://122025854

Reviewed by Tim Horton.

Maintain binary compatibility with third party apps that reach into `WKContentView`'s internal text
input traits object, and expect it to implement all the API methods on `UITextInputTraits`. This was
previously the case when async text input was disabled, because the internal text input traits would
be a concrete `UITextInputTraits` instance which implements all of the optional properties (as well
as all the properties on `UITextInputTraits_Private`).

We lost this when implementing our own `WKExtendedTextInputTraits` that implements the new
`BEExtendedTextInputTraits` protocol from BrowserEngineKit, since this new class only implements
the properties that we internally set in WebKit, along with the new extended traits.

We should instead ensure binary compatibility when using `WKExtendedTextInputTraits` by (at least)
implementing all of the optional properties on `UITextInputTraits` and `WKExtendedTextInputTraits`,
and ensuring that they have default values that mostly* match the default values described in
`<UIKit/UITextInputTraits.h>`.

Test: KeyboardInputTests.ImplementAllOptionalTextInputTraits

* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.h:
* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm:
(-[WKExtendedTextInputTraits init]):
(-[WKExtendedTextInputTraits setPasswordRules:]):
(-[WKExtendedTextInputTraits passwordRules]):
(-[WKExtendedTextInputTraits textContentType]):
* Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:

Add a test that sanity checks all public properties on our text input traits and verifies that the
default values are consistent with UIKit/BrowserEngineKit documentation.

*   Note that this test intentionally leaves out `inlinePredictionType` and `autocorrectionType`,
    since those both have default values in WebKit that are `no`. It's unclear if this is
    intentional, but I'm leaving this behavior intact for now.

Canonical link: https://commits.webkit.org/274035@main
  • Loading branch information
whsieh committed Feb 3, 2024
1 parent 3a3309b commit 674f7d1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
@property (nonatomic) UITextSpellCheckingType spellCheckingType;
@property (nonatomic) UITextSmartQuotesType smartQuotesType;
@property (nonatomic) UITextSmartDashesType smartDashesType;
#if HAVE(INLINE_PREDICTIONS)
@property (nonatomic) UITextInlinePredictionType inlinePredictionType;
#endif
@property (nonatomic) UIKeyboardType keyboardType;
@property (nonatomic) UIKeyboardAppearance keyboardAppearance;
@property (nonatomic) UIReturnKeyType returnKeyType;
Expand All @@ -53,6 +55,9 @@
@property (nonatomic) BOOL typingAdaptationDisabled;
#endif
@property (nonatomic, copy) UITextContentType textContentType;
@property (nonatomic, copy) UITextInputPasswordRules *passwordRules;
@property (nonatomic) UITextSmartInsertDeleteType smartInsertDeleteType;
@property (nonatomic) BOOL enablesReturnKeyAutomatically;

@property (nonatomic, strong) UIColor *insertionPointColor;
#if USE(BROWSERENGINEKIT)
Expand Down
25 changes: 24 additions & 1 deletion Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ @implementation WKExtendedTextInputTraits {
RetainPtr<UIColor> _insertionPointColor;
RetainPtr<UIColor> _selectionHandleColor;
RetainPtr<UIColor> _selectionHighlightColor;
RetainPtr<UITextInputPasswordRules> _passwordRules;
}

- (instancetype)init
{
if (!(self = [super init]))
return nil;

#if USE(BROWSERENGINEKIT)
self.typingAdaptationEnabled = YES;
#endif
self.autocapitalizationType = UITextAutocapitalizationTypeSentences;
return self;
}

- (void)setPasswordRules:(UITextInputPasswordRules *)rules
{
_passwordRules = adoptNS(rules.copy);
}

- (UITextInputPasswordRules *)passwordRules
{
return adoptNS([_passwordRules copy]).autorelease();
}

- (void)setTextContentType:(UITextContentType)type
Expand All @@ -44,7 +67,7 @@ - (void)setTextContentType:(UITextContentType)type

- (UITextContentType)textContentType
{
return _textContentType.get();
return adoptNS([_textContentType copy]).autorelease();
}

- (void)setInsertionPointColor:(UIColor *)color
Expand Down
26 changes: 26 additions & 0 deletions Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,32 @@ static BOOL allowESIMAutoFillForWebKitDomains(id, SEL, NSString *domain, NSError

#endif // HAVE(ESIM_AUTOFILL_SYSTEM_SUPPORT)

TEST(KeyboardInputTests, ImplementAllOptionalTextInputTraits)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]);
auto traits = [webView effectiveTextInputTraits];
EXPECT_EQ(traits.autocapitalizationType, UITextAutocapitalizationTypeSentences);
EXPECT_EQ(traits.spellCheckingType, UITextSpellCheckingTypeDefault);
EXPECT_EQ(traits.smartQuotesType, UITextSmartQuotesTypeDefault);
EXPECT_EQ(traits.smartDashesType, UITextSmartDashesTypeDefault);
EXPECT_EQ(traits.smartInsertDeleteType, UITextSmartInsertDeleteTypeDefault);
EXPECT_EQ(traits.keyboardType, UIKeyboardTypeDefault);
EXPECT_EQ(traits.keyboardAppearance, UIKeyboardAppearanceDefault);
EXPECT_EQ(traits.returnKeyType, UIReturnKeyDefault);
EXPECT_FALSE(traits.enablesReturnKeyAutomatically);
EXPECT_FALSE(traits.secureTextEntry);
EXPECT_NULL(traits.textContentType);
EXPECT_NULL(traits.passwordRules);
#if USE(BROWSERENGINEKIT)
auto extendedTraits = [webView extendedTextInputTraits];
EXPECT_FALSE(extendedTraits.singleLineDocument);
EXPECT_TRUE(extendedTraits.typingAdaptationEnabled);
EXPECT_NULL(extendedTraits.insertionPointColor);
EXPECT_NULL(extendedTraits.selectionHandleColor);
EXPECT_NULL(extendedTraits.selectionHighlightColor);
#endif
}

} // namespace TestWebKitAPI

#endif // PLATFORM(IOS_FAMILY)

0 comments on commit 674f7d1

Please sign in to comment.