Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_uninstall_dialog.cc
blobb805d037e00c0e8e8c1bc9ff842cd0d93429d2da
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/image_loader.h"
18 #include "extensions/common/constants.h"
19 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_icon_set.h"
21 #include "extensions/common/extension_resource.h"
22 #include "extensions/common/extension_urls.h"
23 #include "extensions/common/manifest_handlers/icons_handler.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/page_transition_types.h"
26 #include "ui/base/window_open_disposition.h"
27 #include "ui/gfx/image/image.h"
28 #include "ui/gfx/image/image_skia.h"
30 namespace extensions {
32 namespace {
34 // Returns bitmap for the default icon with size equal to the default icon's
35 // pixel size under maximal supported scale factor.
36 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
37 const gfx::ImageSkia& image =
38 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon();
39 return image.GetRepresentation(
40 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
43 } // namespace
45 ExtensionUninstallDialog::ExtensionUninstallDialog(
46 Profile* profile,
47 ExtensionUninstallDialog::Delegate* delegate)
48 : profile_(profile),
49 delegate_(delegate),
50 extension_(NULL),
51 triggering_extension_(NULL),
52 ui_loop_(base::MessageLoop::current()) {
55 ExtensionUninstallDialog::~ExtensionUninstallDialog() {
58 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall(
59 const Extension* extension,
60 const Extension* triggering_extension) {
61 triggering_extension_ = triggering_extension;
62 ConfirmUninstall(extension);
65 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) {
66 DCHECK(ui_loop_ == base::MessageLoop::current());
67 extension_ = extension;
68 // Bookmark apps may not have 128x128 icons so accept 64x64 icons.
69 const int icon_size = extension_->from_bookmark()
70 ? extension_misc::EXTENSION_ICON_SMALL * 2
71 : extension_misc::EXTENSION_ICON_LARGE;
72 ExtensionResource image = IconsInfo::GetIconResource(
73 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER);
75 // Load the image asynchronously. The response will be sent to OnImageLoaded.
76 ImageLoader* loader = ImageLoader::Get(profile_);
78 SetIcon(gfx::Image());
79 std::vector<ImageLoader::ImageRepresentation> images_list;
80 images_list.push_back(ImageLoader::ImageRepresentation(
81 image,
82 ImageLoader::ImageRepresentation::NEVER_RESIZE,
83 gfx::Size(),
84 ui::SCALE_FACTOR_100P));
85 loader->LoadImagesAsync(extension_,
86 images_list,
87 base::Bind(&ExtensionUninstallDialog::OnImageLoaded,
88 AsWeakPtr(),
89 extension_->id()));
92 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
93 if (image.IsEmpty()) {
94 // Let's set default icon bitmap whose size is equal to the default icon's
95 // pixel size under maximal supported scale factor. If the bitmap is larger
96 // than the one we need, it will be scaled down by the ui code.
97 // TODO(tbarzic): We should use IconImage here and load the required bitmap
98 // lazily.
99 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(
100 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()));
101 } else {
102 icon_ = *image.ToImageSkia();
106 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id,
107 const gfx::Image& image) {
108 const Extension* target_extension =
109 ExtensionRegistry::Get(profile_)
110 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
111 if (!target_extension) {
112 delegate_->ExtensionUninstallCanceled();
113 return;
116 SetIcon(image);
117 Show();
120 std::string ExtensionUninstallDialog::GetHeadingText() {
121 if (triggering_extension_) {
122 return l10n_util::GetStringFUTF8(
123 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING,
124 base::UTF8ToUTF16(triggering_extension_->name()),
125 base::UTF8ToUTF16(extension_->name()));
127 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
128 base::UTF8ToUTF16(extension_->name()));
131 bool ExtensionUninstallDialog::ShouldShowReportAbuseCheckbox() const {
132 return base::FieldTrialList::FindFullName("ExtensionUninstall.ReportAbuse") ==
133 "ShowCheckbox";
136 void ExtensionUninstallDialog::HandleReportAbuse() {
137 chrome::NavigateParams params(
138 profile_,
139 extension_urls::GetWebstoreReportAbuseUrl(extension_->id()),
140 ui::PAGE_TRANSITION_LINK);
141 params.disposition = NEW_FOREGROUND_TAB;
142 chrome::Navigate(&params);
145 } // namespace extensions