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; |
33 const int kNeverTranslateMinCount = 1; | 31 const int kNeverTranslateMinCount = 1; |
34 #elif defined(OS_IOS) | 32 #elif defined(OS_IOS) |
35 // The iOS implementation, like the Android implementation, shows the "Never | 33 // The iOS implementation, like the Android implementation, shows the "Never |
36 // translate" infobar after two denials. There is an offset of one because on | 34 // translate" infobar after two denials. There is an offset of one because on |
37 // Android the last event is not counted. | 35 // Android the last event is not counted. |
38 const int kAlwaysTranslateMinCount = 1; | 36 const int kAlwaysTranslateMinCount = 1; |
39 const int kNeverTranslateMinCount = 2; | 37 const int kNeverTranslateMinCount = 2; |
40 #else | 38 #else |
41 const int kAlwaysTranslateMinCount = 3; | 39 const int kAlwaysTranslateMinCount = 3; |
42 const int kNeverTranslateMinCount = 3; | 40 const int kNeverTranslateMinCount = 3; |
43 #endif | 41 #endif |
44 | 42 |
45 } // namespace | 43 } // namespace |
46 | 44 |
47 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::NO_INDEX; | 45 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::NO_INDEX; |
48 | 46 |
49 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { | 47 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { |
50 } | 48 } |
51 | 49 |
52 // static | 50 // static |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( | 100 scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( |
103 translate_manager, is_off_the_record, step, old_delegate, | 101 translate_manager, is_off_the_record, step, old_delegate, |
104 original_language, target_language, error_type, | 102 original_language, target_language, error_type, |
105 triggered_from_menu)))); | 103 triggered_from_menu)))); |
106 if (old_delegate) | 104 if (old_delegate) |
107 infobar_manager->ReplaceInfoBar(old_infobar, infobar.Pass()); | 105 infobar_manager->ReplaceInfoBar(old_infobar, infobar.Pass()); |
108 else | 106 else |
109 infobar_manager->AddInfoBar(infobar.Pass()); | 107 infobar_manager->AddInfoBar(infobar.Pass()); |
110 } | 108 } |
111 | 109 |
112 | |
113 void TranslateInfoBarDelegate::UpdateOriginalLanguageIndex( | 110 void TranslateInfoBarDelegate::UpdateOriginalLanguageIndex( |
114 size_t language_index) { | 111 size_t language_index) { |
115 ui_delegate_.UpdateOriginalLanguageIndex(language_index); | 112 ui_delegate_.UpdateOriginalLanguageIndex(language_index); |
116 } | 113 } |
117 | 114 |
118 void TranslateInfoBarDelegate::UpdateTargetLanguageIndex( | 115 void TranslateInfoBarDelegate::UpdateTargetLanguageIndex( |
119 size_t language_index) { | 116 size_t language_index) { |
120 ui_delegate_.UpdateTargetLanguageIndex(language_index); | 117 ui_delegate_.UpdateTargetLanguageIndex(language_index); |
121 } | 118 } |
122 | 119 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 176 |
180 void TranslateInfoBarDelegate::AlwaysTranslatePageLanguage() { | 177 void TranslateInfoBarDelegate::AlwaysTranslatePageLanguage() { |
181 DCHECK(!ui_delegate_.ShouldAlwaysTranslate()); | 178 DCHECK(!ui_delegate_.ShouldAlwaysTranslate()); |
182 ui_delegate_.SetAlwaysTranslate(true); | 179 ui_delegate_.SetAlwaysTranslate(true); |
183 Translate(); | 180 Translate(); |
184 } | 181 } |
185 | 182 |
186 void TranslateInfoBarDelegate::NeverTranslatePageLanguage() { | 183 void TranslateInfoBarDelegate::NeverTranslatePageLanguage() { |
187 DCHECK(!ui_delegate_.IsLanguageBlocked()); | 184 DCHECK(!ui_delegate_.IsLanguageBlocked()); |
188 ui_delegate_.SetLanguageBlocked(true); | 185 ui_delegate_.SetLanguageBlocked(true); |
189 infobar()->RemoveSelf(); | 186 infobar()->RemoveSelf(); |
190 } | 187 } |
191 | 188 |
192 base::string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { | 189 base::string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { |
193 if (step_ == translate::TRANSLATE_STEP_TRANSLATING) { | 190 if (step_ == translate::TRANSLATE_STEP_TRANSLATING) { |
194 base::string16 target_language_name = | 191 base::string16 target_language_name = |
195 language_name_at(target_language_index()); | 192 language_name_at(target_language_index()); |
196 return l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_TRANSLATING_TO, | 193 return l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_TRANSLATING_TO, |
197 target_language_name); | 194 target_language_name); |
198 } | 195 } |
199 | 196 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 prefs_(translate_manager->translate_client()->GetTranslatePrefs()), | 330 prefs_(translate_manager->translate_client()->GetTranslatePrefs()), |
334 triggered_from_menu_(triggered_from_menu) { | 331 triggered_from_menu_(triggered_from_menu) { |
335 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), | 332 DCHECK_NE((step_ == translate::TRANSLATE_STEP_TRANSLATE_ERROR), |
336 (error_type_ == TranslateErrors::NONE)); | 333 (error_type_ == TranslateErrors::NONE)); |
337 DCHECK(translate_manager_); | 334 DCHECK(translate_manager_); |
338 | 335 |
339 if (old_delegate && (old_delegate->is_error() != is_error())) | 336 if (old_delegate && (old_delegate->is_error() != is_error())) |
340 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; | 337 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; |
341 } | 338 } |
342 | 339 |
343 TranslateClient* TranslateInfoBarDelegate::GetTranslateClient() { | 340 TranslateClient* TranslateInfoBarDelegate::GetTranslateClient() { |
Peter Kasting
2014/05/22 17:37:24
I'm still not clear on where this is actually call
droger
2014/05/26 12:16:05
It was only called in one place, I removed it.
| |
344 if (!translate_manager_) | 341 if (!translate_manager_) |
345 return NULL; | 342 return NULL; |
346 | 343 |
347 return translate_manager_->translate_client(); | 344 return translate_manager_->translate_client(); |
348 } | 345 } |
349 | 346 |
350 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific | 347 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific |
351 // files. | 348 // files. |
352 | 349 |
353 void TranslateInfoBarDelegate::InfoBarDismissed() { | 350 void TranslateInfoBarDelegate::InfoBarDismissed() { |
354 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) | 351 if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) |
355 return; | 352 return; |
356 | 353 |
357 // The user closed the infobar without clicking the translate button. | 354 // The user closed the infobar without clicking the translate button. |
358 TranslationDeclined(); | 355 TranslationDeclined(); |
359 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); | 356 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); |
360 } | 357 } |
361 | 358 |
362 int TranslateInfoBarDelegate::GetIconID() const { | 359 int TranslateInfoBarDelegate::GetIconID() const { |
363 return IDR_INFOBAR_TRANSLATE; | 360 return translate_manager_->translate_client()->GetInfobarIconID(); |
364 } | 361 } |
365 | 362 |
366 infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() | 363 infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() |
367 const { | 364 const { |
368 return PAGE_ACTION_TYPE; | 365 return PAGE_ACTION_TYPE; |
369 } | 366 } |
370 | 367 |
371 bool TranslateInfoBarDelegate::ShouldExpire( | 368 bool TranslateInfoBarDelegate::ShouldExpire( |
372 const NavigationDetails& details) const { | 369 const NavigationDetails& details) const { |
373 // Note: we allow closing this infobar even if the main frame navigation | 370 // Note: we allow closing this infobar even if the main frame navigation |
374 // was programmatic and not initiated by the user - crbug.com/70261 . | 371 // was programmatic and not initiated by the user - crbug.com/70261 . |
375 if (!details.is_navigation_to_different_page && !details.is_main_frame) | 372 if (!details.is_navigation_to_different_page && !details.is_main_frame) |
376 return false; | 373 return false; |
377 | 374 |
378 return infobars::InfoBarDelegate::ShouldExpireInternal(details); | 375 return infobars::InfoBarDelegate::ShouldExpireInternal(details); |
379 } | 376 } |
380 | 377 |
381 TranslateInfoBarDelegate* | 378 TranslateInfoBarDelegate* |
382 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 379 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
383 return this; | 380 return this; |
384 } | 381 } |
OLD | NEW |