| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/translate/core/browser/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 "components/infobars/core/infobar.h" | 11 #include "components/infobars/core/infobar.h" |
| 12 #include "components/infobars/core/infobar_manager.h" | 12 #include "components/infobars/core/infobar_manager.h" |
| 13 #include "components/translate/core/browser/language_state.h" | 13 #include "components/translate/core/browser/language_state.h" |
| 14 #include "components/translate/core/browser/translate_accept_languages.h" | 14 #include "components/translate/core/browser/translate_accept_languages.h" |
| 15 #include "components/translate/core/browser/translate_client.h" | 15 #include "components/translate/core/browser/translate_client.h" |
| 16 #include "components/translate/core/browser/translate_download_manager.h" | 16 #include "components/translate/core/browser/translate_download_manager.h" |
| 17 #include "components/translate/core/browser/translate_driver.h" | 17 #include "components/translate/core/browser/translate_driver.h" |
| 18 #include "components/translate/core/browser/translate_manager.h" | 18 #include "components/translate/core/browser/translate_manager.h" |
| 19 #include "components/translate/core/common/translate_constants.h" | 19 #include "components/translate/core/common/translate_constants.h" |
| 20 #include "grit/component_strings.h" | 20 #include "grit/component_strings.h" |
| 21 #include "grit/theme_resources.h" | |
| 22 #include "third_party/icu/source/i18n/unicode/coll.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| 26 | 24 |
| 27 // Counts used to decide whether infobars should be shown. | 25 // Counts used to decide whether infobars should be shown. |
| 28 // Android and iOS implementations do not offer a drop down (for space reasons), | 26 // Android and iOS implementations do not offer a drop down (for space reasons), |
| 29 // so we are more aggressive about showing the shortcut to never translate. | 27 // so we are more aggressive about showing the shortcut to never translate. |
| 30 // The "Always Translate" option is always shown on iOS and Android. | 28 // The "Always Translate" option is always shown on iOS and Android. |
| 31 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 32 const int kAlwaysTranslateMinCount = 1; | 30 const int kAlwaysTranslateMinCount = 1; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 prefs_(translate_manager->translate_client()->GetTranslatePrefs()), | 331 prefs_(translate_manager->translate_client()->GetTranslatePrefs()), |
| 334 triggered_from_menu_(triggered_from_menu) { | 332 triggered_from_menu_(triggered_from_menu) { |
| 335 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), | 333 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), |
| 336 (error_type_ == TranslateErrors::NONE)); | 334 (error_type_ == TranslateErrors::NONE)); |
| 337 DCHECK(translate_manager_); | 335 DCHECK(translate_manager_); |
| 338 | 336 |
| 339 if (old_delegate && (old_delegate->is_error() != is_error())) | 337 if (old_delegate && (old_delegate->is_error() != is_error())) |
| 340 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; | 338 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; |
| 341 } | 339 } |
| 342 | 340 |
| 343 TranslateClient* TranslateInfoBarDelegate::GetTranslateClient() { | 341 TranslateClient* TranslateInfoBarDelegate::GetTranslateClient() const { |
| 344 if (!translate_manager_) | 342 if (!translate_manager_) |
| 345 return NULL; | 343 return NULL; |
| 346 | 344 |
| 347 return translate_manager_->translate_client(); | 345 return translate_manager_->translate_client(); |
| 348 } | 346 } |
| 349 | 347 |
| 350 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific | 348 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific |
| 351 // files. | 349 // files. |
| 352 | 350 |
| 353 void TranslateInfoBarDelegate::InfoBarDismissed() { | 351 void TranslateInfoBarDelegate::InfoBarDismissed() { |
| 354 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) | 352 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) |
| 355 return; | 353 return; |
| 356 | 354 |
| 357 // The user closed the infobar without clicking the translate button. | 355 // The user closed the infobar without clicking the translate button. |
| 358 TranslationDeclined(); | 356 TranslationDeclined(); |
| 359 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); | 357 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); |
| 360 } | 358 } |
| 361 | 359 |
| 362 int TranslateInfoBarDelegate::GetIconID() const { | 360 int TranslateInfoBarDelegate::GetIconID() const { |
| 363 return IDR_INFOBAR_TRANSLATE; | 361 return GetTranslateClient()->GetInfobarIconID(); |
| 364 } | 362 } |
| 365 | 363 |
| 366 infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() | 364 infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() |
| 367 const { | 365 const { |
| 368 return PAGE_ACTION_TYPE; | 366 return PAGE_ACTION_TYPE; |
| 369 } | 367 } |
| 370 | 368 |
| 371 bool TranslateInfoBarDelegate::ShouldExpire( | 369 bool TranslateInfoBarDelegate::ShouldExpire( |
| 372 const NavigationDetails& details) const { | 370 const NavigationDetails& details) const { |
| 373 // Note: we allow closing this infobar even if the main frame navigation | 371 // Note: we allow closing this infobar even if the main frame navigation |
| 374 // was programmatic and not initiated by the user - crbug.com/70261 . | 372 // was programmatic and not initiated by the user - crbug.com/70261 . |
| 375 if (!details.is_navigation_to_different_page && !details.is_main_frame) | 373 if (!details.is_navigation_to_different_page && !details.is_main_frame) |
| 376 return false; | 374 return false; |
| 377 | 375 |
| 378 return infobars::InfoBarDelegate::ShouldExpireInternal(details); | 376 return infobars::InfoBarDelegate::ShouldExpireInternal(details); |
| 379 } | 377 } |
| 380 | 378 |
| 381 TranslateInfoBarDelegate* | 379 TranslateInfoBarDelegate* |
| 382 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 380 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 383 return this; | 381 return this; |
| 384 } | 382 } |
| OLD | NEW |