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"
15 #include "components/translate/core/common/translate_errors.h"
21 } // namespace content
23 // The TranslateUIDelegate is a generic delegate for UI which offers Translate
24 // feature to the user.
25 class TranslateUIDelegate
{
31 TranslateUIDelegate(content::WebContents
* web_contents
,
32 const std::string
& original_language
,
33 const std::string
& target_language
);
34 virtual ~TranslateUIDelegate();
36 content::WebContents
* web_contents() { return web_contents_
; }
38 // Handles when an error message is shown.
39 void OnErrorShown(TranslateErrors::Type error_type
);
41 // Returns the number of languages supported.
42 size_t GetNumberOfLanguages() const;
44 // Returns the original language index.
45 size_t GetOriginalLanguageIndex() const;
47 // Updates the original language index.
48 void UpdateOriginalLanguageIndex(size_t language_index
);
50 // Returns the target language index.
51 size_t GetTargetLanguageIndex() const;
53 // Updates the target language index.
54 void UpdateTargetLanguageIndex(size_t language_index
);
56 // Returns the ISO code for the language at |index|.
57 std::string
GetLanguageCodeAt(size_t index
) const;
59 // Returns the displayable name for the language at |index|.
60 base::string16
GetLanguageNameAt(size_t index
) const;
62 // The original language for Translate.
63 std::string
GetOriginalLanguageCode() const;
65 // The target language for Translate.
66 std::string
GetTargetLanguageCode() const;
68 // Starts translating the current page.
71 // Reverts translation.
72 void RevertTranslation();
74 // Processes when the user declines translation.
75 void TranslationDeclined(bool explicitly_closed
);
77 // Returns true if the current language is blocked.
78 bool IsLanguageBlocked();
80 // Sets the value if the current language is blocked.
81 void SetLanguageBlocked(bool value
);
83 // Returns true if the current webpage is blacklisted.
84 bool IsSiteBlacklisted();
86 // Sets the value if the current webpage is blacklisted.
87 void SetSiteBlacklist(bool value
);
89 // Returns true if the webpage in the current original language should be
90 // translated into the current target language automatically.
91 bool ShouldAlwaysTranslate();
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
);
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();
102 content::WebContents
* web_contents_
;
104 typedef std::pair
<std::string
, base::string16
> LanguageNamePair
;
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_
;
112 // The index for language the page is originally in.
113 size_t original_language_index_
;
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_
;
122 // The index for language the page should be translated to.
123 size_t target_language_index_
;
125 // The translation related preferences.
126 scoped_ptr
<TranslatePrefs
> prefs_
;
128 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate
);
131 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_