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/ui/views/extensions/extension_install_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Width of the bullet column in BulletedView. | 59 // Width of the bullet column in BulletedView. |
60 const int kBulletWidth = 20; | 60 const int kBulletWidth = 20; |
61 | 61 |
62 // Size of extension icon in top left of dialog. | 62 // Size of extension icon in top left of dialog. |
63 const int kIconSize = 64; | 63 const int kIconSize = 64; |
64 | 64 |
65 // We offset the icon a little bit from the right edge of the dialog, to make it | 65 // We offset the icon a little bit from the right edge of the dialog, to make it |
66 // align with the button below it. | 66 // align with the button below it. |
67 const int kIconOffset = 16; | 67 const int kIconOffset = 16; |
68 | 68 |
| 69 // Size of the icons of individual extensions for bundle installs. |
| 70 const int kSmallIconSize = 32; |
| 71 |
| 72 // Padding between extension icon and title for bundle installs. |
| 73 const int kSmallIconPadding = 6; |
| 74 |
69 // The dialog will resize based on its content, but this sets a maximum height | 75 // The dialog will resize based on its content, but this sets a maximum height |
70 // before overflowing a scrollbar. | 76 // before overflowing a scrollbar. |
71 const int kDialogMaxHeight = 300; | 77 const int kDialogMaxHeight = 300; |
72 | 78 |
73 // Width of the left column of the dialog when the extension requests | 79 // Width of the left column of the dialog when the extension requests |
74 // permissions. | 80 // permissions. |
75 const int kPermissionsLeftColumnWidth = 250; | 81 const int kPermissionsLeftColumnWidth = 250; |
76 | 82 |
77 // Width of the left column of the dialog when the extension requests no | 83 // Width of the left column of the dialog when the extension requests no |
78 // permissions. | 84 // permissions. |
79 const int kNoPermissionsLeftColumnWidth = 200; | 85 const int kNoPermissionsLeftColumnWidth = 200; |
80 | 86 |
81 // Width of the left column for bundle install prompts. There's only one column | |
82 // in this case, so make it wider than normal. | |
83 const int kBundleLeftColumnWidth = 300; | |
84 | |
85 // Width of the left column for external install prompts. The text is long in | 87 // Width of the left column for external install prompts. The text is long in |
86 // this case, so make it wider than normal. | 88 // this case, so make it wider than normal. |
87 const int kExternalInstallLeftColumnWidth = 350; | 89 const int kExternalInstallLeftColumnWidth = 350; |
88 | 90 |
89 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { | 91 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { |
90 views::View* parent = static_cast<views::View*>(data); | 92 views::View* parent = static_cast<views::View*>(data); |
91 views::ImageView* image_view = new views::ImageView(); | 93 views::ImageView* image_view = new views::ImageView(); |
92 image_view->SetImage(*skia_image); | 94 image_view->SetImage(*skia_image); |
93 parent->AddChildView(image_view); | 95 parent->AddChildView(image_view); |
94 } | 96 } |
(...skipping 23 matching lines...) Expand all Loading... |
118 views::GridLayout::LEADING, | 120 views::GridLayout::LEADING, |
119 0, | 121 0, |
120 views::GridLayout::USE_PREF, | 122 views::GridLayout::USE_PREF, |
121 0, // No fixed width. | 123 0, // No fixed width. |
122 0); | 124 0); |
123 layout->StartRow(0, 0); | 125 layout->StartRow(0, 0); |
124 layout->AddView(new views::Label(PrepareForDisplay(base::string16(), true))); | 126 layout->AddView(new views::Label(PrepareForDisplay(base::string16(), true))); |
125 layout->AddView(view); | 127 layout->AddView(view); |
126 } | 128 } |
127 | 129 |
| 130 IconedView::IconedView(views::View* view, const gfx::ImageSkia& image) { |
| 131 views::GridLayout* layout = new views::GridLayout(this); |
| 132 SetLayoutManager(layout); |
| 133 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 134 column_set->AddColumn(views::GridLayout::CENTER, |
| 135 views::GridLayout::LEADING, |
| 136 0, |
| 137 views::GridLayout::FIXED, |
| 138 kSmallIconSize, |
| 139 0); |
| 140 column_set->AddPaddingColumn(0, kSmallIconPadding); |
| 141 column_set->AddColumn(views::GridLayout::LEADING, |
| 142 views::GridLayout::CENTER, |
| 143 0, |
| 144 views::GridLayout::USE_PREF, |
| 145 0, // No fixed width. |
| 146 0); |
| 147 layout->StartRow(0, 0); |
| 148 |
| 149 gfx::Size size(image.width(), image.height()); |
| 150 if (size.width() > kSmallIconSize || size.height() > kSmallIconSize) |
| 151 size = gfx::Size(kSmallIconSize, kSmallIconSize); |
| 152 views::ImageView* image_view = new views::ImageView; |
| 153 image_view->SetImage(image); |
| 154 image_view->SetImageSize(size); |
| 155 |
| 156 layout->AddView(image_view); |
| 157 layout->AddView(view); |
| 158 } |
| 159 |
128 void ShowExtensionInstallDialogImpl( | 160 void ShowExtensionInstallDialogImpl( |
129 ExtensionInstallPromptShowParams* show_params, | 161 ExtensionInstallPromptShowParams* show_params, |
130 ExtensionInstallPrompt::Delegate* delegate, | 162 ExtensionInstallPrompt::Delegate* delegate, |
131 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) { | 163 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) { |
132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
133 ExtensionInstallDialogView* dialog = | 165 ExtensionInstallDialogView* dialog = |
134 new ExtensionInstallDialogView(show_params->profile(), | 166 new ExtensionInstallDialogView(show_params->profile(), |
135 show_params->GetParentWebContents(), | 167 show_params->GetParentWebContents(), |
136 delegate, | 168 delegate, |
137 prompt); | 169 prompt); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // | permissions_header | | | 229 // | permissions_header | | |
198 // +--------------------| | | 230 // +--------------------| | |
199 // | permission1 | | | 231 // | permission1 | | |
200 // +--------------------| | | 232 // +--------------------| | |
201 // | permission2 | | | 233 // | permission2 | | |
202 // +--------------------+------+ | 234 // +--------------------+------+ |
203 int left_column_width = | 235 int left_column_width = |
204 (prompt_->ShouldShowPermissions() + prompt_->GetRetainedFileCount()) > 0 | 236 (prompt_->ShouldShowPermissions() + prompt_->GetRetainedFileCount()) > 0 |
205 ? kPermissionsLeftColumnWidth | 237 ? kPermissionsLeftColumnWidth |
206 : kNoPermissionsLeftColumnWidth; | 238 : kNoPermissionsLeftColumnWidth; |
207 if (is_bundle_install()) | |
208 left_column_width = kBundleLeftColumnWidth; | |
209 if (is_external_install()) | 239 if (is_external_install()) |
210 left_column_width = kExternalInstallLeftColumnWidth; | 240 left_column_width = kExternalInstallLeftColumnWidth; |
211 | 241 |
212 scroll_view_ = new views::ScrollView(); | 242 scroll_view_ = new views::ScrollView(); |
213 scroll_view_->set_hide_horizontal_scrollbar(true); | 243 scroll_view_->set_hide_horizontal_scrollbar(true); |
214 AddChildView(scroll_view_); | 244 AddChildView(scroll_view_); |
215 | 245 |
216 int column_set_id = 0; | 246 int column_set_id = 0; |
217 // Create the full scrollable view which will contain all the information | 247 // Create the full scrollable view which will contain all the information |
218 // including the permissions. | 248 // including the permissions. |
219 scrollable_ = new CustomScrollableView(); | 249 scrollable_ = new CustomScrollableView(); |
220 views::GridLayout* layout = CreateLayout( | 250 views::GridLayout* layout = CreateLayout( |
221 scrollable_, left_column_width, column_set_id, false); | 251 scrollable_, left_column_width, column_set_id, false); |
222 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 252 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
223 | 253 |
224 scroll_view_->SetContents(scrollable_); | 254 scroll_view_->SetContents(scrollable_); |
225 | 255 |
226 int dialog_width = left_column_width + 2 * views::kPanelHorizMargin; | 256 int dialog_width = left_column_width + 2 * views::kPanelHorizMargin; |
227 if (!is_bundle_install()) | 257 dialog_width += views::kPanelHorizMargin + kIconSize + kIconOffset; |
228 dialog_width += views::kPanelHorizMargin + kIconSize + kIconOffset; | |
229 | 258 |
230 if (prompt_->has_webstore_data()) { | 259 if (prompt_->has_webstore_data()) { |
231 layout->StartRow(0, column_set_id); | 260 layout->StartRow(0, column_set_id); |
232 views::View* rating = new views::View(); | 261 views::View* rating = new views::View(); |
233 rating->SetLayoutManager(new views::BoxLayout( | 262 rating->SetLayoutManager(new views::BoxLayout( |
234 views::BoxLayout::kHorizontal, 0, 0, 0)); | 263 views::BoxLayout::kHorizontal, 0, 0, 0)); |
235 layout->AddView(rating); | 264 layout->AddView(rating); |
236 prompt_->AppendRatingStars(AddResourceIcon, rating); | 265 prompt_->AppendRatingStars(AddResourceIcon, rating); |
237 | 266 |
238 const gfx::FontList& small_font_list = | 267 const gfx::FontList& small_font_list = |
(...skipping 15 matching lines...) Expand all Loading... |
254 views::Link* store_link = new views::Link( | 283 views::Link* store_link = new views::Link( |
255 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); | 284 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); |
256 store_link->SetFontList(small_font_list); | 285 store_link->SetFontList(small_font_list); |
257 store_link->set_listener(this); | 286 store_link->set_listener(this); |
258 layout->AddView(store_link); | 287 layout->AddView(store_link); |
259 } | 288 } |
260 | 289 |
261 if (is_bundle_install()) { | 290 if (is_bundle_install()) { |
262 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( | 291 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( |
263 BundleInstaller::Item::STATE_PENDING); | 292 BundleInstaller::Item::STATE_PENDING); |
264 for (size_t i = 0; i < items.size(); ++i) { | 293 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
265 base::string16 extension_name = | 294 for (const BundleInstaller::Item& item : items) { |
266 base::UTF8ToUTF16(items[i].localized_name); | |
267 base::i18n::AdjustStringForLocaleDirection(&extension_name); | |
268 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
269 layout->StartRow(0, column_set_id); | 295 layout->StartRow(0, column_set_id); |
270 views::Label* extension_label = new views::Label( | 296 views::Label* extension_label = |
271 PrepareForDisplay(extension_name, true)); | 297 new views::Label(item.GetNameForDisplay()); |
272 extension_label->SetMultiLine(true); | 298 extension_label->SetMultiLine(true); |
273 extension_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 299 extension_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
274 extension_label->SizeToFit(left_column_width); | 300 extension_label->SizeToFit( |
275 layout->AddView(extension_label); | 301 left_column_width - kSmallIconSize - kSmallIconPadding); |
| 302 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(item.icon); |
| 303 layout->AddView(new IconedView(extension_label, image)); |
276 } | 304 } |
| 305 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
277 } | 306 } |
278 | 307 |
279 bool has_permissions = | 308 bool has_permissions = |
280 prompt_->GetPermissionCount( | 309 prompt_->GetPermissionCount( |
281 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) > 0; | 310 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) > 0; |
282 if (prompt_->ShouldShowPermissions()) { | 311 if (prompt_->ShouldShowPermissions()) { |
283 AddPermissions( | 312 AddPermissions( |
284 layout, | 313 layout, |
285 rb, | 314 rb, |
286 column_set_id, | 315 column_set_id, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 views::GridLayout* layout = views::GridLayout::CreatePanel(parent); | 494 views::GridLayout* layout = views::GridLayout::CreatePanel(parent); |
466 parent->SetLayoutManager(layout); | 495 parent->SetLayoutManager(layout); |
467 | 496 |
468 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 497 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
469 column_set->AddColumn(views::GridLayout::LEADING, | 498 column_set->AddColumn(views::GridLayout::LEADING, |
470 views::GridLayout::FILL, | 499 views::GridLayout::FILL, |
471 0, // no resizing | 500 0, // no resizing |
472 views::GridLayout::USE_PREF, | 501 views::GridLayout::USE_PREF, |
473 0, // no fixed width | 502 0, // no fixed width |
474 left_column_width); | 503 left_column_width); |
475 if (!is_bundle_install()) { | 504 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
476 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 505 column_set->AddColumn(views::GridLayout::TRAILING, |
477 column_set->AddColumn(views::GridLayout::TRAILING, | 506 views::GridLayout::LEADING, |
478 views::GridLayout::LEADING, | 507 0, // no resizing |
479 0, // no resizing | 508 views::GridLayout::USE_PREF, |
480 views::GridLayout::USE_PREF, | 509 0, // no fixed width |
481 0, // no fixed width | 510 kIconSize); |
482 kIconSize); | |
483 } | |
484 | 511 |
485 layout->StartRow(0, column_set_id); | 512 layout->StartRow(0, column_set_id); |
486 | 513 |
487 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 514 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
488 | 515 |
489 views::Label* heading = new views::Label( | 516 views::Label* heading = new views::Label( |
490 prompt_->GetHeading(), rb.GetFontList(ui::ResourceBundle::MediumFont)); | 517 prompt_->GetHeading(), rb.GetFontList(ui::ResourceBundle::MediumFont)); |
491 heading->SetMultiLine(true); | 518 heading->SetMultiLine(true); |
492 heading->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 519 heading->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
493 heading->SizeToFit(left_column_width); | 520 heading->SizeToFit(left_column_width); |
494 layout->AddView(heading); | 521 layout->AddView(heading); |
495 | 522 |
496 if (!is_bundle_install()) { | 523 // Scale down to icon size, but allow smaller icons (don't scale up). |
497 // Scale down to icon size, but allow smaller icons (don't scale up). | 524 const gfx::ImageSkia* image = prompt_->icon().ToImageSkia(); |
498 const gfx::ImageSkia* image = prompt_->icon().ToImageSkia(); | 525 gfx::Size size(image->width(), image->height()); |
499 gfx::Size size(image->width(), image->height()); | 526 if (size.width() > kIconSize || size.height() > kIconSize) |
500 if (size.width() > kIconSize || size.height() > kIconSize) | 527 size = gfx::Size(kIconSize, kIconSize); |
501 size = gfx::Size(kIconSize, kIconSize); | 528 views::ImageView* icon = new views::ImageView(); |
502 views::ImageView* icon = new views::ImageView(); | 529 icon->SetImageSize(size); |
503 icon->SetImageSize(size); | 530 icon->SetImage(*image); |
504 icon->SetImage(*image); | 531 icon->SetHorizontalAlignment(views::ImageView::CENTER); |
505 icon->SetHorizontalAlignment(views::ImageView::CENTER); | 532 icon->SetVerticalAlignment(views::ImageView::CENTER); |
506 icon->SetVerticalAlignment(views::ImageView::CENTER); | 533 if (single_detail_row) { |
507 if (single_detail_row) { | 534 layout->AddView(icon); |
508 layout->AddView(icon); | 535 } else { |
509 } else { | 536 int icon_row_span = 1; |
510 int icon_row_span = 1; | 537 if (is_inline_install()) { |
511 if (is_inline_install()) { | 538 // Also span the rating, user_count and store_link rows. |
512 // Also span the rating, user_count and store_link rows. | 539 icon_row_span = 4; |
513 icon_row_span = 4; | 540 } else if (prompt_->ShouldShowPermissions()) { |
514 } else if (prompt_->ShouldShowPermissions()) { | 541 size_t permission_count = prompt_->GetPermissionCount( |
515 size_t permission_count = prompt_->GetPermissionCount( | 542 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); |
516 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); | 543 // Also span the permission header and each of the permission rows (all |
517 // Also span the permission header and each of the permission rows (all | 544 // have a padding row above it). This also works for the 'no special |
518 // have a padding row above it). This also works for the 'no special | 545 // permissions' case. |
519 // permissions' case. | 546 icon_row_span = 3 + permission_count * 2; |
520 icon_row_span = 3 + permission_count * 2; | 547 } else if (prompt_->GetRetainedFileCount()) { |
521 } else if (prompt_->GetRetainedFileCount()) { | 548 // Also span the permission header and the retained files container. |
522 // Also span the permission header and the retained files container. | 549 icon_row_span = 4; |
523 icon_row_span = 4; | |
524 } | |
525 layout->AddView(icon, 1, icon_row_span); | |
526 } | 550 } |
| 551 layout->AddView(icon, 1, icon_row_span); |
527 } | 552 } |
| 553 |
528 return layout; | 554 return layout; |
529 } | 555 } |
530 | 556 |
531 void ExtensionInstallDialogView::ContentsChanged() { | 557 void ExtensionInstallDialogView::ContentsChanged() { |
532 Layout(); | 558 Layout(); |
533 } | 559 } |
534 | 560 |
535 int ExtensionInstallDialogView::GetDialogButtons() const { | 561 int ExtensionInstallDialogView::GetDialogButtons() const { |
536 int buttons = prompt_->GetDialogButtons(); | 562 int buttons = prompt_->GetDialogButtons(); |
537 // Simply having just an OK button is *not* supported. See comment on function | 563 // Simply having just an OK button is *not* supported. See comment on function |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 slide_animation_.Hide(); | 845 slide_animation_.Hide(); |
820 else | 846 else |
821 slide_animation_.Show(); | 847 slide_animation_.Show(); |
822 } | 848 } |
823 | 849 |
824 // static | 850 // static |
825 ExtensionInstallPrompt::ShowDialogCallback | 851 ExtensionInstallPrompt::ShowDialogCallback |
826 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { | 852 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { |
827 return base::Bind(&ShowExtensionInstallDialogImpl); | 853 return base::Bind(&ShowExtensionInstallDialogImpl); |
828 } | 854 } |
OLD | NEW |