Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: chrome/browser/translate/translate_infobar_delegate.cc

Issue 7764003: Fix a crash caused by unknown saved language. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/translate/translate_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 DCHECK_LT(language_index, GetLanguageCount()); 82 DCHECK_LT(language_index, GetLanguageCount());
83 original_language_index_ = language_index; 83 original_language_index_ = language_index;
84 if (infobar_view_) 84 if (infobar_view_)
85 infobar_view_->OriginalLanguageChanged(); 85 infobar_view_->OriginalLanguageChanged();
86 if (type_ == AFTER_TRANSLATE) 86 if (type_ == AFTER_TRANSLATE)
87 Translate(); 87 Translate();
88 } 88 }
89 89
90 void TranslateInfoBarDelegate::SetTargetLanguage(size_t language_index) { 90 void TranslateInfoBarDelegate::SetTargetLanguage(size_t language_index) {
91 DCHECK_LT(language_index, GetLanguageCount()); 91 DCHECK_LT(language_index, GetLanguageCount());
92 DCHECK_GE(language_index, 0U);
92 target_language_index_ = language_index; 93 target_language_index_ = language_index;
93 if (infobar_view_) 94 if (infobar_view_)
94 infobar_view_->TargetLanguageChanged(); 95 infobar_view_->TargetLanguageChanged();
95 if (type_ == AFTER_TRANSLATE) 96 if (type_ == AFTER_TRANSLATE)
96 Translate(); 97 Translate();
97 } 98 }
98 99
99 void TranslateInfoBarDelegate::Translate() { 100 void TranslateInfoBarDelegate::Translate() {
100 const std::string& original_language_code = GetOriginalLanguageCode(); 101 const std::string& original_language_code = GetOriginalLanguageCode();
101 if (!tab_contents()->browser_context()->IsOffTheRecord()) { 102 if (!tab_contents()->browser_context()->IsOffTheRecord()) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 for (std::vector<LanguageNamePair>::const_iterator iter = languages_.begin(); 342 for (std::vector<LanguageNamePair>::const_iterator iter = languages_.begin();
342 iter != languages_.end(); ++iter) { 343 iter != languages_.end(); ++iter) {
343 std::string language_code = iter->first; 344 std::string language_code = iter->first;
344 if (language_code == original_language) { 345 if (language_code == original_language) {
345 original_language_index_ = iter - languages_.begin(); 346 original_language_index_ = iter - languages_.begin();
346 initial_original_language_index_ = original_language_index_; 347 initial_original_language_index_ = original_language_index_;
347 } 348 }
348 if (language_code == target_language) 349 if (language_code == target_language)
349 target_language_index_ = iter - languages_.begin(); 350 target_language_index_ = iter - languages_.begin();
350 } 351 }
352 DCHECK_NE(kNoIndex, target_language_index_);
351 } 353 }
352 354
353 bool TranslateInfoBarDelegate::ShouldExpire( 355 bool TranslateInfoBarDelegate::ShouldExpire(
354 const content::LoadCommittedDetails& details) const { 356 const content::LoadCommittedDetails& details) const {
355 // Note: we allow closing this infobar even if the main frame navigation 357 // Note: we allow closing this infobar even if the main frame navigation
356 // was programmatic and not initiated by the user - crbug.com/70261 . 358 // was programmatic and not initiated by the user - crbug.com/70261 .
357 if (!details.is_navigation_to_different_page() && !details.is_main_frame) 359 if (!details.is_navigation_to_different_page() && !details.is_main_frame)
358 return false; 360 return false;
359 361
360 return InfoBarDelegate::ShouldExpireInternal(details); 362 return InfoBarDelegate::ShouldExpireInternal(details);
(...skipping 19 matching lines...) Expand all
380 382
381 TranslateInfoBarDelegate* 383 TranslateInfoBarDelegate*
382 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { 384 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
383 return this; 385 return this;
384 } 386 }
385 387
386 std::string TranslateInfoBarDelegate::GetPageHost() { 388 std::string TranslateInfoBarDelegate::GetPageHost() {
387 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); 389 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
388 return entry ? entry->url().HostNoBrackets() : std::string(); 390 return entry ? entry->url().HostNoBrackets() : std::string();
389 } 391 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/translate/translate_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698