OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 std::string GetTargetLanguageCode() const; | 70 std::string GetTargetLanguageCode() const; |
71 | 71 |
72 // Updates the target language index. | 72 // Updates the target language index. |
73 void UpdateTargetLanguageIndex(size_t language_index); | 73 void UpdateTargetLanguageIndex(size_t language_index); |
74 | 74 |
75 void UpdateTargetLanguage(const std::string& language_code); | 75 void UpdateTargetLanguage(const std::string& language_code); |
76 | 76 |
77 // Returns the ISO code for the language at |index|. | 77 // Returns the ISO code for the language at |index|. |
78 std::string GetLanguageCodeAt(size_t index) const; | 78 std::string GetLanguageCodeAt(size_t index) const; |
79 | 79 |
| 80 // Returns the index of |language_code|. |
| 81 size_t GetLanguageIndex(const std::string& language_code); |
| 82 |
80 // Returns the displayable name for the language at |index|. | 83 // Returns the displayable name for the language at |index|. |
81 base::string16 GetLanguageNameAt(size_t index) const; | 84 base::string16 GetLanguageNameAt(size_t index) const; |
82 | 85 |
83 // Starts translating the current page. | 86 // Starts translating the current page. |
84 void Translate(); | 87 void Translate(); |
85 | 88 |
86 // Reverts translation. | 89 // Reverts translation. |
87 void RevertTranslation(); | 90 void RevertTranslation(); |
88 | 91 |
89 // Processes when the user declines translation. | 92 // Processes when the user declines translation. |
90 // The function name is not accurate. It only means the user did not take | 93 // The function name is not accurate. It only means the user did not take |
91 // affirmative action after the translation ui show up. The user either | 94 // affirmative action after the translation ui show up. The user either |
92 // actively decline the translation or ignore the prompt of translation. | 95 // actively decline the translation or ignore the prompt of translation. |
93 // Pass |explicitly_closed| as true if user explicityly decline the | 96 // Pass |explicitly_closed| as true if user explicityly decline the |
94 // translation. | 97 // translation. |
95 // Pass |explicitly_closed| as false if the translation UI is dismissed | 98 // Pass |explicitly_closed| as false if the translation UI is dismissed |
96 // implicit by some user actions which ignore the translation UI, | 99 // implicit by some user actions which ignore the translation UI, |
97 // such as switch to a new tab/window or navigate to another page by | 100 // such as switch to a new tab/window or navigate to another page by |
98 // click a link. | 101 // click a link. |
99 void TranslationDeclined(bool explicitly_closed); | 102 void TranslationDeclined(bool explicitly_closed); |
100 | 103 |
101 // Returns true if the current language is blocked. | 104 // Returns true if the current language is blocked. |
102 bool IsLanguageBlocked(); | 105 bool IsLanguageBlocked(); |
103 | 106 |
| 107 // Returns true if |language_code| is blocked. |language_code| must not be |
| 108 // empty. |
| 109 bool IsLanguageBlocked(const std::string& language_code); |
| 110 |
104 // Sets the value if the current language is blocked. | 111 // Sets the value if the current language is blocked. |
105 void SetLanguageBlocked(bool value); | 112 void SetLanguageBlocked(bool value); |
106 | 113 |
| 114 // Blocks/unblocks |language_code| for translation. |language_code| must not |
| 115 // be empty. |
| 116 void SetLanguageBlocked(bool value, const std::string& language_code); |
| 117 |
107 // Returns true if the current webpage is blacklisted. | 118 // Returns true if the current webpage is blacklisted. |
108 bool IsSiteBlacklisted(); | 119 bool IsSiteBlacklisted(); |
109 | 120 |
| 121 // Returns true if |page_host| is blacklisted. |page_host| must not be empty. |
| 122 bool IsSiteBlacklisted(const std::string& page_host); |
| 123 |
110 // Sets the value if the current webpage is blacklisted. | 124 // Sets the value if the current webpage is blacklisted. |
111 void SetSiteBlacklist(bool value); | 125 void SetSiteBlacklist(bool value); |
112 | 126 |
| 127 // Sets the value if the |page_host| is blacklisted. |page_host| must not be |
| 128 // empty. |
| 129 void SetSiteBlacklist(bool value, const std::string& page_host); |
| 130 |
113 // Returns true if the webpage in the current original language should be | 131 // Returns true if the webpage in the current original language should be |
114 // translated into the current target language automatically. | 132 // translated into the current target language automatically. |
115 bool ShouldAlwaysTranslate(); | 133 bool ShouldAlwaysTranslate(); |
116 | 134 |
117 // Sets the value if the webpage in the current original language should be | 135 // Sets the value if the webpage in the current original language should be |
118 // translated into the current target language automatically. | 136 // translated into the current target language automatically. |
119 void SetAlwaysTranslate(bool value); | 137 void SetAlwaysTranslate(bool value); |
120 | 138 |
| 139 // If |value| is true, updates the preference to always translate |
| 140 // |from_language| to |to_language| without prompting. If it is called |
| 141 // multiple times for the same |from_language|, the last specified |
| 142 // |to_language| is used. |
| 143 // If |value| is false, updates the preference not to always translate |
| 144 // |from_language|. |target_language| is ignored. |
| 145 void SetAlwaysTranslate(bool value, |
| 146 const std::string& from_language, |
| 147 const std::string& to_language); |
| 148 |
| 149 // Returns the language to always translate |from_language| to, or empty |
| 150 // string if no such language has been set. |
| 151 std::string GetAlwaysTranslateToLanguage(const std::string& from_language); |
| 152 |
121 // Returns true if the Always Translate checkbox should be checked by default. | 153 // Returns true if the Always Translate checkbox should be checked by default. |
122 bool ShouldAlwaysTranslateBeCheckedByDefault(); | 154 bool ShouldAlwaysTranslateBeCheckedByDefault(); |
123 | 155 |
124 private: | 156 private: |
125 // Gets the host of the page being translated, or an empty string if no URL is | 157 // Gets the host of the page being translated, or an empty string if no URL is |
126 // associated with the current page. | 158 // associated with the current page. |
127 std::string GetPageHost(); | 159 std::string GetPageHost(); |
128 | 160 |
129 TranslateDriver* translate_driver_; | 161 TranslateDriver* translate_driver_; |
130 base::WeakPtr<TranslateManager> translate_manager_; | 162 base::WeakPtr<TranslateManager> translate_manager_; |
(...skipping 20 matching lines...) Expand all Loading... |
151 | 183 |
152 // The translation related preferences. | 184 // The translation related preferences. |
153 std::unique_ptr<TranslatePrefs> prefs_; | 185 std::unique_ptr<TranslatePrefs> prefs_; |
154 | 186 |
155 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 187 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
156 }; | 188 }; |
157 | 189 |
158 } // namespace translate | 190 } // namespace translate |
159 | 191 |
160 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 192 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
OLD | NEW |