From 8bc45a996f6c5496d96540b52382b9eee970921f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:27:03 -0700 Subject: [PATCH] [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 --- .../src/flutter/shell/platform/windows/flutter_window.cc | 4 ++++ .../shell/platform/windows/flutter_window_unittests.cc | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/engine/src/flutter/shell/platform/windows/flutter_window.cc b/engine/src/flutter/shell/platform/windows/flutter_window.cc index e5fbc89403..6dba8cadc3 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window.cc @@ -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(); } diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc index a4dd8bc611..e8ec282066 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_unittests.cc @@ -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;