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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc

Issue 1010953002: [Extensions] Add support for reporting abuse on extension uninstallation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/app_list/app_list_service.h" 12 #include "chrome/browser/ui/app_list/app_list_service.h"
13 #include "chrome/browser/ui/native_window_tracker.h" 13 #include "chrome/browser/ui/native_window_tracker.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
16 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/compositor/compositor.h" 18 #include "ui/compositor/compositor.h"
19 #include "ui/compositor/layer.h" 19 #include "ui/compositor/layer.h"
20 #include "ui/views/controls/button/checkbox.h"
20 #include "ui/views/controls/image_view.h" 21 #include "ui/views/controls/image_view.h"
21 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/layout_constants.h" 23 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/view.h" 24 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
25 #include "ui/views/window/dialog_delegate.h" 26 #include "ui/views/window/dialog_delegate.h"
26 27
27 namespace { 28 namespace {
28 29
29 const int kRightColumnWidth = 210; 30 const int kRightColumnWidth = 210;
30 const int kIconSize = 64; 31 const int kIconSize = 64;
31 32
32 class ExtensionUninstallDialogDelegateView; 33 class ExtensionUninstallDialogDelegateView;
33 34
34 // Views implementation of the uninstall dialog. 35 // Views implementation of the uninstall dialog.
35 class ExtensionUninstallDialogViews 36 class ExtensionUninstallDialogViews
36 : public extensions::ExtensionUninstallDialog { 37 : public extensions::ExtensionUninstallDialog {
37 public: 38 public:
38 ExtensionUninstallDialogViews( 39 ExtensionUninstallDialogViews(
39 Profile* profile, 40 Profile* profile,
40 gfx::NativeWindow parent, 41 gfx::NativeWindow parent,
41 extensions::ExtensionUninstallDialog::Delegate* delegate); 42 extensions::ExtensionUninstallDialog::Delegate* delegate);
42 ~ExtensionUninstallDialogViews() override; 43 ~ExtensionUninstallDialogViews() override;
43 44
44 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make 45 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make
45 // sure we invalidate pointers. 46 // sure we invalidate pointers.
46 void DialogDelegateDestroyed() { view_ = NULL; } 47 void DialogDelegateDestroyed() { view_ = NULL; }
47 48
48 // Forwards the accept and cancels to the delegate. 49 // Forwards the accept and cancels to the delegate.
49 void ExtensionUninstallAccepted(); 50 void ExtensionUninstallAccepted(bool handle_report_abuse);
50 void ExtensionUninstallCanceled(); 51 void ExtensionUninstallCanceled();
51 52
52 private: 53 private:
53 void Show() override; 54 void Show() override;
54 55
55 ExtensionUninstallDialogDelegateView* view_; 56 ExtensionUninstallDialogDelegateView* view_;
56 57
57 // The dialog's parent window. 58 // The dialog's parent window.
58 gfx::NativeWindow parent_; 59 gfx::NativeWindow parent_;
59 60
(...skipping 12 matching lines...) Expand all
72 const extensions::Extension* triggering_extension, 73 const extensions::Extension* triggering_extension,
73 gfx::ImageSkia* image); 74 gfx::ImageSkia* image);
74 ~ExtensionUninstallDialogDelegateView() override; 75 ~ExtensionUninstallDialogDelegateView() override;
75 76
76 // Called when the ExtensionUninstallDialog has been destroyed to make sure 77 // Called when the ExtensionUninstallDialog has been destroyed to make sure
77 // we invalidate pointers. 78 // we invalidate pointers.
78 void DialogDestroyed() { dialog_ = NULL; } 79 void DialogDestroyed() { dialog_ = NULL; }
79 80
80 private: 81 private:
81 // views::DialogDelegate: 82 // views::DialogDelegate:
83 views::View* CreateExtraView() override;
82 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; 84 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
83 int GetDefaultDialogButton() const override { 85 int GetDefaultDialogButton() const override {
84 // Default to accept when triggered via chrome://extensions page. 86 // Default to accept when triggered via chrome://extensions page.
85 return triggered_by_extension_ ? 87 return triggered_by_extension_ ?
86 ui::DIALOG_BUTTON_CANCEL : ui::DIALOG_BUTTON_OK; 88 ui::DIALOG_BUTTON_CANCEL : ui::DIALOG_BUTTON_OK;
87 } 89 }
88 bool Accept() override; 90 bool Accept() override;
89 bool Cancel() override; 91 bool Cancel() override;
90 92
91 // views::WidgetDelegate: 93 // views::WidgetDelegate:
92 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; } 94 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; }
93 base::string16 GetWindowTitle() const override; 95 base::string16 GetWindowTitle() const override;
94 96
95 // views::View: 97 // views::View:
96 gfx::Size GetPreferredSize() const override; 98 gfx::Size GetPreferredSize() const override;
97 99
98 void Layout() override; 100 void Layout() override;
99 101
100 ExtensionUninstallDialogViews* dialog_; 102 ExtensionUninstallDialogViews* dialog_;
101 103
102 views::ImageView* icon_; 104 views::ImageView* icon_;
103 views::Label* heading_; 105 views::Label* heading_;
104 bool triggered_by_extension_; 106 bool triggered_by_extension_;
107 views::Checkbox* report_abuse_checkbox_;
105 108
106 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); 109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
107 }; 110 };
108 111
109 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( 112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
110 Profile* profile, 113 Profile* profile,
111 gfx::NativeWindow parent, 114 gfx::NativeWindow parent,
112 extensions::ExtensionUninstallDialog::Delegate* delegate) 115 extensions::ExtensionUninstallDialog::Delegate* delegate)
113 : extensions::ExtensionUninstallDialog(profile, delegate), 116 : extensions::ExtensionUninstallDialog(profile, delegate),
114 view_(NULL), 117 view_(NULL),
(...skipping 14 matching lines...) Expand all
129 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) { 132 if (parent_ && parent_window_tracker_->WasNativeWindowClosed()) {
130 delegate_->ExtensionUninstallCanceled(); 133 delegate_->ExtensionUninstallCanceled();
131 return; 134 return;
132 } 135 }
133 136
134 view_ = new ExtensionUninstallDialogDelegateView( 137 view_ = new ExtensionUninstallDialogDelegateView(
135 this, extension_, triggering_extension_, &icon_); 138 this, extension_, triggering_extension_, &icon_);
136 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show(); 139 constrained_window::CreateBrowserModalDialogViews(view_, parent_)->Show();
137 } 140 }
138 141
139 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { 142 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted(
143 bool report_abuse_checked) {
140 // The widget gets destroyed when the dialog is accepted. 144 // The widget gets destroyed when the dialog is accepted.
141 view_->DialogDestroyed(); 145 view_->DialogDestroyed();
142 view_ = NULL; 146 view_ = NULL;
147 if (report_abuse_checked)
148 HandleReportAbuse();
143 delegate_->ExtensionUninstallAccepted(); 149 delegate_->ExtensionUninstallAccepted();
144 } 150 }
145 151
146 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { 152 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
147 // The widget gets destroyed when the dialog is canceled. 153 // The widget gets destroyed when the dialog is canceled.
148 view_->DialogDestroyed(); 154 view_->DialogDestroyed();
149 view_ = NULL; 155 view_ = NULL;
150 delegate_->ExtensionUninstallCanceled(); 156 delegate_->ExtensionUninstallCanceled();
151 } 157 }
152 158
153 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( 159 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
154 ExtensionUninstallDialogViews* dialog_view, 160 ExtensionUninstallDialogViews* dialog_view,
155 const extensions::Extension* extension, 161 const extensions::Extension* extension,
156 const extensions::Extension* triggering_extension, 162 const extensions::Extension* triggering_extension,
157 gfx::ImageSkia* image) 163 gfx::ImageSkia* image)
158 : dialog_(dialog_view), 164 : dialog_(dialog_view),
159 triggered_by_extension_(triggering_extension != NULL) { 165 triggered_by_extension_(triggering_extension != NULL),
166 report_abuse_checkbox_(nullptr) {
160 // Scale down to icon size, but allow smaller icons (don't scale up). 167 // Scale down to icon size, but allow smaller icons (don't scale up).
161 gfx::Size size(image->width(), image->height()); 168 gfx::Size size(image->width(), image->height());
162 if (size.width() > kIconSize || size.height() > kIconSize) 169 if (size.width() > kIconSize || size.height() > kIconSize)
163 size = gfx::Size(kIconSize, kIconSize); 170 size = gfx::Size(kIconSize, kIconSize);
164 icon_ = new views::ImageView(); 171 icon_ = new views::ImageView();
165 icon_->SetImageSize(size); 172 icon_->SetImageSize(size);
166 icon_->SetImage(*image); 173 icon_->SetImage(*image);
167 AddChildView(icon_); 174 AddChildView(icon_);
168 175
169 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText())); 176 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText()));
170 heading_->SetMultiLine(true); 177 heading_->SetMultiLine(true);
171 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 178 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
172 AddChildView(heading_); 179 AddChildView(heading_);
173 } 180 }
174 181
175 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { 182 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
176 // If we're here, 2 things could have happened. Either the user closed the 183 // If we're here, 2 things could have happened. Either the user closed the
177 // dialog nicely and one of ExtensionUninstallAccepted or 184 // dialog nicely and one of ExtensionUninstallAccepted or
178 // ExtensionUninstallCanceled has been called (in which case dialog_ will be 185 // ExtensionUninstallCanceled has been called (in which case dialog_ will be
179 // NULL), *or* neither of them have been called and we are being forced closed 186 // NULL), *or* neither of them have been called and we are being forced closed
180 // by our parent widget. In this case, we need to make sure to notify dialog_ 187 // by our parent widget. In this case, we need to make sure to notify dialog_
181 // not to call us again, since we're about to be freed by the Widget 188 // not to call us again, since we're about to be freed by the Widget
182 // framework. 189 // framework.
183 if (dialog_) 190 if (dialog_)
184 dialog_->DialogDelegateDestroyed(); 191 dialog_->DialogDelegateDestroyed();
185 } 192 }
186 193
194 views::View* ExtensionUninstallDialogDelegateView::CreateExtraView() {
195 if (dialog_->ShouldShowReportAbuseCheckbox()) {
196 report_abuse_checkbox_ = new views::Checkbox(
197 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE));
198 }
199 return report_abuse_checkbox_;
200 }
201
187 base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel( 202 base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
188 ui::DialogButton button) const { 203 ui::DialogButton button) const {
189 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? 204 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
190 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL); 205 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL);
191 } 206 }
192 207
193 bool ExtensionUninstallDialogDelegateView::Accept() { 208 bool ExtensionUninstallDialogDelegateView::Accept() {
194 if (dialog_) 209 if (dialog_) {
195 dialog_->ExtensionUninstallAccepted(); 210 dialog_->ExtensionUninstallAccepted(
211 report_abuse_checkbox_ && report_abuse_checkbox_->checked());
212 }
196 return true; 213 return true;
197 } 214 }
198 215
199 bool ExtensionUninstallDialogDelegateView::Cancel() { 216 bool ExtensionUninstallDialogDelegateView::Cancel() {
200 if (dialog_) 217 if (dialog_)
201 dialog_->ExtensionUninstallCanceled(); 218 dialog_->ExtensionUninstallCanceled();
202 return true; 219 return true;
203 } 220 }
204 221
205 base::string16 ExtensionUninstallDialogDelegateView::GetWindowTitle() const { 222 base::string16 ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 264
248 } // namespace 265 } // namespace
249 266
250 // static 267 // static
251 extensions::ExtensionUninstallDialog* 268 extensions::ExtensionUninstallDialog*
252 extensions::ExtensionUninstallDialog::Create(Profile* profile, 269 extensions::ExtensionUninstallDialog::Create(Profile* profile,
253 gfx::NativeWindow parent, 270 gfx::NativeWindow parent,
254 Delegate* delegate) { 271 Delegate* delegate) {
255 return new ExtensionUninstallDialogViews(profile, parent, delegate); 272 return new ExtensionUninstallDialogViews(profile, parent, delegate);
256 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698