| 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 #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 | 12 |
| 13 namespace content { |
| 13 class NavigationController; | 14 class NavigationController; |
| 14 | |
| 15 namespace content { | |
| 16 struct LoadCommittedDetails; | 15 struct LoadCommittedDetails; |
| 17 } | 16 } |
| 18 | 17 |
| 19 // This class holds the language state of the current page. | 18 // This class holds the language state of the current page. |
| 20 // There is one LanguageState instance per TabContents. | 19 // There is one LanguageState instance per TabContents. |
| 21 // It is used to determine when navigating to a new page whether it should | 20 // It is used to determine when navigating to a new page whether it should |
| 22 // automatically be translated. | 21 // automatically be translated. |
| 23 // This auto-translate behavior is the expected behavior when: | 22 // This auto-translate behavior is the expected behavior when: |
| 24 // - user is on page in language A that they had translated to language B. | 23 // - user is on page in language A that they had translated to language B. |
| 25 // - user clicks a link in that page that takes them to a page also in language | 24 // - user clicks a link in that page that takes them to a page also in language |
| 26 // A. | 25 // A. |
| 27 | 26 |
| 28 class LanguageState { | 27 class LanguageState { |
| 29 public: | 28 public: |
| 30 explicit LanguageState(NavigationController* nav_controller); | 29 explicit LanguageState(content::NavigationController* nav_controller); |
| 31 ~LanguageState(); | 30 ~LanguageState(); |
| 32 | 31 |
| 33 // Should be called when the page did a new navigation (whether it is a main | 32 // Should be called when the page did a new navigation (whether it is a main |
| 34 // frame or sub-frame navigation). | 33 // frame or sub-frame navigation). |
| 35 void DidNavigate(const content::LoadCommittedDetails& details); | 34 void DidNavigate(const content::LoadCommittedDetails& details); |
| 36 | 35 |
| 37 // Should be called when the language of the page has been determined. | 36 // Should be called when the language of the page has been determined. |
| 38 // |page_translatable| when false indicates that the browser should not offer | 37 // |page_translatable| when false indicates that the browser should not offer |
| 39 // to translate the page. | 38 // to translate the page. |
| 40 void LanguageDetermined(const std::string& page_language, | 39 void LanguageDetermined(const std::string& page_language, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Note that these might be empty if the page language has not been determined | 75 // Note that these might be empty if the page language has not been determined |
| 77 // yet. | 76 // yet. |
| 78 std::string original_lang_; | 77 std::string original_lang_; |
| 79 std::string current_lang_; | 78 std::string current_lang_; |
| 80 | 79 |
| 81 // Same as above but for the previous page. | 80 // Same as above but for the previous page. |
| 82 std::string prev_original_lang_; | 81 std::string prev_original_lang_; |
| 83 std::string prev_current_lang_; | 82 std::string prev_current_lang_; |
| 84 | 83 |
| 85 // The navigation controller of the tab we are associated with. | 84 // The navigation controller of the tab we are associated with. |
| 86 NavigationController* navigation_controller_; | 85 content::NavigationController* navigation_controller_; |
| 87 | 86 |
| 88 // Whether it is OK to offer to translate the page. Some pages explictly | 87 // Whether it is OK to offer to translate the page. Some pages explictly |
| 89 // specify that they should not be translated by the browser (this is the case | 88 // specify that they should not be translated by the browser (this is the case |
| 90 // for GMail for example, which provides its own translation features). | 89 // for GMail for example, which provides its own translation features). |
| 91 bool page_translatable_; | 90 bool page_translatable_; |
| 92 | 91 |
| 93 // Whether a translation is currently pending (TabContents waiting for the | 92 // Whether a translation is currently pending (TabContents waiting for the |
| 94 // PAGE_TRANSLATED notification). This is needed to avoid sending duplicate | 93 // PAGE_TRANSLATED notification). This is needed to avoid sending duplicate |
| 95 // translate requests to a page. TranslateManager initiates translations | 94 // translate requests to a page. TranslateManager initiates translations |
| 96 // when it received the LANGUAGE_DETERMINED notification. This is sent by | 95 // when it received the LANGUAGE_DETERMINED notification. This is sent by |
| 97 // the renderer with the page contents, every time the load stops for the | 96 // the renderer with the page contents, every time the load stops for the |
| 98 // main frame, so we may get several. | 97 // main frame, so we may get several. |
| 99 // TODO(jcampan): make the renderer send the language just once per navigation | 98 // TODO(jcampan): make the renderer send the language just once per navigation |
| 100 // then we can get rid of that state. | 99 // then we can get rid of that state. |
| 101 bool translation_pending_; | 100 bool translation_pending_; |
| 102 | 101 |
| 103 // Whether the user has declined to translate the page (by closing the infobar | 102 // Whether the user has declined to translate the page (by closing the infobar |
| 104 // for example). This is necessary as a new infobar could be shown if a new | 103 // for example). This is necessary as a new infobar could be shown if a new |
| 105 // load happens in the page after the user closed the infobar. | 104 // load happens in the page after the user closed the infobar. |
| 106 bool translation_declined_; | 105 bool translation_declined_; |
| 107 | 106 |
| 108 // Whether the current navigation is a fragment navigation (in page). | 107 // Whether the current navigation is a fragment navigation (in page). |
| 109 bool in_page_navigation_; | 108 bool in_page_navigation_; |
| 110 | 109 |
| 111 DISALLOW_COPY_AND_ASSIGN(LanguageState); | 110 DISALLOW_COPY_AND_ASSIGN(LanguageState); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 113 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ |
| OLD | NEW |