OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/extensions/extension_install_dialog.h" | 15 #include "chrome/browser/extensions/extension_install_dialog.h" |
16 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 16 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
| 17 #include "chrome/browser/infobars/infobar_tab_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/simple_message_box.h" | 19 #include "chrome/browser/simple_message_box.h" |
19 #include "chrome/browser/tabs/tab_strip_model.h" | 20 #include "chrome/browser/tabs/tab_strip_model.h" |
20 #include "chrome/browser/themes/theme_service.h" | 21 #include "chrome/browser/themes/theme_service.h" |
21 #include "chrome/browser/themes/theme_service_factory.h" | 22 #include "chrome/browser/themes/theme_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 24 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/browser/ui/browser_navigator.h" | 26 #include "chrome/browser/ui/browser_navigator.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return; | 255 return; |
255 | 256 |
256 // Get last active tabbed browser of profile. | 257 // Get last active tabbed browser of profile. |
257 Browser* browser = BrowserList::FindTabbedBrowser(profile, true); | 258 Browser* browser = BrowserList::FindTabbedBrowser(profile, true); |
258 if (!browser) | 259 if (!browser) |
259 return; | 260 return; |
260 | 261 |
261 TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); | 262 TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); |
262 if (!tab_contents) | 263 if (!tab_contents) |
263 return; | 264 return; |
| 265 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
264 | 266 |
265 // First find any previous theme preview infobars. | 267 // First find any previous theme preview infobars. |
266 InfoBarDelegate* old_delegate = NULL; | 268 InfoBarDelegate* old_delegate = NULL; |
267 for (size_t i = 0; i < tab_contents->infobar_count(); ++i) { | 269 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
268 InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i); | 270 InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); |
269 ThemeInstalledInfoBarDelegate* theme_infobar = | 271 ThemeInstalledInfoBarDelegate* theme_infobar = |
270 delegate->AsThemePreviewInfobarDelegate(); | 272 delegate->AsThemePreviewInfobarDelegate(); |
271 if (theme_infobar) { | 273 if (theme_infobar) { |
272 // If the user installed the same theme twice, ignore the second install | 274 // If the user installed the same theme twice, ignore the second install |
273 // and keep the first install info bar, so that they can easily undo to | 275 // and keep the first install info bar, so that they can easily undo to |
274 // get back the previous theme. | 276 // get back the previous theme. |
275 if (theme_infobar->MatchesTheme(new_theme)) | 277 if (theme_infobar->MatchesTheme(new_theme)) |
276 return; | 278 return; |
277 old_delegate = delegate; | 279 old_delegate = delegate; |
278 break; | 280 break; |
279 } | 281 } |
280 } | 282 } |
281 | 283 |
282 // Then either replace that old one or add a new one. | 284 // Then either replace that old one or add a new one. |
283 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( | 285 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( |
284 tab_contents->tab_contents(), new_theme, previous_theme_id, | 286 tab_contents->tab_contents(), new_theme, previous_theme_id, |
285 previous_using_native_theme); | 287 previous_using_native_theme); |
286 | 288 |
287 if (old_delegate) | 289 if (old_delegate) |
288 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); | 290 infobar_helper->ReplaceInfoBar(old_delegate, new_delegate); |
289 else | 291 else |
290 tab_contents->AddInfoBar(new_delegate); | 292 infobar_helper->AddInfoBar(new_delegate); |
291 } | 293 } |
292 | 294 |
293 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { | 295 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { |
294 // Load the image asynchronously. For the response, check OnImageLoaded. | 296 // Load the image asynchronously. For the response, check OnImageLoaded. |
295 prompt_type_ = prompt_type; | 297 prompt_type_ = prompt_type; |
296 ExtensionResource image = | 298 ExtensionResource image = |
297 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, | 299 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, |
298 ExtensionIconSet::MATCH_EXACTLY); | 300 ExtensionIconSet::MATCH_EXACTLY); |
299 tracker_.LoadImage(extension_, image, | 301 tracker_.LoadImage(extension_, image, |
300 gfx::Size(kIconSize, kIconSize), | 302 gfx::Size(kIconSize, kIconSize), |
301 ImageLoadingTracker::DONT_CACHE); | 303 ImageLoadingTracker::DONT_CACHE); |
302 } | 304 } |
303 | 305 |
304 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 306 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
305 TabContents* tab_contents, | 307 TabContents* tab_contents, |
306 const Extension* new_theme, | 308 const Extension* new_theme, |
307 const std::string& previous_theme_id, | 309 const std::string& previous_theme_id, |
308 bool previous_using_native_theme) { | 310 bool previous_using_native_theme) { |
309 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 311 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
310 previous_theme_id, | 312 previous_theme_id, |
311 previous_using_native_theme); | 313 previous_using_native_theme); |
312 } | 314 } |
OLD | NEW |