OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
14 #include "components/infobars/core/infobar_delegate.h" | 15 #include "components/infobars/core/infobar_delegate.h" |
15 #include "components/translate/core/browser/translate_prefs.h" | 16 #include "components/translate/core/browser/translate_prefs.h" |
16 #include "components/translate/core/browser/translate_step.h" | 17 #include "components/translate/core/browser/translate_step.h" |
17 #include "components/translate/core/browser/translate_ui_delegate.h" | 18 #include "components/translate/core/browser/translate_ui_delegate.h" |
18 #include "components/translate/core/common/translate_constants.h" | 19 #include "components/translate/core/common/translate_constants.h" |
19 #include "components/translate/core/common/translate_errors.h" | 20 #include "components/translate/core/common/translate_errors.h" |
20 | 21 |
| 22 class InfoBarService; |
21 class PrefService; | 23 class PrefService; |
| 24 class TranslateClient; |
| 25 class TranslateManager; |
22 | 26 |
23 namespace content { | 27 namespace content { |
24 class WebContents; | 28 class WebContents; |
25 } | 29 } |
26 | 30 |
27 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { | 31 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { |
28 public: | 32 public: |
29 // The types of background color animations. | 33 // The types of background color animations. |
30 enum BackgroundAnimationType { | 34 enum BackgroundAnimationType { |
31 NONE, | 35 NONE, |
(...skipping 11 matching lines...) Expand all Loading... |
43 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports | 47 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports |
44 // translating. The lone exception is when the user initiates translation | 48 // translating. The lone exception is when the user initiates translation |
45 // from the context menu, in which case it's legal to call this with | 49 // from the context menu, in which case it's legal to call this with |
46 // |step| == TRANSLATING and |original_language| == kUnknownLanguageCode. | 50 // |step| == TRANSLATING and |original_language| == kUnknownLanguageCode. |
47 // | 51 // |
48 // If |replace_existing_infobar| is true, the infobar is created and added to | 52 // If |replace_existing_infobar| is true, the infobar is created and added to |
49 // the infobar service for |web_contents|, replacing any other translate | 53 // the infobar service for |web_contents|, replacing any other translate |
50 // infobar already present there. Otherwise, the infobar will only be added | 54 // infobar already present there. Otherwise, the infobar will only be added |
51 // if there is no other translate infobar already present. | 55 // if there is no other translate infobar already present. |
52 static void Create(bool replace_existing_infobar, | 56 static void Create(bool replace_existing_infobar, |
53 content::WebContents* web_contents, | 57 const base::WeakPtr<TranslateManager>& translate_manager, |
| 58 InfoBarService* infobar_service, |
| 59 bool is_off_the_record, |
54 translate::TranslateStep step, | 60 translate::TranslateStep step, |
55 const std::string& original_language, | 61 const std::string& original_language, |
56 const std::string& target_language, | 62 const std::string& target_language, |
57 TranslateErrors::Type error_type, | 63 TranslateErrors::Type error_type, |
58 PrefService* prefs, | 64 PrefService* prefs, |
59 bool triggered_from_menu); | 65 bool triggered_from_menu); |
60 | 66 |
61 // Returns the number of languages supported. | 67 // Returns the number of languages supported. |
62 size_t num_languages() const { return ui_delegate_.GetNumberOfLanguages(); } | 68 size_t num_languages() const { return ui_delegate_.GetNumberOfLanguages(); } |
63 | 69 |
64 // Returns the ISO code for the language at |index|. | 70 // Returns the ISO code for the language at |index|. |
65 std::string language_code_at(size_t index) const { | 71 std::string language_code_at(size_t index) const { |
66 return ui_delegate_.GetLanguageCodeAt(index); | 72 return ui_delegate_.GetLanguageCodeAt(index); |
67 } | 73 } |
68 | 74 |
69 // Returns the displayable name for the language at |index|. | 75 // Returns the displayable name for the language at |index|. |
70 base::string16 language_name_at(size_t index) const { | 76 base::string16 language_name_at(size_t index) const { |
71 return ui_delegate_.GetLanguageNameAt(index); | 77 return ui_delegate_.GetLanguageNameAt(index); |
72 } | 78 } |
73 | 79 |
74 translate::TranslateStep translate_step() const { return step_; } | 80 translate::TranslateStep translate_step() const { return step_; } |
75 | 81 |
| 82 bool is_off_the_record() { return is_off_the_record_; } |
| 83 |
76 TranslateErrors::Type error_type() const { return error_type_; } | 84 TranslateErrors::Type error_type() const { return error_type_; } |
77 | 85 |
78 size_t original_language_index() const { | 86 size_t original_language_index() const { |
79 return ui_delegate_.GetOriginalLanguageIndex(); | 87 return ui_delegate_.GetOriginalLanguageIndex(); |
80 } | 88 } |
81 void UpdateOriginalLanguageIndex(size_t language_index); | 89 void UpdateOriginalLanguageIndex(size_t language_index); |
82 | 90 |
83 size_t target_language_index() const { | 91 size_t target_language_index() const { |
84 return ui_delegate_.GetTargetLanguageIndex(); | 92 return ui_delegate_.GetTargetLanguageIndex(); |
85 } | 93 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // text is split in 2 or 3 chunks. |swap_languages| is set to true if | 169 // text is split in 2 or 3 chunks. |swap_languages| is set to true if |
162 // |autodetermined_source_language| is false, and <lang1> and <lang2> | 170 // |autodetermined_source_language| is false, and <lang1> and <lang2> |
163 // should be inverted (some languages express the sentense as "The page has | 171 // should be inverted (some languages express the sentense as "The page has |
164 // been translate to <lang2> from <lang1>."). It is ignored if | 172 // been translate to <lang2> from <lang1>."). It is ignored if |
165 // |autodetermined_source_language| is true. | 173 // |autodetermined_source_language| is true. |
166 static void GetAfterTranslateStrings(std::vector<base::string16>* strings, | 174 static void GetAfterTranslateStrings(std::vector<base::string16>* strings, |
167 bool* swap_languages, | 175 bool* swap_languages, |
168 bool autodetermined_source_language); | 176 bool autodetermined_source_language); |
169 | 177 |
170 protected: | 178 protected: |
171 TranslateInfoBarDelegate(content::WebContents* web_contents, | 179 TranslateInfoBarDelegate( |
172 translate::TranslateStep step, | 180 const base::WeakPtr<TranslateManager>& translate_manager, |
173 TranslateInfoBarDelegate* old_delegate, | 181 bool is_off_the_record, |
174 const std::string& original_language, | 182 translate::TranslateStep step, |
175 const std::string& target_language, | 183 TranslateInfoBarDelegate* old_delegate, |
176 TranslateErrors::Type error_type, | 184 const std::string& original_language, |
177 PrefService* prefs, | 185 const std::string& target_language, |
178 bool triggered_from_menu); | 186 TranslateErrors::Type error_type, |
| 187 PrefService* prefs, |
| 188 bool triggered_from_menu); |
179 | 189 |
180 private: | 190 private: |
181 friend class TranslationInfoBarTest; | 191 friend class TranslationInfoBarTest; |
182 typedef std::pair<std::string, base::string16> LanguageNamePair; | 192 typedef std::pair<std::string, base::string16> LanguageNamePair; |
183 | 193 |
184 // Returns a translate infobar that owns |delegate|. | 194 // Returns a translate infobar that owns |delegate|. |
185 static scoped_ptr<infobars::InfoBar> CreateInfoBar( | 195 static scoped_ptr<infobars::InfoBar> CreateInfoBar( |
186 scoped_ptr<TranslateInfoBarDelegate> delegate); | 196 scoped_ptr<TranslateInfoBarDelegate> delegate); |
187 | 197 |
| 198 // May return NULL if the client has been destroyed. |
| 199 TranslateClient* GetTranslateClient(); |
| 200 |
188 // InfoBarDelegate: | 201 // InfoBarDelegate: |
189 virtual void InfoBarDismissed() OVERRIDE; | 202 virtual void InfoBarDismissed() OVERRIDE; |
190 virtual int GetIconID() const OVERRIDE; | 203 virtual int GetIconID() const OVERRIDE; |
191 virtual infobars::InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; | 204 virtual infobars::InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; |
192 virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE; | 205 virtual bool ShouldExpire(const NavigationDetails& details) const OVERRIDE; |
193 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; | 206 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE; |
194 | 207 |
| 208 bool is_off_the_record_; |
195 translate::TranslateStep step_; | 209 translate::TranslateStep step_; |
196 | 210 |
197 // The type of fading animation if any that should be used when showing this | 211 // The type of fading animation if any that should be used when showing this |
198 // infobar. | 212 // infobar. |
199 BackgroundAnimationType background_animation_; | 213 BackgroundAnimationType background_animation_; |
200 | 214 |
201 TranslateUIDelegate ui_delegate_; | 215 TranslateUIDelegate ui_delegate_; |
| 216 base::WeakPtr<TranslateManager> translate_manager_; |
202 | 217 |
203 // The error that occurred when trying to translate (NONE if no error). | 218 // The error that occurred when trying to translate (NONE if no error). |
204 TranslateErrors::Type error_type_; | 219 TranslateErrors::Type error_type_; |
205 | 220 |
206 // The translation related preferences. | 221 // The translation related preferences. |
207 scoped_ptr<TranslatePrefs> prefs_; | 222 scoped_ptr<TranslatePrefs> prefs_; |
208 | 223 |
209 // Whether the translation was triggered via a menu click vs automatically | 224 // Whether the translation was triggered via a menu click vs automatically |
210 // (due to language detection, preferences...) | 225 // (due to language detection, preferences...) |
211 bool triggered_from_menu_; | 226 bool triggered_from_menu_; |
212 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); | 227 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); |
213 }; | 228 }; |
214 | 229 |
215 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ | 230 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ |
OLD | NEW |