| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_UI_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 | 15 |
| 16 class TranslatePrefs; | 16 class TranslatePrefs; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class WebContents; | 19 class WebContents; |
| 20 } // namespace content | 20 } // namespace content |
| 21 | 21 |
| 22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate | 22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate |
| 23 // feature to the user. | 23 // feature to the user. |
| 24 // |
| 25 // Note: TranslateInfobarDelegate should be updated if this implementation is |
| 26 // updated. |
| 24 class TranslateUIDelegate { | 27 class TranslateUIDelegate { |
| 25 public: | 28 public: |
| 26 enum { | 29 enum { |
| 27 NO_INDEX = -1, | 30 NO_INDEX = -1, |
| 28 }; | 31 }; |
| 29 | 32 |
| 33 // A pair whose key is a language code and value is the language's |
| 34 // displayable name. |
| 35 typedef std::pair<std::string, string16> LanguageNamePair; |
| 36 |
| 30 TranslateUIDelegate(content::WebContents* web_contents, | 37 TranslateUIDelegate(content::WebContents* web_contents, |
| 31 const std::string& original_language, | 38 const std::string& original_language, |
| 32 const std::string& target_language); | 39 const std::string& target_language); |
| 33 virtual ~TranslateUIDelegate(); | 40 virtual ~TranslateUIDelegate(); |
| 34 | 41 |
| 42 // Retrieves the displayable names of the supported languages, based on |
| 43 // |locale|. The returned names are sorted in alphabetical order. |
| 44 static std::vector<LanguageNamePair> GetSortedLanguageNames( |
| 45 const std::string& locale); |
| 46 |
| 47 // Gets the host of the page of |web_contents|, or an empty string if no URL |
| 48 // is associated with the current page. |
| 49 static std::string GetPageHost(content::WebContents* web_contents); |
| 50 |
| 35 content::WebContents* web_contents() { return web_contents_; } | 51 content::WebContents* web_contents() { return web_contents_; } |
| 36 | 52 |
| 37 // Returns the number of languages supported. | 53 // Returns the number of languages supported. |
| 38 size_t GetNumberOfLanguages() const; | 54 size_t GetNumberOfLanguages() const; |
| 39 | 55 |
| 40 // Returns the original language index. | 56 // Returns the original language index. |
| 41 size_t GetOriginalLanguageIndex() const; | 57 size_t GetOriginalLanguageIndex() const; |
| 42 | 58 |
| 43 // Updates the original language index. | 59 // Updates the original language index. |
| 44 void UpdateOriginalLanguageIndex(size_t language_index); | 60 void UpdateOriginalLanguageIndex(size_t language_index); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 100 |
| 85 // Returns true if the webpage in the current original language should be | 101 // Returns true if the webpage in the current original language should be |
| 86 // translated into the current target language automatically. | 102 // translated into the current target language automatically. |
| 87 bool ShouldAlwaysTranslate(); | 103 bool ShouldAlwaysTranslate(); |
| 88 | 104 |
| 89 // Sets the value if the webpage in the current original language should be | 105 // Sets the value if the webpage in the current original language should be |
| 90 // translated into the current target language automatically. | 106 // translated into the current target language automatically. |
| 91 void SetAlwaysTranslate(bool value); | 107 void SetAlwaysTranslate(bool value); |
| 92 | 108 |
| 93 private: | 109 private: |
| 94 // Gets the host of the page being translated, or an empty string if no URL is | |
| 95 // associated with the current page. | |
| 96 std::string GetPageHost(); | |
| 97 | |
| 98 content::WebContents* web_contents_; | 110 content::WebContents* web_contents_; |
| 99 | 111 |
| 100 typedef std::pair<std::string, string16> LanguageNamePair; | |
| 101 | |
| 102 // The list supported languages for translation. | 112 // The list supported languages for translation. |
| 103 // The pair first string is the language ISO code (ex: en, fr...), the second | 113 // The pair first string is the language ISO code (ex: en, fr...), the second |
| 104 // string is the displayable name on the current locale. | 114 // string is the displayable name on the current locale. |
| 105 // The languages are sorted alphabetically based on the displayable name. | 115 // The languages are sorted alphabetically based on the displayable name. |
| 106 std::vector<LanguageNamePair> languages_; | 116 std::vector<LanguageNamePair> languages_; |
| 107 | 117 |
| 108 // The index for language the page is originally in. | 118 // The index for language the page is originally in. |
| 109 size_t original_language_index_; | 119 size_t original_language_index_; |
| 110 | 120 |
| 111 // The index for language the page is originally in that was originally | |
| 112 // reported (original_language_index_ changes if the user selects a new | |
| 113 // original language, but this one does not). This is necessary to report | |
| 114 // language detection errors with the right original language even if the user | |
| 115 // changed the original language. | |
| 116 size_t initial_original_language_index_; | |
| 117 | |
| 118 // The index for language the page should be translated to. | 121 // The index for language the page should be translated to. |
| 119 size_t target_language_index_; | 122 size_t target_language_index_; |
| 120 | 123 |
| 121 // The translation related preferences. | 124 // The translation related preferences. |
| 122 scoped_ptr<TranslatePrefs> prefs_; | 125 scoped_ptr<TranslatePrefs> prefs_; |
| 123 | 126 |
| 124 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 127 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
| 125 }; | 128 }; |
| 126 | 129 |
| 127 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 130 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| OLD | NEW |