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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 8 #include "base/macros.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 26 matching lines...) Expand all Loading... | |
37 class ExtensionUninstallDialogViews | 37 class ExtensionUninstallDialogViews |
38 : public extensions::ExtensionUninstallDialog { | 38 : public extensions::ExtensionUninstallDialog { |
39 public: | 39 public: |
40 ExtensionUninstallDialogViews( | 40 ExtensionUninstallDialogViews( |
41 Profile* profile, | 41 Profile* profile, |
42 gfx::NativeWindow parent, | 42 gfx::NativeWindow parent, |
43 extensions::ExtensionUninstallDialog::Delegate* delegate); | 43 extensions::ExtensionUninstallDialog::Delegate* delegate); |
44 ~ExtensionUninstallDialogViews() override; | 44 ~ExtensionUninstallDialogViews() override; |
45 | 45 |
46 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make | 46 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make |
47 // sure we invalidate pointers. | 47 // sure we invalidate pointers. This object will also be freed. |
48 void DialogDelegateDestroyed() { view_ = NULL; } | 48 void DialogDelegateDestroyed(); |
49 | 49 |
50 // Forwards the accept and cancels to the delegate. | 50 // Forwards the accept and cancels to the delegate. |
51 void DialogAccepted(bool handle_report_abuse); | 51 void DialogAccepted(bool handle_report_abuse); |
52 void DialogCanceled(); | 52 void DialogCanceled(); |
53 | 53 |
54 private: | 54 private: |
55 void Show() override; | 55 void Show() override; |
56 | 56 |
57 ExtensionUninstallDialogDelegateView* view_; | 57 ExtensionUninstallDialogDelegateView* view_; |
58 | 58 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) { | 133 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) { |
134 OnDialogClosed(CLOSE_ACTION_CANCELED); | 134 OnDialogClosed(CLOSE_ACTION_CANCELED); |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
138 view_ = new ExtensionUninstallDialogDelegateView( | 138 view_ = new ExtensionUninstallDialogDelegateView( |
139 this, triggering_extension() != nullptr, &icon()); | 139 this, triggering_extension() != nullptr, &icon()); |
140 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show(); | 140 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show(); |
141 } | 141 } |
142 | 142 |
143 void ExtensionUninstallDialogViews::DialogDelegateDestroyed() { | |
144 // Checks view_ to ensure OnDialogClosed() will not be called twice. | |
145 if (view_) { | |
146 view_ = NULL; | |
Devlin
2016/11/14 17:49:12
nit: prefer nullptr in new code.
lgcheng
2016/11/14 19:10:33
Done.
| |
147 OnDialogClosed(CLOSE_ACTION_CANCELED); | |
148 } | |
149 } | |
150 | |
143 void ExtensionUninstallDialogViews::DialogAccepted(bool report_abuse_checked) { | 151 void ExtensionUninstallDialogViews::DialogAccepted(bool report_abuse_checked) { |
144 // The widget gets destroyed when the dialog is accepted. | 152 // The widget gets destroyed when the dialog is accepted. |
153 DCHECK(view_); | |
145 view_->DialogDestroyed(); | 154 view_->DialogDestroyed(); |
146 view_ = nullptr; | 155 view_ = nullptr; |
147 OnDialogClosed(report_abuse_checked ? | 156 OnDialogClosed(report_abuse_checked ? |
148 CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE : CLOSE_ACTION_UNINSTALL); | 157 CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE : CLOSE_ACTION_UNINSTALL); |
149 } | 158 } |
150 | 159 |
151 void ExtensionUninstallDialogViews::DialogCanceled() { | 160 void ExtensionUninstallDialogViews::DialogCanceled() { |
152 // The widget gets destroyed when the dialog is canceled. | 161 // The widget gets destroyed when the dialog is canceled. |
162 DCHECK(view_); | |
153 view_->DialogDestroyed(); | 163 view_->DialogDestroyed(); |
154 view_ = nullptr; | 164 view_ = nullptr; |
155 OnDialogClosed(CLOSE_ACTION_CANCELED); | 165 OnDialogClosed(CLOSE_ACTION_CANCELED); |
156 } | 166 } |
157 | 167 |
158 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( | 168 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
159 ExtensionUninstallDialogViews* dialog_view, | 169 ExtensionUninstallDialogViews* dialog_view, |
160 bool triggered_by_extension, | 170 bool triggered_by_extension, |
161 const gfx::ImageSkia* image) | 171 const gfx::ImageSkia* image) |
162 : dialog_(dialog_view), | 172 : dialog_(dialog_view), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 | 279 |
270 } // namespace | 280 } // namespace |
271 | 281 |
272 // static | 282 // static |
273 extensions::ExtensionUninstallDialog* | 283 extensions::ExtensionUninstallDialog* |
274 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 284 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
275 gfx::NativeWindow parent, | 285 gfx::NativeWindow parent, |
276 Delegate* delegate) { | 286 Delegate* delegate) { |
277 return new ExtensionUninstallDialogViews(profile, parent, delegate); | 287 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
278 } | 288 } |
OLD | NEW |