| 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/translate/translate_infobar_delegate.h" | 5 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/string_compare.h" | 9 #include "base/i18n/string_compare.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/infobars/infobar.h" | |
| 14 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/translate/translate_tab_helper.h" | 15 #include "chrome/browser/translate/translate_tab_helper.h" |
| 16 #include "components/infobars/core/infobar.h" |
| 17 #include "components/translate/core/browser/translate_accept_languages.h" | 17 #include "components/translate/core/browser/translate_accept_languages.h" |
| 18 #include "components/translate/core/browser/translate_download_manager.h" | 18 #include "components/translate/core/browser/translate_download_manager.h" |
| 19 #include "components/translate/core/browser/translate_manager.h" | 19 #include "components/translate/core/browser/translate_manager.h" |
| 20 #include "components/translate/core/common/translate_constants.h" | 20 #include "components/translate/core/common/translate_constants.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "third_party/icu/source/i18n/unicode/coll.h" | 25 #include "third_party/icu/source/i18n/unicode/coll.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if ((step == translate::TRANSLATE_STEP_AFTER_TRANSLATE) || | 78 if ((step == translate::TRANSLATE_STEP_AFTER_TRANSLATE) || |
| 79 (step == translate::TRANSLATE_STEP_TRANSLATING)) { | 79 (step == translate::TRANSLATE_STEP_TRANSLATING)) { |
| 80 TranslateTabHelper* translate_tab_helper = | 80 TranslateTabHelper* translate_tab_helper = |
| 81 TranslateTabHelper::FromWebContents(web_contents); | 81 TranslateTabHelper::FromWebContents(web_contents); |
| 82 if (!translate_tab_helper || | 82 if (!translate_tab_helper || |
| 83 translate_tab_helper->GetLanguageState().InTranslateNavigation()) | 83 translate_tab_helper->GetLanguageState().InTranslateNavigation()) |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Find any existing translate infobar delegate. | 87 // Find any existing translate infobar delegate. |
| 88 InfoBar* old_infobar = NULL; | 88 infobars::InfoBar* old_infobar = NULL; |
| 89 InfoBarService* infobar_service = | 89 InfoBarService* infobar_service = |
| 90 InfoBarService::FromWebContents(web_contents); | 90 InfoBarService::FromWebContents(web_contents); |
| 91 TranslateInfoBarDelegate* old_delegate = NULL; | 91 TranslateInfoBarDelegate* old_delegate = NULL; |
| 92 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 92 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 93 old_infobar = infobar_service->infobar_at(i); | 93 old_infobar = infobar_service->infobar_at(i); |
| 94 old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); | 94 old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); |
| 95 if (old_delegate) { | 95 if (old_delegate) { |
| 96 if (!replace_existing_infobar) | 96 if (!replace_existing_infobar) |
| 97 return; | 97 return; |
| 98 break; | 98 break; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Add the new delegate. | 102 // Add the new delegate. |
| 103 scoped_ptr<InfoBar> infobar(CreateInfoBar( | 103 scoped_ptr<infobars::InfoBar> infobar(CreateInfoBar( |
| 104 scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( | 104 scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( |
| 105 web_contents, step, old_delegate, original_language, | 105 web_contents, step, old_delegate, original_language, |
| 106 target_language, error_type, prefs, | 106 target_language, error_type, prefs, |
| 107 triggered_from_menu)))); | 107 triggered_from_menu)))); |
| 108 if (old_delegate) | 108 if (old_delegate) |
| 109 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); | 109 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); |
| 110 else | 110 else |
| 111 infobar_service->AddInfoBar(infobar.Pass()); | 111 infobar_service->AddInfoBar(infobar.Pass()); |
| 112 } | 112 } |
| 113 | 113 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 TranslateInfoBarDelegate::TranslateInfoBarDelegate( | 328 TranslateInfoBarDelegate::TranslateInfoBarDelegate( |
| 329 content::WebContents* web_contents, | 329 content::WebContents* web_contents, |
| 330 translate::TranslateStep step, | 330 translate::TranslateStep step, |
| 331 TranslateInfoBarDelegate* old_delegate, | 331 TranslateInfoBarDelegate* old_delegate, |
| 332 const std::string& original_language, | 332 const std::string& original_language, |
| 333 const std::string& target_language, | 333 const std::string& target_language, |
| 334 TranslateErrors::Type error_type, | 334 TranslateErrors::Type error_type, |
| 335 PrefService* prefs, | 335 PrefService* prefs, |
| 336 bool triggered_from_menu) | 336 bool triggered_from_menu) |
| 337 : InfoBarDelegate(), | 337 : infobars::InfoBarDelegate(), |
| 338 step_(step), | 338 step_(step), |
| 339 background_animation_(NONE), | 339 background_animation_(NONE), |
| 340 ui_delegate_(TranslateTabHelper::FromWebContents(web_contents), | 340 ui_delegate_(TranslateTabHelper::FromWebContents(web_contents), |
| 341 TranslateTabHelper::GetManagerFromWebContents(web_contents), | 341 TranslateTabHelper::GetManagerFromWebContents(web_contents), |
| 342 original_language, | 342 original_language, |
| 343 target_language), | 343 target_language), |
| 344 error_type_(error_type), | 344 error_type_(error_type), |
| 345 prefs_(TranslateTabHelper::CreateTranslatePrefs(prefs)), | 345 prefs_(TranslateTabHelper::CreateTranslatePrefs(prefs)), |
| 346 triggered_from_menu_(triggered_from_menu) { | 346 triggered_from_menu_(triggered_from_menu) { |
| 347 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), | 347 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 360 | 360 |
| 361 // The user closed the infobar without clicking the translate button. | 361 // The user closed the infobar without clicking the translate button. |
| 362 TranslationDeclined(); | 362 TranslationDeclined(); |
| 363 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); | 363 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); |
| 364 } | 364 } |
| 365 | 365 |
| 366 int TranslateInfoBarDelegate::GetIconID() const { | 366 int TranslateInfoBarDelegate::GetIconID() const { |
| 367 return IDR_INFOBAR_TRANSLATE; | 367 return IDR_INFOBAR_TRANSLATE; |
| 368 } | 368 } |
| 369 | 369 |
| 370 InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const { | 370 infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() |
| 371 const { |
| 371 return PAGE_ACTION_TYPE; | 372 return PAGE_ACTION_TYPE; |
| 372 } | 373 } |
| 373 | 374 |
| 374 bool TranslateInfoBarDelegate::ShouldExpire( | 375 bool TranslateInfoBarDelegate::ShouldExpire( |
| 375 const NavigationDetails& details) const { | 376 const NavigationDetails& details) const { |
| 376 // Note: we allow closing this infobar even if the main frame navigation | 377 // Note: we allow closing this infobar even if the main frame navigation |
| 377 // was programmatic and not initiated by the user - crbug.com/70261 . | 378 // was programmatic and not initiated by the user - crbug.com/70261 . |
| 378 if (!details.is_navigation_to_different_page && !details.is_main_frame) | 379 if (!details.is_navigation_to_different_page && !details.is_main_frame) |
| 379 return false; | 380 return false; |
| 380 | 381 |
| 381 return InfoBarDelegate::ShouldExpireInternal(details); | 382 return infobars::InfoBarDelegate::ShouldExpireInternal(details); |
| 382 } | 383 } |
| 383 | 384 |
| 384 TranslateInfoBarDelegate* | 385 TranslateInfoBarDelegate* |
| 385 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 386 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 386 return this; | 387 return this; |
| 387 } | 388 } |
| OLD | NEW |