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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/global_error_bubble_view.cc
diff --git a/chrome/browser/ui/views/global_error_bubble_view.cc b/chrome/browser/ui/views/global_error_bubble_view.cc
index 62789d901a1a452384093144da1d94ce2f126c3a..bdbcd639e7f732d95f83f2143a03e8d59cee24bd 100644
--- a/chrome/browser/ui/views/global_error_bubble_view.cc
+++ b/chrome/browser/ui/views/global_error_bubble_view.cc
@@ -74,12 +74,17 @@ GlobalErrorBubbleView::GlobalErrorBubbleView(
GlobalErrorBubbleView::~GlobalErrorBubbleView() {}
base::string16 GlobalErrorBubbleView::GetWindowTitle() const {
+ if (!error_)
+ return base::string16();
return error_->GetBubbleViewTitle();
}
gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() {
- gfx::Image image = error_->GetBubbleViewIcon();
- DCHECK(!image.IsEmpty());
+ gfx::Image image;
+ if (error_) {
+ image = error_->GetBubbleViewIcon();
+ DCHECK(!image.IsEmpty());
+ }
return *image.ToImageSkia();
}
@@ -93,6 +98,9 @@ void GlobalErrorBubbleView::WindowClosing() {
}
void GlobalErrorBubbleView::Init() {
+ // |error_| is assumed to be valid, and stay valid, at least until Init()
+ // returns.
+
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(
GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
@@ -129,12 +137,16 @@ void GlobalErrorBubbleView::Init() {
void GlobalErrorBubbleView::UpdateButton(views::LabelButton* button,
ui::DialogButton type) {
- BubbleDialogDelegateView::UpdateButton(button, type);
- if (type == ui::DIALOG_BUTTON_OK &&
- error_->ShouldAddElevationIconToAcceptButton()) {
- elevation_icon_setter_.reset(new ElevationIconSetter(
- button, base::Bind(&GlobalErrorBubbleView::SizeToContents,
- base::Unretained(this))));
+ if (error_) {
+ // UpdateButton can result in calls back in to GlobalErrorBubbleView,
+ // possibly accessing |error_|.
+ BubbleDialogDelegateView::UpdateButton(button, type);
+ if (type == ui::DIALOG_BUTTON_OK &&
+ error_->ShouldAddElevationIconToAcceptButton()) {
+ elevation_icon_setter_.reset(new ElevationIconSetter(
+ button, base::Bind(&GlobalErrorBubbleView::SizeToContents,
+ base::Unretained(this))));
+ }
}
}
@@ -148,12 +160,16 @@ bool GlobalErrorBubbleView::ShouldDefaultButtonBeBlue() const {
base::string16 GlobalErrorBubbleView::GetDialogButtonLabel(
ui::DialogButton button) const {
+ if (!error_)
+ return base::string16();
return button == ui::DIALOG_BUTTON_OK
? error_->GetBubbleViewAcceptButtonLabel()
: error_->GetBubbleViewCancelButtonLabel();
}
int GlobalErrorBubbleView::GetDialogButtons() const {
+ if (!error_)
+ return ui::DIALOG_BUTTON_NONE;
return ui::DIALOG_BUTTON_OK |
(error_->GetBubbleViewCancelButtonLabel().empty()
? 0
@@ -161,12 +177,14 @@ int GlobalErrorBubbleView::GetDialogButtons() const {
}
bool GlobalErrorBubbleView::Cancel() {
- error_->BubbleViewCancelButtonPressed(browser_);
+ if (error_)
+ error_->BubbleViewCancelButtonPressed(browser_);
return true;
}
bool GlobalErrorBubbleView::Accept() {
- error_->BubbleViewAcceptButtonPressed(browser_);
+ if (error_)
+ error_->BubbleViewAcceptButtonPressed(browser_);
return true;
}
« 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