| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "chrome/common/chrome_constants.h" |
| 15 |
| 16 class TranslatePrefs; |
| 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } // namespace content |
| 21 |
| 22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate |
| 23 // feature to the user. |
| 24 class TranslateUIDelegate { |
| 25 public: |
| 26 enum { |
| 27 NO_INDEX = -1, |
| 28 }; |
| 29 |
| 30 TranslateUIDelegate(content::WebContents* web_contents, |
| 31 const std::string& original_language, |
| 32 const std::string& target_language); |
| 33 virtual ~TranslateUIDelegate(); |
| 34 |
| 35 content::WebContents* web_contents() { return web_contents_; } |
| 36 |
| 37 // Returns the number of languages supported. |
| 38 size_t GetNumberOfLanguages() const; |
| 39 |
| 40 // Returns the original language index. |
| 41 size_t GetOriginalLanguageIndex() const; |
| 42 |
| 43 // Sets the original language index. |
| 44 void SetOriginalLanguageIndex(size_t language_index); |
| 45 |
| 46 // Returns the target language index. |
| 47 size_t GetTargetLanguageIndex() const; |
| 48 |
| 49 // Sets the target language index. |
| 50 void SetTargetLanguageIndex(size_t language_index); |
| 51 |
| 52 // Returns the ISO code for the language at |index|. |
| 53 std::string GetLanguageCodeAt(size_t index) const; |
| 54 |
| 55 // Returns the displayable name for the language at |index|. |
| 56 string16 GetLanguageNameAt(size_t index) const; |
| 57 |
| 58 // The original language for Translate. |
| 59 std::string GetOriginalLanguageCode() const; |
| 60 |
| 61 // The target language for Translate. |
| 62 std::string GetTargetLanguageCode() const; |
| 63 |
| 64 // Starts translating the current page. |
| 65 void Translate(); |
| 66 |
| 67 // Reverts translation. |
| 68 void RevertTranslation(); |
| 69 |
| 70 // Processes when the user declines translation. |
| 71 void TranslationDeclined(); |
| 72 |
| 73 // Returns true if the current language is blocked. |
| 74 bool IsLanguageBlocked(); |
| 75 |
| 76 // Sets the value if the current language is blocked. |
| 77 void SetLanguageBlocked(bool value); |
| 78 |
| 79 // Returns true if the current webpage is blacklisted. |
| 80 bool IsSiteBlacklisted(); |
| 81 |
| 82 // Sets the value if the current webpage is blacklisted. |
| 83 void SetSiteBlacklist(bool value); |
| 84 |
| 85 // Returns true if the webpage in the current original language should be |
| 86 // translated into the current target language automatically. |
| 87 bool ShouldAlwaysTranslate(); |
| 88 |
| 89 // Sets the value if the webpage in the current original language should be |
| 90 // translated into the current target language automatically. |
| 91 void SetAlwaysTranslate(bool value); |
| 92 |
| 93 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_; |
| 99 |
| 100 typedef std::pair<std::string, string16> LanguageNamePair; |
| 101 |
| 102 // The list supported languages for translation. |
| 103 // The pair first string is the language ISO code (ex: en, fr...), the second |
| 104 // string is the displayable name on the current locale. |
| 105 // The languages are sorted alphabetically based on the displayable name. |
| 106 std::vector<LanguageNamePair> languages_; |
| 107 |
| 108 // The index for language the page is originally in. |
| 109 size_t original_language_index_; |
| 110 |
| 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. |
| 119 size_t target_language_index_; |
| 120 |
| 121 // The translation related preferences. |
| 122 scoped_ptr<TranslatePrefs> prefs_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
| 125 }; |
| 126 |
| 127 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
| OLD | NEW |