| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/translate/core/browser/translate_infobar_delegate.h" | 5 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // The iOS implementation, like the Android implementation, shows the "Never | 39 // The iOS implementation, like the Android implementation, shows the "Never |
| 40 // translate" infobar after two denials. There is an offset of one because on | 40 // translate" infobar after two denials. There is an offset of one because on |
| 41 // Android the last event is not counted. | 41 // Android the last event is not counted. |
| 42 const int kAlwaysTranslateMinCount = 1; | 42 const int kAlwaysTranslateMinCount = 1; |
| 43 const int kNeverTranslateMinCount = 2; | 43 const int kNeverTranslateMinCount = 2; |
| 44 #else | 44 #else |
| 45 const int kAlwaysTranslateMinCount = 3; | 45 const int kAlwaysTranslateMinCount = 3; |
| 46 const int kNeverTranslateMinCount = 3; | 46 const int kNeverTranslateMinCount = 3; |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 // For Compact UI, if number of consecutive translations is equal to this |
| 50 // number, infobar will automatically trigger "Always Translate". |
| 51 const int kAcceptCountThreshold = 5; |
| 52 |
| 49 } // namespace | 53 } // namespace |
| 50 | 54 |
| 51 const base::Feature kTranslateCompactUI{"TranslateCompactUI", | 55 const base::Feature kTranslateCompactUI{"TranslateCompactUI", |
| 52 base::FEATURE_DISABLED_BY_DEFAULT}; | 56 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 53 | 57 |
| 54 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::kNoIndex; | 58 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::kNoIndex; |
| 55 | 59 |
| 56 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { | 60 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { |
| 57 } | 61 } |
| 58 | 62 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 295 } |
| 292 | 296 |
| 293 #if defined(OS_IOS) | 297 #if defined(OS_IOS) |
| 294 void TranslateInfoBarDelegate::ShowNeverTranslateInfobar() { | 298 void TranslateInfoBarDelegate::ShowNeverTranslateInfobar() { |
| 295 Create(true, translate_manager_, infobar()->owner(), is_off_the_record_, | 299 Create(true, translate_manager_, infobar()->owner(), is_off_the_record_, |
| 296 translate::TRANSLATE_STEP_NEVER_TRANSLATE, original_language_code(), | 300 translate::TRANSLATE_STEP_NEVER_TRANSLATE, original_language_code(), |
| 297 target_language_code(), TranslateErrors::NONE, false); | 301 target_language_code(), TranslateErrors::NONE, false); |
| 298 } | 302 } |
| 299 #endif | 303 #endif |
| 300 | 304 |
| 305 bool TranslateInfoBarDelegate::ShouldAutoAlwaysTranslate() { |
| 306 return (IsCompactUIEnabled() && |
| 307 prefs_->GetTranslationAcceptedCount(original_language_code()) == |
| 308 kAcceptCountThreshold); |
| 309 } |
| 310 |
| 301 // static | 311 // static |
| 302 void TranslateInfoBarDelegate::GetAfterTranslateStrings( | 312 void TranslateInfoBarDelegate::GetAfterTranslateStrings( |
| 303 std::vector<base::string16>* strings, | 313 std::vector<base::string16>* strings, |
| 304 bool* swap_languages, | 314 bool* swap_languages, |
| 305 bool autodetermined_source_language) { | 315 bool autodetermined_source_language) { |
| 306 DCHECK(strings); | 316 DCHECK(strings); |
| 307 | 317 |
| 308 if (autodetermined_source_language) { | 318 if (autodetermined_source_language) { |
| 309 size_t offset; | 319 size_t offset; |
| 310 base::string16 text = l10n_util::GetStringFUTF16( | 320 base::string16 text = l10n_util::GetStringFUTF16( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return PAGE_ACTION_TYPE; | 381 return PAGE_ACTION_TYPE; |
| 372 } | 382 } |
| 373 | 383 |
| 374 int TranslateInfoBarDelegate::GetIconId() const { | 384 int TranslateInfoBarDelegate::GetIconId() const { |
| 375 return translate_manager_->translate_client()->GetInfobarIconID(); | 385 return translate_manager_->translate_client()->GetInfobarIconID(); |
| 376 } | 386 } |
| 377 | 387 |
| 378 void TranslateInfoBarDelegate::InfoBarDismissed() { | 388 void TranslateInfoBarDelegate::InfoBarDismissed() { |
| 379 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) | 389 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) |
| 380 return; | 390 return; |
| 381 | 391 if (IsCompactUIEnabled()) |
| 392 return; |
| 382 // The user closed the infobar without clicking the translate button. | 393 // The user closed the infobar without clicking the translate button. |
| 383 TranslationDeclined(); | 394 TranslationDeclined(); |
| 384 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); | 395 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); |
| 385 } | 396 } |
| 386 | 397 |
| 387 TranslateInfoBarDelegate* | 398 TranslateInfoBarDelegate* |
| 388 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 399 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 389 return this; | 400 return this; |
| 390 } | 401 } |
| 391 | 402 |
| 392 } // namespace translate | 403 } // namespace translate |
| OLD | NEW |