diff --git a/chrome/browser/ui/views/autofill/popup/popup_view_views.cc b/chrome/browser/ui/views/autofill/popup/popup_view_views.cc index c4b19c7292bdf..260e20eeb2076 100644 --- a/chrome/browser/ui/views/autofill/popup/popup_view_views.cc +++ b/chrome/browser/ui/views/autofill/popup/popup_view_views.cc @@ -323,7 +323,10 @@ bool PopupViewViews::Show( MaybeAnnounceCurrentTabAndFootnote(); MaybeAnnouncePasswordRecoveryPopup(); MaybeAnnounceLoadingState(); - MaybeA11yFocusInformationalSuggestion(); + if (!MaybeA11yFocusInformationalSuggestion()) { + // `this` was destroyed during the synchronous a11y event dispatch. + return false; + } return !CanActivate() || (GetWidget() && GetWidget()->IsActive()); } @@ -811,7 +814,10 @@ void PopupViewViews::OnSuggestionsChanged(bool prefer_prev_arrow_side) { MaybeAutoSelectSuggestion(); MaybeAnnouncePasswordRecoveryPopup(); MaybeAnnounceLoadingState(); - MaybeA11yFocusInformationalSuggestion(); + if (!MaybeA11yFocusInformationalSuggestion()) { + // `this` was destroyed during the synchronous a11y event dispatch. + return; + } ShowIPHFeaturePromos(); } @@ -1690,21 +1696,23 @@ bool PopupViewViews::SelectParentPopupContentCell() { return true; } -void PopupViewViews::MaybeA11yFocusInformationalSuggestion() { +bool PopupViewViews::MaybeA11yFocusInformationalSuggestion() { if (rows_.size() != 1) { - return; + return true; } if (auto* warning_view = std::get_if(&rows_[0]); warning_view && *warning_view) { PopupWarningView* view_ptr = *warning_view; - TrackAndRun( + return TrackAndRun( view_ptr, [this, view_ptr]() { NotifyAXSelection(*view_ptr); }, [view_ptr]() { view_ptr->NotifyAccessibilityEventDeprecated(ax::mojom::Event::kFocus, true); }); } + + return true; } base::WeakPtr PopupViewViews::GetWeakPtr() { diff --git a/chrome/browser/ui/views/autofill/popup/popup_view_views.h b/chrome/browser/ui/views/autofill/popup/popup_view_views.h index f984cc3acc95a..f4f81ea78df3b 100644 --- a/chrome/browser/ui/views/autofill/popup/popup_view_views.h +++ b/chrome/browser/ui/views/autofill/popup/popup_view_views.h @@ -328,8 +328,10 @@ class PopupViewViews : public PopupBaseView, // suggestion with a special type in this case. This method makes sure // the suggestion's message is being announced to the user by focusing the row // view (which must be selectable). Currently, only `PopupWarningView` is - // supported. - void MaybeA11yFocusInformationalSuggestion(); + // supported. Returns `false` if `this` was destroyed during the synchronous + // accessibility event dispatch (Windows ::NotifyWinEvent may pump a nested + // message loop). + [[nodiscard]] bool MaybeA11yFocusInformationalSuggestion(); // Controller for this view. base::WeakPtr controller_ = nullptr;