OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_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/memory/weak_ptr.h" | |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "components/translate/core/common/translate_errors.h" | 15 #include "components/translate/core/common/translate_errors.h" |
15 | 16 |
16 class LanguageState; | 17 class LanguageState; |
17 class TranslateClient; | 18 class TranslateClient; |
18 class TranslateDriver; | 19 class TranslateDriver; |
19 class TranslateManager; | 20 class TranslateManager; |
20 class TranslatePrefs; | 21 class TranslatePrefs; |
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 class TranslateUIDelegate { | 25 class TranslateUIDelegate { |
25 public: | 26 public: |
26 enum { NO_INDEX = -1, }; | 27 enum { NO_INDEX = -1, }; |
27 | 28 |
28 TranslateUIDelegate(TranslateClient* translate_client, | 29 TranslateUIDelegate(TranslateClient* translate_client, |
droger
2014/06/05 08:36:35
Optional cleanup while you are here:
1) remove the
nshaik
2014/06/05 18:45:30
Done.
| |
29 TranslateManager* translate_manager, | 30 const base::WeakPtr<TranslateManager>& translate_manager, |
30 const std::string& original_language, | 31 const std::string& original_language, |
31 const std::string& target_language); | 32 const std::string& target_language); |
32 virtual ~TranslateUIDelegate(); | 33 virtual ~TranslateUIDelegate(); |
33 | 34 |
34 // Handles when an error message is shown. | 35 // Handles when an error message is shown. |
35 void OnErrorShown(TranslateErrors::Type error_type); | 36 void OnErrorShown(TranslateErrors::Type error_type); |
36 | 37 |
37 // Returns the LanguageState associated with this object. | 38 // Returns the LanguageState associated with this object. |
38 const LanguageState& GetLanguageState(); | 39 const LanguageState& GetLanguageState(); |
39 | 40 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 // translated into the current target language automatically. | 94 // translated into the current target language automatically. |
94 void SetAlwaysTranslate(bool value); | 95 void SetAlwaysTranslate(bool value); |
95 | 96 |
96 private: | 97 private: |
97 // Gets the host of the page being translated, or an empty string if no URL is | 98 // Gets the host of the page being translated, or an empty string if no URL is |
98 // associated with the current page. | 99 // associated with the current page. |
99 std::string GetPageHost(); | 100 std::string GetPageHost(); |
100 | 101 |
101 TranslateClient* translate_client_; | 102 TranslateClient* translate_client_; |
102 TranslateDriver* translate_driver_; | 103 TranslateDriver* translate_driver_; |
103 TranslateManager* translate_manager_; | 104 base::WeakPtr<TranslateManager> translate_manager_; |
104 | 105 |
105 typedef std::pair<std::string, base::string16> LanguageNamePair; | 106 typedef std::pair<std::string, base::string16> LanguageNamePair; |
106 | 107 |
107 // The list supported languages for translation. | 108 // The list supported languages for translation. |
108 // The pair first string is the language ISO code (ex: en, fr...), the second | 109 // The pair first string is the language ISO code (ex: en, fr...), the second |
109 // string is the displayable name on the current locale. | 110 // string is the displayable name on the current locale. |
110 // The languages are sorted alphabetically based on the displayable name. | 111 // The languages are sorted alphabetically based on the displayable name. |
111 std::vector<LanguageNamePair> languages_; | 112 std::vector<LanguageNamePair> languages_; |
112 | 113 |
113 // The index for language the page is originally in. | 114 // The index for language the page is originally in. |
114 size_t original_language_index_; | 115 size_t original_language_index_; |
115 | 116 |
116 // The index for language the page is originally in that was originally | 117 // The index for language the page is originally in that was originally |
117 // reported (original_language_index_ changes if the user selects a new | 118 // reported (original_language_index_ changes if the user selects a new |
118 // original language, but this one does not). This is necessary to report | 119 // original language, but this one does not). This is necessary to report |
119 // language detection errors with the right original language even if the user | 120 // language detection errors with the right original language even if the user |
120 // changed the original language. | 121 // changed the original language. |
121 size_t initial_original_language_index_; | 122 size_t initial_original_language_index_; |
122 | 123 |
123 // The index for language the page should be translated to. | 124 // The index for language the page should be translated to. |
124 size_t target_language_index_; | 125 size_t target_language_index_; |
125 | 126 |
126 // The translation related preferences. | 127 // The translation related preferences. |
127 scoped_ptr<TranslatePrefs> prefs_; | 128 scoped_ptr<TranslatePrefs> prefs_; |
128 | 129 |
129 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 130 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
130 }; | 131 }; |
131 | 132 |
132 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ | 133 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
OLD | NEW |