Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_STATE_H_ |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_STATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 class LanguageStateObserver; | 12 class TranslateDriver; |
| 13 | |
| 14 namespace content { | |
| 15 struct LoadCommittedDetails; | |
| 16 class NavigationController; | |
| 17 class WebContents; | |
| 18 } | |
| 19 | 13 |
| 20 // This class holds the language state of the current page. | 14 // This class holds the language state of the current page. |
| 21 // There is one LanguageState instance per WebContents. | 15 // There is one LanguageState instance per tab. |
| 22 // 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 |
| 23 // automatically be translated. | 17 // automatically be translated. |
| 24 // This auto-translate behavior is the expected behavior when: | 18 // This auto-translate behavior is the expected behavior when: |
| 25 // - 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. |
| 26 // - 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 |
| 27 // A. | 21 // A. |
| 28 | 22 |
| 29 class LanguageState { | 23 class LanguageState { |
| 30 public: | 24 public: |
| 31 explicit LanguageState(content::NavigationController* nav_controller); | 25 LanguageState(TranslateDriver* driver); |
|
MAD
2014/01/20 16:12:25
Why did you remove the "explicit"?
droger
2014/01/20 17:05:05
This was a mistake, explicit is back.
| |
| 32 ~LanguageState(); | 26 ~LanguageState(); |
| 33 | 27 |
| 34 // 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 |
| 35 // frame or sub-frame navigation). | 29 // frame or sub-frame navigation). |
| 36 void DidNavigate(const content::LoadCommittedDetails& details); | 30 void DidNavigate(bool in_page_navigation, bool is_main_frame, bool reload); |
| 37 | 31 |
| 38 // 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. |
| 39 // |page_needs_translation| when false indicates that the browser should not | 33 // |page_needs_translation| when false indicates that the browser should not |
| 40 // offer to translate the page. | 34 // offer to translate the page. |
| 41 void LanguageDetermined(const std::string& page_language, | 35 void LanguageDetermined(const std::string& page_language, |
| 42 bool page_needs_translation); | 36 bool page_needs_translation); |
| 43 | 37 |
| 44 // 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 |
| 45 // previous page languages and the transition. This should be called after | 39 // previous page languages and the transition. This should be called after |
| 46 // the language page has been determined. | 40 // the language page has been determined. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 65 void set_translation_pending(bool value) { translation_pending_ = value; } | 59 void set_translation_pending(bool value) { translation_pending_ = value; } |
| 66 | 60 |
| 67 // Whether the user has already declined to translate the page. | 61 // Whether the user has already declined to translate the page. |
| 68 bool translation_declined() const { return translation_declined_; } | 62 bool translation_declined() const { return translation_declined_; } |
| 69 void set_translation_declined(bool value) { translation_declined_ = value; } | 63 void set_translation_declined(bool value) { translation_declined_ = value; } |
| 70 | 64 |
| 71 // Whether the current page was navigated through an in-page (fragment) | 65 // Whether the current page was navigated through an in-page (fragment) |
| 72 // navigation. | 66 // navigation. |
| 73 bool in_page_navigation() const { return in_page_navigation_; } | 67 bool in_page_navigation() const { return in_page_navigation_; } |
| 74 | 68 |
| 75 // Whether the translate is enabled. This value is supposed to be used for the | 69 // Whether the translate is enabled. This value is supposed to be used for the |
|
blundell
2014/01/20 14:22:53
The second sentence of this comment should go now
| |
| 76 // Translate icon on the Omnibox. | 70 // Translate icon on the Omnibox. |
| 77 bool translate_enabled() const { return translate_enabled_; } | 71 bool translate_enabled() const { return translate_enabled_; } |
| 78 void SetTranslateEnabled(bool value); | 72 void SetTranslateEnabled(bool value); |
| 79 | 73 |
| 80 // Whether the current page's language is different from the previous | 74 // Whether the current page's language is different from the previous |
| 81 // language. | 75 // language. |
| 82 bool HasLanguageChanged() const; | 76 bool HasLanguageChanged() const; |
| 83 | 77 |
| 84 void set_observer(LanguageStateObserver* observer) { observer_ = observer; } | |
| 85 | |
| 86 private: | 78 private: |
| 87 void SetIsPageTranslated(bool value); | 79 void SetIsPageTranslated(bool value); |
| 88 | 80 |
| 89 // Whether the page is translated or not. | 81 // Whether the page is translated or not. |
| 90 bool is_page_translated_; | 82 bool is_page_translated_; |
| 91 | 83 |
| 92 // The languages this page is in. Note that current_lang_ is different from | 84 // The languages this page is in. Note that current_lang_ is different from |
| 93 // original_lang_ when the page has been translated. | 85 // original_lang_ when the page has been translated. |
| 94 // Note that these might be empty if the page language has not been determined | 86 // Note that these might be empty if the page language has not been determined |
| 95 // yet. | 87 // yet. |
| 96 std::string original_lang_; | 88 std::string original_lang_; |
| 97 std::string current_lang_; | 89 std::string current_lang_; |
| 98 | 90 |
| 99 // Same as above but for the previous page. | 91 // Same as above but for the previous page. |
| 100 std::string prev_original_lang_; | 92 std::string prev_original_lang_; |
| 101 std::string prev_current_lang_; | 93 std::string prev_current_lang_; |
| 102 | 94 |
| 103 // The navigation controller of the tab we are associated with. | 95 TranslateDriver* translate_driver_; |
|
blundell
2014/01/20 14:22:53
Should have a comment, including lifetime expectat
| |
| 104 content::NavigationController* navigation_controller_; | |
| 105 | 96 |
| 106 // Whether it is OK to offer to translate the page. Some pages explictly | 97 // Whether it is OK to offer to translate the page. Some pages explictly |
| 107 // specify that they should not be translated by the browser (this is the case | 98 // specify that they should not be translated by the browser (this is the case |
| 108 // for GMail for example, which provides its own translation features). | 99 // for GMail for example, which provides its own translation features). |
| 109 bool page_needs_translation_; | 100 bool page_needs_translation_; |
| 110 | 101 |
| 111 // Whether a translation is currently pending (WebContents waiting for the | 102 // Whether a translation is currently pending. |
| 112 // PAGE_TRANSLATED notification). This is needed to avoid sending duplicate | 103 // This is needed to avoid sending duplicate translate requests to a page. |
| 113 // translate requests to a page. TranslateManager initiates translations | 104 // Translations may be initiated every time the load stops for the main frame, |
| 114 // when it received the LANGUAGE_DETERMINED notification. This is sent by | 105 // which may happen several times. |
| 115 // the renderer with the page contents, every time the load stops for the | 106 // TODO(jcampan): make the client send the language just once per navigation |
| 116 // main frame, so we may get several. | |
| 117 // TODO(jcampan): make the renderer send the language just once per navigation | |
| 118 // then we can get rid of that state. | 107 // then we can get rid of that state. |
| 119 bool translation_pending_; | 108 bool translation_pending_; |
| 120 | 109 |
| 121 // Whether the user has declined to translate the page (by closing the infobar | 110 // Whether the user has declined to translate the page (by closing the infobar |
| 122 // for example). This is necessary as a new infobar could be shown if a new | 111 // for example). This is necessary as a new infobar could be shown if a new |
| 123 // load happens in the page after the user closed the infobar. | 112 // load happens in the page after the user closed the infobar. |
| 124 bool translation_declined_; | 113 bool translation_declined_; |
| 125 | 114 |
| 126 // Whether the current navigation is a fragment navigation (in page). | 115 // Whether the current navigation is a fragment navigation (in page). |
| 127 bool in_page_navigation_; | 116 bool in_page_navigation_; |
| 128 | 117 |
| 129 // Whether the Translate is enabled. | 118 // Whether the Translate is enabled. |
| 130 bool translate_enabled_; | 119 bool translate_enabled_; |
| 131 | 120 |
| 132 LanguageStateObserver* observer_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(LanguageState); | 121 DISALLOW_COPY_AND_ASSIGN(LanguageState); |
| 135 }; | 122 }; |
| 136 | 123 |
| 137 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 124 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_STATE_H_ |
| OLD | NEW |