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.
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
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"
20 } // namespace content
22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate
23 // feature to the user.
24 class TranslateUIDelegate {
30 TranslateUIDelegate(content::WebContents* web_contents,
31 const std::string& original_language,
32 const std::string& target_language);
33 virtual ~TranslateUIDelegate();
35 content::WebContents* web_contents() { return web_contents_; }
37 // Returns the number of languages supported.
38 size_t GetNumberOfLanguages() const;
40 // Returns the original language index.
41 size_t GetOriginalLanguageIndex() const;
43 // Updates the original language index.
44 void UpdateOriginalLanguageIndex(size_t language_index);
46 // Returns the target language index.
47 size_t GetTargetLanguageIndex() const;
49 // Updates the target language index.
50 void UpdateTargetLanguageIndex(size_t language_index);
52 // Returns the ISO code for the language at |index|.
53 std::string GetLanguageCodeAt(size_t index) const;
55 // Returns the displayable name for the language at |index|.
56 string16 GetLanguageNameAt(size_t index) const;
58 // The original language for Translate.
59 std::string GetOriginalLanguageCode() const;
61 // The target language for Translate.
62 std::string GetTargetLanguageCode() const;
64 // Starts translating the current page.
67 // Reverts translation.
68 void RevertTranslation();
70 // Processes when the user declines translation.
71 void TranslationDeclined();
73 // Returns true if the current language is blocked.
74 bool IsLanguageBlocked();
76 // Sets the value if the current language is blocked.
77 void SetLanguageBlocked(bool value);
79 // Returns true if the current webpage is blacklisted.
80 bool IsSiteBlacklisted();
82 // Sets the value if the current webpage is blacklisted.
83 void SetSiteBlacklist(bool value);
85 // Returns true if the webpage in the current original language should be
86 // translated into the current target language automatically.
87 bool ShouldAlwaysTranslate();
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);
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();
98 content::WebContents* web_contents_;
100 typedef std::pair<std::string, string16> LanguageNamePair;
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_;
108 // The index for language the page is originally in.
109 size_t original_language_index_;
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_;
118 // The index for language the page should be translated to.
119 size_t target_language_index_;
121 // The translation related preferences.
122 scoped_ptr<TranslatePrefs> prefs_;
124 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
127 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_