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" |
11 #include "chrome/browser/ui/app_list/app_list_service.h" | 11 #include "chrome/browser/ui/app_list/app_list_service.h" |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_window.h" | |
14 #include "chrome/browser/ui/views/constrained_window_views.h" | 12 #include "chrome/browser/ui/views/constrained_window_views.h" |
15 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
16 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
19 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
20 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
21 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
22 #include "ui/views/layout/layout_constants.h" | 20 #include "ui/views/layout/layout_constants.h" |
23 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
24 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
25 #include "ui/views/window/dialog_delegate.h" | 23 #include "ui/views/window/dialog_delegate.h" |
26 | 24 |
27 namespace { | 25 namespace { |
28 | 26 |
29 const int kRightColumnWidth = 210; | 27 const int kRightColumnWidth = 210; |
30 const int kIconSize = 64; | 28 const int kIconSize = 64; |
31 | 29 |
32 class ExtensionUninstallDialogDelegateView; | 30 class ExtensionUninstallDialogDelegateView; |
33 | 31 |
34 // Returns parent window for extension uninstall dialog. | |
35 gfx::NativeWindow GetParent(Browser* browser) { | |
36 if (browser && browser->window()) | |
37 return browser->window()->GetNativeWindow(); | |
38 return NULL; | |
39 } | |
40 | |
41 // Views implementation of the uninstall dialog. | 32 // Views implementation of the uninstall dialog. |
42 class ExtensionUninstallDialogViews | 33 class ExtensionUninstallDialogViews |
43 : public extensions::ExtensionUninstallDialog { | 34 : public extensions::ExtensionUninstallDialog { |
44 public: | 35 public: |
45 ExtensionUninstallDialogViews( | 36 ExtensionUninstallDialogViews( |
46 Profile* profile, | 37 Profile* profile, |
47 Browser* browser, | 38 gfx::NativeWindow parent, |
48 extensions::ExtensionUninstallDialog::Delegate* delegate); | 39 extensions::ExtensionUninstallDialog::Delegate* delegate); |
49 virtual ~ExtensionUninstallDialogViews(); | 40 virtual ~ExtensionUninstallDialogViews(); |
50 | 41 |
51 // Forwards the accept and cancels to the delegate. | 42 // Forwards the accept and cancels to the delegate. |
52 void ExtensionUninstallAccepted(); | 43 void ExtensionUninstallAccepted(); |
53 void ExtensionUninstallCanceled(); | 44 void ExtensionUninstallCanceled(); |
54 | 45 |
55 ExtensionUninstallDialogDelegateView* view() { return view_; } | |
56 | |
57 private: | 46 private: |
58 virtual void Show() OVERRIDE; | 47 virtual void Show() OVERRIDE; |
59 | 48 |
60 ExtensionUninstallDialogDelegateView* view_; | 49 ExtensionUninstallDialogDelegateView* view_; |
61 bool show_in_app_list_; | |
62 | 50 |
63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 51 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
64 }; | 52 }; |
65 | 53 |
66 // The dialog's view, owned by the views framework. | 54 // The dialog's view, owned by the views framework. |
67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { | 55 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
68 public: | 56 public: |
69 ExtensionUninstallDialogDelegateView( | 57 ExtensionUninstallDialogDelegateView( |
70 ExtensionUninstallDialogViews* dialog_view, | 58 ExtensionUninstallDialogViews* dialog_view, |
71 const extensions::Extension* extension, | 59 const extensions::Extension* extension, |
72 const extensions::Extension* triggering_extension, | 60 const extensions::Extension* triggering_extension, |
73 gfx::ImageSkia* icon); | 61 gfx::ImageSkia* image); |
74 virtual ~ExtensionUninstallDialogDelegateView(); | 62 virtual ~ExtensionUninstallDialogDelegateView(); |
75 | 63 |
76 // Called when the ExtensionUninstallDialog has been destroyed to make sure | 64 // Called when the ExtensionUninstallDialog has been destroyed to make sure |
77 // we invalidate pointers. | 65 // we invalidate pointers. |
78 void DialogDestroyed() { dialog_ = NULL; } | 66 void DialogDestroyed() { dialog_ = NULL; } |
79 | 67 |
80 private: | 68 private: |
81 // views::DialogDelegate: | 69 // views::DialogDelegate: |
82 virtual base::string16 GetDialogButtonLabel( | 70 virtual base::string16 GetDialogButtonLabel( |
83 ui::DialogButton button) const OVERRIDE; | 71 ui::DialogButton button) const OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
104 | 92 |
105 views::ImageView* icon_; | 93 views::ImageView* icon_; |
106 views::Label* heading_; | 94 views::Label* heading_; |
107 bool triggered_by_extension_; | 95 bool triggered_by_extension_; |
108 | 96 |
109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); | 97 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); |
110 }; | 98 }; |
111 | 99 |
112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( | 100 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( |
113 Profile* profile, | 101 Profile* profile, |
114 Browser* browser, | 102 gfx::NativeWindow parent, |
115 extensions::ExtensionUninstallDialog::Delegate* delegate) | 103 extensions::ExtensionUninstallDialog::Delegate* delegate) |
116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), | 104 : extensions::ExtensionUninstallDialog(profile, parent, delegate), |
117 view_(NULL), | 105 view_(NULL) { |
118 show_in_app_list_(!browser) { | |
119 } | 106 } |
120 | 107 |
121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { | 108 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { |
122 // Close the widget (the views framework will delete view_). | 109 // Close the widget (the views framework will delete view_). |
123 if (view_) { | 110 if (view_) { |
124 view_->DialogDestroyed(); | 111 view_->DialogDestroyed(); |
125 view_->GetWidget()->CloseNow(); | 112 view_->GetWidget()->CloseNow(); |
126 } | 113 } |
127 } | 114 } |
128 | 115 |
129 void ExtensionUninstallDialogViews::Show() { | 116 void ExtensionUninstallDialogViews::Show() { |
130 // TODO(tapted): A true |desktop_type| needs to be passed in at creation time | |
131 // to remove reliance on GetActiveDesktop(). http://crbug.com/308360 | |
132 gfx::NativeWindow parent = show_in_app_list_ ? | |
133 AppListService::Get(chrome::GetActiveDesktop())->GetAppListWindow() : | |
134 GetParent(browser_); | |
135 if (browser_ && !parent) { | |
136 delegate_->ExtensionUninstallCanceled(); | |
137 return; | |
138 } | |
139 | |
140 view_ = new ExtensionUninstallDialogDelegateView( | 117 view_ = new ExtensionUninstallDialogDelegateView( |
141 this, extension_, triggering_extension_, &icon_); | 118 this, extension_, triggering_extension_, &icon_); |
142 CreateBrowserModalDialogViews(view_, parent)->Show(); | 119 CreateBrowserModalDialogViews(view_, parent_)->Show(); |
143 } | 120 } |
144 | 121 |
145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 122 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
146 // The widget gets destroyed when the dialog is accepted. | 123 // The widget gets destroyed when the dialog is accepted. |
147 view_ = NULL; | 124 view_ = NULL; |
148 delegate_->ExtensionUninstallAccepted(); | 125 delegate_->ExtensionUninstallAccepted(); |
149 } | 126 } |
150 | 127 |
151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 128 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
152 // The widget gets destroyed when the dialog is canceled. | 129 // The widget gets destroyed when the dialog is canceled. |
153 view_ = NULL; | 130 view_ = NULL; |
154 delegate_->ExtensionUninstallCanceled(); | 131 delegate_->ExtensionUninstallCanceled(); |
155 } | 132 } |
156 | 133 |
157 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( | 134 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
158 ExtensionUninstallDialogViews* dialog_view, | 135 ExtensionUninstallDialogViews* dialog_view, |
159 const extensions::Extension* extension, | 136 const extensions::Extension* extension, |
160 const extensions::Extension* triggering_extension, | 137 const extensions::Extension* triggering_extension, |
161 gfx::ImageSkia* icon) | 138 gfx::ImageSkia* image) |
162 : dialog_(dialog_view), | 139 : dialog_(dialog_view), |
163 triggered_by_extension_(triggering_extension != NULL) { | 140 triggered_by_extension_(triggering_extension != NULL) { |
164 // Scale down to icon size, but allow smaller icons (don't scale up). | 141 // Scale down to icon size, but allow smaller icons (don't scale up). |
165 gfx::Size size(icon->width(), icon->height()); | 142 gfx::Size size(image->width(), image->height()); |
166 if (size.width() > kIconSize || size.height() > kIconSize) | 143 if (size.width() > kIconSize || size.height() > kIconSize) |
167 size = gfx::Size(kIconSize, kIconSize); | 144 size = gfx::Size(kIconSize, kIconSize); |
168 icon_ = new views::ImageView(); | 145 icon_ = new views::ImageView(); |
169 icon_->SetImageSize(size); | 146 icon_->SetImageSize(size); |
170 icon_->SetImage(*icon); | 147 icon_->SetImage(*image); |
171 AddChildView(icon_); | 148 AddChildView(icon_); |
172 | 149 |
173 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText())); | 150 heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText())); |
174 heading_->SetMultiLine(true); | 151 heading_->SetMultiLine(true); |
175 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 152 heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
176 AddChildView(heading_); | 153 AddChildView(heading_); |
177 } | 154 } |
178 | 155 |
179 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { | 156 ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { |
180 } | 157 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 heading_->SetX(x); | 215 heading_->SetX(x); |
239 heading_->SetY(y); | 216 heading_->SetY(y); |
240 } | 217 } |
241 } | 218 } |
242 | 219 |
243 } // namespace | 220 } // namespace |
244 | 221 |
245 // static | 222 // static |
246 extensions::ExtensionUninstallDialog* | 223 extensions::ExtensionUninstallDialog* |
247 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 224 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
248 Browser* browser, | 225 gfx::NativeWindow parent, |
249 Delegate* delegate) { | 226 Delegate* delegate) { |
250 return new ExtensionUninstallDialogViews(profile, browser, delegate); | 227 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
251 } | 228 } |
OLD | NEW |