Skip to content

Commit

Permalink
Assert that several private protocol methods are never called when as…
Browse files Browse the repository at this point in the history
…ync interactions are enabled

https://bugs.webkit.org/show_bug.cgi?id=264522
rdar://118202852

Reviewed by Tim Horton, Megan Gardner and Abrar Rahman Protyasha.

Add several release assertions to make it easier to identify cases where legacy UIKit SPIs are still
being exercised, in the case where these SPI methods are invoked, but the async interactions are
enabled in WebKit.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView startAutoscroll:]):
(-[WKContentView scrollSelectionToVisible:]):
(-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
(-[WKContentView applyAutocorrection:toString:isCandidate:withCompletionHandler:]):
(-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
(-[WKContentView modifierFlagsDidChangeFrom:to:]):
(-[WKContentView handleKeyWebEvent:withCompletionHandler:]):
(-[WKContentView _internalHandleKeyWebEvent:withCompletionHandler:]):
(-[WKContentView requestRVItemInSelectedRangeWithCompletionHandler:]):
(-[WKContentView prepareSelectionForContextMenuWithLocationInView:completionHandler:]):
(-[WKContentView handleAsyncKeyEvent:withCompletionHandler:]):
(-[WKContentView handleKeyWebEvent:]): Deleted.

Canonical link: https://commits.webkit.org/270497@main
  • Loading branch information
whsieh committed Nov 10, 2023
1 parent fde8b31 commit 8fa45e3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,13 @@ - (void)_internalContextMenuInteraction:(UIContextMenuInteraction *)interaction
#endif
@end

#define RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED() do { \
if (UNLIKELY(self.shouldUseAsyncInteractions)) { \
RELEASE_LOG_ERROR(TextInteraction, "Received unexpected call to %s", __PRETTY_FUNCTION__); \
RELEASE_ASSERT_NOT_REACHED(); \
} \
} while (0)

@implementation WKContentView (WKInteraction)

- (BOOL)preventsPanningInXAxis
Expand Down Expand Up @@ -1516,6 +1523,8 @@ - (CGRect)unobscuredContentRect

- (void)startAutoscroll:(CGPoint)pointInDocument
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

_page->startAutoscrollAtPosition(pointInDocument);
}

Expand All @@ -1526,6 +1535,7 @@ - (void)cancelAutoscroll

- (void)scrollSelectionToVisible:(BOOL)animated
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();
// Used to scroll selection on keyboard up; we already scroll to visible.
}

Expand Down Expand Up @@ -4876,6 +4886,8 @@ - (void)moveByOffset:(NSInteger)offset
// The completion handler can pass nil if input does not match the actual text preceding the insertion point.
- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

if (!completionHandler) {
[NSException raise:NSInvalidArgumentException format:@"Expected a nonnull completion handler in %s.", __PRETTY_FUNCTION__];
return;
Expand Down Expand Up @@ -5288,6 +5300,8 @@ - (void)replaceDictatedText:(NSString*)oldText withText:(NSString *)newText
// The completion handler should pass the rect of the correction text after replacing the input text, or nil if the replacement could not be performed.
- (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input isCandidate:(BOOL)isCandidate withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForCorrection))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self _internalReplaceText:input withText:correction isCandidate:isCandidate completion:[completionHandler = makeBlockPtr(completionHandler), view = retainPtr(self)](bool wasApplied) {
completionHandler(wasApplied ? [WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:view->_autocorrectionData.textFirstRect lastCGRect:view->_autocorrectionData.textLastRect] : nil);
}];
Expand Down Expand Up @@ -5334,6 +5348,8 @@ - (void)_cancelPendingAutocorrectionContextHandler

- (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

if (!completionHandler) {
[NSException raise:NSInvalidArgumentException format:@"Expected a nonnull completion handler in %s.", __PRETTY_FUNCTION__];
return;
Expand Down Expand Up @@ -6724,7 +6740,14 @@ - (void)handleKeyWebEvent:(::WebEvent *)theEvent
_page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent, WebKit::NativeWebKeyboardEvent::HandledByInputMethod::No));
}

- (void)handleKeyWebEvent:(::WebEvent *)theEvent withCompletionHandler:(void (^)(::WebEvent *theEvent, BOOL wasHandled))completionHandler
- (void)handleKeyWebEvent:(::WebEvent *)event withCompletionHandler:(void (^)(::WebEvent *theEvent, BOOL wasHandled))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self _internalHandleKeyWebEvent:event withCompletionHandler:completionHandler];
}

- (void)_internalHandleKeyWebEvent:(::WebEvent *)theEvent withCompletionHandler:(void (^)(::WebEvent *theEvent, BOOL wasHandled))completionHandler
{
if (!isUIThread()) {
RELEASE_LOG_FAULT(KeyHandling, "%s was invoked on a background thread.", __PRETTY_FUNCTION__);
Expand Down Expand Up @@ -8258,6 +8281,8 @@ - (BOOL)supportsTextSelectionWithCharacterGranularity
#if ENABLE(REVEAL)
- (void)requestRVItemInSelectedRangeWithCompletionHandler:(void(^)(RVItem *item))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

_page->requestRVItemInCurrentSelectedRange([completionHandler = makeBlockPtr(completionHandler), weakSelf = WeakObjCPtr<WKContentView>(self)](const WebKit::RevealItem& item) {
auto strongSelf = weakSelf.get();
if (!strongSelf)
Expand All @@ -8269,6 +8294,8 @@ - (void)requestRVItemInSelectedRangeWithCompletionHandler:(void(^)(RVItem *item)

- (void)prepareSelectionForContextMenuWithLocationInView:(CGPoint)locationInView completionHandler:(void(^)(BOOL shouldPresentMenu, RVItem *item))completionHandler
{
RELEASE_ASSERT_ASYNC_TEXT_INTERACTIONS_DISABLED();

[self _internalSelectTextForContextMenuWithLocationInView:locationInView completionHandler:[completionHandler = makeBlockPtr(completionHandler)](BOOL shouldPresentMenu, const WebKit::RevealItem& item) {
completionHandler(shouldPresentMenu, item.item());
}];
Expand Down Expand Up @@ -11983,7 +12010,7 @@ - (void)setAsyncSystemInputDelegate:(id<UIAsyncTextInputDelegate>)delegate
- (void)handleAsyncKeyEvent:(UIKeyEvent *)event withCompletionHandler:(void(^)(UIKeyEvent *, BOOL))completionHandler
{
auto webEvent = adoptNS([[::WebEvent alloc] initWithUIKeyEvent:event]);
[self handleKeyWebEvent:webEvent.get() withCompletionHandler:[originalEvent = retainPtr(event), completionHandler = makeBlockPtr(completionHandler)](::WebEvent *webEvent, BOOL handled) {
[self _internalHandleKeyWebEvent:webEvent.get() withCompletionHandler:[originalEvent = retainPtr(event), completionHandler = makeBlockPtr(completionHandler)](::WebEvent *webEvent, BOOL handled) {
ASSERT(webEvent.originalUIKeyEvent == originalEvent);
completionHandler(originalEvent.get(), handled);
}];
Expand Down

0 comments on commit 8fa45e3

Please sign in to comment.