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

Side by Side Diff: chrome/browser/ui/views/global_error_bubble_view.cc

Issue 2650923002: Fixes ungraceful handling of destroyed GlobalError GlobalErrorBubbleView. (Closed)
Patch Set: Use fake instead of mock button listener Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/global_error_bubble_view.h" 5 #include "chrome/browser/ui/views/global_error_bubble_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 : BubbleDialogDelegateView(anchor_view, arrow), 67 : BubbleDialogDelegateView(anchor_view, arrow),
68 browser_(browser), 68 browser_(browser),
69 error_(error) { 69 error_(error) {
70 if (!anchor_view) 70 if (!anchor_view)
71 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 71 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
72 } 72 }
73 73
74 GlobalErrorBubbleView::~GlobalErrorBubbleView() {} 74 GlobalErrorBubbleView::~GlobalErrorBubbleView() {}
75 75
76 base::string16 GlobalErrorBubbleView::GetWindowTitle() const { 76 base::string16 GlobalErrorBubbleView::GetWindowTitle() const {
77 if (!error_)
78 return base::string16();
77 return error_->GetBubbleViewTitle(); 79 return error_->GetBubbleViewTitle();
78 } 80 }
79 81
80 gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() { 82 gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() {
81 gfx::Image image = error_->GetBubbleViewIcon(); 83 gfx::Image image;
82 DCHECK(!image.IsEmpty()); 84 if (error_) {
85 image = error_->GetBubbleViewIcon();
86 DCHECK(!image.IsEmpty());
87 }
83 return *image.ToImageSkia(); 88 return *image.ToImageSkia();
84 } 89 }
85 90
86 bool GlobalErrorBubbleView::ShouldShowWindowIcon() const { 91 bool GlobalErrorBubbleView::ShouldShowWindowIcon() const {
87 return true; 92 return true;
88 } 93 }
89 94
90 void GlobalErrorBubbleView::WindowClosing() { 95 void GlobalErrorBubbleView::WindowClosing() {
91 if (error_) 96 if (error_)
92 error_->BubbleViewDidClose(browser_); 97 error_->BubbleViewDidClose(browser_);
93 } 98 }
94 99
95 void GlobalErrorBubbleView::Init() { 100 void GlobalErrorBubbleView::Init() {
101 // |error_| is assumed to be valid, and stay valid, at least until Init()
102 // returns.
103
96 // Compensate for built-in vertical padding in the anchor view's image. 104 // Compensate for built-in vertical padding in the anchor view's image.
97 set_anchor_view_insets(gfx::Insets( 105 set_anchor_view_insets(gfx::Insets(
98 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 106 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
99 107
100 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); 108 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages());
101 std::vector<views::Label*> message_labels; 109 std::vector<views::Label*> message_labels;
102 for (size_t i = 0; i < message_strings.size(); ++i) { 110 for (size_t i = 0; i < message_strings.size(); ++i) {
103 views::Label* message_label = new views::Label(message_strings[i]); 111 views::Label* message_label = new views::Label(message_strings[i]);
104 message_label->SetMultiLine(true); 112 message_label->SetMultiLine(true);
105 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 113 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 16 matching lines...) Expand all
122 } 130 }
123 131
124 // These bubbles show at times where activation is sporadic (like at startup, 132 // These bubbles show at times where activation is sporadic (like at startup,
125 // or a new window opening). Make sure the bubble doesn't disappear before the 133 // or a new window opening). Make sure the bubble doesn't disappear before the
126 // user sees it, if the bubble needs to be acknowledged. 134 // user sees it, if the bubble needs to be acknowledged.
127 set_close_on_deactivate(error_->ShouldCloseOnDeactivate()); 135 set_close_on_deactivate(error_->ShouldCloseOnDeactivate());
128 } 136 }
129 137
130 void GlobalErrorBubbleView::UpdateButton(views::LabelButton* button, 138 void GlobalErrorBubbleView::UpdateButton(views::LabelButton* button,
131 ui::DialogButton type) { 139 ui::DialogButton type) {
132 BubbleDialogDelegateView::UpdateButton(button, type); 140 if (error_) {
133 if (type == ui::DIALOG_BUTTON_OK && 141 // UpdateButton can result in calls back in to GlobalErrorBubbleView,
134 error_->ShouldAddElevationIconToAcceptButton()) { 142 // possibly accessing |error_|.
135 elevation_icon_setter_.reset(new ElevationIconSetter( 143 BubbleDialogDelegateView::UpdateButton(button, type);
136 button, base::Bind(&GlobalErrorBubbleView::SizeToContents, 144 if (type == ui::DIALOG_BUTTON_OK &&
137 base::Unretained(this)))); 145 error_->ShouldAddElevationIconToAcceptButton()) {
146 elevation_icon_setter_.reset(new ElevationIconSetter(
147 button, base::Bind(&GlobalErrorBubbleView::SizeToContents,
148 base::Unretained(this))));
149 }
138 } 150 }
139 } 151 }
140 152
141 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { 153 bool GlobalErrorBubbleView::ShouldShowCloseButton() const {
142 return error_ && error_->ShouldShowCloseButton(); 154 return error_ && error_->ShouldShowCloseButton();
143 } 155 }
144 156
145 bool GlobalErrorBubbleView::ShouldDefaultButtonBeBlue() const { 157 bool GlobalErrorBubbleView::ShouldDefaultButtonBeBlue() const {
146 return true; 158 return true;
147 } 159 }
148 160
149 base::string16 GlobalErrorBubbleView::GetDialogButtonLabel( 161 base::string16 GlobalErrorBubbleView::GetDialogButtonLabel(
150 ui::DialogButton button) const { 162 ui::DialogButton button) const {
163 if (!error_)
164 return base::string16();
151 return button == ui::DIALOG_BUTTON_OK 165 return button == ui::DIALOG_BUTTON_OK
152 ? error_->GetBubbleViewAcceptButtonLabel() 166 ? error_->GetBubbleViewAcceptButtonLabel()
153 : error_->GetBubbleViewCancelButtonLabel(); 167 : error_->GetBubbleViewCancelButtonLabel();
154 } 168 }
155 169
156 int GlobalErrorBubbleView::GetDialogButtons() const { 170 int GlobalErrorBubbleView::GetDialogButtons() const {
171 if (!error_)
172 return ui::DIALOG_BUTTON_NONE;
157 return ui::DIALOG_BUTTON_OK | 173 return ui::DIALOG_BUTTON_OK |
158 (error_->GetBubbleViewCancelButtonLabel().empty() 174 (error_->GetBubbleViewCancelButtonLabel().empty()
159 ? 0 175 ? 0
160 : ui::DIALOG_BUTTON_CANCEL); 176 : ui::DIALOG_BUTTON_CANCEL);
161 } 177 }
162 178
163 bool GlobalErrorBubbleView::Cancel() { 179 bool GlobalErrorBubbleView::Cancel() {
164 error_->BubbleViewCancelButtonPressed(browser_); 180 if (error_)
181 error_->BubbleViewCancelButtonPressed(browser_);
165 return true; 182 return true;
166 } 183 }
167 184
168 bool GlobalErrorBubbleView::Accept() { 185 bool GlobalErrorBubbleView::Accept() {
169 error_->BubbleViewAcceptButtonPressed(browser_); 186 if (error_)
187 error_->BubbleViewAcceptButtonPressed(browser_);
170 return true; 188 return true;
171 } 189 }
172 190
173 bool GlobalErrorBubbleView::Close() { 191 bool GlobalErrorBubbleView::Close() {
174 // Don't fall through to either Cancel() or Accept(). 192 // Don't fall through to either Cancel() or Accept().
175 return true; 193 return true;
176 } 194 }
177 195
178 void GlobalErrorBubbleView::CloseBubbleView() { 196 void GlobalErrorBubbleView::CloseBubbleView() {
179 GetWidget()->Close(); 197 GetWidget()->Close();
180 } 198 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/global_error/global_error.h ('k') | chrome/browser/ui/views/global_error_bubble_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698