summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
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_; }