blob: 619b9be443eb4aef74c99667799de6cfba6f1c67 [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]e0ebb8d2014-05-21 20:26:2713#include "extensions/browser/extension_registry.h"
[email protected]326e6f02014-06-20 04:53:3714#include "extensions/browser/image_loader.h"
[email protected]cda103d2014-04-04 16:22:3915#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4116#include "extensions/common/extension.h"
[email protected]4b7908842014-04-07 23:50:2217#include "extensions/common/extension_icon_set.h"
[email protected]993da5e2013-03-23 21:25:1618#include "extensions/common/extension_resource.h"
[email protected]0db486f2014-04-09 19:32:2219#include "extensions/common/manifest_handlers/icons_handler.h"
[email protected]502e39612011-03-26 01:36:2820#include "grit/generated_resources.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]502e39612011-03-26 01:36:2823#include "ui/base/resource/resource_bundle.h"
[email protected]bdd6eec2012-03-03 19:58:0624#include "ui/gfx/image/image.h"
[email protected]50b66262013-09-24 03:25:4825#include "ui/gfx/image/image_skia.h"
[email protected]502e39612011-03-26 01:36:2826
[email protected]d4050672014-06-04 09:18:4027namespace extensions {
28
[email protected]dd46a4ce2012-09-15 10:50:5029namespace {
30
[email protected]dd46a4ce2012-09-15 10:50:5031// Returns bitmap for the default icon with size equal to the default icon's
32// pixel size under maximal supported scale factor.
33SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
[email protected]d4050672014-06-04 09:18:4034 const gfx::ImageSkia& image =
35 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon();
[email protected]50b66262013-09-24 03:25:4836 return image.GetRepresentation(
37 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
[email protected]dd46a4ce2012-09-15 10:50:5038}
39
40} // namespace
41
[email protected]6f03db062011-09-22 20:37:1442ExtensionUninstallDialog::ExtensionUninstallDialog(
[email protected]520414b12013-01-22 19:27:3643 Profile* profile,
[email protected]2a4939a2014-07-25 09:22:5244 gfx::NativeWindow parent,
[email protected]6f03db062011-09-22 20:37:1445 ExtensionUninstallDialog::Delegate* delegate)
[email protected]520414b12013-01-22 19:27:3646 : profile_(profile),
[email protected]2a4939a2014-07-25 09:22:5247 parent_(parent),
[email protected]6f03db062011-09-22 20:37:1448 delegate_(delegate),
[email protected]502e39612011-03-26 01:36:2849 extension_(NULL),
[email protected]226d79ad2014-03-14 21:34:5750 triggering_extension_(NULL),
[email protected]b3a25092013-05-28 22:08:1651 ui_loop_(base::MessageLoop::current()) {
[email protected]5f1ba412012-06-25 20:10:5252}
[email protected]502e39612011-03-26 01:36:2853
[email protected]5f1ba412012-06-25 20:10:5254ExtensionUninstallDialog::~ExtensionUninstallDialog() {
[email protected]5f1ba412012-06-25 20:10:5255}
[email protected]502e39612011-03-26 01:36:2856
[email protected]226d79ad2014-03-14 21:34:5757void ExtensionUninstallDialog::ConfirmProgrammaticUninstall(
[email protected]d4050672014-06-04 09:18:4058 const Extension* extension,
59 const Extension* triggering_extension) {
[email protected]226d79ad2014-03-14 21:34:5760 triggering_extension_ = triggering_extension;
61 ConfirmUninstall(extension);
62}
63
[email protected]d4050672014-06-04 09:18:4064void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) {
[email protected]b3a25092013-05-28 22:08:1665 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]502e39612011-03-26 01:36:2866 extension_ = extension;
[email protected]0d0ba182014-06-03 12:40:4367 // Bookmark apps may not have 128x128 icons so accept 64x64 icons.
[email protected]36a813162014-02-05 05:32:1968 const int icon_size = extension_->from_bookmark()
[email protected]0d0ba182014-06-03 12:40:4369 ? extension_misc::EXTENSION_ICON_SMALL * 2
70 : extension_misc::EXTENSION_ICON_LARGE;
[email protected]d4050672014-06-04 09:18:4071 ExtensionResource image = IconsInfo::GetIconResource(
72 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER);
[email protected]eed85492013-01-14 20:37:4673
74 // Load the image asynchronously. The response will be sent to OnImageLoaded.
[email protected]d4050672014-06-04 09:18:4075 ImageLoader* loader = ImageLoader::Get(profile_);
[email protected]0d0ba182014-06-03 12:40:4376
[email protected]2a4939a2014-07-25 09:22:5277 SetIcon(gfx::Image());
[email protected]d4050672014-06-04 09:18:4078 std::vector<ImageLoader::ImageRepresentation> images_list;
79 images_list.push_back(ImageLoader::ImageRepresentation(
[email protected]0d0ba182014-06-03 12:40:4380 image,
[email protected]d4050672014-06-04 09:18:4081 ImageLoader::ImageRepresentation::NEVER_RESIZE,
[email protected]0d0ba182014-06-03 12:40:4382 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]502e39612011-03-26 01:36:2889}
90
[email protected]bdd6eec2012-03-03 19:58:0691void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
92 if (image.IsEmpty()) {
[email protected]dd46a4ce2012-09-15 10:50:5093 // 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]32e7a9b2013-01-23 23:00:1998 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(
[email protected]1bc3ef02012-10-24 16:49:5999 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()));
[email protected]bdd6eec2012-03-03 19:58:06100 } else {
[email protected]6280b5882012-06-05 21:56:41101 icon_ = *image.ToImageSkia();
[email protected]502e39612011-03-26 01:36:28102 }
103}
104
[email protected]e0ebb8d2014-05-21 20:26:27105void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id,
106 const gfx::Image& image) {
[email protected]d4050672014-06-04 09:18:40107 const Extension* target_extension =
108 ExtensionRegistry::Get(profile_)
109 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
[email protected]e0ebb8d2014-05-21 20:26:27110 if (!target_extension) {
111 delegate_->ExtensionUninstallCanceled();
112 return;
113 }
114
[email protected]502e39612011-03-26 01:36:28115 SetIcon(image);
[email protected]2a4939a2014-07-25 09:22:52116 Show();
[email protected]5f1ba412012-06-25 20:10:52117}
[email protected]226d79ad2014-03-14 21:34:57118
119std::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]d4050672014-06-04 09:18:40129
130} // namespace extensions