Chromium Code Reviews| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 break; | 67 break; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Create the new delegate. | 70 // Create the new delegate. |
| 71 scoped_ptr<TranslateInfoBarDelegate> infobar( | 71 scoped_ptr<TranslateInfoBarDelegate> infobar( |
| 72 new TranslateInfoBarDelegate(infobar_type, error_type, infobar_service, | 72 new TranslateInfoBarDelegate(infobar_type, error_type, infobar_service, |
| 73 prefs, shortcut_config, | 73 prefs, shortcut_config, |
| 74 original_language, target_language)); | 74 original_language, target_language)); |
| 75 infobar->UpdateBackgroundAnimation(old_delegate); | 75 infobar->UpdateBackgroundAnimation(old_delegate); |
| 76 | 76 |
| 77 // Do not create the after translate infobar if we are auto translating. | |
| 78 if (infobar_type == TranslateInfoBarDelegate::AFTER_TRANSLATE | |
|
Takashi Toyoshima
2013/06/21 12:19:53
In chromium style, "||" should be the end of previ
Miguel Garcia
2013/06/21 13:24:59
Done.
| |
| 79 || infobar_type == TranslateInfoBarDelegate::TRANSLATING) { | |
| 80 TranslateTabHelper* translate_tab_helper = | |
| 81 TranslateTabHelper::FromWebContents(infobar_service->web_contents()); | |
| 82 if (!translate_tab_helper | |
| 83 || translate_tab_helper->language_state().InTranslateNavigation()) | |
| 84 return; | |
| 85 } | |
| 86 | |
| 77 // Add the new delegate if necessary. | 87 // Add the new delegate if necessary. |
| 78 if (!old_delegate) { | 88 if (!old_delegate) { |
| 79 infobar_service->AddInfoBar(infobar.PassAs<InfoBarDelegate>()); | 89 infobar_service->AddInfoBar(infobar.PassAs<InfoBarDelegate>()); |
| 80 } else if (replace_existing_infobar) { | 90 } else if (replace_existing_infobar) { |
| 81 infobar_service->ReplaceInfoBar(old_delegate, | 91 infobar_service->ReplaceInfoBar(old_delegate, |
| 82 infobar.PassAs<InfoBarDelegate>()); | 92 infobar.PassAs<InfoBarDelegate>()); |
| 83 } | 93 } |
| 84 } | 94 } |
| 85 | 95 |
| 86 void TranslateInfoBarDelegate::Translate() { | 96 void TranslateInfoBarDelegate::Translate() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // translations when getting a LANGUAGE_DETERMINED from the page, which | 129 // translations when getting a LANGUAGE_DETERMINED from the page, which |
| 120 // happens when a load stops. That could happen multiple times, including | 130 // happens when a load stops. That could happen multiple times, including |
| 121 // after the user already declined the translation.) | 131 // after the user already declined the translation.) |
| 122 TranslateTabHelper* translate_tab_helper = | 132 TranslateTabHelper* translate_tab_helper = |
| 123 TranslateTabHelper::FromWebContents(web_contents()); | 133 TranslateTabHelper::FromWebContents(web_contents()); |
| 124 translate_tab_helper->language_state().set_translation_declined(true); | 134 translate_tab_helper->language_state().set_translation_declined(true); |
| 125 | 135 |
| 126 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslate, true); | 136 UMA_HISTOGRAM_BOOLEAN(kDeclineTranslate, true); |
| 127 } | 137 } |
| 128 | 138 |
| 129 bool TranslateInfoBarDelegate::InTranslateNavigation() { | |
| 130 TranslateTabHelper* translate_tab_helper = | |
| 131 TranslateTabHelper::FromWebContents(web_contents()); | |
| 132 if (!translate_tab_helper) | |
| 133 return false; | |
| 134 return translate_tab_helper->language_state().InTranslateNavigation(); | |
| 135 } | |
| 136 | |
| 137 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { | 139 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { |
| 138 Profile* profile = | 140 Profile* profile = |
| 139 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 141 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 140 Profile* original_profile = profile->GetOriginalProfile(); | 142 Profile* original_profile = profile->GetOriginalProfile(); |
| 141 return TranslatePrefs::CanTranslateLanguage(original_profile, | 143 return TranslatePrefs::CanTranslateLanguage(original_profile, |
| 142 original_language_code()); | 144 original_language_code()); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void TranslateInfoBarDelegate::ToggleTranslatableLanguageByPrefs() { | 147 void TranslateInfoBarDelegate::ToggleTranslatableLanguageByPrefs() { |
| 146 const std::string& original_lang = original_language_code(); | 148 const std::string& original_lang = original_language_code(); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 | 414 |
| 413 TranslateInfoBarDelegate* | 415 TranslateInfoBarDelegate* |
| 414 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 416 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 415 return this; | 417 return this; |
| 416 } | 418 } |
| 417 | 419 |
| 418 std::string TranslateInfoBarDelegate::GetPageHost() { | 420 std::string TranslateInfoBarDelegate::GetPageHost() { |
| 419 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 421 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
| 420 return entry ? entry->GetURL().HostNoBrackets() : std::string(); | 422 return entry ? entry->GetURL().HostNoBrackets() : std::string(); |
| 421 } | 423 } |
| OLD | NEW |