diff --git a/ui/views/bubble/bubble_dialog_model_host.cc b/ui/views/bubble/bubble_dialog_model_host.cc index 7e6417ba5ea20..7392795d870cb 100644 --- a/ui/views/bubble/bubble_dialog_model_host.cc +++ b/ui/views/bubble/bubble_dialog_model_host.cc @@ -1073,6 +1073,17 @@ View* BubbleDialogModelHost::GetInitiallyFocusedView() { model_->GetFieldByUniqueId(unique_id))); } +bool BubbleDialogModelHost::ShouldAllowKeyEventsDuringInputProtection() const { + // ui::DialogModel::Builder::SetInitiallyFocusedField() is commonly used to + // give the OK button initial keyboard focus. Without this override, an Enter + // or Space key press that the user was already issuing when the dialog + // appeared bypasses InputEventActivationProtector's time-based gate (it + // returns false for key events when allow_key_events=true). Mirror + // ExternalProtocolDialog / ExtensionInstallDialogView and subject key events + // to the same protection window as mouse clicks. + return false; +} + void BubbleDialogModelHost::OnWidgetInitialized() { // Dialog buttons are added on dialog initialization. UpdateDialogButtons(); diff --git a/ui/views/bubble/bubble_dialog_model_host.h b/ui/views/bubble/bubble_dialog_model_host.h index a577ffb9a94c2..e05eaa00b2cd5 100644 --- a/ui/views/bubble/bubble_dialog_model_host.h +++ b/ui/views/bubble/bubble_dialog_model_host.h @@ -115,6 +115,7 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegate, // TODO(pbos): Populate initparams with initial view instead of overriding // GetInitiallyFocusedView(). View* GetInitiallyFocusedView() override; + bool ShouldAllowKeyEventsDuringInputProtection() const override; void OnWidgetInitialized() override; bool OnCloseRequested(views::Widget::ClosedReason close_reason) override;