[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 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" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 9 | #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] | d7a8ef6 | 2012-06-22 16:28:46 | [diff] [blame] | 13 | #include "grit/theme_resources_standard.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 14 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 15 | #include "ui/gfx/image/image.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 16 | |
| 17 | // Size of extension icon in top left of dialog. |
| 18 | static const int kIconSize = 69; |
| 19 | |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 20 | ExtensionUninstallDialog::ExtensionUninstallDialog( |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 21 | Browser* browser, |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 22 | ExtensionUninstallDialog::Delegate* delegate) |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 23 | : browser_(browser), |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 24 | delegate_(delegate), |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 25 | extension_(NULL), |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 26 | ui_loop_(MessageLoop::current()) { |
| 27 | tracker_.reset(new ImageLoadingTracker(this)); |
| 28 | BrowserList::AddObserver(this); |
| 29 | } |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 30 | |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 31 | ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
| 32 | BrowserList::RemoveObserver(this); |
| 33 | } |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 34 | |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 35 | void ExtensionUninstallDialog::ConfirmUninstall( |
| 36 | const extensions::Extension* extension) { |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 37 | DCHECK(ui_loop_ == MessageLoop::current()); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 38 | extension_ = extension; |
| 39 | |
| 40 | ExtensionResource image = |
[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 41 | extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, |
| 42 | ExtensionIconSet::MATCH_BIGGER); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 43 | // Load the image asynchronously. The response will be sent to OnImageLoaded. |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 44 | tracker_->LoadImage(extension_, image, |
| 45 | gfx::Size(kIconSize, kIconSize), |
| 46 | ImageLoadingTracker::DONT_CACHE); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 49 | void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { |
| 50 | if (image.IsEmpty()) { |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 51 | if (extension_->is_app()) { |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 52 | icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 53 | IDR_APP_DEFAULT_ICON); |
| 54 | } else { |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 55 | icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 56 | IDR_EXTENSION_DEFAULT_ICON); |
| 57 | } |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 58 | } else { |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 59 | icon_ = *image.ToImageSkia(); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 63 | void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image, |
| 64 | const std::string& extension_id, |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 65 | int index) { |
| 66 | SetIcon(image); |
| 67 | |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 68 | // 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] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 72 | Show(); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 73 | } |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame^] | 74 | |
| 75 | void 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 | } |