OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/translate/translate_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 482 } |
483 | 483 |
484 // If the user has previously selected "always translate" for this language we | 484 // If the user has previously selected "always translate" for this language we |
485 // automatically translate. Note that in incognito mode we disable that | 485 // automatically translate. Note that in incognito mode we disable that |
486 // feature; the user will get an infobar, so they can control whether the | 486 // feature; the user will get an infobar, so they can control whether the |
487 // page's text is sent to the translate server. | 487 // page's text is sent to the translate server. |
488 std::string auto_target_lang; | 488 std::string auto_target_lang; |
489 if (!tab->browser_context()->IsOffTheRecord() && | 489 if (!tab->browser_context()->IsOffTheRecord() && |
490 TranslatePrefs::ShouldAutoTranslate(prefs, language_code, | 490 TranslatePrefs::ShouldAutoTranslate(prefs, language_code, |
491 &auto_target_lang)) { | 491 &auto_target_lang)) { |
492 TranslatePage(tab, language_code, auto_target_lang); | 492 // We need to confirm that the saved target language is still supported. |
493 return; | 493 // Also, GetLanguageCode will take care of removing country code if any. |
| 494 auto_target_lang = GetLanguageCode(auto_target_lang); |
| 495 if (IsSupportedLanguage(auto_target_lang)) { |
| 496 TranslatePage(tab, language_code, auto_target_lang); |
| 497 return; |
| 498 } |
494 } | 499 } |
495 | 500 |
496 TabContentsWrapper* wrapper = | 501 TabContentsWrapper* wrapper = |
497 TabContentsWrapper::GetCurrentWrapperForContents(tab); | 502 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
498 if (!wrapper || !wrapper->translate_tab_helper()) | 503 if (!wrapper || !wrapper->translate_tab_helper()) |
499 return; | 504 return; |
500 | 505 |
501 TranslateTabHelper* helper = wrapper->translate_tab_helper(); | 506 TranslateTabHelper* helper = wrapper->translate_tab_helper(); |
502 std::string auto_translate_to = helper->language_state().AutoTranslateTo(); | 507 std::string auto_translate_to = helper->language_state().AutoTranslateTo(); |
503 if (!auto_translate_to.empty()) { | 508 if (!auto_translate_to.empty()) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 return NULL; | 803 return NULL; |
799 | 804 |
800 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { | 805 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { |
801 TranslateInfoBarDelegate* delegate = | 806 TranslateInfoBarDelegate* delegate = |
802 wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 807 wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
803 if (delegate) | 808 if (delegate) |
804 return delegate; | 809 return delegate; |
805 } | 810 } |
806 return NULL; | 811 return NULL; |
807 } | 812 } |
OLD | NEW |