Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/extensions/extension_uninstall_dialog.cc

Issue 307413002: Move ExtensionUninstallDialog into extensions namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 10 matching lines...) Expand all
21 #include "extensions/common/extension_icon_set.h" 21 #include "extensions/common/extension_icon_set.h"
22 #include "extensions/common/extension_resource.h" 22 #include "extensions/common/extension_resource.h"
23 #include "extensions/common/manifest_handlers/icons_handler.h" 23 #include "extensions/common/manifest_handlers/icons_handler.h"
24 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
30 30
31 namespace extensions {
32
31 namespace { 33 namespace {
32 34
33 // Returns bitmap for the default icon with size equal to the default icon's 35 // Returns bitmap for the default icon with size equal to the default icon's
34 // pixel size under maximal supported scale factor. 36 // pixel size under maximal supported scale factor.
35 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { 37 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
36 const gfx::ImageSkia& image = is_app ? 38 const gfx::ImageSkia& image =
37 extensions::util::GetDefaultAppIcon() : 39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon();
38 extensions::util::GetDefaultExtensionIcon();
39 return image.GetRepresentation( 40 return image.GetRepresentation(
40 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); 41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
41 } 42 }
42 43
43 } // namespace 44 } // namespace
44 45
45 ExtensionUninstallDialog::ExtensionUninstallDialog( 46 ExtensionUninstallDialog::ExtensionUninstallDialog(
46 Profile* profile, 47 Profile* profile,
47 Browser* browser, 48 Browser* browser,
48 ExtensionUninstallDialog::Delegate* delegate) 49 ExtensionUninstallDialog::Delegate* delegate)
49 : profile_(profile), 50 : profile_(profile),
50 browser_(browser), 51 browser_(browser),
51 delegate_(delegate), 52 delegate_(delegate),
52 extension_(NULL), 53 extension_(NULL),
53 triggering_extension_(NULL), 54 triggering_extension_(NULL),
54 state_(kImageIsLoading), 55 state_(kImageIsLoading),
55 ui_loop_(base::MessageLoop::current()) { 56 ui_loop_(base::MessageLoop::current()) {
56 if (browser) { 57 if (browser) {
57 registrar_.Add(this, 58 registrar_.Add(this,
58 chrome::NOTIFICATION_BROWSER_CLOSED, 59 chrome::NOTIFICATION_BROWSER_CLOSED,
59 content::Source<Browser>(browser)); 60 content::Source<Browser>(browser));
60 } 61 }
61 } 62 }
62 63
63 ExtensionUninstallDialog::~ExtensionUninstallDialog() { 64 ExtensionUninstallDialog::~ExtensionUninstallDialog() {
64 } 65 }
65 66
66 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( 67 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall(
67 const extensions::Extension* extension, 68 const Extension* extension,
68 const extensions::Extension* triggering_extension) { 69 const Extension* triggering_extension) {
69 triggering_extension_ = triggering_extension; 70 triggering_extension_ = triggering_extension;
70 ConfirmUninstall(extension); 71 ConfirmUninstall(extension);
71 } 72 }
72 73
73 void ExtensionUninstallDialog::ConfirmUninstall( 74 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) {
74 const extensions::Extension* extension) {
75 DCHECK(ui_loop_ == base::MessageLoop::current()); 75 DCHECK(ui_loop_ == base::MessageLoop::current());
76 extension_ = extension; 76 extension_ = extension;
77 // Bookmark apps may not have 128x128 icons so accept 64x64 icons. 77 // Bookmark apps may not have 128x128 icons so accept 64x64 icons.
78 const int icon_size = extension_->from_bookmark() 78 const int icon_size = extension_->from_bookmark()
79 ? extension_misc::EXTENSION_ICON_SMALL * 2 79 ? extension_misc::EXTENSION_ICON_SMALL * 2
80 : extension_misc::EXTENSION_ICON_LARGE; 80 : extension_misc::EXTENSION_ICON_LARGE;
81 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( 81 ExtensionResource image = IconsInfo::GetIconResource(
82 extension_, 82 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER);
83 icon_size,
84 ExtensionIconSet::MATCH_BIGGER);
85 83
86 // Load the image asynchronously. The response will be sent to OnImageLoaded. 84 // Load the image asynchronously. The response will be sent to OnImageLoaded.
87 state_ = kImageIsLoading; 85 state_ = kImageIsLoading;
88 extensions::ImageLoader* loader = 86 ImageLoader* loader = ImageLoader::Get(profile_);
89 extensions::ImageLoader::Get(profile_);
90 87
91 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; 88 std::vector<ImageLoader::ImageRepresentation> images_list;
92 images_list.push_back(extensions::ImageLoader::ImageRepresentation( 89 images_list.push_back(ImageLoader::ImageRepresentation(
93 image, 90 image,
94 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, 91 ImageLoader::ImageRepresentation::NEVER_RESIZE,
95 gfx::Size(), 92 gfx::Size(),
96 ui::SCALE_FACTOR_100P)); 93 ui::SCALE_FACTOR_100P));
97 loader->LoadImagesAsync(extension_, 94 loader->LoadImagesAsync(extension_,
98 images_list, 95 images_list,
99 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, 96 base::Bind(&ExtensionUninstallDialog::OnImageLoaded,
100 AsWeakPtr(), 97 AsWeakPtr(),
101 extension_->id())); 98 extension_->id()));
102 } 99 }
103 100
104 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { 101 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
105 if (image.IsEmpty()) { 102 if (image.IsEmpty()) {
106 // Let's set default icon bitmap whose size is equal to the default icon's 103 // Let's set default icon bitmap whose size is equal to the default icon's
107 // pixel size under maximal supported scale factor. If the bitmap is larger 104 // pixel size under maximal supported scale factor. If the bitmap is larger
108 // than the one we need, it will be scaled down by the ui code. 105 // than the one we need, it will be scaled down by the ui code.
109 // TODO(tbarzic): We should use IconImage here and load the required bitmap 106 // TODO(tbarzic): We should use IconImage here and load the required bitmap
110 // lazily. 107 // lazily.
111 icon_ = gfx::ImageSkia::CreateFrom1xBitmap( 108 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(
112 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app())); 109 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()));
113 } else { 110 } else {
114 icon_ = *image.ToImageSkia(); 111 icon_ = *image.ToImageSkia();
115 } 112 }
116 } 113 }
117 114
118 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id, 115 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id,
119 const gfx::Image& image) { 116 const gfx::Image& image) {
120 const extensions::Extension* target_extension = 117 const Extension* target_extension =
121 extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( 118 ExtensionRegistry::Get(profile_)
122 extension_id, extensions::ExtensionRegistry::EVERYTHING); 119 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
123 if (!target_extension) { 120 if (!target_extension) {
124 delegate_->ExtensionUninstallCanceled(); 121 delegate_->ExtensionUninstallCanceled();
125 return; 122 return;
126 } 123 }
127 124
128 SetIcon(image); 125 SetIcon(image);
129 126
130 // Show the dialog unless the browser has been closed while we were waiting 127 // Show the dialog unless the browser has been closed while we were waiting
131 // for the image. 128 // for the image.
132 DCHECK(state_ == kImageIsLoading || state_ == kBrowserIsClosing); 129 DCHECK(state_ == kImageIsLoading || state_ == kBrowserIsClosing);
(...skipping 22 matching lines...) Expand all
155 std::string ExtensionUninstallDialog::GetHeadingText() { 152 std::string ExtensionUninstallDialog::GetHeadingText() {
156 if (triggering_extension_) { 153 if (triggering_extension_) {
157 return l10n_util::GetStringFUTF8( 154 return l10n_util::GetStringFUTF8(
158 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, 155 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING,
159 base::UTF8ToUTF16(triggering_extension_->name()), 156 base::UTF8ToUTF16(triggering_extension_->name()),
160 base::UTF8ToUTF16(extension_->name())); 157 base::UTF8ToUTF16(extension_->name()));
161 } 158 }
162 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, 159 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
163 base::UTF8ToUTF16(extension_->name())); 160 base::UTF8ToUTF16(extension_->name()));
164 } 161 }
162
163 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_uninstall_dialog.h ('k') | chrome/browser/ui/app_list/extension_uninstaller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698