[iOS] Fix App crash when use WebView with iOS VoiceOver (flutter/engine#52484)

This PR fix the issue [flutter/flutter
#140528](https://github.com/flutter/flutter/issues/140528).

This fix cleans up declarations regarding `retain` and `release`.
`flutterAccessibilityContainer` needs to be managed in
`FlutterPlatformViews.mm`, and problems will occur if `retain` or
`release` is performed in `SemanticsObject.mm`.

This fix is checked by the `testFlutterPlatformViewSemanticsContainer`
function in the `SemanticsObjectTest.mm`.
The result is not changed.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
Kihara, Takuya
2024-05-10 12:40:41 +09:00
committed by GitHub
parent f0f469735d
commit fbab4c0057
4 changed files with 24 additions and 17 deletions

View File

@@ -981,10 +981,6 @@ void FlutterPlatformViewsController::ResetFrameState() {
fml::scoped_nsobject<DelayingGestureRecognizer> _delayingRecognizer;
FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy;
UIView* _embeddedView;
// The used as the accessiblityContainer.
// The `accessiblityContainer` is used in UIKit to determine the parent of this accessibility
// node.
NSObject* _flutterAccessibilityContainer;
}
- (instancetype)initWithEmbeddedView:(UIView*)embeddedView
platformViewsController:
@@ -1063,14 +1059,15 @@ void FlutterPlatformViewsController::ResetFrameState() {
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
}
- (void)setFlutterAccessibilityContainer:(NSObject*)flutterAccessibilityContainer {
_flutterAccessibilityContainer = flutterAccessibilityContainer;
}
- (id)accessibilityContainer {
return _flutterAccessibilityContainer;
}
- (void)dealloc {
[_flutterAccessibilityContainer release];
[super dealloc];
}
@end
@implementation DelayingGestureRecognizer {

View File

@@ -440,7 +440,7 @@ class FlutterPlatformViewsController {
- (UIView*)embeddedView;
// Sets flutterAccessibilityContainer as this view's accessibilityContainer.
- (void)setFlutterAccessibilityContainer:(NSObject*)flutterAccessibilityContainer;
@property(nonatomic, retain) id flutterAccessibilityContainer;
@end
@interface UIView (FirstResponder)

View File

@@ -867,7 +867,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
@end
@interface FlutterPlatformViewSemanticsContainer ()
@property(nonatomic, retain) UIView* platformView;
@property(nonatomic, assign) UIView* platformView;
@end
@implementation FlutterPlatformViewSemanticsContainer
@@ -876,14 +876,13 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
uid:(int32_t)uid
platformView:(nonnull FlutterTouchInterceptingView*)platformView {
if (self = [super initWithBridge:bridge uid:uid]) {
_platformView = [platformView retain];
_platformView = platformView;
[platformView setFlutterAccessibilityContainer:self];
}
return self;
}
- (void)dealloc {
[_platformView release];
_platformView = nil;
[super dealloc];
}

View File

@@ -994,19 +994,30 @@ FLUTTER_ASSERT_ARC
new flutter::testing::MockAccessibilityBridge());
fml::WeakPtr<flutter::testing::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
__weak FlutterTouchInterceptingView* weakPlatformView;
__weak FlutterPlatformViewSemanticsContainer* weakContainer;
@autoreleasepool {
FlutterTouchInterceptingView* platformView = [[FlutterTouchInterceptingView alloc] init];
weakPlatformView = platformView;
FlutterPlatformViewSemanticsContainer* container =
[[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge
uid:1
platformView:platformView];
XCTAssertEqualObjects(platformView.accessibilityContainer, container);
@autoreleasepool {
FlutterPlatformViewSemanticsContainer* container =
[[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge
uid:1
platformView:platformView];
weakContainer = container;
XCTAssertEqualObjects(platformView.accessibilityContainer, container);
XCTAssertNotNil(weakPlatformView);
XCTAssertNotNil(weakContainer);
}
// Check the variables are still lived.
// `container` is `retain` in `platformView`, so it will not be nil here.
XCTAssertNotNil(weakPlatformView);
XCTAssertNotNil(weakContainer);
}
// Check if there's no more strong references to `platformView` after container and platformView
// are released.
XCTAssertNil(weakPlatformView);
XCTAssertNil(weakContainer);
}
- (void)testTextInputSemanticsObject {