OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/i18n/string_compare.h" | 9 #include "base/i18n/string_compare.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 Type infobar_type, TranslateErrors::Type error_type, PrefService* prefs, | 41 Type infobar_type, TranslateErrors::Type error_type, PrefService* prefs, |
42 const ShortcutConfiguration& shortcut_config, | 42 const ShortcutConfiguration& shortcut_config, |
43 const std::string& original_language, const std::string& target_language) { | 43 const std::string& original_language, const std::string& target_language) { |
44 // Check preconditions. | 44 // Check preconditions. |
45 if (infobar_type != TRANSLATION_ERROR) { | 45 if (infobar_type != TRANSLATION_ERROR) { |
46 DCHECK(TranslateManager::IsSupportedLanguage(target_language)); | 46 DCHECK(TranslateManager::IsSupportedLanguage(target_language)); |
47 if (!TranslateManager::IsSupportedLanguage(original_language)) { | 47 if (!TranslateManager::IsSupportedLanguage(original_language)) { |
48 // The original language can only be "unknown" for the "translating" | 48 // The original language can only be "unknown" for the "translating" |
49 // infobar, which is the case when the user started a translation from the | 49 // infobar, which is the case when the user started a translation from the |
50 // context menu. | 50 // context menu. |
51 DCHECK_EQ(TRANSLATING, infobar_type); | 51 DCHECK(infobar_type == TRANSLATING || infobar_type == AFTER_TRANSLATE); |
52 DCHECK_EQ(chrome::kUnknownLanguageCode, original_language); | 52 DCHECK_EQ(chrome::kUnknownLanguageCode, original_language); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 // Find any existing translate infobar delegate. | 56 // Find any existing translate infobar delegate. |
57 TranslateInfoBarDelegate* old_delegate = NULL; | 57 TranslateInfoBarDelegate* old_delegate = NULL; |
58 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 58 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
59 old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate(); | 59 old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate(); |
60 if (old_delegate) | 60 if (old_delegate) |
61 break; | 61 break; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 *swap_languages = (offsets[0] > offsets[1]); | 293 *swap_languages = (offsets[0] > offsets[1]); |
294 if (*swap_languages) | 294 if (*swap_languages) |
295 std::swap(offsets[0], offsets[1]); | 295 std::swap(offsets[0], offsets[1]); |
296 | 296 |
297 strings->push_back(text.substr(0, offsets[0])); | 297 strings->push_back(text.substr(0, offsets[0])); |
298 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); | 298 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0])); |
299 strings->push_back(text.substr(offsets[1])); | 299 strings->push_back(text.substr(offsets[1])); |
300 } | 300 } |
301 | 301 |
| 302 // static |
| 303 void TranslateInfoBarDelegate::GetAfterTranslateWithAutoStrings( |
| 304 std::vector<string16>* strings) { |
| 305 DCHECK(strings); |
| 306 |
| 307 size_t offset; |
| 308 string16 text = |
| 309 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_WITH_AUTO, |
| 310 string16(), &offset); |
| 311 |
| 312 strings->push_back(text.substr(0, offset)); |
| 313 strings->push_back(text.substr(offset)); |
| 314 } |
| 315 |
302 TranslateInfoBarDelegate::TranslateInfoBarDelegate( | 316 TranslateInfoBarDelegate::TranslateInfoBarDelegate( |
303 Type infobar_type, | 317 Type infobar_type, |
304 TranslateErrors::Type error_type, | 318 TranslateErrors::Type error_type, |
305 InfoBarService* infobar_service, | 319 InfoBarService* infobar_service, |
306 PrefService* prefs, | 320 PrefService* prefs, |
307 ShortcutConfiguration shortcut_config, | 321 ShortcutConfiguration shortcut_config, |
308 const std::string& original_language, | 322 const std::string& original_language, |
309 const std::string& target_language) | 323 const std::string& target_language) |
310 : InfoBarDelegate(infobar_service), | 324 : InfoBarDelegate(infobar_service), |
311 infobar_type_(infobar_type), | 325 infobar_type_(infobar_type), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 401 |
388 TranslateInfoBarDelegate* | 402 TranslateInfoBarDelegate* |
389 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 403 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
390 return this; | 404 return this; |
391 } | 405 } |
392 | 406 |
393 std::string TranslateInfoBarDelegate::GetPageHost() { | 407 std::string TranslateInfoBarDelegate::GetPageHost() { |
394 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 408 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
395 return entry ? entry->GetURL().HostNoBrackets() : std::string(); | 409 return entry ? entry->GetURL().HostNoBrackets() : std::string(); |
396 } | 410 } |
OLD | NEW |