OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_install_ui.h" | 5 #include "chrome/browser/extensions/extension_install_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 DCHECK(hosts.size() == 0); | 120 DCHECK(hosts.size() == 0); |
121 if (extension->api_permissions().empty()) | 121 if (extension->api_permissions().empty()) |
122 return L""; | 122 return L""; |
123 else | 123 else |
124 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); | 124 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); |
125 } | 125 } |
126 | 126 |
127 } // namespace | 127 } // namespace |
128 | 128 |
129 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 129 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
130 : profile_(profile), ui_loop_(MessageLoop::current()) | 130 : profile_(profile), |
131 ui_loop_(MessageLoop::current()), | |
132 extension_(NULL), | |
133 delegate_(NULL), | |
134 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) | |
131 #if defined(TOOLKIT_GTK) | 135 #if defined(TOOLKIT_GTK) |
132 ,previous_use_gtk_theme_(false) | 136 , previous_use_gtk_theme_(false) |
133 #endif | 137 #endif |
134 {} | 138 {} |
135 | 139 |
136 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, | 140 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, |
137 Extension* extension, | 141 Extension* extension) { |
138 SkBitmap* install_icon) { | |
139 DCHECK(ui_loop_ == MessageLoop::current()); | 142 DCHECK(ui_loop_ == MessageLoop::current()); |
143 extension_ = extension; | |
144 delegate_ = delegate; | |
140 | 145 |
141 // We special-case themes to not show any confirm UI. Instead they are | 146 // We special-case themes to not show any confirm UI. Instead they are |
142 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 147 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
143 // to allow the user to revert if they don't like it. | 148 // to allow the user to revert if they don't like it. |
144 if (extension->IsTheme()) { | 149 if (extension->IsTheme()) { |
145 // Remember the current theme in case the user pressed undo. | 150 // Remember the current theme in case the user pressed undo. |
146 Extension* previous_theme = profile_->GetTheme(); | 151 Extension* previous_theme = profile_->GetTheme(); |
147 if (previous_theme) | 152 if (previous_theme) |
148 previous_theme_id_ = previous_theme->id(); | 153 previous_theme_id_ = previous_theme->id(); |
149 | 154 |
150 #if defined(TOOLKIT_GTK) | 155 #if defined(TOOLKIT_GTK) |
151 // On linux, we also need to take the user's system settings into account | 156 // On Linux, we also need to take the user's system settings into account |
152 // to undo theme installation. | 157 // to undo theme installation. |
153 previous_use_gtk_theme_ = | 158 previous_use_gtk_theme_ = |
154 GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); | 159 GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); |
155 #endif | 160 #endif |
156 | 161 |
157 delegate->InstallUIProceed(false); | 162 delegate->InstallUIProceed(false); |
158 return; | 163 return; |
159 } | 164 } |
160 | 165 |
161 if (!install_icon) { | 166 // Load the image asynchronously. For the response, check OnImageLoaded. |
162 install_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 167 ExtensionResource image = |
163 IDR_EXTENSION_DEFAULT_ICON); | 168 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); |
164 } | 169 tracker_.PostLoadImageTask( |
165 icon_ = *install_icon; | 170 image, |
166 | 171 gfx::Size(Extension::EXTENSION_ICON_LARGE, |
167 NotificationService* service = NotificationService::current(); | 172 Extension::EXTENSION_ICON_LARGE), |
168 service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, | 173 IDS_EXTENSION_INSTALL_PROMPT_TITLE); |
169 Source<ExtensionInstallUI>(this), | |
170 NotificationService::NoDetails()); | |
171 | |
172 ShowExtensionInstallUIPromptImpl( | |
173 profile_, delegate, extension, &icon_, | |
174 WideToUTF16Hack(GetInstallWarning(extension)), INSTALL_PROMPT); | |
175 } | 174 } |
176 | 175 |
177 void ExtensionInstallUI::ConfirmUninstall(Delegate* delegate, | 176 void ExtensionInstallUI::ConfirmUninstall(Delegate* delegate, |
178 Extension* extension, | 177 Extension* extension) { |
179 SkBitmap* icon) { | |
180 DCHECK(ui_loop_ == MessageLoop::current()); | 178 DCHECK(ui_loop_ == MessageLoop::current()); |
179 extension_ = extension; | |
180 delegate_ = delegate; | |
181 | 181 |
182 if (!icon) { | 182 // Load the image asynchronously. For the response, check OnImageLoaded. |
183 icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 183 ExtensionResource image = |
184 IDR_EXTENSION_DEFAULT_ICON); | 184 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); |
Aaron Boodman
2010/03/23 19:10:55
Looks like you could share this code in a LoadImag
| |
185 } | 185 tracker_.PostLoadImageTask( |
186 | 186 image, |
187 string16 message = | 187 gfx::Size(Extension::EXTENSION_ICON_LARGE, |
188 l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); | 188 Extension::EXTENSION_ICON_LARGE), |
189 ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, | 189 IDS_EXTENSION_UNINSTALL_PROMPT_TITLE); |
190 message, UNINSTALL_PROMPT); | |
191 } | 190 } |
192 | 191 |
193 void ExtensionInstallUI::ConfirmEnableIncognito(Delegate* delegate, | 192 void ExtensionInstallUI::ConfirmEnableIncognito(Delegate* delegate, |
194 Extension* extension, | 193 Extension* extension) { |
195 SkBitmap* icon) { | |
196 DCHECK(ui_loop_ == MessageLoop::current()); | 194 DCHECK(ui_loop_ == MessageLoop::current()); |
195 extension_ = extension; | |
196 delegate_ = delegate; | |
197 | 197 |
198 if (!icon) { | 198 // Load the image asynchronously. For the response, check OnImageLoaded. |
199 icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 199 ExtensionResource image = |
200 IDR_EXTENSION_DEFAULT_ICON); | 200 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); |
201 } | 201 tracker_.PostLoadImageTask(image, |
202 | 202 gfx::Size(Extension::EXTENSION_ICON_LARGE, |
203 string16 message = | 203 Extension::EXTENSION_ICON_LARGE), |
204 l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, | 204 IDS_EXTENSION_ENABLE_INCOGNITO_PROMPT_TITLE); |
205 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
206 ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, | |
207 message, ENABLE_INCOGNITO_PROMPT); | |
208 } | 205 } |
209 | 206 |
210 void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { | 207 void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { |
211 if (extension->IsTheme()) { | 208 if (extension->IsTheme()) { |
212 ShowThemeInfoBar(extension); | 209 ShowThemeInfoBar(extension); |
213 return; | 210 return; |
214 } | 211 } |
215 | 212 |
216 // GetLastActiveWithProfile will fail on the build bots. This needs to | 213 // GetLastActiveWithProfile will fail on the build bots. This needs to be |
217 // implemented differently if any test is created which depends on | 214 // implemented differently if any test is created which depends on |
218 // ExtensionInstalledBubble showing. | 215 // ExtensionInstalledBubble showing. |
219 #if defined(TOOLKIT_VIEWS) | 216 #if defined(TOOLKIT_VIEWS) |
220 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 217 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
221 if (!browser) | 218 if (!browser) |
222 return; | 219 return; |
223 | 220 |
224 ExtensionInstalledBubble::Show(extension, browser, icon_); | 221 ExtensionInstalledBubble::Show(extension, browser, icon_); |
225 #elif defined(OS_MACOSX) | 222 #elif defined(OS_MACOSX) |
226 if (extension->browser_action() || | 223 if (extension->browser_action() || |
(...skipping 24 matching lines...) Expand all Loading... | |
251 platform_util::SimpleErrorBox( | 248 platform_util::SimpleErrorBox( |
252 browser ? browser->window()->GetNativeHandle() : NULL, | 249 browser ? browser->window()->GetNativeHandle() : NULL, |
253 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_FAILURE_TITLE), | 250 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_FAILURE_TITLE), |
254 UTF8ToUTF16(error)); | 251 UTF8ToUTF16(error)); |
255 } | 252 } |
256 | 253 |
257 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { | 254 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { |
258 ShowThemeInfoBar(extension); | 255 ShowThemeInfoBar(extension); |
259 } | 256 } |
260 | 257 |
258 void ExtensionInstallUI::OnImageLoaded(SkBitmap* image, int index) { | |
259 if (image) | |
260 icon_ = *image; | |
261 else | |
262 icon_ = SkBitmap(); | |
263 if (icon_.empty()) { | |
264 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
265 IDR_EXTENSION_DEFAULT_ICON); | |
266 } | |
267 | |
268 if (index == IDS_EXTENSION_INSTALL_PROMPT_TITLE) { | |
Aaron Boodman
2010/03/23 19:10:55
whoa there cowboy. Overloading a param named "inde
| |
269 NotificationService* service = NotificationService::current(); | |
270 service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, | |
271 Source<ExtensionInstallUI>(this), | |
272 NotificationService::NoDetails()); | |
273 | |
274 ShowExtensionInstallUIPromptImpl( | |
275 profile_, delegate_, extension_, &icon_, | |
276 WideToUTF16Hack(GetInstallWarning(extension_)), INSTALL_PROMPT); | |
277 } else if (index == IDS_EXTENSION_UNINSTALL_PROMPT_TITLE) { | |
278 string16 message = | |
279 l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); | |
280 ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, | |
281 message, UNINSTALL_PROMPT); | |
282 } else if (index == IDS_EXTENSION_ENABLE_INCOGNITO_PROMPT_TITLE) { | |
283 string16 message = | |
284 l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, | |
285 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
286 ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, | |
287 message, ENABLE_INCOGNITO_PROMPT); | |
288 } else { | |
289 NOTREACHED() << "Unknown message"; | |
290 } | |
291 } | |
292 | |
261 void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { | 293 void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { |
262 if (!new_theme->IsTheme()) | 294 if (!new_theme->IsTheme()) |
263 return; | 295 return; |
264 | 296 |
265 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 297 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
266 if (!browser) | 298 if (!browser) |
267 return; | 299 return; |
268 | 300 |
269 TabContents* tab_contents = browser->GetSelectedTabContents(); | 301 TabContents* tab_contents = browser->GetSelectedTabContents(); |
270 if (!tab_contents) | 302 if (!tab_contents) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 InfoBarDelegate* ExtensionInstallUI::GetNewInfoBarDelegate( | 345 InfoBarDelegate* ExtensionInstallUI::GetNewInfoBarDelegate( |
314 Extension* new_theme, TabContents* tab_contents) { | 346 Extension* new_theme, TabContents* tab_contents) { |
315 #if defined(TOOLKIT_GTK) | 347 #if defined(TOOLKIT_GTK) |
316 return new GtkThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 348 return new GtkThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
317 previous_theme_id_, previous_use_gtk_theme_); | 349 previous_theme_id_, previous_use_gtk_theme_); |
318 #else | 350 #else |
319 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 351 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
320 previous_theme_id_); | 352 previous_theme_id_); |
321 #endif | 353 #endif |
322 } | 354 } |
OLD | NEW |