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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_icon_set.h" | 11 #include "chrome/common/extensions/extension_icon_set.h" |
12 #include "chrome/common/extensions/extension_resource.h" | 12 #include "chrome/common/extensions/extension_resource.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image.h" |
16 | 17 |
17 // Size of extension icon in top left of dialog. | 18 // Size of extension icon in top left of dialog. |
18 static const int kIconSize = 69; | 19 static const int kIconSize = 69; |
19 | 20 |
20 ExtensionUninstallDialog::ExtensionUninstallDialog( | 21 ExtensionUninstallDialog::ExtensionUninstallDialog( |
21 Profile* profile, | 22 Profile* profile, |
22 ExtensionUninstallDialog::Delegate* delegate) | 23 ExtensionUninstallDialog::Delegate* delegate) |
23 : profile_(profile), | 24 : profile_(profile), |
24 delegate_(delegate), | 25 delegate_(delegate), |
25 extension_(NULL), | 26 extension_(NULL), |
26 ui_loop_(MessageLoop::current()), | 27 ui_loop_(MessageLoop::current()), |
27 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {} | 28 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {} |
28 | 29 |
29 ExtensionUninstallDialog::~ExtensionUninstallDialog() {} | 30 ExtensionUninstallDialog::~ExtensionUninstallDialog() {} |
30 | 31 |
31 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { | 32 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { |
32 DCHECK(ui_loop_ == MessageLoop::current()); | 33 DCHECK(ui_loop_ == MessageLoop::current()); |
33 extension_ = extension; | 34 extension_ = extension; |
34 | 35 |
35 ExtensionResource image = | 36 ExtensionResource image = |
36 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, | 37 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, |
37 ExtensionIconSet::MATCH_BIGGER); | 38 ExtensionIconSet::MATCH_BIGGER); |
38 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 39 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
39 tracker_.LoadImage(extension_, image, | 40 tracker_.LoadImage(extension_, image, |
40 gfx::Size(kIconSize, kIconSize), | 41 gfx::Size(kIconSize, kIconSize), |
41 ImageLoadingTracker::DONT_CACHE); | 42 ImageLoadingTracker::DONT_CACHE); |
42 } | 43 } |
43 | 44 |
44 void ExtensionUninstallDialog::SetIcon(SkBitmap* image) { | 45 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { |
45 if (image) | 46 if (image.IsEmpty()) { |
46 icon_ = *image; | |
47 else | |
48 icon_ = SkBitmap(); | |
49 if (icon_.empty()) { | |
50 if (extension_->is_app()) { | 47 if (extension_->is_app()) { |
51 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 48 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
52 IDR_APP_DEFAULT_ICON); | 49 IDR_APP_DEFAULT_ICON); |
53 } else { | 50 } else { |
54 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 51 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
55 IDR_EXTENSION_DEFAULT_ICON); | 52 IDR_EXTENSION_DEFAULT_ICON); |
56 } | 53 } |
| 54 } else { |
| 55 icon_ = *image.ToSkBitmap(); |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 void ExtensionUninstallDialog::OnImageLoaded(SkBitmap* image, | 59 void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image, |
61 const ExtensionResource& resource, | 60 const std::string& extension_id, |
62 int index) { | 61 int index) { |
63 SetIcon(image); | 62 SetIcon(image); |
64 | 63 |
65 Show(); | 64 Show(); |
66 } | 65 } |
OLD | NEW |