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