Commit 0c8d28bf authored by mad@chromium.org's avatar mad@chromium.org

Fix a crash caused by unknown saved language.

The language index in the dump referred by the crbug is left to -1, meaning that the language passed to TranslateInfoBarDelegate's constructor...

The call stack showed that the call came from an auto translate preference, so my only guess would be that a preference was saved for a language that is not available anymore, so I added code to protect against that.

BUG=93291
TEST=TranslateManagerTest.UnsupportedSavedLanguage

Review URL: http://codereview.chromium.org/7764003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98661 0039d316-1c4b-4281-b951-d872f2087c98
parent 0b600640
......@@ -89,6 +89,7 @@ void TranslateInfoBarDelegate::SetOriginalLanguage(size_t language_index) {
void TranslateInfoBarDelegate::SetTargetLanguage(size_t language_index) {
DCHECK_LT(language_index, GetLanguageCount());
DCHECK_GE(language_index, 0U);
target_language_index_ = language_index;
if (infobar_view_)
infobar_view_->TargetLanguageChanged();
......@@ -348,6 +349,7 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
if (language_code == target_language)
target_language_index_ = iter - languages_.begin();
}
DCHECK_NE(kNoIndex, target_language_index_);
}
bool TranslateInfoBarDelegate::ShouldExpire(
......
......@@ -489,8 +489,13 @@ void TranslateManager::InitiateTranslation(TabContents* tab,
if (!tab->browser_context()->IsOffTheRecord() &&
TranslatePrefs::ShouldAutoTranslate(prefs, language_code,
&auto_target_lang)) {
TranslatePage(tab, language_code, auto_target_lang);
return;
// We need to confirm that the saved target language is still supported.
// Also, GetLanguageCode will take care of removing country code if any.
auto_target_lang = GetLanguageCode(auto_target_lang);
if (IsSupportedLanguage(auto_target_lang)) {
TranslatePage(tab, language_code, auto_target_lang);
return;
}
}
TabContentsWrapper* wrapper =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment