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

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

Issue 382133003: Refactored ExtensionUninstallDialog to take a NativeWindow instead of a Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small change: Display the default icon while the real icon is being loaded Created 6 years, 5 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 | Annotate | Revision Log
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 27 matching lines...) Expand all
38 const gfx::ImageSkia& image = 38 const gfx::ImageSkia& image =
39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); 39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon();
40 return image.GetRepresentation( 40 return image.GetRepresentation(
41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); 41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 ExtensionUninstallDialog::ExtensionUninstallDialog( 46 ExtensionUninstallDialog::ExtensionUninstallDialog(
47 Profile* profile, 47 Profile* profile,
48 Browser* browser, 48 gfx::NativeWindow parent,
49 ExtensionUninstallDialog::Delegate* delegate) 49 ExtensionUninstallDialog::Delegate* delegate)
50 : profile_(profile), 50 : profile_(profile),
51 browser_(browser), 51 parent_(parent),
52 delegate_(delegate), 52 delegate_(delegate),
53 extension_(NULL), 53 extension_(NULL),
54 triggering_extension_(NULL), 54 triggering_extension_(NULL),
55 state_(kImageIsLoading),
56 ui_loop_(base::MessageLoop::current()) { 55 ui_loop_(base::MessageLoop::current()) {
57 if (browser) {
58 registrar_.Add(this,
59 chrome::NOTIFICATION_BROWSER_CLOSED,
60 content::Source<Browser>(browser));
61 }
62 } 56 }
63 57
64 ExtensionUninstallDialog::~ExtensionUninstallDialog() { 58 ExtensionUninstallDialog::~ExtensionUninstallDialog() {
65 } 59 }
66 60
67 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( 61 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall(
68 const Extension* extension, 62 const Extension* extension,
69 const Extension* triggering_extension) { 63 const Extension* triggering_extension) {
70 triggering_extension_ = triggering_extension; 64 triggering_extension_ = triggering_extension;
71 ConfirmUninstall(extension); 65 ConfirmUninstall(extension);
72 } 66 }
73 67
74 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { 68 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) {
75 DCHECK(ui_loop_ == base::MessageLoop::current()); 69 DCHECK(ui_loop_ == base::MessageLoop::current());
76 extension_ = extension; 70 extension_ = extension;
77 // Bookmark apps may not have 128x128 icons so accept 64x64 icons. 71 // Bookmark apps may not have 128x128 icons so accept 64x64 icons.
78 const int icon_size = extension_->from_bookmark() 72 const int icon_size = extension_->from_bookmark()
79 ? extension_misc::EXTENSION_ICON_SMALL * 2 73 ? extension_misc::EXTENSION_ICON_SMALL * 2
80 : extension_misc::EXTENSION_ICON_LARGE; 74 : extension_misc::EXTENSION_ICON_LARGE;
81 ExtensionResource image = IconsInfo::GetIconResource( 75 ExtensionResource image = IconsInfo::GetIconResource(
82 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER); 76 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER);
83 77
84 // Load the image asynchronously. The response will be sent to OnImageLoaded. 78 // Load the image asynchronously. The response will be sent to OnImageLoaded.
85 state_ = kImageIsLoading;
86 ImageLoader* loader = ImageLoader::Get(profile_); 79 ImageLoader* loader = ImageLoader::Get(profile_);
87 80
81 SetIcon(gfx::Image());
88 std::vector<ImageLoader::ImageRepresentation> images_list; 82 std::vector<ImageLoader::ImageRepresentation> images_list;
89 images_list.push_back(ImageLoader::ImageRepresentation( 83 images_list.push_back(ImageLoader::ImageRepresentation(
90 image, 84 image,
91 ImageLoader::ImageRepresentation::NEVER_RESIZE, 85 ImageLoader::ImageRepresentation::NEVER_RESIZE,
92 gfx::Size(), 86 gfx::Size(),
93 ui::SCALE_FACTOR_100P)); 87 ui::SCALE_FACTOR_100P));
94 loader->LoadImagesAsync(extension_, 88 loader->LoadImagesAsync(extension_,
95 images_list, 89 images_list,
96 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, 90 base::Bind(&ExtensionUninstallDialog::OnImageLoaded,
97 AsWeakPtr(), 91 AsWeakPtr(),
98 extension_->id())); 92 extension_->id()));
93 Show();
99 } 94 }
100 95
101 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { 96 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
102 if (image.IsEmpty()) { 97 if (image.IsEmpty()) {
103 // Let's set default icon bitmap whose size is equal to the default icon's 98 // Let's set default icon bitmap whose size is equal to the default icon's
104 // pixel size under maximal supported scale factor. If the bitmap is larger 99 // pixel size under maximal supported scale factor. If the bitmap is larger
105 // than the one we need, it will be scaled down by the ui code. 100 // than the one we need, it will be scaled down by the ui code.
106 // TODO(tbarzic): We should use IconImage here and load the required bitmap 101 // TODO(tbarzic): We should use IconImage here and load the required bitmap
107 // lazily. 102 // lazily.
108 icon_ = gfx::ImageSkia::CreateFrom1xBitmap( 103 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(
109 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app())); 104 GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()));
110 } else { 105 } else {
111 icon_ = *image.ToImageSkia(); 106 icon_ = *image.ToImageSkia();
112 } 107 }
113 } 108 }
114 109
115 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id, 110 void ExtensionUninstallDialog::OnImageLoaded(const std::string& extension_id,
116 const gfx::Image& image) { 111 const gfx::Image& image) {
117 const Extension* target_extension = 112 const Extension* target_extension =
118 ExtensionRegistry::Get(profile_) 113 ExtensionRegistry::Get(profile_)
119 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); 114 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
120 if (!target_extension) { 115 if (!target_extension) {
121 delegate_->ExtensionUninstallCanceled(); 116 delegate_->ExtensionUninstallCanceled();
122 return; 117 return;
123 } 118 }
124 119
125 SetIcon(image); 120 SetIcon(image);
126 121 RefreshIcon();
tapted 2014/07/24 00:35:36 I think you can just move the `Show()` down here,
sashab 2014/07/24 03:03:35 Done. The original reason I did it this way was to
127 // Show the dialog unless the browser has been closed while we were waiting
128 // for the image.
129 DCHECK(state_ == kImageIsLoading || state_ == kBrowserIsClosing);
130 if (state_ == kImageIsLoading) {
131 state_ = kDialogIsShowing;
132 Show();
133 }
134 }
135
136 void ExtensionUninstallDialog::Observe(
137 int type,
138 const content::NotificationSource& source,
139 const content::NotificationDetails& details) {
140 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED);
141
142 browser_ = NULL;
143 // If the browser is closed while waiting for the image, we need to send a
144 // "cancel" event here, because there will not be another opportunity to
145 // notify the delegate of the cancellation as we won't open the dialog.
146 if (state_ == kImageIsLoading) {
147 state_ = kBrowserIsClosing;
148 delegate_->ExtensionUninstallCanceled();
149 }
150 } 122 }
151 123
152 std::string ExtensionUninstallDialog::GetHeadingText() { 124 std::string ExtensionUninstallDialog::GetHeadingText() {
153 if (triggering_extension_) { 125 if (triggering_extension_) {
154 return l10n_util::GetStringFUTF8( 126 return l10n_util::GetStringFUTF8(
155 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, 127 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING,
156 base::UTF8ToUTF16(triggering_extension_->name()), 128 base::UTF8ToUTF16(triggering_extension_->name()),
157 base::UTF8ToUTF16(extension_->name())); 129 base::UTF8ToUTF16(extension_->name()));
158 } 130 }
159 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, 131 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
160 base::UTF8ToUTF16(extension_->name())); 132 base::UTF8ToUTF16(extension_->name()));
161 } 133 }
162 134
163 } // namespace extensions 135 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698