Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.cc

Issue 2762893002: Fix a lifetime issue in ToolbarActionsBarBubbleViews (Closed)
Patch Set: Update comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h"
6 6
7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
8 #include "chrome/browser/ui/views/harmony/layout_delegate.h" 7 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
9 #include "chrome/grit/locale_settings.h" 8 #include "chrome/grit/locale_settings.h"
10 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/paint_vector_icon.h" 11 #include "ui/gfx/paint_vector_icon.h"
13 #include "ui/views/controls/button/label_button.h" 12 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/link.h" 15 #include "ui/views/controls/link.h"
17 #include "ui/views/layout/box_layout.h" 16 #include "ui/views/layout/box_layout.h"
18 17
19 namespace { 18 namespace {
20 const int kIconSize = 16; 19 const int kIconSize = 16;
21 } 20 }
22 21
23 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( 22 ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews(
24 views::View* anchor_view, 23 views::View* anchor_view,
25 const gfx::Point& anchor_point, 24 const gfx::Point& anchor_point,
26 bool anchored_to_action, 25 bool anchored_to_action,
27 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate) 26 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate)
28 : views::BubbleDialogDelegateView(anchor_view, 27 : views::BubbleDialogDelegateView(anchor_view,
29 views::BubbleBorder::TOP_RIGHT), 28 views::BubbleBorder::TOP_RIGHT),
30 delegate_(std::move(delegate)), 29 delegate_(std::move(delegate)),
30 close_reason_(
31 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION),
31 item_list_(nullptr), 32 item_list_(nullptr),
32 link_(nullptr), 33 link_(nullptr),
33 anchored_to_action_(anchored_to_action) { 34 anchored_to_action_(anchored_to_action) {
34 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); 35 set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate());
35 if (!anchor_view) 36 if (!anchor_view)
36 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 37 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
37 } 38 }
38 39
39 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {} 40 ToolbarActionsBarBubbleViews::~ToolbarActionsBarBubbleViews() {}
40 41
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); 94 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION);
94 return true; 95 return true;
95 } 96 }
96 97
97 bool ToolbarActionsBarBubbleViews::Accept() { 98 bool ToolbarActionsBarBubbleViews::Accept() {
98 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); 99 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE);
99 return true; 100 return true;
100 } 101 }
101 102
102 bool ToolbarActionsBarBubbleViews::Close() { 103 bool ToolbarActionsBarBubbleViews::Close() {
103 if (delegate_) { 104 delegate_->OnBubbleClosed(close_reason_);
104 delegate_->OnBubbleClosed(
105 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION);
106 }
107 return true; 105 return true;
108 } 106 }
109 107
110 void ToolbarActionsBarBubbleViews::Init() { 108 void ToolbarActionsBarBubbleViews::Init() {
111 LayoutDelegate* delegate = LayoutDelegate::Get(); 109 LayoutDelegate* delegate = LayoutDelegate::Get();
112 SetLayoutManager(new views::BoxLayout( 110 SetLayoutManager(new views::BoxLayout(
113 views::BoxLayout::kVertical, 0, 0, 111 views::BoxLayout::kVertical, 0, 0,
114 delegate->GetMetric( 112 delegate->GetMetric(
115 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING))); 113 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING)));
116 114
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 154 }
157 155
158 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel( 156 base::string16 ToolbarActionsBarBubbleViews::GetDialogButtonLabel(
159 ui::DialogButton button) const { 157 ui::DialogButton button) const {
160 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText() 158 return button == ui::DIALOG_BUTTON_OK ? delegate_->GetActionButtonText()
161 : delegate_->GetDismissButtonText(); 159 : delegate_->GetDismissButtonText();
162 } 160 }
163 161
164 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link, 162 void ToolbarActionsBarBubbleViews::LinkClicked(views::Link* link,
165 int event_flags) { 163 int event_flags) {
166 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); 164 close_reason_ = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE;
Finnur 2017/03/22 10:56:04 Have you verified none of the different ways of cl
tapted 2017/03/23 00:07:06 The test coverage for this is pretty good. Eg. Tes
167 // Reset delegate so we don't send extra OnBubbleClosed()s.
168 delegate_.reset();
169 GetWidget()->Close(); 165 GetWidget()->Close();
170 } 166 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698