Chromium Code Reviews

Side by Side Diff: chrome/browser/views/extensions/extension_install_prompt.cc

Issue 3332016: Add a confirmation prompt to app uninstallation on the ntp. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: fix layout on Windows, remove some old crap Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « chrome/browser/resources/ntp/apps.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
(...skipping 10 matching lines...)
21 #include "views/window/window.h" 21 #include "views/window/window.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "app/win_util.h" 24 #include "app/win_util.h"
25 #endif 25 #endif
26 26
27 class Profile; 27 class Profile;
28 28
29 namespace { 29 namespace {
30 30
31 // Since apps don't (currently) have any privilege disclosure text, the dialog 31 const int kRightColumnWidth = 210;
32 // looks a bit empty if it is sized the same as extensions. So we scale 32 const int kIconSize = 69;
33 // everything down a bit for apps for the time being.
34 const int kRightColumnWidthApp = 210;
35 const int kRightColumnWidthExtension = 270;
36 const int kIconSizeApp = 69;
37 const int kIconSizeExtension = 85;
38 33
39 // Implements the extension installation prompt for Windows. 34 // Implements the extension installation prompt for Windows.
40 class InstallDialogContent : public views::View, public views::DialogDelegate { 35 class InstallDialogContent : public views::View, public views::DialogDelegate {
41 public: 36 public:
42 InstallDialogContent(ExtensionInstallUI::Delegate* delegate, 37 InstallDialogContent(ExtensionInstallUI::Delegate* delegate,
43 Extension* extension, SkBitmap* icon, const std::wstring& warning_text, 38 Extension* extension, SkBitmap* icon, ExtensionInstallUI::PromptType type)
44 ExtensionInstallUI::PromptType type) 39 : delegate_(delegate), icon_(NULL), type_(type) {
45 : delegate_(delegate), icon_(NULL), warning_(NULL),
46 create_shortcut_(NULL), type_(type) {
47 if (extension->GetFullLaunchURL().is_valid()) {
48 icon_size_ = kIconSizeApp;
49 right_column_width_ = kRightColumnWidthApp;
50 } else {
51 icon_size_ = kIconSizeExtension;
52 right_column_width_ = kRightColumnWidthExtension;
53 }
54
55 // Scale down to icon size, but allow smaller icons (don't scale up). 40 // Scale down to icon size, but allow smaller icons (don't scale up).
56 gfx::Size size(icon->width(), icon->height()); 41 gfx::Size size(icon->width(), icon->height());
57 if (size.width() > icon_size_ || size.height() > icon_size_) 42 if (size.width() > kIconSize || size.height() > kIconSize)
58 size = gfx::Size(icon_size_, icon_size_); 43 size = gfx::Size(kIconSize, kIconSize);
59 icon_ = new views::ImageView(); 44 icon_ = new views::ImageView();
60 icon_->SetImageSize(size); 45 icon_->SetImageSize(size);
61 icon_->SetImage(*icon); 46 icon_->SetImage(*icon);
62 AddChildView(icon_); 47 AddChildView(icon_);
63 48
64 heading_ = new views::Label( 49 heading_ = new views::Label(
65 l10n_util::GetStringF(ExtensionInstallUI::kHeadingIds[type_], 50 l10n_util::GetStringF(ExtensionInstallUI::kHeadingIds[type_],
66 UTF8ToWide(extension->name()))); 51 UTF8ToWide(extension->name())));
67 heading_->SetFont(heading_->font().DeriveFont(1, gfx::Font::BOLD));
68 heading_->SetMultiLine(true); 52 heading_->SetMultiLine(true);
69 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 53 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
70 AddChildView(heading_); 54 AddChildView(heading_);
71
72 if (type_ == ExtensionInstallUI::INSTALL_PROMPT &&
73 extension->GetFullLaunchURL().is_valid()) {
74 create_shortcut_ = new views::Checkbox(
75 l10n_util::GetString(IDS_EXTENSION_PROMPT_CREATE_SHORTCUT));
76 create_shortcut_->SetChecked(true);
77 create_shortcut_->SetMultiLine(true);
78 AddChildView(create_shortcut_);
79 } else {
80 warning_ = new views::Label(warning_text);
81 warning_->SetMultiLine(true);
82 warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
83 AddChildView(warning_);
84 }
85 } 55 }
86 56
87 private: 57 private:
88 // DialogDelegate 58 // DialogDelegate
89 virtual std::wstring GetDialogButtonLabel( 59 virtual std::wstring GetDialogButtonLabel(
90 MessageBoxFlags::DialogButton button) const { 60 MessageBoxFlags::DialogButton button) const {
91 switch (button) { 61 switch (button) {
92 case MessageBoxFlags::DIALOGBUTTON_OK: 62 case MessageBoxFlags::DIALOGBUTTON_OK:
93 return l10n_util::GetString(ExtensionInstallUI::kButtonIds[type_]); 63 return l10n_util::GetString(ExtensionInstallUI::kButtonIds[type_]);
94 case MessageBoxFlags::DIALOGBUTTON_CANCEL: 64 case MessageBoxFlags::DIALOGBUTTON_CANCEL:
95 return l10n_util::GetString(IDS_CANCEL); 65 return l10n_util::GetString(IDS_CANCEL);
96 default: 66 default:
97 NOTREACHED(); 67 NOTREACHED();
98 return L""; 68 return L"";
99 } 69 }
100 } 70 }
101 71
102 virtual int GetDefaultDialogButton() const { 72 virtual int GetDefaultDialogButton() const {
103 return MessageBoxFlags::DIALOGBUTTON_CANCEL; 73 return MessageBoxFlags::DIALOGBUTTON_CANCEL;
104 } 74 }
105 75
106 virtual bool Accept() { 76 virtual bool Accept() {
107 delegate_->InstallUIProceed( 77 // We don't support shortcut creation from this dialog anymore.
108 create_shortcut_ && create_shortcut_->checked()); 78 // TODO(aa): Remove this param from ExtensionInstallUI::Delegate.
79 delegate_->InstallUIProceed(false);
109 return true; 80 return true;
110 } 81 }
111 82
112 virtual bool Cancel() { 83 virtual bool Cancel() {
113 delegate_->InstallUIAbort(); 84 delegate_->InstallUIAbort();
114 return true; 85 return true;
115 } 86 }
116 87
117 88
118 // WindowDelegate 89 // WindowDelegate
119 virtual bool IsModal() const { return true; } 90 virtual bool IsModal() const { return true; }
120 virtual std::wstring GetWindowTitle() const { 91 virtual std::wstring GetWindowTitle() const {
121 return l10n_util::GetString(ExtensionInstallUI::kTitleIds[type_]); 92 return l10n_util::GetString(ExtensionInstallUI::kTitleIds[type_]);
122 } 93 }
123 virtual views::View* GetContentsView() { return this; } 94 virtual views::View* GetContentsView() { return this; }
124 95
125 // View 96 // View
126 virtual gfx::Size GetPreferredSize() { 97 virtual gfx::Size GetPreferredSize() {
127 int width = right_column_width_ + kPanelHorizMargin + kPanelHorizMargin; 98 int width = kRightColumnWidth;
128 width += icon_size_; 99 width += kIconSize;
129 width += kPanelHorizMargin; 100 width += kPanelHorizMargin * 3;
130 101
131 int height = kPanelVertMargin * 2; 102 int height = kPanelVertMargin * 2;
132 height += heading_->GetHeightForWidth(right_column_width_); 103 height += heading_->GetHeightForWidth(kRightColumnWidth);
133 height += kPanelVertMargin;
134
135 if (warning_)
136 height += warning_->GetHeightForWidth(right_column_width_);
137 else
138 height += create_shortcut_->GetPreferredSize().height();
139
140 height += kPanelVertMargin;
141 104
142 return gfx::Size(width, 105 return gfx::Size(width,
143 std::max(height, icon_size_ + kPanelVertMargin * 2)); 106 std::max(height, kIconSize + kPanelVertMargin * 2));
144 } 107 }
145 108
146 virtual void Layout() { 109 virtual void Layout() {
147 int x = kPanelHorizMargin; 110 int x = kPanelHorizMargin;
148 int y = kPanelVertMargin; 111 int y = kPanelVertMargin;
149 112
150 icon_->SetBounds(x, y, icon_size_, icon_size_); 113 heading_->SizeToFit(kRightColumnWidth);
151 x += icon_size_;
152 x += kPanelHorizMargin;
153 114
154 heading_->SizeToFit(right_column_width_); 115 if (heading_->height() <= kIconSize) {
155 heading_->SetX(x); 116 icon_->SetBounds(x, y, kIconSize, kIconSize);
156 heading_->SetY(y); 117 x += kIconSize;
157 y += heading_->height(); 118 x += kPanelHorizMargin;
158 119
159 y += kPanelVertMargin; 120 heading_->SetX(x);
121 heading_->SetY(y + (kIconSize - heading_->height()) / 2);
122 } else {
123 icon_->SetBounds(x,
124 y + (heading_->height() - kIconSize) / 2,
125 kIconSize,
126 kIconSize);
127 x += kIconSize;
128 x += kPanelHorizMargin;
160 129
161 if (create_shortcut_) { 130 heading_->SetX(x);
162 create_shortcut_->SetBounds(x, y, right_column_width_, 0); 131 heading_->SetY(y);
163 create_shortcut_->SetBounds(x, y, right_column_width_,
164 create_shortcut_->GetPreferredSize().height());
165
166 int bottom_aligned = icon_->y() + icon_->height() -
167 create_shortcut_->height();
168 if (bottom_aligned > y) {
169 create_shortcut_->SetY(bottom_aligned);
170 y = bottom_aligned;
171 }
172 y += create_shortcut_->height();
173 } else {
174 warning_->SizeToFit(right_column_width_);
175 warning_->SetX(x);
176 warning_->SetY(y);
177 y += warning_->height();
178 } 132 }
179
180 y += kPanelVertMargin;
181 } 133 }
182 134
183 ExtensionInstallUI::Delegate* delegate_; 135 ExtensionInstallUI::Delegate* delegate_;
184 views::ImageView* icon_; 136 views::ImageView* icon_;
185 views::Label* heading_; 137 views::Label* heading_;
186 views::Label* warning_;
187 views::Checkbox* create_shortcut_;
188 ExtensionInstallUI::PromptType type_; 138 ExtensionInstallUI::PromptType type_;
189 int right_column_width_;
190 int icon_size_;
191 139
192 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); 140 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent);
193 }; 141 };
194 142
195 } // namespace 143 } // namespace
196 144
197 // static 145 // static
198 void ExtensionInstallUI::ShowExtensionInstallUIPromptImpl( 146 void ExtensionInstallUI::ShowExtensionInstallUIPromptImpl(
199 Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, 147 Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon,
200 const string16& warning_text, PromptType type) { 148 PromptType type) {
201 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 149 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
202 if (!browser) { 150 if (!browser) {
203 delegate->InstallUIAbort(); 151 delegate->InstallUIAbort();
204 return; 152 return;
205 } 153 }
206 154
207 BrowserWindow* window = browser->window(); 155 BrowserWindow* window = browser->window();
208 if (!window) { 156 if (!window) {
209 delegate->InstallUIAbort(); 157 delegate->InstallUIAbort();
210 return; 158 return;
211 } 159 }
212 160
213 views::Window::CreateChromeWindow(window->GetNativeHandle(), gfx::Rect(), 161 views::Window::CreateChromeWindow(window->GetNativeHandle(), gfx::Rect(),
214 new InstallDialogContent(delegate, extension, icon, 162 new InstallDialogContent(delegate, extension, icon,
215 UTF16ToWideHack(warning_text),
216 type))->Show(); 163 type))->Show();
217 } 164 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp/apps.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine