summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authormiguelg@chromium.org <miguelg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-26 00:56:21 +0000
committermiguelg@chromium.org <miguelg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-26 00:56:21 +0000
commit6b6099ef7c5dd708461d39b0e7edef6cbe97fe41 (patch)
treeb5e8651bc3b83b4c9a0fa87b7a2158a36983a5ad /chrome/browser/tab_contents
parent82b35a9db43197fe546faa289ff8cf5b418ec6e9 (diff)
downloadchromium_src-6b6099ef7c5dd708461d39b0e7edef6cbe97fe41.zip
chromium_src-6b6099ef7c5dd708461d39b0e7edef6cbe97fe41.tar.gz
chromium_src-6b6099ef7c5dd708461d39b0e7edef6cbe97fe41.tar.bz2
[Translate] Expose whether the user is within a navigation session as part of the infobar delegate
- Add a new method to language state that returns if the user is navigating over translated links. - Use that method for the existing AutoTranslate() implementation. BUG=234159 Review URL: https://chromiumcodereview.appspot.com/14392011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/language_state.cc26
-rw-r--r--chrome/browser/tab_contents/language_state.h3
2 files changed, 19 insertions, 10 deletions
diff --git a/chrome/browser/tab_contents/language_state.cc b/chrome/browser/tab_contents/language_state.cc
index d57c959..00fd388 100644
--- a/chrome/browser/tab_contents/language_state.cc
+++ b/chrome/browser/tab_contents/language_state.cc
@@ -59,20 +59,26 @@ void LanguageState::LanguageDetermined(const std::string& page_language,
current_lang_ = page_language;
}
-std::string LanguageState::AutoTranslateTo() const {
- // Only auto-translate if:
- // - no translation is pending
- // - this page is in the same language as the previous page
- // - the previous page had been translated
- // - this page is not already translated
- // - the new page was navigated through a link.
- if (!translation_pending_ &&
+bool LanguageState::InTranslateNavigation() const {
+ // The user is in the same translate session if
+ // - no translation is pending
+ // - this page is in the same language as the previous page
+ // - the previous page had been translated
+ // - the new page was navigated through a link.
+ return
+ !translation_pending_ &&
prev_original_lang_ == original_lang_ &&
prev_original_lang_ != prev_current_lang_ &&
- original_lang_ == current_lang_ &&
navigation_controller_->GetActiveEntry() &&
navigation_controller_->GetActiveEntry()->GetTransitionType() ==
- content::PAGE_TRANSITION_LINK) {
+ content::PAGE_TRANSITION_LINK;
+}
+
+
+std::string LanguageState::AutoTranslateTo() const {
+ if (InTranslateNavigation() &&
+ // The page is not yet translated.
+ original_lang_ == current_lang_ ) {
return prev_current_lang_;
}
diff --git a/chrome/browser/tab_contents/language_state.h b/chrome/browser/tab_contents/language_state.h
index 7fc4059..e97e710 100644
--- a/chrome/browser/tab_contents/language_state.h
+++ b/chrome/browser/tab_contents/language_state.h
@@ -44,6 +44,9 @@ class LanguageState {
// Returns an empty string if the page should not be auto-translated.
std::string AutoTranslateTo() const;
+ // Returns true if the user is navigating through translated links.
+ bool InTranslateNavigation() const;
+
// Returns true if the current page in the associated tab has been translated.
bool IsPageTranslated() const { return original_lang_ != current_lang_; }