OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/translate/translate_infobar_delegate.h" | 5 #include "chrome/browser/translate/translate_infobar_delegate.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return type_ == TRANSLATION_ERROR; | 150 return type_ == TRANSLATION_ERROR; |
151 } | 151 } |
152 | 152 |
153 void TranslateInfoBarDelegate::Translate() { | 153 void TranslateInfoBarDelegate::Translate() { |
154 const std::string& original_language_code = GetOriginalLanguageCode(); | 154 const std::string& original_language_code = GetOriginalLanguageCode(); |
155 if (!tab_contents()->profile()->IsOffTheRecord()) { | 155 if (!tab_contents()->profile()->IsOffTheRecord()) { |
156 prefs_.ResetTranslationDeniedCount(original_language_code); | 156 prefs_.ResetTranslationDeniedCount(original_language_code); |
157 prefs_.IncrementTranslationAcceptedCount(original_language_code); | 157 prefs_.IncrementTranslationAcceptedCount(original_language_code); |
158 } | 158 } |
159 | 159 |
160 Singleton<TranslateManager>::get()->TranslatePage( | 160 TranslateManager::GetInstance()->TranslatePage( |
161 tab_contents_, | 161 tab_contents_, |
162 GetLanguageCodeAt(original_language_index()), | 162 GetLanguageCodeAt(original_language_index()), |
163 GetLanguageCodeAt(target_language_index())); | 163 GetLanguageCodeAt(target_language_index())); |
164 } | 164 } |
165 | 165 |
166 void TranslateInfoBarDelegate::RevertTranslation() { | 166 void TranslateInfoBarDelegate::RevertTranslation() { |
167 Singleton<TranslateManager>::get()->RevertTranslation(tab_contents_); | 167 TranslateManager::GetInstance()->RevertTranslation(tab_contents_); |
168 tab_contents_->RemoveInfoBar(this); | 168 tab_contents_->RemoveInfoBar(this); |
169 } | 169 } |
170 | 170 |
171 void TranslateInfoBarDelegate::ReportLanguageDetectionError() { | 171 void TranslateInfoBarDelegate::ReportLanguageDetectionError() { |
172 Singleton<TranslateManager>::get()-> | 172 TranslateManager::GetInstance()-> |
173 ReportLanguageDetectionError(tab_contents_); | 173 ReportLanguageDetectionError(tab_contents_); |
174 } | 174 } |
175 | 175 |
176 void TranslateInfoBarDelegate::TranslationDeclined() { | 176 void TranslateInfoBarDelegate::TranslationDeclined() { |
177 const std::string& original_language_code = GetOriginalLanguageCode(); | 177 const std::string& original_language_code = GetOriginalLanguageCode(); |
178 if (!tab_contents()->profile()->IsOffTheRecord()) { | 178 if (!tab_contents()->profile()->IsOffTheRecord()) { |
179 prefs_.ResetTranslationAcceptedCount(original_language_code); | 179 prefs_.ResetTranslationAcceptedCount(original_language_code); |
180 prefs_.IncrementTranslationDeniedCount(original_language_code); | 180 prefs_.IncrementTranslationDeniedCount(original_language_code); |
181 } | 181 } |
182 | 182 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { | 335 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { |
336 DCHECK(type_ == TRANSLATION_ERROR); | 336 DCHECK(type_ == TRANSLATION_ERROR); |
337 if (error_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { | 337 if (error_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { |
338 RevertTranslation(); | 338 RevertTranslation(); |
339 return; | 339 return; |
340 } | 340 } |
341 // This is the "Try again..." case. | 341 // This is the "Try again..." case. |
342 Singleton<TranslateManager>::get()->TranslatePage( | 342 TranslateManager::GetInstance()->TranslatePage( |
343 tab_contents_, GetOriginalLanguageCode(), GetTargetLanguageCode()); | 343 tab_contents_, GetOriginalLanguageCode(), GetTargetLanguageCode()); |
344 } | 344 } |
345 | 345 |
346 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { | 346 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { |
347 return !GetMessageInfoBarButtonText().empty(); | 347 return !GetMessageInfoBarButtonText().empty(); |
348 } | 348 } |
349 | 349 |
350 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateButton() { | 350 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateButton() { |
351 DCHECK(type_ == BEFORE_TRANSLATE); | 351 DCHECK(type_ == BEFORE_TRANSLATE); |
352 if (tab_contents()->profile()->IsOffTheRecord()) | 352 if (tab_contents()->profile()->IsOffTheRecord()) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 std::swap(offsets[0], offsets[1]); | 399 std::swap(offsets[0], offsets[1]); |
400 *swap_languages = true; | 400 *swap_languages = true; |
401 } else { | 401 } else { |
402 *swap_languages = false; | 402 *swap_languages = false; |
403 } | 403 } |
404 | 404 |
405 strings->push_back(text.substr(0, offsets[0])); | 405 strings->push_back(text.substr(0, offsets[0])); |
406 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); | 406 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); |
407 strings->push_back(text.substr(offsets[1])); | 407 strings->push_back(text.substr(offsets[1])); |
408 } | 408 } |
OLD | NEW |