Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/browser/tab_contents/language_state.cc

Issue 14392011: [Translate] Expose whether the user is within a navigation session as part of the infobar delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tab_contents/language_state.h" 5 #include "chrome/browser/tab_contents/language_state.h"
6 6
7 #include "content/public/browser/navigation_controller.h" 7 #include "content/public/browser/navigation_controller.h"
8 #include "content/public/browser/navigation_details.h" 8 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/navigation_entry.h" 9 #include "content/public/browser/navigation_entry.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // In-page navigation, we don't expect our states to change. 52 // In-page navigation, we don't expect our states to change.
53 // Note that we'll set the languages if original_lang_ is empty. This might 53 // Note that we'll set the languages if original_lang_ is empty. This might
54 // happen if the we did not get called on the top-page. 54 // happen if the we did not get called on the top-page.
55 return; 55 return;
56 } 56 }
57 page_translatable_ = page_translatable; 57 page_translatable_ = page_translatable;
58 original_lang_ = page_language; 58 original_lang_ = page_language;
59 current_lang_ = page_language; 59 current_lang_ = page_language;
60 } 60 }
61 61
62 std::string LanguageState::AutoTranslateTo() const { 62 bool LanguageState::InTranslateNavigation() const {
63 // Only auto-translate if: 63 // The user is in the same translate session if
64 // - no translation is pending 64 // - no translation is pending
65 // - this page is in the same language as the previous page 65 // - this page is in the same language as the previous page
66 // - the previous page had been translated 66 // - the previous page had been translated
67 // - this page is not already translated 67 // - the new page was navigated through a link.
68 // - the new page was navigated through a link. 68 return
69 if (!translation_pending_ && 69 !translation_pending_ &&
70 prev_original_lang_ == original_lang_ && 70 prev_original_lang_ == original_lang_ &&
71 prev_original_lang_ != prev_current_lang_ && 71 prev_original_lang_ != prev_current_lang_ &&
72 original_lang_ == current_lang_ &&
73 navigation_controller_->GetActiveEntry() && 72 navigation_controller_->GetActiveEntry() &&
74 navigation_controller_->GetActiveEntry()->GetTransitionType() == 73 navigation_controller_->GetActiveEntry()->GetTransitionType() ==
75 content::PAGE_TRANSITION_LINK) { 74 content::PAGE_TRANSITION_LINK;
75 }
76
77
78 std::string LanguageState::AutoTranslateTo() const {
79 if (InTranslateNavigation() &&
80 // The page is not yet translated.
81 original_lang_ == current_lang_ ) {
76 return prev_current_lang_; 82 return prev_current_lang_;
77 } 83 }
78 84
79 return std::string(); 85 return std::string();
80 } 86 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/language_state.h ('k') | chrome/browser/translate/translate_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698