fix: check the root window in MenuBar::SetPanelFocus (#16581)

This commit is contained in:
Cheng Zhao 2019-01-30 06:21:32 +09:00 committed by Shelley Vohr
parent 940c4c0787
commit 323b688ab8

View file

@ -10,6 +10,7 @@
#include "atom/browser/ui/views/submenu_button.h"
#include "atom/common/keyboard_util.h"
#include "ui/aura/window.h"
#include "ui/base/models/menu_model.h"
#include "ui/views/background.h"
#include "ui/views/layout/box_layout.h"
@ -174,6 +175,27 @@ bool MenuBar::AcceleratorPressed(const ui::Accelerator& accelerator) {
}
bool MenuBar::SetPaneFocus(views::View* initial_focus) {
// TODO(zcbenz): Submit patch to upstream Chromium to fix the crash.
//
// Without this check, Electron would crash when running tests.
//
// Check failed: rules_->CanFocusWindow(window, nullptr).
// logging::LogMessage::~LogMessage
// wm::FocusController::SetFocusedWindow
// wm::FocusController::ResetFocusWithinActiveWindow
// views::View::OnFocus
// views::Button::OnFocus
// views::LabelButton::OnFocus
// views::View::Focus
// views::FocusManager::SetFocusedViewWithReason
// views::AccessiblePaneView::SetPaneFocus
// atom::MenuBar::SetPaneFocus
if (initial_focus && initial_focus->GetWidget()) {
aura::Window* window = initial_focus->GetWidget()->GetNativeWindow();
if (!window || !window->GetRootWindow())
return false;
}
bool result = views::AccessiblePaneView::SetPaneFocus(initial_focus);
if (result) {