OLD | NEW |
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/browser/tab_contents/navigation_details.h" | 7 #include "content/browser/tab_contents/navigation_details.h" |
8 #include "content/browser/tab_contents/navigation_entry.h" | 8 #include "content/browser/tab_contents/navigation_entry.h" |
9 | 9 |
10 LanguageState::LanguageState(NavigationController* nav_controller) | 10 LanguageState::LanguageState(NavigationController* nav_controller) |
11 : navigation_controller_(nav_controller), | 11 : navigation_controller_(nav_controller), |
12 page_translatable_(false), | 12 page_translatable_(false), |
13 translation_pending_(false), | 13 translation_pending_(false), |
14 translation_declined_(false), | 14 translation_declined_(false), |
15 in_page_navigation_(false) { | 15 in_page_navigation_(false) { |
16 } | 16 } |
17 | 17 |
18 LanguageState::~LanguageState() { | 18 LanguageState::~LanguageState() { |
19 } | 19 } |
20 | 20 |
21 void LanguageState::DidNavigate( | 21 void LanguageState::DidNavigate( |
22 const content::LoadCommittedDetails& details) { | 22 const content::LoadCommittedDetails& details) { |
23 in_page_navigation_ = details.is_in_page; | 23 in_page_navigation_ = details.is_in_page; |
24 if (in_page_navigation_ || !details.is_main_frame) | 24 if (in_page_navigation_ || !details.is_main_frame) |
25 return; // Don't reset our states, the page has not changed. | 25 return; // Don't reset our states, the page has not changed. |
26 | 26 |
27 bool reload = details.entry->transition_type() == PageTransition::RELOAD || | 27 bool reload = |
28 details.type == NavigationType::SAME_PAGE; | 28 details.entry->transition_type() == content::PAGE_TRANSITION_RELOAD || |
| 29 details.type == NavigationType::SAME_PAGE; |
29 if (reload) { | 30 if (reload) { |
30 // We might not get a LanguageDetermined notifications on reloads. Make sure | 31 // We might not get a LanguageDetermined notifications on reloads. Make sure |
31 // to keep the original language and to set current_lang_ so | 32 // to keep the original language and to set current_lang_ so |
32 // IsPageTranslated() returns false. | 33 // IsPageTranslated() returns false. |
33 current_lang_ = original_lang_; | 34 current_lang_ = original_lang_; |
34 } else { | 35 } else { |
35 prev_original_lang_ = original_lang_; | 36 prev_original_lang_ = original_lang_; |
36 prev_current_lang_ = current_lang_; | 37 prev_current_lang_ = current_lang_; |
37 original_lang_.clear(); | 38 original_lang_.clear(); |
38 current_lang_.clear(); | 39 current_lang_.clear(); |
(...skipping 22 matching lines...) Expand all Loading... |
61 // - this page is in the same language as the previous page | 62 // - this page is in the same language as the previous page |
62 // - the previous page had been translated | 63 // - the previous page had been translated |
63 // - this page is not already translated | 64 // - this page is not already translated |
64 // - the new page was navigated through a link. | 65 // - the new page was navigated through a link. |
65 if (!translation_pending_ && | 66 if (!translation_pending_ && |
66 prev_original_lang_ == original_lang_ && | 67 prev_original_lang_ == original_lang_ && |
67 prev_original_lang_ != prev_current_lang_ && | 68 prev_original_lang_ != prev_current_lang_ && |
68 original_lang_ == current_lang_ && | 69 original_lang_ == current_lang_ && |
69 navigation_controller_->GetActiveEntry() && | 70 navigation_controller_->GetActiveEntry() && |
70 navigation_controller_->GetActiveEntry()->transition_type() == | 71 navigation_controller_->GetActiveEntry()->transition_type() == |
71 PageTransition::LINK) { | 72 content::PAGE_TRANSITION_LINK) { |
72 return prev_current_lang_; | 73 return prev_current_lang_; |
73 } | 74 } |
74 | 75 |
75 return std::string(); | 76 return std::string(); |
76 } | 77 } |
OLD | NEW |