Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / translate / core / browser / translate_ui_delegate.h
blobcf8a9a2ab3c9bb8bcced75deea004ffd85656719
1 // Copyright 2014 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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_
8 #include <string>
9 #include <vector>
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "components/translate/core/common/translate_errors.h"
17 namespace translate {
19 class LanguageState;
20 class TranslateClient;
21 class TranslateDriver;
22 class TranslateManager;
23 class TranslatePrefs;
25 // The TranslateUIDelegate is a generic delegate for UI which offers Translate
26 // feature to the user.
27 class TranslateUIDelegate {
28 public:
29 static const size_t kNoIndex = static_cast<size_t>(-1);
31 TranslateUIDelegate(const base::WeakPtr<TranslateManager>& translate_manager,
32 const std::string& original_language,
33 const std::string& target_language);
34 virtual ~TranslateUIDelegate();
36 // Handles when an error message is shown.
37 void OnErrorShown(TranslateErrors::Type error_type);
39 // Returns the LanguageState associated with this object.
40 const LanguageState& GetLanguageState();
42 // Returns the number of languages supported.
43 size_t GetNumberOfLanguages() const;
45 // Returns the original language index.
46 size_t GetOriginalLanguageIndex() const;
48 // Updates the original language index.
49 void UpdateOriginalLanguageIndex(size_t language_index);
51 // Returns the target language index.
52 size_t GetTargetLanguageIndex() const;
54 // Updates the target language index.
55 void UpdateTargetLanguageIndex(size_t language_index);
57 // Returns the ISO code for the language at |index|.
58 std::string GetLanguageCodeAt(size_t index) const;
60 // Returns the displayable name for the language at |index|.
61 base::string16 GetLanguageNameAt(size_t index) const;
63 // The original language for Translate.
64 std::string GetOriginalLanguageCode() const;
66 // The target language for Translate.
67 std::string GetTargetLanguageCode() const;
69 // Starts translating the current page.
70 void Translate();
72 // Reverts translation.
73 void RevertTranslation();
75 // Processes when the user declines translation.
76 void TranslationDeclined(bool explicitly_closed);
78 // Returns true if the current language is blocked.
79 bool IsLanguageBlocked();
81 // Sets the value if the current language is blocked.
82 void SetLanguageBlocked(bool value);
84 // Returns true if the current webpage is blacklisted.
85 bool IsSiteBlacklisted();
87 // Sets the value if the current webpage is blacklisted.
88 void SetSiteBlacklist(bool value);
90 // Returns true if the webpage in the current original language should be
91 // translated into the current target language automatically.
92 bool ShouldAlwaysTranslate();
94 // Sets the value if the webpage in the current original language should be
95 // translated into the current target language automatically.
96 void SetAlwaysTranslate(bool value);
98 private:
99 // Gets the host of the page being translated, or an empty string if no URL is
100 // associated with the current page.
101 std::string GetPageHost();
103 TranslateDriver* translate_driver_;
104 base::WeakPtr<TranslateManager> translate_manager_;
106 typedef std::pair<std::string, base::string16> LanguageNamePair;
108 // The list supported languages for translation.
109 // The pair first string is the language ISO code (ex: en, fr...), the second
110 // string is the displayable name on the current locale.
111 // The languages are sorted alphabetically based on the displayable name.
112 std::vector<LanguageNamePair> languages_;
114 // The index for language the page is originally in.
115 size_t original_language_index_;
117 // The index for language the page is originally in that was originally
118 // reported (original_language_index_ changes if the user selects a new
119 // original language, but this one does not). This is necessary to report
120 // language detection errors with the right original language even if the user
121 // changed the original language.
122 size_t initial_original_language_index_;
124 // The index for language the page should be translated to.
125 size_t target_language_index_;
127 // The translation related preferences.
128 scoped_ptr<TranslatePrefs> prefs_;
130 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
133 } // namespace translate
135 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_