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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "extensions/common/manifest_handlers/icons_handler.h" | 23 #include "extensions/common/manifest_handlers/icons_handler.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
29 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Returns pixel size under maximal scale factor for the icon whose device | |
34 // independent size is |size_in_dip| | |
35 int GetSizeForMaxScaleFactor(int size_in_dip) { | |
36 float max_scale_factor_scale = gfx::ImageSkia::GetMaxSupportedScale(); | |
37 | |
38 return static_cast<int>(size_in_dip * max_scale_factor_scale); | |
39 } | |
40 | |
41 // Returns bitmap for the default icon with size equal to the default icon's | 33 // Returns bitmap for the default icon with size equal to the default icon's |
42 // pixel size under maximal supported scale factor. | 34 // pixel size under maximal supported scale factor. |
43 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { | 35 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
44 const gfx::ImageSkia& image = is_app ? | 36 const gfx::ImageSkia& image = is_app ? |
45 extensions::util::GetDefaultAppIcon() : | 37 extensions::util::GetDefaultAppIcon() : |
46 extensions::util::GetDefaultExtensionIcon(); | 38 extensions::util::GetDefaultExtensionIcon(); |
47 return image.GetRepresentation( | 39 return image.GetRepresentation( |
48 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 40 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
49 } | 41 } |
50 | 42 |
51 } // namespace | 43 } // namespace |
52 | 44 |
53 // Size of extension icon in top left of dialog. | |
54 static const int kIconSize = 69; | |
tapted
2014/05/29 05:14:28
drive-by: This constant is used in some mac .xib (
sashab
2014/05/29 05:19:18
This was feedback from a UX reviewer. The icon siz
| |
55 | |
56 ExtensionUninstallDialog::ExtensionUninstallDialog( | 45 ExtensionUninstallDialog::ExtensionUninstallDialog( |
57 Profile* profile, | 46 Profile* profile, |
58 Browser* browser, | 47 Browser* browser, |
59 ExtensionUninstallDialog::Delegate* delegate) | 48 ExtensionUninstallDialog::Delegate* delegate) |
60 : profile_(profile), | 49 : profile_(profile), |
61 browser_(browser), | 50 browser_(browser), |
62 delegate_(delegate), | 51 delegate_(delegate), |
63 extension_(NULL), | 52 extension_(NULL), |
64 triggering_extension_(NULL), | 53 triggering_extension_(NULL), |
65 state_(kImageIsLoading), | 54 state_(kImageIsLoading), |
(...skipping 15 matching lines...) Expand all Loading... | |
81 ConfirmUninstall(extension); | 70 ConfirmUninstall(extension); |
82 } | 71 } |
83 | 72 |
84 void ExtensionUninstallDialog::ConfirmUninstall( | 73 void ExtensionUninstallDialog::ConfirmUninstall( |
85 const extensions::Extension* extension) { | 74 const extensions::Extension* extension) { |
86 DCHECK(ui_loop_ == base::MessageLoop::current()); | 75 DCHECK(ui_loop_ == base::MessageLoop::current()); |
87 extension_ = extension; | 76 extension_ = extension; |
88 // Bookmark apps may not have 128x128 icons so accept 48x48 icons. | 77 // Bookmark apps may not have 128x128 icons so accept 48x48 icons. |
89 const int icon_size = extension_->from_bookmark() | 78 const int icon_size = extension_->from_bookmark() |
90 ? extension_misc::EXTENSION_ICON_MEDIUM | 79 ? extension_misc::EXTENSION_ICON_MEDIUM |
91 : extension_misc::EXTENSION_ICON_LARGE; | 80 : extension_misc::EXTENSION_ICON_LARGE; |
calamity
2014/05/29 05:36:21
I have a hunch that you can now change this to use
| |
92 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 81 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
93 extension_, | 82 extension_, |
94 icon_size, | 83 icon_size, |
95 ExtensionIconSet::MATCH_BIGGER); | 84 ExtensionIconSet::MATCH_BIGGER); |
96 // Load the icon whose pixel size is large enough to be displayed under | |
97 // maximal supported scale factor. UI code will scale the icon down if needed. | |
98 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | |
99 | 85 |
100 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 86 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
101 state_ = kImageIsLoading; | 87 state_ = kImageIsLoading; |
102 extensions::ImageLoader* loader = | 88 extensions::ImageLoader* loader = |
103 extensions::ImageLoader::Get(profile_); | 89 extensions::ImageLoader::Get(profile_); |
104 loader->LoadImageAsync(extension_, | 90 |
105 image, | 91 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
106 gfx::Size(pixel_size, pixel_size), | 92 images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
107 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, | 93 image, |
108 AsWeakPtr(), | 94 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
109 extension_->id())); | 95 gfx::Size(0, 0), |
calamity
2014/05/29 05:36:21
gfx::Size()
sashab
2014/05/29 05:46:15
Done.
| |
96 ui::SCALE_FACTOR_100P)); | |
97 loader->LoadImagesAsync(extension_, | |
98 images_list, | |
99 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, | |
100 AsWeakPtr(), | |
101 extension_->id())); | |
110 } | 102 } |
111 | 103 |
112 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { | 104 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { |
113 if (image.IsEmpty()) { | 105 if (image.IsEmpty()) { |
114 // Let's set default icon bitmap whose size is equal to the default icon's | 106 // Let's set default icon bitmap whose size is equal to the default icon's |
115 // pixel size under maximal supported scale factor. If the bitmap is larger | 107 // pixel size under maximal supported scale factor. If the bitmap is larger |
116 // than the one we need, it will be scaled down by the ui code. | 108 // than the one we need, it will be scaled down by the ui code. |
117 // TODO(tbarzic): We should use IconImage here and load the required bitmap | 109 // TODO(tbarzic): We should use IconImage here and load the required bitmap |
118 // lazily. | 110 // lazily. |
119 icon_ = gfx::ImageSkia::CreateFrom1xBitmap( | 111 icon_ = gfx::ImageSkia::CreateFrom1xBitmap( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 std::string ExtensionUninstallDialog::GetHeadingText() { | 155 std::string ExtensionUninstallDialog::GetHeadingText() { |
164 if (triggering_extension_) { | 156 if (triggering_extension_) { |
165 return l10n_util::GetStringFUTF8( | 157 return l10n_util::GetStringFUTF8( |
166 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, | 158 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, |
167 base::UTF8ToUTF16(triggering_extension_->name()), | 159 base::UTF8ToUTF16(triggering_extension_->name()), |
168 base::UTF8ToUTF16(extension_->name())); | 160 base::UTF8ToUTF16(extension_->name())); |
169 } | 161 } |
170 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, | 162 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
171 base::UTF8ToUTF16(extension_->name())); | 163 base::UTF8ToUTF16(extension_->name())); |
172 } | 164 } |
OLD | NEW |