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

Side by Side Diff: chrome/browser/ui/views/apps/app_info_dialog_views.cc

Issue 146583010: Extend App Info dialog to include app shortcut and list of permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor typo Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/apps/app_info_dialog_views.h ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/apps/app_info_dialog_views.h" 5 #include "chrome/browser/ui/views/apps/app_info_dialog_views.h"
6 6
7 #include "base/bind.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/image_loader.h"
10 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/apps/app_info_dialog.h" 11 #include "chrome/browser/ui/apps/app_info_dialog.h"
9 #include "chrome/browser/ui/views/constrained_window_views.h" 12 #include "chrome/browser/ui/views/constrained_window_views.h"
13 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_icon_set.h"
15 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
10 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
17 #include "extensions/common/permissions/permission_message_provider.h"
18 #include "extensions/common/permissions/permission_set.h"
11 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/grid_layout.h" 22 #include "ui/views/layout/grid_layout.h"
15 #include "ui/views/layout/layout_constants.h" 23 #include "ui/views/layout/layout_constants.h"
16 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
17 25
26 // Size of extension icon in top left of dialog.
27 const int kIconSize = 64;
28
18 void ShowChromeAppInfoDialog(gfx::NativeWindow parent_window, 29 void ShowChromeAppInfoDialog(gfx::NativeWindow parent_window,
19 Profile* profile, 30 Profile* profile,
20 const extensions::Extension* app, 31 const extensions::Extension* app,
21 const base::Closure& close_callback) { 32 const base::Closure& close_callback) {
22 CreateBrowserModalDialogViews(new AppInfoView(profile, app, close_callback), 33 CreateBrowserModalDialogViews(new AppInfoView(profile, app, close_callback),
23 parent_window)->Show(); 34 parent_window)->Show();
24 } 35 }
25 36
37 PermissionsScrollView::PermissionsScrollView(int min_height,
38 int max_height,
39 const extensions::Extension* app)
40 : message_center::BoundedScrollView(min_height, max_height) {
41 inner_scrollable_view = new views::View();
42 this->SetContents(inner_scrollable_view);
43
44 // Get the permission messages for the app
45 scoped_refptr<const extensions::PermissionSet> permissions =
46 app->GetActivePermissions();
47 extensions::Manifest::Type extension_type =
48 app ? app->GetType() : extensions::Manifest::TYPE_UNKNOWN;
benwells 2014/02/19 00:23:29 I don't think app can be NULL here (you deref it u
sashab 2014/02/19 03:03:00 Yup, you're right, thanks for pointing this out. I
49 std::vector<base::string16> permission_messages =
50 extensions::PermissionMessageProvider::Get()->GetWarningMessages(
51 permissions, extension_type);
52
53 // Create the layout
54 views::GridLayout* layout =
55 views::GridLayout::CreatePanel(inner_scrollable_view);
56 inner_scrollable_view->SetLayoutManager(layout);
57
58 // Create 2 columns: one for the bullet, one for the bullet text
59 static const int kPermissionBulletsColumnSetId = 1;
60 views::ColumnSet* permission_bullets_column_set =
61 layout->AddColumnSet(kPermissionBulletsColumnSetId);
62 permission_bullets_column_set->AddPaddingColumn(0, 10);
63 permission_bullets_column_set->AddColumn(views::GridLayout::LEADING,
64 views::GridLayout::LEADING,
65 0,
66 views::GridLayout::USE_PREF,
67 0, // no fixed width
68 0);
69 permission_bullets_column_set->AddPaddingColumn(0, 5);
70 permission_bullets_column_set->AddColumn(views::GridLayout::LEADING,
71 views::GridLayout::LEADING,
72 0,
73 views::GridLayout::USE_PREF,
74 0, // no fixed width
75 0);
76
77 // Add permissions to scrollable view
78 for (std::vector<base::string16>::const_iterator it =
79 permission_messages.begin();
80 it != permission_messages.end();
81 ++it) {
82 views::Label* permission_label = new views::Label(*it);
83
84 permission_label->SetMultiLine(true);
85 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
86 permission_label->SizeToFit(250);
87
88 layout->StartRow(0, kPermissionBulletsColumnSetId);
89 // Extract only the bullet from the IDS_EXTENSION_PERMISSION_LINE text.
90 layout->AddView(new views::Label(l10n_util::GetStringFUTF16(
91 IDS_EXTENSION_PERMISSION_LINE, base::string16())));
92 // Place the text second, so multi-lined permissions line up below the
93 // bullet.
94 layout->AddView(permission_label);
95
96 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
97 }
98 }
99
100 PermissionsScrollView::~PermissionsScrollView() {}
101
26 AppInfoView::AppInfoView(Profile* profile, 102 AppInfoView::AppInfoView(Profile* profile,
27 const extensions::Extension* app, 103 const extensions::Extension* app,
28 const base::Closure& close_callback) 104 const base::Closure& close_callback)
29 : profile_(profile), 105 : profile_(profile),
30 app_name_label(NULL), 106 app_name_label(NULL),
31 app_description_label(NULL), 107 app_description_label(NULL),
32 app_(app), 108 app_(app),
33 close_callback_(close_callback) { 109 close_callback_(close_callback),
110 weak_ptr_factory_(this) {
34 // Create controls 111 // Create controls
35 app_name_label = new views::Label(base::UTF8ToUTF16(app_->name())); 112 app_name_label = new views::Label(base::UTF8ToUTF16(app_->name()));
36 app_name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 113 app_name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
37 114
38 app_description_label = 115 app_description_label =
39 new views::Label(base::UTF8ToUTF16(app_->description())); 116 new views::Label(base::UTF8ToUTF16(app_->description()));
40 app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 117 app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
41 118
42 // Layout controls 119 app_version_label =
120 new views::Label(base::UTF8ToUTF16(app_->VersionString()));
121 app_version_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
122
123 app_icon = new views::ImageView();
124 app_icon->SetImageSize(gfx::Size(kIconSize, kIconSize));
125
126 permission_list_heading = new views::Label(
127 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_CAN_ACCESS));
128 permission_list_heading->SetHorizontalAlignment(gfx::ALIGN_LEFT);
129
130 permissions_scroll_view = new PermissionsScrollView(0, 100, app);
131
132 // Load the app icon asynchronously. For the response, check OnImageLoaded.
133 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
134 app,
135 extension_misc::EXTENSION_ICON_LARGE,
136 ExtensionIconSet::MATCH_BIGGER);
137 int pixel_size =
138 static_cast<int>(kIconSize * gfx::ImageSkia::GetMaxSupportedScale());
139 extensions::ImageLoader::Get(profile)
140 ->LoadImageAsync(app,
141 image,
142 gfx::Size(pixel_size, pixel_size),
143 base::Bind(&AppInfoView::OnAppImageLoaded, AsWeakPtr()));
144
145 // Create the layout
43 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 146 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
44 SetLayoutManager(layout); 147 SetLayoutManager(layout);
45 148
149 // Header column set with app icon and information
46 static const int kHeaderColumnSetId = 0; 150 static const int kHeaderColumnSetId = 0;
47 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); 151 views::ColumnSet* header_column_set =
48 column_set->AddColumn(views::GridLayout::FILL, 152 layout->AddColumnSet(kHeaderColumnSetId);
49 views::GridLayout::CENTER, 153 header_column_set->AddColumn(views::GridLayout::FILL,
50 100.0f, 154 views::GridLayout::CENTER,
51 views::GridLayout::FIXED, 155 0,
52 0, 156 views::GridLayout::FIXED,
53 0); 157 kIconSize,
158 0);
159 header_column_set->AddPaddingColumn(0,
160 views::kRelatedControlHorizontalSpacing);
161 header_column_set->AddColumn(views::GridLayout::FILL,
162 views::GridLayout::CENTER,
163 100.0f,
164 views::GridLayout::FIXED,
165 0,
166 0);
167
168 // Column set with scrollable permissions
169 static const int kPermissionsColumnSetId = 1;
170 views::ColumnSet* permissions_column_set =
171 layout->AddColumnSet(kPermissionsColumnSetId);
172 permissions_column_set->AddColumn(views::GridLayout::FILL,
173 views::GridLayout::CENTER,
174 100.0f,
175 views::GridLayout::FIXED,
176 0,
177 0);
178
179 // The app icon takes up 3 rows
180 layout->StartRow(0, kHeaderColumnSetId);
181 layout->AddView(app_icon, 1, 3);
182
183 // The app information fills up the right side of the icon
184 layout->AddView(app_name_label);
54 185
55 layout->StartRow(0, kHeaderColumnSetId); 186 layout->StartRow(0, kHeaderColumnSetId);
56 layout->AddView(app_name_label); 187 layout->SkipColumns(1);
188 layout->AddView(app_version_label);
57 189
58 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing);
59 layout->StartRow(0, kHeaderColumnSetId); 190 layout->StartRow(0, kHeaderColumnSetId);
191 layout->SkipColumns(1);
60 layout->AddView(app_description_label); 192 layout->AddView(app_description_label);
193
194 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
195
196 layout->StartRow(0, kPermissionsColumnSetId);
197 layout->AddView(permission_list_heading);
198
199 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
200
201 layout->StartRow(0, kPermissionsColumnSetId);
202 layout->AddView(permissions_scroll_view);
61 } 203 }
62 204
63 AppInfoView::~AppInfoView() {} 205 AppInfoView::~AppInfoView() {}
64 206
65 bool AppInfoView::Cancel() { 207 bool AppInfoView::Cancel() {
66 if (!close_callback_.is_null()) 208 if (!close_callback_.is_null())
67 close_callback_.Run(); 209 close_callback_.Run();
68 return true; 210 return true;
69 } 211 }
70 212
71 gfx::Size AppInfoView::GetPreferredSize() { 213 gfx::Size AppInfoView::GetPreferredSize() {
72 static const int kDialogWidth = 360; 214 static const int kDialogWidth = 360;
73 int height = 215 int height =
74 GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth); 216 GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth);
75 return gfx::Size(kDialogWidth, height); 217 return gfx::Size(kDialogWidth, height);
76 } 218 }
77 219
78 base::string16 AppInfoView::GetDialogButtonLabel(ui::DialogButton button) 220 base::string16 AppInfoView::GetDialogButtonLabel(ui::DialogButton button)
79 const { 221 const {
80 if (button == ui::DIALOG_BUTTON_CANCEL) { 222 if (button == ui::DIALOG_BUTTON_CANCEL) {
81 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_CLOSE_BUTTON); 223 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_CLOSE_BUTTON);
82 } 224 }
83 return views::DialogDelegateView::GetDialogButtonLabel(button); 225 return views::DialogDelegateView::GetDialogButtonLabel(button);
84 } 226 }
85 227
86 int AppInfoView::GetDialogButtons() const { 228 int AppInfoView::GetDialogButtons() const { return ui::DIALOG_BUTTON_CANCEL; }
87 return ui::DIALOG_BUTTON_CANCEL;
88 }
89 229
90 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const { 230 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const {
91 return true; 231 return true;
92 } 232 }
93 233
94 ui::ModalType AppInfoView::GetModalType() const { 234 ui::ModalType AppInfoView::GetModalType() const {
95 return ui::MODAL_TYPE_WINDOW; 235 return ui::MODAL_TYPE_WINDOW;
96 } 236 }
97 237
98 base::string16 AppInfoView::GetWindowTitle() const { 238 base::string16 AppInfoView::GetWindowTitle() const {
99 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE); 239 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE);
100 } 240 }
241
242 void AppInfoView::OnAppImageLoaded(const gfx::Image& image) {
243 const SkBitmap* bitmap = image.ToSkBitmap();
244 if (image.IsEmpty()) {
245 bitmap = &extensions::IconsInfo::GetDefaultAppIcon()
246 .GetRepresentation(gfx::ImageSkia::GetMaxSupportedScale())
247 .sk_bitmap();
248 }
249
250 app_icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(*bitmap));
251 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/app_info_dialog_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698