[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 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 8 | #include "base/logging.h" |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 9 | #include "base/message_loop/message_loop.h" |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 472522b | 2013-10-25 00:41:28 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
[email protected] | e0ebb8d | 2014-05-21 20:26:27 | [diff] [blame] | 13 | #include "extensions/browser/extension_registry.h" |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 14 | #include "extensions/browser/image_loader.h" |
[email protected] | cda103d | 2014-04-04 16:22:39 | [diff] [blame] | 15 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 16 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 17 | #include "extensions/common/extension_icon_set.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 18 | #include "extensions/common/extension_resource.h" |
[email protected] | 0db486f | 2014-04-09 19:32:22 | [diff] [blame] | 19 | #include "extensions/common/manifest_handlers/icons_handler.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 20 | #include "grit/generated_resources.h" |
[email protected] | 2a28133 | 2012-07-11 22:20:23 | [diff] [blame] | 21 | #include "grit/theme_resources.h" |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 22 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 23 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 24 | #include "ui/gfx/image/image.h" |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 25 | #include "ui/gfx/image/image_skia.h" |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 26 | |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 27 | namespace extensions { |
| 28 | |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 29 | namespace { |
| 30 | |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 31 | // Returns bitmap for the default icon with size equal to the default icon's |
| 32 | // pixel size under maximal supported scale factor. |
| 33 | SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 34 | const gfx::ImageSkia& image = |
| 35 | is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 36 | return image.GetRepresentation( |
| 37 | gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | } // namespace |
| 41 | |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 42 | ExtensionUninstallDialog::ExtensionUninstallDialog( |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 43 | Profile* profile, |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame^] | 44 | gfx::NativeWindow parent, |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 45 | ExtensionUninstallDialog::Delegate* delegate) |
[email protected] | 520414b1 | 2013-01-22 19:27:36 | [diff] [blame] | 46 | : profile_(profile), |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame^] | 47 | parent_(parent), |
[email protected] | 6f03db06 | 2011-09-22 20:37:14 | [diff] [blame] | 48 | delegate_(delegate), |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 49 | extension_(NULL), |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 50 | triggering_extension_(NULL), |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 51 | ui_loop_(base::MessageLoop::current()) { |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame] | 52 | } |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 53 | |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame] | 54 | ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame] | 55 | } |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 56 | |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 57 | void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 58 | const Extension* extension, |
| 59 | const Extension* triggering_extension) { |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 60 | triggering_extension_ = triggering_extension; |
| 61 | ConfirmUninstall(extension); |
| 62 | } |
| 63 | |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 64 | void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 65 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 66 | extension_ = extension; |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 67 | // Bookmark apps may not have 128x128 icons so accept 64x64 icons. |
[email protected] | 36a81316 | 2014-02-05 05:32:19 | [diff] [blame] | 68 | const int icon_size = extension_->from_bookmark() |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 69 | ? extension_misc::EXTENSION_ICON_SMALL * 2 |
| 70 | : extension_misc::EXTENSION_ICON_LARGE; |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 71 | ExtensionResource image = IconsInfo::GetIconResource( |
| 72 | extension_, icon_size, ExtensionIconSet::MATCH_BIGGER); |
[email protected] | eed8549 | 2013-01-14 20:37:46 | [diff] [blame] | 73 | |
| 74 | // Load the image asynchronously. The response will be sent to OnImageLoaded. |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 75 | ImageLoader* loader = ImageLoader::Get(profile_); |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 76 | |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame^] | 77 | SetIcon(gfx::Image()); |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 78 | std::vector<ImageLoader::ImageRepresentation> images_list; |
| 79 | images_list.push_back(ImageLoader::ImageRepresentation( |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 80 | image, |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 81 | ImageLoader::ImageRepresentation::NEVER_RESIZE, |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 82 | gfx::Size(), |
| 83 | ui::SCALE_FACTOR_100P)); |
| 84 | loader->LoadImagesAsync(extension_, |
| 85 | images_list, |
| 86 | base::Bind(&ExtensionUninstallDialog::OnImageLoaded, |
| 87 | AsWeakPtr(), |
| 88 | extension_->id())); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 91 | void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { |
| 92 | if (image.IsEmpty()) { |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 93 | // Let's set default icon bitmap whose size is equal to the default icon's |
| 94 | // pixel size under maximal supported scale factor. If the bitmap is larger |
| 95 | // than the one we need, it will be scaled down by the ui code. |
| 96 | // TODO(tbarzic): We should use IconImage here and load the required bitmap |
| 97 | // lazily. |
[email protected] | 32e7a9b | 2013-01-23 23:00:19 | [diff] [blame] | 98 | icon_ = gfx::ImageSkia::CreateFrom1xBitmap( |
[email protected] | 1bc3ef0 | 2012-10-24 16:49:59 | [diff] [blame] | 99 | GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app())); |
[email protected] | bdd6eec | 2012-03-03 19:58:06 | [diff] [blame] | 100 | } else { |
[email protected] | 6280b588 | 2012-06-05 21:56:41 | [diff] [blame] | 101 | icon_ = *image.ToImageSkia(); |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
[email protected] | e0ebb8d | 2014-05-21 20:26:27 | [diff] [blame] | 105 | void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id, |
| 106 | const gfx::Image& image) { |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 107 | const Extension* target_extension = |
| 108 | ExtensionRegistry::Get(profile_) |
| 109 | ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
[email protected] | e0ebb8d | 2014-05-21 20:26:27 | [diff] [blame] | 110 | if (!target_extension) { |
| 111 | delegate_->ExtensionUninstallCanceled(); |
| 112 | return; |
| 113 | } |
| 114 | |
[email protected] | 502e3961 | 2011-03-26 01:36:28 | [diff] [blame] | 115 | SetIcon(image); |
[email protected] | 2a4939a | 2014-07-25 09:22:52 | [diff] [blame^] | 116 | Show(); |
[email protected] | 5f1ba41 | 2012-06-25 20:10:52 | [diff] [blame] | 117 | } |
[email protected] | 226d79ad | 2014-03-14 21:34:57 | [diff] [blame] | 118 | |
| 119 | std::string ExtensionUninstallDialog::GetHeadingText() { |
| 120 | if (triggering_extension_) { |
| 121 | return l10n_util::GetStringFUTF8( |
| 122 | IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, |
| 123 | base::UTF8ToUTF16(triggering_extension_->name()), |
| 124 | base::UTF8ToUTF16(extension_->name())); |
| 125 | } |
| 126 | return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
| 127 | base::UTF8ToUTF16(extension_->name())); |
| 128 | } |
[email protected] | d405067 | 2014-06-04 09:18:40 | [diff] [blame] | 129 | |
| 130 | } // namespace extensions |