OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ |
6 #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "chrome/browser/tab_contents/navigation_controller.h" | 12 #include "chrome/browser/tab_contents/navigation_controller.h" |
13 | 13 |
14 // This class holds the language state of the current page. | 14 // This class holds the language state of the current page. |
15 // There is one LanguageState instance per TabContents. | 15 // There is one LanguageState instance per TabContents. |
16 // It is used to determine when navigating to a new page whether it should | 16 // It is used to determine when navigating to a new page whether it should |
17 // automatically be translated. | 17 // automatically be translated. |
18 // This auto-translate behavior is the expected behavior when: | 18 // This auto-translate behavior is the expected behavior when: |
19 // - user is on page in language A that they had translated to language B. | 19 // - user is on page in language A that they had translated to language B. |
20 // - user clicks a link in that page that takes them to a page also in language | 20 // - user clicks a link in that page that takes them to a page also in language |
21 // A. | 21 // A. |
22 | 22 |
23 class LanguageState { | 23 class LanguageState { |
24 public: | 24 public: |
25 explicit LanguageState(NavigationController* nav_controller); | 25 explicit LanguageState(NavigationController* nav_controller); |
26 ~LanguageState(); | 26 virtual ~LanguageState(); |
27 | 27 |
28 // Should be called when the page did a new navigation (whether it is a main | 28 // Should be called when the page did a new navigation (whether it is a main |
29 // frame or sub-frame navigation). | 29 // frame or sub-frame navigation). |
30 void DidNavigate(const NavigationController::LoadCommittedDetails& details); | 30 void DidNavigate(const NavigationController::LoadCommittedDetails& details); |
31 | 31 |
32 // Should be called when the language of the page has been determined. | 32 // Should be called when the language of the page has been determined. |
33 // |page_translatable| when false indicates that the browser should not offer | 33 // |page_translatable| when false indicates that the browser should not offer |
34 // to translate the page. | 34 // to translate the page. |
35 void LanguageDetermined(const std::string& page_language, | 35 void LanguageDetermined(const std::string& page_language, |
36 bool page_translatable); | 36 bool page_translatable); |
37 | 37 |
38 // Returns the language the current page should be translated to, based on the | 38 // Returns the language the current page should be translated to, based on the |
39 // previous page languages and the transition. This should be called after | 39 // previous page languages and the transition. This should be called after |
40 // the language page has been determined. | 40 // the language page has been determined. |
41 // Returns an empty string if the page should not be auto-translated. | 41 // Returns an empty string if the page should not be auto-translated. |
42 std::string AutoTranslateTo() const; | 42 std::string AutoTranslateTo() const; |
43 | 43 |
44 // Returns true if the current page in the associated tab has been translated. | 44 // Returns true if the current page in the associated tab has been translated. |
45 bool IsPageTranslated() const { return original_lang_ != current_lang_; } | 45 bool IsPageTranslated() const { return original_lang_ != current_lang_; } |
46 | 46 |
47 const std::string& original_language() const { return original_lang_; } | 47 virtual const std::string& original_language() const { |
| 48 return original_lang_; |
| 49 } |
48 | 50 |
49 void set_current_language(const std::string& language) { | 51 void set_current_language(const std::string& language) { |
50 current_lang_ = language; | 52 current_lang_ = language; |
51 } | 53 } |
52 const std::string& current_language() const { return current_lang_; } | 54 virtual const std::string& current_language() const { return current_lang_; } |
53 | 55 |
54 bool page_translatable() const { return page_translatable_; } | 56 bool page_translatable() const { return page_translatable_; } |
55 | 57 |
56 // Whether the page is currently in the process of being translated. | 58 // Whether the page is currently in the process of being translated. |
57 bool translation_pending() const { return translation_pending_; } | 59 bool translation_pending() const { return translation_pending_; } |
58 void set_translation_pending(bool value) { translation_pending_ = value; } | 60 void set_translation_pending(bool value) { translation_pending_ = value; } |
59 | 61 |
60 // Whether the user has already declined to translate the page. | 62 // Whether the user has already declined to translate the page. |
61 bool translation_declined() const { return translation_declined_; } | 63 bool translation_declined() const { return translation_declined_; } |
62 void set_translation_declined(bool value) { translation_declined_ = value; } | 64 void set_translation_declined(bool value) { translation_declined_ = value; } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 bool translation_declined_; | 103 bool translation_declined_; |
102 | 104 |
103 // Whether the current navigation is a fragment navigation (in page). | 105 // Whether the current navigation is a fragment navigation (in page). |
104 bool in_page_navigation_; | 106 bool in_page_navigation_; |
105 | 107 |
106 DISALLOW_COPY_AND_ASSIGN(LanguageState); | 108 DISALLOW_COPY_AND_ASSIGN(LanguageState); |
107 }; | 109 }; |
108 | 110 |
109 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 111 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ |
110 | 112 |
OLD | NEW |