1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_icon_set.h"
12 #include "chrome/common/extensions/extension_resource.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/resource/resource_bundle.h"
16
17 // Size of extension icon in top left of dialog.
18 static const int kIconSize = 69;
19
ExtensionUninstallDialog(Profile * profile)20 ExtensionUninstallDialog::ExtensionUninstallDialog(Profile* profile)
21 : profile_(profile),
22 ui_loop_(MessageLoop::current()),
23 delegate_(NULL),
24 extension_(NULL),
25 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
26 }
27
~ExtensionUninstallDialog()28 ExtensionUninstallDialog::~ExtensionUninstallDialog() {
29 }
30
ConfirmUninstall(Delegate * delegate,const Extension * extension)31 void ExtensionUninstallDialog::ConfirmUninstall(Delegate* delegate,
32 const Extension* extension) {
33 DCHECK(ui_loop_ == MessageLoop::current());
34 delegate_ = delegate;
35 extension_ = extension;
36
37 ExtensionResource image =
38 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE,
39 ExtensionIconSet::MATCH_EXACTLY);
40 // Load the image asynchronously. The response will be sent to OnImageLoaded.
41 tracker_.LoadImage(extension_, image,
42 gfx::Size(kIconSize, kIconSize),
43 ImageLoadingTracker::DONT_CACHE);
44 }
45
SetIcon(SkBitmap * image)46 void ExtensionUninstallDialog::SetIcon(SkBitmap* image) {
47 if (image)
48 icon_ = *image;
49 else
50 icon_ = SkBitmap();
51 if (icon_.empty()) {
52 if (extension_->is_app()) {
53 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed(
54 IDR_APP_DEFAULT_ICON);
55 } else {
56 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed(
57 IDR_EXTENSION_DEFAULT_ICON);
58 }
59 }
60 }
61
OnImageLoaded(SkBitmap * image,const ExtensionResource & resource,int index)62 void ExtensionUninstallDialog::OnImageLoaded(SkBitmap* image,
63 const ExtensionResource& resource,
64 int index) {
65 SetIcon(image);
66
67 Show(profile_, delegate_, extension_, &icon_);
68 }
69