| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_TRANSLATE_TRANSLATE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // net::URLFetcherDelegate implementation: | 86 // net::URLFetcherDelegate implementation: |
| 87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 88 | 88 |
| 89 // Used by unit-tests to override the default delay after which the translate | 89 // Used by unit-tests to override the default delay after which the translate |
| 90 // script is fetched again from the translation server. | 90 // script is fetched again from the translation server. |
| 91 void set_translate_script_expiration_delay(int delay_ms) { | 91 void set_translate_script_expiration_delay(int delay_ms) { |
| 92 translate_script_expiration_delay_ = | 92 translate_script_expiration_delay_ = |
| 93 base::TimeDelta::FromMilliseconds(delay_ms); | 93 base::TimeDelta::FromMilliseconds(delay_ms); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Convenience method to know if a tab is showing a translate infobar. | |
| 97 static bool IsShowingTranslateInfobar(content::WebContents* web_contents); | |
| 98 | |
| 99 // Returns true if the URL can be translated. | 96 // Returns true if the URL can be translated. |
| 100 static bool IsTranslatableURL(const GURL& url); | 97 static bool IsTranslatableURL(const GURL& url); |
| 101 | 98 |
| 102 // Fills |languages| with the list of languages that the translate server can | 99 // Fills |languages| with the list of languages that the translate server can |
| 103 // translate to and from. | 100 // translate to and from. |
| 104 static void GetSupportedLanguages(std::vector<std::string>* languages); | 101 static void GetSupportedLanguages(std::vector<std::string>* languages); |
| 105 | 102 |
| 106 // Returns the language code that can be used with the Translate method for a | 103 // Returns the language code that can be used with the Translate method for a |
| 107 // specified |chrome_locale|. | 104 // specified |chrome_locale|. |
| 108 static std::string GetLanguageCode(const std::string& chrome_locale); | 105 static std::string GetLanguageCode(const std::string& chrome_locale); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 const std::string& language); | 164 const std::string& language); |
| 168 | 165 |
| 169 // Initializes the |accept_languages_| language table based on the associated | 166 // Initializes the |accept_languages_| language table based on the associated |
| 170 // preference in |prefs|. | 167 // preference in |prefs|. |
| 171 void InitAcceptLanguages(PrefServiceBase* prefs); | 168 void InitAcceptLanguages(PrefServiceBase* prefs); |
| 172 | 169 |
| 173 // Fetches the JS translate script (the script that is injected in the page | 170 // Fetches the JS translate script (the script that is injected in the page |
| 174 // to translate it). | 171 // to translate it). |
| 175 void RequestTranslateScript(); | 172 void RequestTranslateScript(); |
| 176 | 173 |
| 177 // Shows the specified translate |infobar| in the given |tab|. If a current | |
| 178 // translate infobar is showing, it just replaces it with the new one. | |
| 179 void ShowInfoBar(content::WebContents* web_contents, | |
| 180 TranslateInfoBarDelegate* infobar); | |
| 181 | |
| 182 // Returns the language to translate to. The language returned is the | 174 // Returns the language to translate to. The language returned is the |
| 183 // first language found in the following list that is supported by the | 175 // first language found in the following list that is supported by the |
| 184 // translation service: | 176 // translation service: |
| 185 // the UI language | 177 // the UI language |
| 186 // the accept-language list | 178 // the accept-language list |
| 187 // If no language is found then an empty string is returned. | 179 // If no language is found then an empty string is returned. |
| 188 static std::string GetTargetLanguage(PrefService* prefs); | 180 static std::string GetTargetLanguage(PrefService* prefs); |
| 189 | 181 |
| 190 // Returns the translate info bar showing in |tab| or NULL if none is showing. | |
| 191 static TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( | |
| 192 content::WebContents* web_contents); | |
| 193 | |
| 194 content::NotificationRegistrar notification_registrar_; | 182 content::NotificationRegistrar notification_registrar_; |
| 195 | 183 |
| 196 // Each PrefChangeRegistrar only tracks a single PrefService, so a map from | 184 // Each PrefChangeRegistrar only tracks a single PrefService, so a map from |
| 197 // each PrefService used to its registrar is needed. | 185 // each PrefService used to its registrar is needed. |
| 198 typedef std::map<PrefService*, PrefChangeRegistrar*> PrefServiceRegistrarMap; | 186 typedef std::map<PrefService*, PrefChangeRegistrar*> PrefServiceRegistrarMap; |
| 199 PrefServiceRegistrarMap pref_change_registrars_; | 187 PrefServiceRegistrarMap pref_change_registrars_; |
| 200 | 188 |
| 201 // A map that associates a profile with its parsed "accept languages". | 189 // A map that associates a profile with its parsed "accept languages". |
| 202 typedef std::set<std::string> LanguageSet; | 190 typedef std::set<std::string> LanguageSet; |
| 203 typedef std::map<PrefServiceBase*, LanguageSet> PrefServiceLanguagesMap; | 191 typedef std::map<PrefServiceBase*, LanguageSet> PrefServiceLanguagesMap; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 224 // server. | 212 // server. |
| 225 std::vector<PendingRequest> pending_requests_; | 213 std::vector<PendingRequest> pending_requests_; |
| 226 | 214 |
| 227 // The languages supported by the translation server. | 215 // The languages supported by the translation server. |
| 228 static base::LazyInstance<std::set<std::string> > supported_languages_; | 216 static base::LazyInstance<std::set<std::string> > supported_languages_; |
| 229 | 217 |
| 230 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 218 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
| 231 }; | 219 }; |
| 232 | 220 |
| 233 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 221 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
| OLD | NEW |