OLD | NEW |
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/extensions/extension_uninstall_dialog.h" | 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // Views implementation of the uninstall dialog. | 32 // Views implementation of the uninstall dialog. |
33 class ExtensionUninstallDialogViews | 33 class ExtensionUninstallDialogViews |
34 : public extensions::ExtensionUninstallDialog { | 34 : public extensions::ExtensionUninstallDialog { |
35 public: | 35 public: |
36 ExtensionUninstallDialogViews( | 36 ExtensionUninstallDialogViews( |
37 Profile* profile, | 37 Profile* profile, |
38 gfx::NativeWindow parent, | 38 gfx::NativeWindow parent, |
39 extensions::ExtensionUninstallDialog::Delegate* delegate); | 39 extensions::ExtensionUninstallDialog::Delegate* delegate); |
40 virtual ~ExtensionUninstallDialogViews(); | 40 virtual ~ExtensionUninstallDialogViews(); |
41 | 41 |
| 42 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make |
| 43 // sure we invalidate pointers. |
| 44 void DialogDelegateDestroyed() { view_ = NULL; } |
| 45 |
42 // Forwards the accept and cancels to the delegate. | 46 // Forwards the accept and cancels to the delegate. |
43 void ExtensionUninstallAccepted(); | 47 void ExtensionUninstallAccepted(); |
44 void ExtensionUninstallCanceled(); | 48 void ExtensionUninstallCanceled(); |
45 | 49 |
46 private: | 50 private: |
47 virtual void Show() OVERRIDE; | 51 virtual void Show() OVERRIDE; |
48 | 52 |
49 ExtensionUninstallDialogDelegateView* view_; | 53 ExtensionUninstallDialogDelegateView* view_; |
50 | 54 |
51 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 55 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 118 } |
115 | 119 |
116 void ExtensionUninstallDialogViews::Show() { | 120 void ExtensionUninstallDialogViews::Show() { |
117 view_ = new ExtensionUninstallDialogDelegateView( | 121 view_ = new ExtensionUninstallDialogDelegateView( |
118 this, extension_, triggering_extension_, &icon_); | 122 this, extension_, triggering_extension_, &icon_); |
119 CreateBrowserModalDialogViews(view_, parent_)->Show(); | 123 CreateBrowserModalDialogViews(view_, parent_)->Show(); |
120 } | 124 } |
121 | 125 |
122 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 126 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
123 // The widget gets destroyed when the dialog is accepted. | 127 // The widget gets destroyed when the dialog is accepted. |
| 128 view_->DialogDestroyed(); |
124 view_ = NULL; | 129 view_ = NULL; |
125 delegate_->ExtensionUninstallAccepted(); | 130 delegate_->ExtensionUninstallAccepted(); |
126 } | 131 } |
127 | 132 |
128 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 133 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
129 // The widget gets destroyed when the dialog is canceled. | 134 // The widget gets destroyed when the dialog is canceled. |
| 135 view_->DialogDestroyed(); |
130 view_ = NULL; | 136 view_ = NULL; |
131 delegate_->ExtensionUninstallCanceled(); | 137 delegate_->ExtensionUninstallCanceled(); |
132 } | 138 } |
133 | 139 |
134 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( | 140 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
135 ExtensionUninstallDialogViews* dialog_view, | 141 ExtensionUninstallDialogViews* dialog_view, |
136 const extensions::Extension* extension, | 142 const extensions::Extension* extension, |
137 const extensions::Extension* triggering_extension, | 143 const extensions::Extension* triggering_extension, |
138 gfx::ImageSkia* image) | 144 gfx::ImageSkia* image) |
139 : dialog_(dialog_view), | 145 : dialog_(dialog_view), |
140 triggered_by_extension_(triggering_extension != NULL) { | 146 triggered_by_extension_(triggering_extension != NULL) { |
141 // Scale down to icon size, but allow smaller icons (don't scale up). | 147 // Scale down to icon size, but allow smaller icons (don't scale up). |
142 gfx::Size size(image->width(), image->height()); | 148 gfx::Size size(image->width(), image->height()); |
143 if (size.width() > kIconSize || size.height() > kIconSize) | 149 if (size.width() > kIconSize || size.height() > kIconSize) |
144 size = gfx::Size(kIconSize, kIconSize); | 150 size = gfx::Size(kIconSize, kIconSize); |
145 icon_ = new views::ImageView(); | 151 icon_ = new views::ImageView(); |
146 icon_->SetImageSize(size); | 152 icon_->SetImageSize(size); |
147 icon_->SetImage(*image); | 153 icon_->SetImage(*image); |
148 AddChildView(icon_); | 154 AddChildView(icon_); |
149 | 155 |
150 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText())); | 156 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText())); |
151 heading_->SetMultiLine(true); | 157 heading_->SetMultiLine(true); |
152 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 158 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
153 AddChildView(heading_); | 159 AddChildView(heading_); |
154 } | 160 } |
155 | 161 |
156 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { | 162 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { |
| 163 // If we're here, 2 things could have happened. Either the user closed the |
| 164 // dialog nicely and one of ExtensionUninstallAccepted or |
| 165 // ExtensionUninstallCanceled has been called (in which case dialog_ will be |
| 166 // NULL), *or* neither of them have been called and we are being forced closed |
| 167 // by our parent widget. In this case, we need to make sure to notify dialog_ |
| 168 // not to call us again, since we're about to be freed by the Widget |
| 169 // framework. |
| 170 if (dialog_) |
| 171 dialog_->DialogDelegateDestroyed(); |
157 } | 172 } |
158 | 173 |
159 base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel( | 174 base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel( |
160 ui::DialogButton button) const { | 175 ui::DialogButton button) const { |
161 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? | 176 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? |
162 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL); | 177 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL); |
163 } | 178 } |
164 | 179 |
165 bool ExtensionUninstallDialogDelegateView::Accept() { | 180 bool ExtensionUninstallDialogDelegateView::Accept() { |
166 if (dialog_) | 181 if (dialog_) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 234 |
220 } // namespace | 235 } // namespace |
221 | 236 |
222 // static | 237 // static |
223 extensions::ExtensionUninstallDialog* | 238 extensions::ExtensionUninstallDialog* |
224 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 239 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
225 gfx::NativeWindow parent, | 240 gfx::NativeWindow parent, |
226 Delegate* delegate) { | 241 Delegate* delegate) { |
227 return new ExtensionUninstallDialogViews(profile, parent, delegate); | 242 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
228 } | 243 } |
OLD | NEW |