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

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

Issue 6537015: Start moving core pieces of Chrome multi-process code to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/tab_contents/language_state.h"
6
7 #include "chrome/browser/tab_contents/navigation_controller.h"
8 #include "chrome/browser/tab_contents/navigation_entry.h"
9
10 LanguageState::LanguageState(NavigationController* nav_controller)
11 : navigation_controller_(nav_controller),
12 page_translatable_(false),
13 translation_pending_(false),
14 translation_declined_(false),
15 in_page_navigation_(false) {
16 }
17
18 LanguageState::~LanguageState() {
19 }
20
21 void LanguageState::DidNavigate(
22 const NavigationController::LoadCommittedDetails& details) {
23 in_page_navigation_ = details.is_in_page;
24 if (in_page_navigation_ || !details.is_main_frame)
25 return; // Don't reset our states, the page has not changed.
26
27 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
28 details.type == NavigationType::SAME_PAGE;
29 if (reload) {
30 // We might not get a LanguageDetermined notifications on reloads. Make sure
31 // to keep the original language and to set current_lang_ so
32 // IsPageTranslated() returns false.
33 current_lang_ = original_lang_;
34 } else {
35 prev_original_lang_ = original_lang_;
36 prev_current_lang_ = current_lang_;
37 original_lang_.clear();
38 current_lang_.clear();
39 }
40
41 translation_pending_ = false;
42 translation_declined_ = false;
43 }
44
45 void LanguageState::LanguageDetermined(const std::string& page_language,
46 bool page_translatable) {
47 if (in_page_navigation_ && !original_lang_.empty()) {
48 // In-page navigation, we don't expect our states to change.
49 // Note that we'll set the languages if original_lang_ is empty. This might
50 // happen if the we did not get called on the top-page.
51 return;
52 }
53 page_translatable_ = page_translatable;
54 original_lang_ = page_language;
55 current_lang_ = page_language;
56 }
57
58 std::string LanguageState::AutoTranslateTo() const {
59 // Only auto-translate if:
60 // - no translation is pending
61 // - this page is in the same language as the previous page
62 // - the previous page had been translated
63 // - this page is not already translated
64 // - the new page was navigated through a link.
65 if (!translation_pending_ &&
66 prev_original_lang_ == original_lang_ &&
67 prev_original_lang_ != prev_current_lang_ &&
68 original_lang_ == current_lang_ &&
69 navigation_controller_->GetActiveEntry() &&
70 navigation_controller_->GetActiveEntry()->transition_type() ==
71 PageTransition::LINK) {
72 return prev_current_lang_;
73 }
74
75 return std::string();
76 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/language_state.h ('k') | chrome/browser/tab_contents/navigation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698