OLD | NEW |
---|---|
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 using extensions::Manifest; | |
Matt Giuca
2014/02/12 06:22:34
Is there a good reason to have this using here? Yo
sashab
2014/02/17 07:20:56
Was using it more before an edit :) Removed, thank
| |
27 | |
28 // Size of extension icon in top left of dialog. | |
29 const int kIconSize = 64; | |
Matt Giuca
2014/02/12 06:22:34
So does it look good (crisp) now using 64 instead
sashab
2014/02/17 07:20:56
Yes, comparing 69 to 64 there is a noticable diffe
| |
30 | |
18 void ShowChromeAppInfoDialog(gfx::NativeWindow parent_window, | 31 void ShowChromeAppInfoDialog(gfx::NativeWindow parent_window, |
19 Profile* profile, | 32 Profile* profile, |
20 const extensions::Extension* app, | 33 const extensions::Extension* app, |
21 const base::Closure& close_callback) { | 34 const base::Closure& close_callback) { |
22 CreateBrowserModalDialogViews(new AppInfoView(profile, app, close_callback), | 35 CreateBrowserModalDialogViews(new AppInfoView(profile, app, close_callback), |
23 parent_window)->Show(); | 36 parent_window)->Show(); |
24 } | 37 } |
25 | 38 |
26 AppInfoView::AppInfoView(Profile* profile, | 39 AppInfoView::AppInfoView(Profile* profile, |
27 const extensions::Extension* app, | 40 const extensions::Extension* app, |
28 const base::Closure& close_callback) | 41 const base::Closure& close_callback) |
29 : profile_(profile), | 42 : profile_(profile), |
30 app_name_label(NULL), | 43 app_name_label(NULL), |
31 app_description_label(NULL), | 44 app_description_label(NULL), |
32 app_(app), | 45 app_(app), |
33 close_callback_(close_callback) { | 46 close_callback_(close_callback), |
47 weak_ptr_factory_(this) { | |
Matt Giuca
2014/02/12 06:22:34
I think we discussed this using weak pointers but
sashab
2014/02/17 07:20:56
From my understanding, this is actually correct -
| |
48 | |
34 // Create controls | 49 // Create controls |
35 app_name_label = new views::Label(base::UTF8ToUTF16(app_->name())); | 50 app_name_label = new views::Label(base::UTF8ToUTF16(app_->name())); |
36 app_name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 51 app_name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
37 | 52 |
38 app_description_label = | 53 app_description_label = |
39 new views::Label(base::UTF8ToUTF16(app_->description())); | 54 new views::Label(base::UTF8ToUTF16(app_->description())); |
40 app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 55 app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
41 | 56 |
42 // Layout controls | 57 app_version_label = |
58 new views::Label(base::UTF8ToUTF16(app_->VersionString())); | |
59 app_version_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
60 | |
61 app_icon = new views::ImageView(); | |
62 app_icon->SetImageSize(gfx::Size(kIconSize, kIconSize)); | |
63 | |
64 permission_list_heading = new views::Label( | |
65 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_CAN_ACCESS)); | |
66 permission_list_heading->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
67 | |
68 // Get the permission messages for the app | |
69 scoped_refptr<const extensions::PermissionSet> permissions = | |
70 app_->GetActivePermissions(); | |
71 Manifest::Type extension_type = | |
72 app_ ? app_->GetType() : Manifest::TYPE_UNKNOWN; | |
73 std::vector<base::string16> permission_messages = | |
74 extensions::PermissionMessageProvider::Get()->GetWarningMessages( | |
75 permissions, extension_type); | |
76 | |
77 // Load the app icon asynchronously. For the response, check OnImageLoaded. | |
78 // TODO(sashab, mguica): Update this to use ImageFamily::GetBest() instead. | |
Matt Giuca
2014/02/12 06:22:34
TODOs should preferably have only one person in th
sashab
2014/02/17 07:20:56
Ahh yes, you're right, this is old :) Removed, tha
| |
79 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | |
80 app, | |
81 extension_misc::EXTENSION_ICON_LARGE, | |
82 ExtensionIconSet::MATCH_BIGGER); | |
83 int pixel_size = | |
84 static_cast<int>(kIconSize * gfx::ImageSkia::GetMaxSupportedScale()); | |
85 extensions::ImageLoader::Get(profile) | |
86 ->LoadImageAsync(app, | |
87 image, | |
88 gfx::Size(pixel_size, pixel_size), | |
89 base::Bind(&AppInfoView::OnAppImageLoaded, AsWeakPtr())); | |
90 | |
91 // Create the layout | |
43 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 92 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
44 SetLayoutManager(layout); | 93 SetLayoutManager(layout); |
45 | 94 |
95 // Header column set with app icon and information | |
46 static const int kHeaderColumnSetId = 0; | 96 static const int kHeaderColumnSetId = 0; |
47 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); | 97 views::ColumnSet* header_column_set = |
48 column_set->AddColumn(views::GridLayout::FILL, | 98 layout->AddColumnSet(kHeaderColumnSetId); |
49 views::GridLayout::CENTER, | 99 header_column_set->AddColumn(views::GridLayout::FILL, |
50 100.0f, | 100 views::GridLayout::CENTER, |
51 views::GridLayout::FIXED, | 101 0, |
52 0, | 102 views::GridLayout::FIXED, |
53 0); | 103 kIconSize, |
104 0); | |
105 header_column_set->AddPaddingColumn(0, | |
106 views::kRelatedControlHorizontalSpacing); | |
107 header_column_set->AddColumn(views::GridLayout::FILL, | |
108 views::GridLayout::CENTER, | |
109 100.0f, | |
110 views::GridLayout::FIXED, | |
111 0, | |
112 0); | |
113 | |
114 // Create 2 columns: 1 for the bullet, one for the bullet text | |
115 static const int kPermissionBulletsColumnSetId = 1; | |
Matt Giuca
2014/02/12 06:22:34
I remember when sammc did his permissions dialog,
sashab
2014/02/17 07:20:56
Okay, the permissions part is now scrollable. Ther
| |
116 views::ColumnSet* permission_bullets_column_set = | |
117 layout->AddColumnSet(kPermissionBulletsColumnSetId); | |
118 permission_bullets_column_set->AddPaddingColumn(0, 10); | |
119 permission_bullets_column_set->AddColumn(views::GridLayout::LEADING, | |
120 views::GridLayout::LEADING, | |
121 0, | |
122 views::GridLayout::USE_PREF, | |
123 0, // no fixed width | |
124 0); | |
125 permission_bullets_column_set->AddPaddingColumn(0, 5); | |
126 permission_bullets_column_set->AddColumn(views::GridLayout::LEADING, | |
127 views::GridLayout::LEADING, | |
128 0, | |
129 views::GridLayout::USE_PREF, | |
130 0, // no fixed width | |
131 0); | |
132 | |
133 // The app icon takes up 3 rows | |
134 layout->StartRow(0, kHeaderColumnSetId); | |
135 layout->AddView(app_icon, 1, 3); | |
136 | |
137 // The app information fills up the right side of the icon | |
138 layout->AddView(app_name_label); | |
54 | 139 |
55 layout->StartRow(0, kHeaderColumnSetId); | 140 layout->StartRow(0, kHeaderColumnSetId); |
56 layout->AddView(app_name_label); | 141 layout->SkipColumns(1); |
142 layout->AddView(app_version_label); | |
57 | 143 |
58 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); | |
59 layout->StartRow(0, kHeaderColumnSetId); | 144 layout->StartRow(0, kHeaderColumnSetId); |
145 layout->SkipColumns(1); | |
60 layout->AddView(app_description_label); | 146 layout->AddView(app_description_label); |
147 | |
148 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
149 | |
150 layout->StartRow(0, kHeaderColumnSetId); | |
151 layout->AddView(permission_list_heading); | |
152 | |
153 for (std::vector<base::string16>::const_iterator it = | |
154 permission_messages.begin(); | |
155 it != permission_messages.end(); | |
156 ++it) { | |
157 views::Label* permission_label = new views::Label(*it); | |
158 | |
159 permission_label->SetMultiLine(true); | |
160 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
161 permission_label->SizeToFit(250); | |
162 | |
163 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
164 layout->StartRow(0, kPermissionBulletsColumnSetId); | |
165 // Extract only the bullet from the IDS_EXTENSION_PERMISSION_LINE text. | |
166 layout->AddView(new views::Label(l10n_util::GetStringFUTF16( | |
167 IDS_EXTENSION_PERMISSION_LINE, base::string16()))); | |
168 // Place the text second, so multi-lined permissions line up below the | |
169 // bullet. | |
170 layout->AddView(permission_label); | |
171 } | |
61 } | 172 } |
62 | 173 |
63 AppInfoView::~AppInfoView() {} | 174 AppInfoView::~AppInfoView() {} |
64 | 175 |
65 bool AppInfoView::Cancel() { | 176 bool AppInfoView::Cancel() { |
66 if (!close_callback_.is_null()) | 177 if (!close_callback_.is_null()) |
67 close_callback_.Run(); | 178 close_callback_.Run(); |
68 return true; | 179 return true; |
69 } | 180 } |
70 | 181 |
71 gfx::Size AppInfoView::GetPreferredSize() { | 182 gfx::Size AppInfoView::GetPreferredSize() { |
72 static const int kDialogWidth = 360; | 183 static const int kDialogWidth = 360; |
73 int height = | 184 int height = |
74 GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth); | 185 GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth); |
75 return gfx::Size(kDialogWidth, height); | 186 return gfx::Size(kDialogWidth, height); |
76 } | 187 } |
77 | 188 |
78 base::string16 AppInfoView::GetDialogButtonLabel(ui::DialogButton button) | 189 base::string16 AppInfoView::GetDialogButtonLabel(ui::DialogButton button) |
79 const { | 190 const { |
80 if (button == ui::DIALOG_BUTTON_CANCEL) { | 191 if (button == ui::DIALOG_BUTTON_CANCEL) { |
81 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_CLOSE_BUTTON); | 192 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_CLOSE_BUTTON); |
82 } | 193 } |
83 return views::DialogDelegateView::GetDialogButtonLabel(button); | 194 return views::DialogDelegateView::GetDialogButtonLabel(button); |
84 } | 195 } |
85 | 196 |
86 int AppInfoView::GetDialogButtons() const { | 197 int AppInfoView::GetDialogButtons() const { return ui::DIALOG_BUTTON_CANCEL; } |
87 return ui::DIALOG_BUTTON_CANCEL; | |
88 } | |
89 | 198 |
90 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const { | 199 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const { |
91 return true; | 200 return true; |
92 } | 201 } |
93 | 202 |
94 ui::ModalType AppInfoView::GetModalType() const { | 203 ui::ModalType AppInfoView::GetModalType() const { |
95 return ui::MODAL_TYPE_WINDOW; | 204 return ui::MODAL_TYPE_WINDOW; |
96 } | 205 } |
97 | 206 |
98 base::string16 AppInfoView::GetWindowTitle() const { | 207 base::string16 AppInfoView::GetWindowTitle() const { |
99 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE); | 208 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE); |
100 } | 209 } |
210 | |
211 void AppInfoView::OnAppImageLoaded(const gfx::Image& image) { | |
212 const SkBitmap* bitmap = image.ToSkBitmap(); | |
213 if (image.IsEmpty()) { | |
214 // Let's set default icon bitmap whose size is equal to the default icon's | |
Matt Giuca
2014/02/12 06:22:34
This is somewhat informal.
I think you just want
sashab
2014/02/17 07:20:56
Oh, I didn't write this, whoops. I think it's left
| |
215 // pixel size under maximal supported scale factor. If the bitmap is larger | |
216 // than the one we need, it will be scaled down by the ui code | |
217 bitmap = &extensions::IconsInfo::GetDefaultAppIcon() | |
218 .GetRepresentation(gfx::ImageSkia::GetMaxSupportedScale()) | |
219 .sk_bitmap(); | |
220 } | |
221 | |
222 app_icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(*bitmap)); | |
223 } | |
OLD | NEW |