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

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: (rebasing) Created 7 years, 2 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 GetNumberOfLanguages() const;
37
38 // Returns the original language index.
39 size_t GetOriginalLanguageIndex() const;
40
41 // Sets the original language index.
42 void SetOriginalLanguageIndex(size_t language_index);
43
44 // Returns the target language index.
45 size_t GetTargetLanguageIndex() const;
46
47 // Sets the target language index.
48 void SetTargetLanguageIndex(size_t language_index);
49
50 // Returns the ISO code for the language at |index|.
51 std::string GetLanguageCodeAt(size_t index) const;
52
53 // Returns the displayable name for the language at |index|.
54 string16 GetLanguageNameAt(size_t index) const;
55
56 // The original language for Translate.
57 std::string GetOriginalLanguageCode() const;
58
59 // The target language for Translate.
60 std::string GetTargetLanguageCode() const;
61
62 // Starts translating the current page.
63 void Translate();
64
65 // Reverts translation.
66 void RevertTranslation();
67
68 // Processes when the user declines translation.
69 void TranslationDeclined();
70
71 // Returns true if the current language is blocked.
72 bool IsLanguageBlocked();
73
74 // Sets the value if the current language is blocked.
75 void SetLanguageBlocked(bool value);
76
77 // Returns true if the current webpage is blacklisted.
78 bool IsSiteBlacklisted();
79
80 // Sets the value if the current webpage is blacklisted.
81 void SetSiteBlacklist(bool value);
82
83 // Returns true if the webpage in the current original language should be
84 // translated into the current target language automatically.
85 bool ShouldAlwaysTranslate();
86
87 // Sets the value if the webpage in the current original language should be
88 // translated into the current target language automatically.
89 void SetAlwaysTranslate(bool value);
90
91 private:
92 // Gets the host of the page being translated, or an empty string if no URL is
93 // associated with the current page.
94 std::string GetPageHost();
95
96 content::WebContents* web_contents_;
97
98 typedef std::pair<std::string, string16> LanguageNamePair;
99
100 // The list supported languages for translation.
101 // The pair first string is the language ISO code (ex: en, fr...), the second
102 // string is the displayable name on the current locale.
103 // The languages are sorted alphabetically based on the displayable name.
104 std::vector<LanguageNamePair> languages_;
105
106 // The index for language the page is originally in.
107 size_t original_language_index_;
108
109 // The index for language the page is originally in that was originally
110 // reported (original_language_index_ changes if the user selects a new
111 // original language, but this one does not). This is necessary to report
112 // language detection errors with the right original language even if the user
113 // changed the original language.
114 size_t initial_original_language_index_;
115
116 // The index for language the page should be translated to.
117 size_t target_language_index_;
118
119 // The translation related preferences.
120 scoped_ptr<TranslatePrefs> prefs_;
121
122 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate);
123 };
124
125 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698