OLD | NEW |
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" |
11 #include "chrome/browser/chrome_notification_types.h" | |
12 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 #include "content/public/browser/notification_source.h" | |
17 #include "extensions/browser/extension_registry.h" | 13 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/image_loader.h" | 14 #include "extensions/browser/image_loader.h" |
19 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
20 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_icon_set.h" | 17 #include "extensions/common/extension_icon_set.h" |
22 #include "extensions/common/extension_resource.h" | 18 #include "extensions/common/extension_resource.h" |
23 #include "extensions/common/manifest_handlers/icons_handler.h" | 19 #include "extensions/common/manifest_handlers/icons_handler.h" |
24 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
26 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
38 const gfx::ImageSkia& image = | 34 const gfx::ImageSkia& image = |
39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); | 35 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); |
40 return image.GetRepresentation( | 36 return image.GetRepresentation( |
41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 37 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
42 } | 38 } |
43 | 39 |
44 } // namespace | 40 } // namespace |
45 | 41 |
46 ExtensionUninstallDialog::ExtensionUninstallDialog( | 42 ExtensionUninstallDialog::ExtensionUninstallDialog( |
47 Profile* profile, | 43 Profile* profile, |
48 Browser* browser, | 44 gfx::NativeWindow parent, |
49 ExtensionUninstallDialog::Delegate* delegate) | 45 ExtensionUninstallDialog::Delegate* delegate) |
50 : profile_(profile), | 46 : profile_(profile), |
51 browser_(browser), | 47 parent_(parent), |
52 delegate_(delegate), | 48 delegate_(delegate), |
53 extension_(NULL), | 49 extension_(NULL), |
54 triggering_extension_(NULL), | 50 triggering_extension_(NULL), |
55 state_(kImageIsLoading), | |
56 ui_loop_(base::MessageLoop::current()) { | 51 ui_loop_(base::MessageLoop::current()) { |
57 if (browser) { | |
58 registrar_.Add(this, | |
59 chrome::NOTIFICATION_BROWSER_CLOSED, | |
60 content::Source<Browser>(browser)); | |
61 } | |
62 } | 52 } |
63 | 53 |
64 ExtensionUninstallDialog::~ExtensionUninstallDialog() { | 54 ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
65 } | 55 } |
66 | 56 |
67 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( | 57 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( |
68 const Extension* extension, | 58 const Extension* extension, |
69 const Extension* triggering_extension) { | 59 const Extension* triggering_extension) { |
70 triggering_extension_ = triggering_extension; | 60 triggering_extension_ = triggering_extension; |
71 ConfirmUninstall(extension); | 61 ConfirmUninstall(extension); |
72 } | 62 } |
73 | 63 |
74 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { | 64 void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { |
75 DCHECK(ui_loop_ == base::MessageLoop::current()); | 65 DCHECK(ui_loop_ == base::MessageLoop::current()); |
76 extension_ = extension; | 66 extension_ = extension; |
77 // Bookmark apps may not have 128x128 icons so accept 64x64 icons. | 67 // Bookmark apps may not have 128x128 icons so accept 64x64 icons. |
78 const int icon_size = extension_->from_bookmark() | 68 const int icon_size = extension_->from_bookmark() |
79 ? extension_misc::EXTENSION_ICON_SMALL * 2 | 69 ? extension_misc::EXTENSION_ICON_SMALL * 2 |
80 : extension_misc::EXTENSION_ICON_LARGE; | 70 : extension_misc::EXTENSION_ICON_LARGE; |
81 ExtensionResource image = IconsInfo::GetIconResource( | 71 ExtensionResource image = IconsInfo::GetIconResource( |
82 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER); | 72 extension_, icon_size, ExtensionIconSet::MATCH_BIGGER); |
83 | 73 |
84 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 74 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
85 state_ = kImageIsLoading; | |
86 ImageLoader* loader = ImageLoader::Get(profile_); | 75 ImageLoader* loader = ImageLoader::Get(profile_); |
87 | 76 |
| 77 SetIcon(gfx::Image()); |
88 std::vector<ImageLoader::ImageRepresentation> images_list; | 78 std::vector<ImageLoader::ImageRepresentation> images_list; |
89 images_list.push_back(ImageLoader::ImageRepresentation( | 79 images_list.push_back(ImageLoader::ImageRepresentation( |
90 image, | 80 image, |
91 ImageLoader::ImageRepresentation::NEVER_RESIZE, | 81 ImageLoader::ImageRepresentation::NEVER_RESIZE, |
92 gfx::Size(), | 82 gfx::Size(), |
93 ui::SCALE_FACTOR_100P)); | 83 ui::SCALE_FACTOR_100P)); |
94 loader->LoadImagesAsync(extension_, | 84 loader->LoadImagesAsync(extension_, |
95 images_list, | 85 images_list, |
96 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, | 86 base::Bind(&ExtensionUninstallDialog::OnImageLoaded, |
97 AsWeakPtr(), | 87 AsWeakPtr(), |
(...skipping 18 matching lines...) Expand all Loading... |
116 const gfx::Image& image) { | 106 const gfx::Image& image) { |
117 const Extension* target_extension = | 107 const Extension* target_extension = |
118 ExtensionRegistry::Get(profile_) | 108 ExtensionRegistry::Get(profile_) |
119 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 109 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
120 if (!target_extension) { | 110 if (!target_extension) { |
121 delegate_->ExtensionUninstallCanceled(); | 111 delegate_->ExtensionUninstallCanceled(); |
122 return; | 112 return; |
123 } | 113 } |
124 | 114 |
125 SetIcon(image); | 115 SetIcon(image); |
126 | 116 Show(); |
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 } | 117 } |
151 | 118 |
152 std::string ExtensionUninstallDialog::GetHeadingText() { | 119 std::string ExtensionUninstallDialog::GetHeadingText() { |
153 if (triggering_extension_) { | 120 if (triggering_extension_) { |
154 return l10n_util::GetStringFUTF8( | 121 return l10n_util::GetStringFUTF8( |
155 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, | 122 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, |
156 base::UTF8ToUTF16(triggering_extension_->name()), | 123 base::UTF8ToUTF16(triggering_extension_->name()), |
157 base::UTF8ToUTF16(extension_->name())); | 124 base::UTF8ToUTF16(extension_->name())); |
158 } | 125 } |
159 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, | 126 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
160 base::UTF8ToUTF16(extension_->name())); | 127 base::UTF8ToUTF16(extension_->name())); |
161 } | 128 } |
162 | 129 |
163 } // namespace extensions | 130 } // namespace extensions |
OLD | NEW |