Chromium Code Reviews| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
| 264 | 265 |
| 265 // First find any previous theme preview infobars. | 266 // First find any previous theme preview infobars. |
| 266 InfoBarDelegate* old_delegate = NULL; | 267 InfoBarDelegate* old_delegate = NULL; |
| 267 for (size_t i = 0; i < tab_contents->infobar_count(); ++i) { | 268 for (size_t i = 0; |
| 268 InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i); | 269 i < tab_contents->infobar_tab_helper()->infobar_count(); |
|
Peter Kasting
2011/08/31 18:47:32
Nit: Can you factor the infobar_tab_helper() out t
| |
| 270 ++i) { | |
| 271 InfoBarDelegate* delegate = | |
| 272 tab_contents->infobar_tab_helper()->GetInfoBarDelegateAt(i); | |
| 269 ThemeInstalledInfoBarDelegate* theme_infobar = | 273 ThemeInstalledInfoBarDelegate* theme_infobar = |
| 270 delegate->AsThemePreviewInfobarDelegate(); | 274 delegate->AsThemePreviewInfobarDelegate(); |
| 271 if (theme_infobar) { | 275 if (theme_infobar) { |
| 272 // If the user installed the same theme twice, ignore the second install | 276 // 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 | 277 // and keep the first install info bar, so that they can easily undo to |
| 274 // get back the previous theme. | 278 // get back the previous theme. |
| 275 if (theme_infobar->MatchesTheme(new_theme)) | 279 if (theme_infobar->MatchesTheme(new_theme)) |
| 276 return; | 280 return; |
| 277 old_delegate = delegate; | 281 old_delegate = delegate; |
| 278 break; | 282 break; |
| 279 } | 283 } |
| 280 } | 284 } |
| 281 | 285 |
| 282 // Then either replace that old one or add a new one. | 286 // Then either replace that old one or add a new one. |
| 283 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( | 287 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( |
| 284 tab_contents->tab_contents(), new_theme, previous_theme_id, | 288 tab_contents->tab_contents(), new_theme, previous_theme_id, |
| 285 previous_using_native_theme); | 289 previous_using_native_theme); |
| 286 | 290 |
| 287 if (old_delegate) | 291 if (old_delegate) |
| 288 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); | 292 tab_contents->infobar_tab_helper()->ReplaceInfoBar(old_delegate, |
| 293 new_delegate); | |
| 289 else | 294 else |
| 290 tab_contents->AddInfoBar(new_delegate); | 295 tab_contents->infobar_tab_helper()->AddInfoBar(new_delegate); |
| 291 } | 296 } |
| 292 | 297 |
| 293 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { | 298 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { |
| 294 // Load the image asynchronously. For the response, check OnImageLoaded. | 299 // Load the image asynchronously. For the response, check OnImageLoaded. |
| 295 prompt_type_ = prompt_type; | 300 prompt_type_ = prompt_type; |
| 296 ExtensionResource image = | 301 ExtensionResource image = |
| 297 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, | 302 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, |
| 298 ExtensionIconSet::MATCH_EXACTLY); | 303 ExtensionIconSet::MATCH_EXACTLY); |
| 299 tracker_.LoadImage(extension_, image, | 304 tracker_.LoadImage(extension_, image, |
| 300 gfx::Size(kIconSize, kIconSize), | 305 gfx::Size(kIconSize, kIconSize), |
| 301 ImageLoadingTracker::DONT_CACHE); | 306 ImageLoadingTracker::DONT_CACHE); |
| 302 } | 307 } |
| 303 | 308 |
| 304 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 309 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
| 305 TabContents* tab_contents, | 310 TabContents* tab_contents, |
| 306 const Extension* new_theme, | 311 const Extension* new_theme, |
| 307 const std::string& previous_theme_id, | 312 const std::string& previous_theme_id, |
| 308 bool previous_using_native_theme) { | 313 bool previous_using_native_theme) { |
| 309 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 314 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
| 310 previous_theme_id, | 315 previous_theme_id, |
| 311 previous_using_native_theme); | 316 previous_using_native_theme); |
| 312 } | 317 } |
| OLD | NEW |