Chromium Code Reviews| 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. | |
| 108 bool IsLanguageBlocked(const std::string& language_code); | |
| 109 | |
| 104 // Sets the value if the current language is blocked. | 110 // Sets the value if the current language is blocked. |
| 105 void SetLanguageBlocked(bool value); | 111 void SetLanguageBlocked(bool value); |
| 106 | 112 |
| 113 // Sets the value if the |language_code| is blocked. | |
| 114 void SetLanguageBlocked(bool value, const std::string& language_code); | |
|
Hiroshi Ichikawa
2017/05/10 08:36:55
Optional: I slightly prefer the opposite order of
jzw1
2017/05/11 03:03:17
I kind of like this order since I'm overloading th
| |
| 115 | |
| 107 // Returns true if the current webpage is blacklisted. | 116 // Returns true if the current webpage is blacklisted. |
| 108 bool IsSiteBlacklisted(); | 117 bool IsSiteBlacklisted(); |
| 109 | 118 |
| 119 // Returns true if |page_host| is blacklisted. | |
| 120 bool IsSiteBlacklisted(const std::string& page_host); | |
| 121 | |
| 110 // Sets the value if the current webpage is blacklisted. | 122 // Sets the value if the current webpage is blacklisted. |
| 111 void SetSiteBlacklist(bool value); | 123 void SetSiteBlacklist(bool value); |
| 112 | 124 |
| 125 // Sets the value if the |page_host| is blacklisted. | |
| 126 void SetSiteBlacklist(bool value, const std::string& page_host); | |
| 127 | |
| 113 // Returns true if the webpage in the current original language should be | 128 // Returns true if the webpage in the current original language should be |
| 114 // translated into the current target language automatically. | 129 // translated into the current target language automatically. |
| 115 bool ShouldAlwaysTranslate(); | 130 bool ShouldAlwaysTranslate(); |
| 116 | 131 |
| 132 // Returns true if the webpage in the |from_language| should be | |
| 133 // translated into the |to_language| automatically. | |
| 134 bool ShouldAlwaysTranslate(const std::string& from_language, | |
|
Hiroshi Ichikawa
2017/05/10 08:36:55
Is this method used? Looks sufficient with only Ge
jzw1
2017/05/11 03:03:17
Done.
| |
| 135 const std::string& to_language); | |
| 136 | |
| 117 // Sets the value if the webpage in the current original language should be | 137 // Sets the value if the webpage in the current original language should be |
| 118 // translated into the current target language automatically. | 138 // translated into the current target language automatically. |
| 119 void SetAlwaysTranslate(bool value); | 139 void SetAlwaysTranslate(bool value); |
| 120 | 140 |
| 141 // Sets the value if the webpage in the |from_language| should be | |
| 142 // translated into the |to_language| automatically. | |
| 143 void SetAlwaysTranslate(bool value, | |
|
Hiroshi Ichikawa
2017/05/10 08:36:55
This API looks a bit weird. This API seems to indi
jzw1
2017/05/11 03:03:17
Wouldn't you still be able to do something like:
E
Hiroshi Ichikawa
2017/05/11 04:14:15
My point is rather that having a boolean parameter
jzw1
2017/05/11 04:42:59
I'll just update the comment.
| |
| 144 const std::string& from_language, | |
| 145 const std::string& to_language); | |
| 146 | |
| 147 // Returns the language to always translate |from_language| to. | |
|
Hiroshi Ichikawa
2017/05/10 08:36:55
Can you document the return value in case |from_la
jzw1
2017/05/11 03:03:17
Done.
| |
| 148 std::string GetAlwaysTranslateToLanguage(const std::string& from_language); | |
| 149 | |
| 121 // Returns true if the Always Translate checkbox should be checked by default. | 150 // Returns true if the Always Translate checkbox should be checked by default. |
| 122 bool ShouldAlwaysTranslateBeCheckedByDefault(); | 151 bool ShouldAlwaysTranslateBeCheckedByDefault(); |
| 123 | 152 |
| 124 private: | 153 private: |
| 125 // Gets the host of the page being translated, or an empty string if no URL is | 154 // Gets the host of the page being translated, or an empty string if no URL is |
| 126 // associated with the current page. | 155 // associated with the current page. |
| 127 std::string GetPageHost(); | 156 std::string GetPageHost(); |
| 128 | 157 |
| 129 TranslateDriver* translate_driver_; | 158 TranslateDriver* translate_driver_; |
| 130 base::WeakPtr<TranslateManager> translate_manager_; | 159 base::WeakPtr<TranslateManager> translate_manager_; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 151 | 180 |
| 152 // The translation related preferences. | 181 // The translation related preferences. |
| 153 std::unique_ptr<TranslatePrefs> prefs_; | 182 std::unique_ptr<TranslatePrefs> prefs_; |
| 154 | 183 |
| 155 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 184 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
| 156 }; | 185 }; |
| 157 | 186 |
| 158 } // namespace translate | 187 } // namespace translate |
| 159 | 188 |
| 160 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 189 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
| OLD | NEW |