Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc |
| diff --git a/chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc b/chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc |
| index 8842a43d252a97c2bfbc1c7029109a0e5aaec212..bbc10745b7c2f025ab540c72dd4a9dc7d2e83e7e 100644 |
| --- a/chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc |
| +++ b/chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc |
| @@ -27,8 +27,7 @@ ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( |
| : views::BubbleDialogDelegateView(anchor_view, |
| views::BubbleBorder::TOP_RIGHT), |
| delegate_(std::move(delegate)), |
| - close_reason_( |
| - ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION), |
| + delegate_notified_of_close_(false), |
| item_list_(nullptr), |
| link_(nullptr), |
| anchored_to_action_(anchored_to_action) { |
| @@ -101,7 +100,13 @@ bool ToolbarActionsBarBubbleViews::Accept() { |
| } |
| bool ToolbarActionsBarBubbleViews::Close() { |
| - delegate_->OnBubbleClosed(close_reason_); |
| + // If delegate_->OnBubbleClosed() was called by LinkClicked(), the bubble may |
|
Devlin
2017/04/20 16:12:15
We could make this a little less corner-casey (and
tapted
2017/04/21 00:24:33
Done.
|
| + // close automatically in response to the delegate action (e.g. losing focus |
| + // when a tab is opened). |
| + if (!delegate_notified_of_close_) { |
| + delegate_->OnBubbleClosed( |
| + ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION); |
| + } |
| return true; |
| } |
| @@ -159,6 +164,14 @@ base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( |
| void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, |
| int event_flags) { |
| - close_reason_ = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE; |
| + delegate_notified_of_close_ = true; |
| + // Force the delegate action to happen here rather than in Close(). Close() is |
|
Devlin
2017/04/20 16:12:15
Similarly here, we could just have this be the nor
tapted
2017/04/21 00:24:33
Done.
|
| + // called from Widget::CanClose() so attempting to open a link there can cause |
| + // recursion. |
| + delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| + // Note that the Widget may or may not already be closed at this point, |
| + // depending on delegate_->ShouldCloseOnDeactivate(). Widget::Close() protects |
| + // against multiple calls (so long as they are not nested), and Widget |
| + // destruction is asynchronous, so it is safe to call Close() again. |
| GetWidget()->Close(); |
| } |