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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 scoped_ptr<NativeWindowTracker> parent_window_tracker_; | 62 scoped_ptr<NativeWindowTracker> parent_window_tracker_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 64 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
65 }; | 65 }; |
66 | 66 |
67 // The dialog's view, owned by the views framework. | 67 // The dialog's view, owned by the views framework. |
68 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { | 68 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
69 public: | 69 public: |
70 ExtensionUninstallDialogDelegateView( | 70 ExtensionUninstallDialogDelegateView( |
71 ExtensionUninstallDialogViews* dialog_view, | 71 ExtensionUninstallDialogViews* dialog_view, |
72 const extensions::Extension* extension, | 72 bool triggered_by_extension, |
73 const extensions::Extension* triggering_extension, | |
74 gfx::ImageSkia* image); | 73 gfx::ImageSkia* image); |
75 ~ExtensionUninstallDialogDelegateView() override; | 74 ~ExtensionUninstallDialogDelegateView() override; |
76 | 75 |
77 // Called when the ExtensionUninstallDialog has been destroyed to make sure | 76 // Called when the ExtensionUninstallDialog has been destroyed to make sure |
78 // we invalidate pointers. | 77 // we invalidate pointers. |
79 void DialogDestroyed() { dialog_ = NULL; } | 78 void DialogDestroyed() { dialog_ = NULL; } |
80 | 79 |
81 private: | 80 private: |
82 // views::DialogDelegate: | 81 // views::DialogDelegate: |
83 views::View* CreateExtraView() override; | 82 views::View* CreateExtraView() override; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 127 } |
129 } | 128 } |
130 | 129 |
131 void ExtensionUninstallDialogViews::Show() { | 130 void ExtensionUninstallDialogViews::Show() { |
132 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) { | 131 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) { |
133 delegate_->ExtensionUninstallCanceled(); | 132 delegate_->ExtensionUninstallCanceled(); |
134 return; | 133 return; |
135 } | 134 } |
136 | 135 |
137 view_ = new ExtensionUninstallDialogDelegateView( | 136 view_ = new ExtensionUninstallDialogDelegateView( |
138 this, extension_, triggering_extension_, &icon_); | 137 this, triggering_extension_.get() != nullptr, &icon_); |
139 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show(); | 138 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show(); |
140 } | 139 } |
141 | 140 |
142 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted( | 141 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted( |
143 bool report_abuse_checked) { | 142 bool report_abuse_checked) { |
144 // The widget gets destroyed when the dialog is accepted. | 143 // The widget gets destroyed when the dialog is accepted. |
145 view_->DialogDestroyed(); | 144 view_->DialogDestroyed(); |
146 view_ = nullptr; | 145 view_ = nullptr; |
147 if (report_abuse_checked) | 146 if (report_abuse_checked) |
148 HandleReportAbuse(); | 147 HandleReportAbuse(); |
149 OnDialogClosed(report_abuse_checked ? | 148 OnDialogClosed(report_abuse_checked ? |
150 CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE : CLOSE_ACTION_UNINSTALL); | 149 CLOSE_ACTION_UNINSTALL_AND_REPORT_ABUSE : CLOSE_ACTION_UNINSTALL); |
151 | 150 |
152 delegate_->ExtensionUninstallAccepted(); | 151 delegate_->ExtensionUninstallAccepted(); |
153 } | 152 } |
154 | 153 |
155 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 154 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
156 // The widget gets destroyed when the dialog is canceled. | 155 // The widget gets destroyed when the dialog is canceled. |
157 view_->DialogDestroyed(); | 156 view_->DialogDestroyed(); |
158 view_ = nullptr; | 157 view_ = nullptr; |
159 OnDialogClosed(CLOSE_ACTION_CANCELED); | 158 OnDialogClosed(CLOSE_ACTION_CANCELED); |
160 delegate_->ExtensionUninstallCanceled(); | 159 delegate_->ExtensionUninstallCanceled(); |
161 } | 160 } |
162 | 161 |
163 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( | 162 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
164 ExtensionUninstallDialogViews* dialog_view, | 163 ExtensionUninstallDialogViews* dialog_view, |
165 const extensions::Extension* extension, | 164 bool triggered_by_extension, |
166 const extensions::Extension* triggering_extension, | |
167 gfx::ImageSkia* image) | 165 gfx::ImageSkia* image) |
168 : dialog_(dialog_view), | 166 : dialog_(dialog_view), |
169 triggered_by_extension_(triggering_extension != NULL), | 167 triggered_by_extension_(triggered_by_extension), |
170 report_abuse_checkbox_(nullptr) { | 168 report_abuse_checkbox_(nullptr) { |
171 // Scale down to icon size, but allow smaller icons (don't scale up). | 169 // Scale down to icon size, but allow smaller icons (don't scale up). |
172 gfx::Size size(image->width(), image->height()); | 170 gfx::Size size(image->width(), image->height()); |
173 if (size.width() > kIconSize || size.height() > kIconSize) | 171 if (size.width() > kIconSize || size.height() > kIconSize) |
174 size = gfx::Size(kIconSize, kIconSize); | 172 size = gfx::Size(kIconSize, kIconSize); |
175 icon_ = new views::ImageView(); | 173 icon_ = new views::ImageView(); |
176 icon_->SetImageSize(size); | 174 icon_->SetImageSize(size); |
177 icon_->SetImage(*image); | 175 icon_->SetImage(*image); |
178 AddChildView(icon_); | 176 AddChildView(icon_); |
179 | 177 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 266 |
269 } // namespace | 267 } // namespace |
270 | 268 |
271 // static | 269 // static |
272 extensions::ExtensionUninstallDialog* | 270 extensions::ExtensionUninstallDialog* |
273 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 271 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
274 gfx::NativeWindow parent, | 272 gfx::NativeWindow parent, |
275 Delegate* delegate) { | 273 Delegate* delegate) { |
276 return new ExtensionUninstallDialogViews(profile, parent, delegate); | 274 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
277 } | 275 } |
OLD | NEW |