blob: 735f95354c7ba67d60c4bac4b2f78f8f150ebd98 [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
[email protected]0d9a1da82013-03-14 21:52:077#include "base/bind.h"
[email protected]502e39612011-03-26 01:36:288#include "base/logging.h"
[email protected]b19fe572013-07-18 04:54:269#include "base/message_loop/message_loop.h"
[email protected]226d79ad2014-03-14 21:34:5710#include "base/strings/utf_string_conversions.h"
[email protected]7eb20e32014-04-30 08:50:5611#include "chrome/browser/extensions/extension_util.h"
[email protected]472522b2013-10-25 00:41:2812#include "chrome/browser/profiles/profile.h"
[email protected]af39f002014-08-22 10:18:1813#include "chrome/grit/generated_resources.h"
[email protected]e0ebb8d2014-05-21 20:26:2714#include "extensions/browser/extension_registry.h"
[email protected]326e6f02014-06-20 04:53:3715#include "extensions/browser/image_loader.h"
[email protected]cda103d2014-04-04 16:22:3916#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4117#include "extensions/common/extension.h"
[email protected]4b7908842014-04-07 23:50:2218#include "extensions/common/extension_icon_set.h"
[email protected]993da5e2013-03-23 21:25:1619#include "extensions/common/extension_resource.h"
[email protected]0db486f2014-04-09 19:32:2220#include "extensions/common/manifest_handlers/icons_handler.h"
[email protected]2a281332012-07-11 22:20:2321#include "grit/theme_resources.h"
[email protected]226d79ad2014-03-14 21:34:5722#include "ui/base/l10n/l10n_util.h"
[email protected]bdd6eec2012-03-03 19:58:0623#include "ui/gfx/image/image.h"
[email protected]50b66262013-09-24 03:25:4824#include "ui/gfx/image/image_skia.h"
[email protected]502e39612011-03-26 01:36:2825
[email protected]d4050672014-06-04 09:18:4026namespace extensions {
27
[email protected]dd46a4ce2012-09-15 10:50:5028namespace {
29
[email protected]dd46a4ce2012-09-15 10:50:5030// Returns bitmap for the default icon with size equal to the default icon's
31// pixel size under maximal supported scale factor.
32SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
[email protected]d4050672014-06-04 09:18:4033 const gfx::ImageSkia& image =
34 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon();
[email protected]50b66262013-09-24 03:25:4835 return image.GetRepresentation(
36 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
[email protected]dd46a4ce2012-09-15 10:50:5037}
38
39} // namespace
40
[email protected]6f03db062011-09-22 20:37:1441ExtensionUninstallDialog::ExtensionUninstallDialog(
[email protected]520414b12013-01-22 19:27:3642 Profile* profile,
[email protected]2a4939a2014-07-25 09:22:5243 gfx::NativeWindow parent,
[email protected]6f03db062011-09-22 20:37:1444 ExtensionUninstallDialog::Delegate* delegate)
[email protected]520414b12013-01-22 19:27:3645 : profile_(profile),
[email protected]2a4939a2014-07-25 09:22:5246 parent_(parent),
[email protected]6f03db062011-09-22 20:37:1447 delegate_(delegate),
[email protected]502e39612011-03-26 01:36:2848 extension_(NULL),
[email protected]226d79ad2014-03-14 21:34:5749 triggering_extension_(NULL),
[email protected]b3a25092013-05-28 22:08:1650 ui_loop_(base::MessageLoop::current()) {
[email protected]5f1ba412012-06-25 20:10:5251}
[email protected]502e39612011-03-26 01:36:2852
[email protected]5f1ba412012-06-25 20:10:5253ExtensionUninstallDialog::~ExtensionUninstallDialog() {
[email protected]5f1ba412012-06-25 20:10:5254}
[email protected]502e39612011-03-26 01:36:2855
[email protected]226d79ad2014-03-14 21:34:5756void ExtensionUninstallDialog::ConfirmProgrammaticUninstall(
[email protected]d4050672014-06-04 09:18:4057 const Extension* extension,
58 const Extension* triggering_extension) {
[email protected]226d79ad2014-03-14 21:34:5759 triggering_extension_ = triggering_extension;
60 ConfirmUninstall(extension);
61}
62
[email protected]d4050672014-06-04 09:18:4063void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) {
[email protected]b3a25092013-05-28 22:08:1664 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]502e39612011-03-26 01:36:2865 extension_ = extension;
[email protected]0d0ba182014-06-03 12:40:4366 // Bookmark apps may not have 128x128 icons so accept 64x64 icons.
[email protected]36a813162014-02-05 05:32:1967 const int icon_size = extension_->from_bookmark()
[email protected]0d0ba182014-06-03 12:40:4368 ? extension_misc::EXTENSION_ICON_SMALL * 2
69 : extension_misc::EXTENSION_ICON_LARGE;
[email protected]d4050672014-06-04 09:18:4070 ExtensionResource image = IconsInfo::GetIconResource(
71 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER);
[email protected]eed85492013-01-14 20:37:4672
73 // Load the image asynchronously. The response will be sent to OnImageLoaded.
[email protected]d4050672014-06-04 09:18:4074 ImageLoader* loader = ImageLoader::Get(profile_);
[email protected]0d0ba182014-06-03 12:40:4375
[email protected]2a4939a2014-07-25 09:22:5276 SetIcon(gfx::Image());
[email protected]d4050672014-06-04 09:18:4077 std::vector<ImageLoader::ImageRepresentation> images_list;
78 images_list.push_back(ImageLoader::ImageRepresentation(
[email protected]0d0ba182014-06-03 12:40:4379 image,
[email protected]d4050672014-06-04 09:18:4080 ImageLoader::ImageRepresentation::NEVER_RESIZE,
[email protected]0d0ba182014-06-03 12:40:4381 gfx::Size(),
82 ui::SCALE_FACTOR_100P));
83 loader->LoadImagesAsync(extension_,
84 images_list,
85 base::Bind(&ExtensionUninstallDialog::OnImageLoaded,
86 AsWeakPtr(),
87 extension_->id()));
[email protected]502e39612011-03-26 01:36:2888}
89
[email protected]bdd6eec2012-03-03 19:58:0690void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
91 if (image.IsEmpty()) {
[email protected]dd46a4ce2012-09-15 10:50:5092 // Let's set default icon bitmap whose size is equal to the default icon's
93 // pixel size under maximal supported scale factor. If the bitmap is larger
94 // than the one we need, it will be scaled down by the ui code.
95 // TODO(tbarzic): We should use IconImage here and load the required bitmap
96 // lazily.
[email protected]32e7a9b2013-01-23 23:00:1997 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(
[email protected]1bc3ef02012-10-24 16:49:5998 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()));
[email protected]bdd6eec2012-03-03 19:58:0699 } else {
[email protected]6280b5882012-06-05 21:56:41100 icon_ = *image.ToImageSkia();
[email protected]502e39612011-03-26 01:36:28101 }
102}
103
[email protected]e0ebb8d2014-05-21 20:26:27104void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id,
105 const gfx::Image& image) {
[email protected]d4050672014-06-04 09:18:40106 const Extension* target_extension =
107 ExtensionRegistry::Get(profile_)
108 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
[email protected]e0ebb8d2014-05-21 20:26:27109 if (!target_extension) {
110 delegate_->ExtensionUninstallCanceled();
111 return;
112 }
113
[email protected]502e39612011-03-26 01:36:28114 SetIcon(image);
[email protected]2a4939a2014-07-25 09:22:52115 Show();
[email protected]5f1ba412012-06-25 20:10:52116}
[email protected]226d79ad2014-03-14 21:34:57117
118std::string ExtensionUninstallDialog::GetHeadingText() {
119 if (triggering_extension_) {
120 return l10n_util::GetStringFUTF8(
121 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING,
122 base::UTF8ToUTF16(triggering_extension_->name()),
123 base::UTF8ToUTF16(extension_->name()));
124 }
125 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
126 base::UTF8ToUTF16(extension_->name()));
127}
[email protected]d4050672014-06-04 09:18:40128
129} // namespace extensions