| 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 #include "components/translate/core/common/translate_errors.h" | |
| 16 | |
| 17 class TranslatePrefs; | |
| 18 | |
| 19 namespace content { | |
| 20 class WebContents; | |
| 21 } // namespace content | |
| 22 | |
| 23 // The TranslateUIDelegate is a generic delegate for UI which offers Translate | |
| 24 // feature to the user. | |
| 25 class TranslateUIDelegate { | |
| 26 public: | |
| 27 enum { | |
| 28 NO_INDEX = -1, | |
| 29 }; | |
| 30 | |
| 31 TranslateUIDelegate(content::WebContents* web_contents, | |
| 32 const std::string& original_language, | |
| 33 const std::string& target_language); | |
| 34 virtual ~TranslateUIDelegate(); | |
| 35 | |
| 36 content::WebContents* web_contents() { return web_contents_; } | |
| 37 | |
| 38 // Handles when an error message is shown. | |
| 39 void OnErrorShown(TranslateErrors::Type error_type); | |
| 40 | |
| 41 // Returns the number of languages supported. | |
| 42 size_t GetNumberOfLanguages() const; | |
| 43 | |
| 44 // Returns the original language index. | |
| 45 size_t GetOriginalLanguageIndex() const; | |
| 46 | |
| 47 // Updates the original language index. | |
| 48 void UpdateOriginalLanguageIndex(size_t language_index); | |
| 49 | |
| 50 // Returns the target language index. | |
| 51 size_t GetTargetLanguageIndex() const; | |
| 52 | |
| 53 // Updates the target language index. | |
| 54 void UpdateTargetLanguageIndex(size_t language_index); | |
| 55 | |
| 56 // Returns the ISO code for the language at |index|. | |
| 57 std::string GetLanguageCodeAt(size_t index) const; | |
| 58 | |
| 59 // Returns the displayable name for the language at |index|. | |
| 60 base::string16 GetLanguageNameAt(size_t index) const; | |
| 61 | |
| 62 // The original language for Translate. | |
| 63 std::string GetOriginalLanguageCode() const; | |
| 64 | |
| 65 // The target language for Translate. | |
| 66 std::string GetTargetLanguageCode() const; | |
| 67 | |
| 68 // Starts translating the current page. | |
| 69 void Translate(); | |
| 70 | |
| 71 // Reverts translation. | |
| 72 void RevertTranslation(); | |
| 73 | |
| 74 // Processes when the user declines translation. | |
| 75 void TranslationDeclined(bool explicitly_closed); | |
| 76 | |
| 77 // Returns true if the current language is blocked. | |
| 78 bool IsLanguageBlocked(); | |
| 79 | |
| 80 // Sets the value if the current language is blocked. | |
| 81 void SetLanguageBlocked(bool value); | |
| 82 | |
| 83 // Returns true if the current webpage is blacklisted. | |
| 84 bool IsSiteBlacklisted(); | |
| 85 | |
| 86 // Sets the value if the current webpage is blacklisted. | |
| 87 void SetSiteBlacklist(bool value); | |
| 88 | |
| 89 // Returns true if the webpage in the current original language should be | |
| 90 // translated into the current target language automatically. | |
| 91 bool ShouldAlwaysTranslate(); | |
| 92 | |
| 93 // Sets the value if the webpage in the current original language should be | |
| 94 // translated into the current target language automatically. | |
| 95 void SetAlwaysTranslate(bool value); | |
| 96 | |
| 97 private: | |
| 98 // Gets the host of the page being translated, or an empty string if no URL is | |
| 99 // associated with the current page. | |
| 100 std::string GetPageHost(); | |
| 101 | |
| 102 content::WebContents* web_contents_; | |
| 103 | |
| 104 typedef std::pair<std::string, base::string16> LanguageNamePair; | |
| 105 | |
| 106 // The list supported languages for translation. | |
| 107 // The pair first string is the language ISO code (ex: en, fr...), the second | |
| 108 // string is the displayable name on the current locale. | |
| 109 // The languages are sorted alphabetically based on the displayable name. | |
| 110 std::vector<LanguageNamePair> languages_; | |
| 111 | |
| 112 // The index for language the page is originally in. | |
| 113 size_t original_language_index_; | |
| 114 | |
| 115 // The index for language the page is originally in that was originally | |
| 116 // reported (original_language_index_ changes if the user selects a new | |
| 117 // original language, but this one does not). This is necessary to report | |
| 118 // language detection errors with the right original language even if the user | |
| 119 // changed the original language. | |
| 120 size_t initial_original_language_index_; | |
| 121 | |
| 122 // The index for language the page should be translated to. | |
| 123 size_t target_language_index_; | |
| 124 | |
| 125 // The translation related preferences. | |
| 126 scoped_ptr<TranslatePrefs> prefs_; | |
| 127 | |
| 128 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | |
| 129 }; | |
| 130 | |
| 131 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | |
| OLD | NEW |