Chromium Code Reviews| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 class NavigationController; | 13 class NavigationController; |
| 14 struct LoadCommittedDetails; | 14 struct LoadCommittedDetails; |
| 15 class WebContents; | |
|
Takashi Toyoshima
2013/10/08 14:54:09
sort these names (line 13:14 were wrong originally
hajimehoshi
2013/10/10 11:07:10
Done.
| |
| 15 } | 16 } |
| 16 | 17 |
| 17 // This class holds the language state of the current page. | 18 // This class holds the language state of the current page. |
| 18 // There is one LanguageState instance per WebContents. | 19 // There is one LanguageState instance per WebContents. |
| 19 // 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 |
| 20 // automatically be translated. | 21 // automatically be translated. |
| 21 // This auto-translate behavior is the expected behavior when: | 22 // This auto-translate behavior is the expected behavior when: |
| 22 // - 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. |
| 23 // - 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 |
| 24 // A. | 25 // A. |
| 25 | 26 |
| 26 class LanguageState { | 27 class LanguageState { |
| 27 public: | 28 public: |
| 29 class Observer { | |
| 30 public: | |
| 31 virtual void OnIsTranslateSuggestedChanged( | |
| 32 content::WebContents* source) = 0; | |
| 33 | |
| 34 protected: | |
| 35 virtual ~Observer() {} | |
| 36 }; | |
| 37 | |
| 28 explicit LanguageState(content::NavigationController* nav_controller); | 38 explicit LanguageState(content::NavigationController* nav_controller); |
| 29 ~LanguageState(); | 39 ~LanguageState(); |
| 30 | 40 |
| 31 // Should be called when the page did a new navigation (whether it is a main | 41 // Should be called when the page did a new navigation (whether it is a main |
| 32 // frame or sub-frame navigation). | 42 // frame or sub-frame navigation). |
| 33 void DidNavigate(const content::LoadCommittedDetails& details); | 43 void DidNavigate(const content::LoadCommittedDetails& details); |
| 34 | 44 |
| 35 // Should be called when the language of the page has been determined. | 45 // Should be called when the language of the page has been determined. |
| 36 // |page_needs_translation| when false indicates that the browser should not | 46 // |page_needs_translation| when false indicates that the browser should not |
| 37 // offer to translate the page. | 47 // offer to translate the page. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 64 void set_translation_pending(bool value) { translation_pending_ = value; } | 74 void set_translation_pending(bool value) { translation_pending_ = value; } |
| 65 | 75 |
| 66 // Whether the user has already declined to translate the page. | 76 // Whether the user has already declined to translate the page. |
| 67 bool translation_declined() const { return translation_declined_; } | 77 bool translation_declined() const { return translation_declined_; } |
| 68 void set_translation_declined(bool value) { translation_declined_ = value; } | 78 void set_translation_declined(bool value) { translation_declined_ = value; } |
| 69 | 79 |
| 70 // Whether the current page was navigated through an in-page (fragment) | 80 // Whether the current page was navigated through an in-page (fragment) |
| 71 // navigation. | 81 // navigation. |
| 72 bool in_page_navigation() const { return in_page_navigation_; } | 82 bool in_page_navigation() const { return in_page_navigation_; } |
| 73 | 83 |
| 84 bool is_translate_suggested() const { return is_translate_suggested_; } | |
|
Takashi Toyoshima
2013/10/08 14:54:09
To be consistent, translation_suggested() and SetT
hajimehoshi
2013/10/10 11:07:10
Done.
| |
| 85 void SetIsTranslateSuggested(bool value); | |
| 86 | |
| 87 // Whether the current page's language is different from the previous | |
| 88 // language. | |
| 89 bool IsLanguageChanged() const; | |
| 90 | |
| 91 void set_observer(Observer* observer) { observer_ = observer; } | |
| 92 | |
| 74 private: | 93 private: |
| 75 // The languages this page is in. Note that current_lang_ is different from | 94 // The languages this page is in. Note that current_lang_ is different from |
| 76 // original_lang_ when the page has been translated. | 95 // original_lang_ when the page has been translated. |
| 77 // Note that these might be empty if the page language has not been determined | 96 // Note that these might be empty if the page language has not been determined |
| 78 // yet. | 97 // yet. |
| 79 std::string original_lang_; | 98 std::string original_lang_; |
| 80 std::string current_lang_; | 99 std::string current_lang_; |
| 81 | 100 |
| 82 // Same as above but for the previous page. | 101 // Same as above but for the previous page. |
| 83 std::string prev_original_lang_; | 102 std::string prev_original_lang_; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 102 bool translation_pending_; | 121 bool translation_pending_; |
| 103 | 122 |
| 104 // Whether the user has declined to translate the page (by closing the infobar | 123 // Whether the user has declined to translate the page (by closing the infobar |
| 105 // for example). This is necessary as a new infobar could be shown if a new | 124 // for example). This is necessary as a new infobar could be shown if a new |
| 106 // load happens in the page after the user closed the infobar. | 125 // load happens in the page after the user closed the infobar. |
| 107 bool translation_declined_; | 126 bool translation_declined_; |
| 108 | 127 |
| 109 // Whether the current navigation is a fragment navigation (in page). | 128 // Whether the current navigation is a fragment navigation (in page). |
| 110 bool in_page_navigation_; | 129 bool in_page_navigation_; |
| 111 | 130 |
| 131 // Whether the user is encouraged to use Translate. | |
| 132 bool is_translate_suggested_; | |
| 133 | |
| 134 Observer* observer_; | |
| 135 | |
| 112 DISALLOW_COPY_AND_ASSIGN(LanguageState); | 136 DISALLOW_COPY_AND_ASSIGN(LanguageState); |
| 113 }; | 137 }; |
| 114 | 138 |
| 115 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ | 139 #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ |
| OLD | NEW |