Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Side by Side Diff: chrome/browser/translate/translate_ui_delegate.h

Issue 23708029: Translate: Refactoring: Create TranslateUIDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 static const size_t kNoIndex;
27
28 TranslateUIDelegate(content::WebContents* web_contents,
29 const std::string& original_language,
30 const std::string& target_language);
31 virtual ~TranslateUIDelegate();
32
33 content::WebContents* web_contents() { return web_contents_; }
34
35 // Returns the number of languages supported.
36 size_t num_languages() const { return languages_.size(); }
37
38 // Returns the ISO code for the language at |index|.
39 std::string language_code_at(size_t index) const {
Takashi Toyoshima 2013/09/10 09:33:16 I'm not sure, but having these function as inline
hajimehoshi 2013/09/12 06:16:04 I agree. I moved the implementations of language_
40 DCHECK_LT(index, num_languages());
41 return languages_[index].first;
42 }
43
44 // Returns the displayable name for the language at |index|.
45 string16 language_name_at(size_t index) const {
46 if (index == kNoIndex)
47 return string16();
48 DCHECK_LT(index, num_languages());
49 return languages_[index].second;
50 }
51
52 size_t original_language_index() const { return original_language_index_; }
53 void set_original_language_index(size_t language_index) {
54 DCHECK_LT(language_index, num_languages());
55 original_language_index_ = language_index;
56 }
57
58 size_t target_language_index() const { return target_language_index_; }
59 void set_target_language_index(size_t language_index) {
60 DCHECK_LT(language_index, num_languages());
61 target_language_index_ = language_index;
62 }
63
64 // The source language for Translate.
65 std::string original_language_code() const {
66 return (original_language_index() == kNoIndex) ?
67 chrome::kUnknownLanguageCode :
68 language_code_at(original_language_index());
69 }
70
71 // The target language for Translate.
72 std::string target_language_code() const {
73 return language_code_at(target_language_index());
74 }
75
76 // Starts translating the current page.
77 void Translate();
78
79 // Reverts translation.
80 void RevertTranslation();
81
82 // Processes when the user declines translation.
83 void TranslationDeclined();
84
85 // Returns true if the current language is blocked.
86 bool IsLanguageBlocked();
87
88 // Sets the value if the current language is blocked.
89 void SetLanguageBlocked(bool value);
90
91 // Returns true if the current webpage is blacklisted.
92 bool IsSiteBlacklisted();
93
94 // Sets the value if the current webpage is blacklisted.
95 void SetSiteBlacklist(bool value);
96
97 // Returns true if the webpage in the current original language should be
98 // translated into the current target language automatically.
99 bool ShouldAlwaysTranslate();
100
101 // Sets the value if the webpage in the current original language should be
102 // translated into the current target language automatically.
103 void SetAlwaysTranslate(bool value);
104
105 private:
106 // Gets the host of the page being translated, or an empty string if no URL is
107 // associated with the current page.
108 std::string GetPageHost();
109
110 content::WebContents* web_contents_;
111
112 typedef std::pair<std::string, string16> LanguageNamePair;
113
114 // The list supported languages for translation.
115 // The pair first string is the language ISO code (ex: en, fr...), the second
116 // string is the displayable name on the current locale.
117 // The languages are sorted alphabetically based on the displayable name.
118 std::vector<LanguageNamePair> languages_;
119
120 // The index for language the page is originally in.
121 size_t original_language_index_;
122
123 // The index for language the page is originally in that was originally
124 // reported (original_language_index_ changes if the user selects a new
125 // original language, but this one does not). This is necessary to report
126 // language detection errors with the right original language even if the user
127 // changed the original language.
128 size_t initial_original_language_index_;
129
130 // The index for language the page should be translated to.
131 size_t target_language_index_;
132
133 // The translation related preferences.
134 scoped_ptr<TranslatePrefs> prefs_;
135
136 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
137 };
138
139 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698