Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: components/translate/core/browser/translate_ui_delegate.h

Issue 2872083003: Added translation policy API. (Closed)
Patch Set: don't expose index unnecessairly in translate_ui_delegate Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 displayable name for the language with |language_code|.
81 base::string16 GetLanguageNameForLanguageCode(
82 const std::string& language_code);
83
80 // Returns the displayable name for the language at |index|. 84 // Returns the displayable name for the language at |index|.
81 base::string16 GetLanguageNameAt(size_t index) const; 85 base::string16 GetLanguageNameAt(size_t index) const;
82 86
83 // Starts translating the current page. 87 // Starts translating the current page.
84 void Translate(); 88 void Translate();
85 89
86 // Reverts translation. 90 // Reverts translation.
87 void RevertTranslation(); 91 void RevertTranslation();
88 92
89 // Processes when the user declines translation. 93 // Processes when the user declines translation.
90 // The function name is not accurate. It only means the user did not take 94 // 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 95 // affirmative action after the translation ui show up. The user either
92 // actively decline the translation or ignore the prompt of translation. 96 // actively decline the translation or ignore the prompt of translation.
93 // Pass |explicitly_closed| as true if user explicityly decline the 97 // Pass |explicitly_closed| as true if user explicityly decline the
94 // translation. 98 // translation.
95 // Pass |explicitly_closed| as false if the translation UI is dismissed 99 // Pass |explicitly_closed| as false if the translation UI is dismissed
96 // implicit by some user actions which ignore the translation UI, 100 // 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 101 // such as switch to a new tab/window or navigate to another page by
98 // click a link. 102 // click a link.
99 void TranslationDeclined(bool explicitly_closed); 103 void TranslationDeclined(bool explicitly_closed);
100 104
101 // Returns true if the current language is blocked. 105 // Returns true if the current language is blocked.
102 bool IsLanguageBlocked(); 106 bool IsLanguageBlocked();
103 107
108 // Returns true if |language_code| is blocked. |language_code| must not be
109 // empty.
110 bool IsLanguageBlocked(const std::string& language_code);
111
104 // Sets the value if the current language is blocked. 112 // Sets the value if the current language is blocked.
105 void SetLanguageBlocked(bool value); 113 void SetLanguageBlocked(bool value);
106 114
115 // Blocks/unblocks |language_code| for translation. |language_code| must not
116 // be empty.
117 void SetLanguageBlocked(bool value, const std::string& language_code);
118
107 // Returns true if the current webpage is blacklisted. 119 // Returns true if the current webpage is blacklisted.
108 bool IsSiteBlacklisted(); 120 bool IsSiteBlacklisted();
109 121
122 // Returns true if |page_host| is blacklisted. |page_host| must not be empty.
123 bool IsSiteBlacklisted(const std::string& page_host);
124
110 // Sets the value if the current webpage is blacklisted. 125 // Sets the value if the current webpage is blacklisted.
111 void SetSiteBlacklist(bool value); 126 void SetSiteBlacklist(bool value);
112 127
128 // Sets the value if the |page_host| is blacklisted. |page_host| must not be
129 // empty.
130 void SetSiteBlacklist(bool value, const std::string& page_host);
131
113 // Returns true if the webpage in the current original language should be 132 // Returns true if the webpage in the current original language should be
114 // translated into the current target language automatically. 133 // translated into the current target language automatically.
115 bool ShouldAlwaysTranslate(); 134 bool ShouldAlwaysTranslate();
116 135
117 // Sets the value if the webpage in the current original language should be 136 // Sets the value if the webpage in the current original language should be
118 // translated into the current target language automatically. 137 // translated into the current target language automatically.
119 void SetAlwaysTranslate(bool value); 138 void SetAlwaysTranslate(bool value);
120 139
140 // If |value| is true, updates the preference to always translate
141 // |from_language| to |to_language| without prompting. If it is called
142 // multiple times for the same |from_language|, the last specified
143 // |to_language| is used.
144 // If |value| is false, updates the preference not to always translate
145 // |from_language|. |target_language| is ignored.
146 void SetAlwaysTranslate(bool value,
147 const std::string& from_language,
148 const std::string& to_language);
149
150 // Returns the language to always translate |from_language| to, or empty
151 // string if no such language has been set.
152 std::string GetAlwaysTranslateToLanguage(const std::string& from_language);
153
121 // Returns true if the Always Translate checkbox should be checked by default. 154 // Returns true if the Always Translate checkbox should be checked by default.
122 bool ShouldAlwaysTranslateBeCheckedByDefault(); 155 bool ShouldAlwaysTranslateBeCheckedByDefault();
123 156
124 private: 157 private:
125 // Gets the host of the page being translated, or an empty string if no URL is 158 // Gets the host of the page being translated, or an empty string if no URL is
126 // associated with the current page. 159 // associated with the current page.
127 std::string GetPageHost(); 160 std::string GetPageHost();
128 161
129 TranslateDriver* translate_driver_; 162 TranslateDriver* translate_driver_;
130 base::WeakPtr<TranslateManager> translate_manager_; 163 base::WeakPtr<TranslateManager> translate_manager_;
(...skipping 20 matching lines...) Expand all
151 184
152 // The translation related preferences. 185 // The translation related preferences.
153 std::unique_ptr<TranslatePrefs> prefs_; 186 std::unique_ptr<TranslatePrefs> prefs_;
154 187
155 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); 188 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
156 }; 189 };
157 190
158 } // namespace translate 191 } // namespace translate
159 192
160 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ 193 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698