OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/translate/translate_errors.h" |
15 | 16 |
16 class TranslatePrefs; | 17 class TranslatePrefs; |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 class WebContents; | 20 class WebContents; |
20 } // namespace content | 21 } // namespace content |
21 | 22 |
22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate | 23 // The TranslateUIDelegate is a generic delegate for UI which offers Translate |
23 // feature to the user. | 24 // feature to the user. |
24 // | 25 // |
25 // Note: TranslateInfobarDelegate should be updated if this implementation is | 26 // Note: TranslateInfobarDelegate should be updated if this implementation is |
26 // updated. | 27 // updated. |
27 class TranslateUIDelegate { | 28 class TranslateUIDelegate { |
28 public: | 29 public: |
29 enum { | 30 enum { |
30 NO_INDEX = -1, | 31 NO_INDEX = -1, |
31 }; | 32 }; |
32 | 33 |
33 // A pair whose key is a language code and value is the language's | 34 // A pair whose key is a language code and value is the language's |
34 // displayable name. | 35 // displayable name. |
35 typedef std::pair<std::string, string16> LanguageNamePair; | 36 typedef std::pair<std::string, string16> LanguageNamePair; |
36 | 37 |
37 TranslateUIDelegate(content::WebContents* web_contents, | 38 TranslateUIDelegate(content::WebContents* web_contents, |
38 const std::string& original_language, | 39 const std::string& original_language, |
39 const std::string& target_language); | 40 const std::string& target_language, |
| 41 TranslateErrors::Type error_type); |
40 virtual ~TranslateUIDelegate(); | 42 virtual ~TranslateUIDelegate(); |
41 | 43 |
42 // Retrieves the displayable names of the supported languages, based on | 44 // Retrieves the displayable names of the supported languages, based on |
43 // |locale|. The returned names are sorted in alphabetical order. | 45 // |locale|. The returned names are sorted in alphabetical order. |
44 static std::vector<LanguageNamePair> GetSortedLanguageNames( | 46 static std::vector<LanguageNamePair> GetSortedLanguageNames( |
45 const std::string& locale); | 47 const std::string& locale); |
46 | 48 |
47 // Gets the host of the page of |web_contents|, or an empty string if no URL | 49 // Gets the host of the page of |web_contents|, or an empty string if no URL |
48 // is associated with the current page. | 50 // is associated with the current page. |
49 static std::string GetPageHost(content::WebContents* web_contents); | 51 static std::string GetPageHost(content::WebContents* web_contents); |
50 | 52 |
51 content::WebContents* web_contents() { return web_contents_; } | 53 content::WebContents* web_contents() { return web_contents_; } |
52 | 54 |
| 55 TranslateErrors::Type error_type() const { return error_type_; } |
| 56 |
| 57 void set_error_type(TranslateErrors::Type error_type) { |
| 58 error_type_ = error_type; |
| 59 } |
| 60 |
53 // Returns the number of languages supported. | 61 // Returns the number of languages supported. |
54 size_t GetNumberOfLanguages() const; | 62 size_t GetNumberOfLanguages() const; |
55 | 63 |
56 // Returns the original language index. | 64 // Returns the original language index. |
57 size_t GetOriginalLanguageIndex() const; | 65 size_t GetOriginalLanguageIndex() const; |
58 | 66 |
59 // Updates the original language index. | 67 // Updates the original language index. |
60 void UpdateOriginalLanguageIndex(size_t language_index); | 68 void UpdateOriginalLanguageIndex(size_t language_index); |
61 | 69 |
62 // Returns the target language index. | 70 // Returns the target language index. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 125 |
118 // The index for language the page is originally in. | 126 // The index for language the page is originally in. |
119 size_t original_language_index_; | 127 size_t original_language_index_; |
120 | 128 |
121 // The index for language the page should be translated to. | 129 // The index for language the page should be translated to. |
122 size_t target_language_index_; | 130 size_t target_language_index_; |
123 | 131 |
124 // The translation related preferences. | 132 // The translation related preferences. |
125 scoped_ptr<TranslatePrefs> prefs_; | 133 scoped_ptr<TranslatePrefs> prefs_; |
126 | 134 |
| 135 // The error type. |
| 136 TranslateErrors::Type error_type_; |
| 137 |
127 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 138 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
128 }; | 139 }; |
129 | 140 |
130 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 141 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ |
OLD | NEW |