[Windows] Fix FlutterWindow::GetNativeViewAccessible crash (flutter/engine#43368)

Flutter shouldn't crash if a view's `HWND` receives a `WM_GETOBJECT` message before it is attached to the view.

Fixes https://github.com/flutter/flutter/issues/129791

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Loïc Sharma
2023-07-05 10:27:03 -07:00
committed by GitHub
parent 45ac2b64e6
commit 8bc45a996f
2 changed files with 13 additions and 0 deletions

View File

@@ -279,6 +279,10 @@ bool FlutterWindow::OnBitmapSurfaceUpdated(const void* allocation,
}
gfx::NativeViewAccessible FlutterWindow::GetNativeViewAccessible() {
if (binding_handler_delegate_ == nullptr) {
return nullptr;
}
return binding_handler_delegate_->GetNativeViewAccessible();
}

View File

@@ -272,6 +272,15 @@ TEST(FlutterWindowTest, OnThemeChange) {
win32window.InjectWindowMessage(WM_THEMECHANGED, 0, 0);
}
// The window should return no root accessibility node if
// it isn't attached to a view.
// Regression test for https://github.com/flutter/flutter/issues/129791
TEST(FlutterWindowTest, AccessibilityNodeWithoutView) {
MockFlutterWindow win32window;
EXPECT_EQ(win32window.GetNativeViewAccessible(), nullptr);
}
TEST(FlutterWindowTest, InitialAccessibilityFeatures) {
MockFlutterWindow win32window;
MockWindowBindingHandlerDelegate delegate;