blob: 1425f57ec7d9b593f47073aa209bd70370fb4aa9 [file] [log] [blame]
[email protected]e3c0bc22012-02-24 01:34:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]502e39612011-03-26 01:36:282// 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"
[email protected]502e39612011-03-26 01:36:289#include "chrome/common/extensions/extension.h"
10#include "chrome/common/extensions/extension_icon_set.h"
11#include "chrome/common/extensions/extension_resource.h"
12#include "grit/generated_resources.h"
[email protected]d7a8ef62012-06-22 16:28:4613#include "grit/theme_resources_standard.h"
[email protected]502e39612011-03-26 01:36:2814#include "ui/base/resource/resource_bundle.h"
[email protected]bdd6eec2012-03-03 19:58:0615#include "ui/gfx/image/image.h"
[email protected]502e39612011-03-26 01:36:2816
17// Size of extension icon in top left of dialog.
18static const int kIconSize = 69;
19
[email protected]6f03db062011-09-22 20:37:1420ExtensionUninstallDialog::ExtensionUninstallDialog(
[email protected]5f1ba412012-06-25 20:10:5221 Browser* browser,
[email protected]6f03db062011-09-22 20:37:1422 ExtensionUninstallDialog::Delegate* delegate)
[email protected]5f1ba412012-06-25 20:10:5223 : browser_(browser),
[email protected]6f03db062011-09-22 20:37:1424 delegate_(delegate),
[email protected]502e39612011-03-26 01:36:2825 extension_(NULL),
[email protected]5f1ba412012-06-25 20:10:5226 ui_loop_(MessageLoop::current()) {
27 tracker_.reset(new ImageLoadingTracker(this));
28 BrowserList::AddObserver(this);
29}
[email protected]502e39612011-03-26 01:36:2830
[email protected]5f1ba412012-06-25 20:10:5231ExtensionUninstallDialog::~ExtensionUninstallDialog() {
32 BrowserList::RemoveObserver(this);
33}
[email protected]502e39612011-03-26 01:36:2834
[email protected]1c321ee52012-05-21 03:02:3435void ExtensionUninstallDialog::ConfirmUninstall(
36 const extensions::Extension* extension) {
[email protected]502e39612011-03-26 01:36:2837 DCHECK(ui_loop_ == MessageLoop::current());
[email protected]502e39612011-03-26 01:36:2838 extension_ = extension;
39
40 ExtensionResource image =
[email protected]e3c0bc22012-02-24 01:34:1541 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE,
42 ExtensionIconSet::MATCH_BIGGER);
[email protected]502e39612011-03-26 01:36:2843 // Load the image asynchronously. The response will be sent to OnImageLoaded.
[email protected]5f1ba412012-06-25 20:10:5244 tracker_->LoadImage(extension_, image,
45 gfx::Size(kIconSize, kIconSize),
46 ImageLoadingTracker::DONT_CACHE);
[email protected]502e39612011-03-26 01:36:2847}
48
[email protected]bdd6eec2012-03-03 19:58:0649void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
50 if (image.IsEmpty()) {
[email protected]502e39612011-03-26 01:36:2851 if (extension_->is_app()) {
[email protected]6280b5882012-06-05 21:56:4152 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
[email protected]502e39612011-03-26 01:36:2853 IDR_APP_DEFAULT_ICON);
54 } else {
[email protected]6280b5882012-06-05 21:56:4155 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
[email protected]502e39612011-03-26 01:36:2856 IDR_EXTENSION_DEFAULT_ICON);
57 }
[email protected]bdd6eec2012-03-03 19:58:0658 } else {
[email protected]6280b5882012-06-05 21:56:4159 icon_ = *image.ToImageSkia();
[email protected]502e39612011-03-26 01:36:2860 }
61}
62
[email protected]bdd6eec2012-03-03 19:58:0663void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image,
64 const std::string& extension_id,
[email protected]502e39612011-03-26 01:36:2865 int index) {
66 SetIcon(image);
67
[email protected]5f1ba412012-06-25 20:10:5268 // Reset the tracker so that we can use its presence as a signal that we're
69 // still waiting for the icon to load.
70 tracker_.reset();
71
[email protected]6f03db062011-09-22 20:37:1472 Show();
[email protected]502e39612011-03-26 01:36:2873}
[email protected]5f1ba412012-06-25 20:10:5274
75void ExtensionUninstallDialog::OnBrowserRemoved(Browser* browser) {
76 if (browser_ != browser)
77 return;
78
79 browser_ = NULL;
80 if (tracker_.get()) {
81 // If we're waiting for the icon, stop doing so because we're not going to
82 // show the dialog.
83 tracker_.reset();
84 delegate_->ExtensionUninstallCanceled();
85 }
86}