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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 namespace extensions { | 35 namespace extensions { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char kExtensionRemovedError[] = | 39 const char kExtensionRemovedError[] = |
40 "Extension was removed before dialog closed."; | 40 "Extension was removed before dialog closed."; |
41 | 41 |
42 const char kReferrerId[] = "chrome-remove-extension-dialog"; | 42 const char kReferrerId[] = "chrome-remove-extension-dialog"; |
43 | 43 |
44 // Returns bitmap for the default icon with size equal to the default icon's | 44 // Returns gfx::ImageSkia for the default icon. |
45 // pixel size under maximal supported scale factor. | 45 gfx::ImageSkia GetDefaultIconImage(bool is_app) { |
46 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { | 46 return is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); |
47 const gfx::ImageSkia& image = | |
48 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); | |
49 return image.GetRepresentation( | |
50 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | |
51 } | 47 } |
52 | 48 |
53 } // namespace | 49 } // namespace |
54 | 50 |
55 ExtensionUninstallDialog::ExtensionUninstallDialog( | 51 ExtensionUninstallDialog::ExtensionUninstallDialog( |
56 Profile* profile, | 52 Profile* profile, |
57 ExtensionUninstallDialog::Delegate* delegate) | 53 ExtensionUninstallDialog::Delegate* delegate) |
58 : profile_(profile), | 54 : profile_(profile), |
59 delegate_(delegate), | 55 delegate_(delegate), |
60 uninstall_reason_(UNINSTALL_REASON_FOR_TESTING) { | 56 uninstall_reason_(UNINSTALL_REASON_FOR_TESTING) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 ImageLoader::ImageRepresentation::NEVER_RESIZE, | 96 ImageLoader::ImageRepresentation::NEVER_RESIZE, |
101 gfx::Size(), | 97 gfx::Size(), |
102 ui::SCALE_FACTOR_100P)); | 98 ui::SCALE_FACTOR_100P)); |
103 loader->LoadImagesAsync(extension_.get(), images_list, | 99 loader->LoadImagesAsync(extension_.get(), images_list, |
104 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, | 100 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, |
105 AsWeakPtr(), extension_->id())); | 101 AsWeakPtr(), extension_->id())); |
106 } | 102 } |
107 | 103 |
108 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { | 104 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { |
109 if (image.IsEmpty()) { | 105 if (image.IsEmpty()) { |
110 // Let's set default icon bitmap whose size is equal to the default icon's | 106 icon_ = GetDefaultIconImage(extension_->is_app()); |
111 // pixel size under maximal supported scale factor. If the bitmap is larger | |
112 // than the one we need, it will be scaled down by the ui code. | |
113 // TODO(tbarzic): We should use IconImage here and load the required bitmap | |
114 // lazily. | |
115 icon_ = gfx::ImageSkia::CreateFrom1xBitmap( | |
116 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app())); | |
117 } else { | 107 } else { |
118 icon_ = *image.ToImageSkia(); | 108 icon_ = *image.ToImageSkia(); |
119 } | 109 } |
120 } | 110 } |
121 | 111 |
122 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id, | 112 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id, |
123 const gfx::Image& image) { | 113 const gfx::Image& image) { |
124 const Extension* target_extension = | 114 const Extension* target_extension = |
125 ExtensionRegistry::Get(profile_) | 115 ExtensionRegistry::Get(profile_) |
126 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 116 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void ExtensionUninstallDialog::HandleReportAbuse() { | 193 void ExtensionUninstallDialog::HandleReportAbuse() { |
204 chrome::NavigateParams params( | 194 chrome::NavigateParams params( |
205 profile_, | 195 profile_, |
206 extension_urls::GetWebstoreReportAbuseUrl(extension_->id(), kReferrerId), | 196 extension_urls::GetWebstoreReportAbuseUrl(extension_->id(), kReferrerId), |
207 ui::PAGE_TRANSITION_LINK); | 197 ui::PAGE_TRANSITION_LINK); |
208 params.disposition = NEW_FOREGROUND_TAB; | 198 params.disposition = NEW_FOREGROUND_TAB; |
209 chrome::Navigate(¶ms); | 199 chrome::Navigate(¶ms); |
210 } | 200 } |
211 | 201 |
212 } // namespace extensions | 202 } // namespace extensions |
OLD | NEW |