Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 void TranslateInfoBarDelegate::Translate() { | 124 void TranslateInfoBarDelegate::Translate() { |
| 125 ui_delegate_.Translate(); | 125 ui_delegate_.Translate(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void TranslateInfoBarDelegate::RevertTranslation() { | 128 void TranslateInfoBarDelegate::RevertTranslation() { |
| 129 ui_delegate_.RevertTranslation(); | 129 ui_delegate_.RevertTranslation(); |
| 130 infobar()->RemoveSelf(); | 130 infobar()->RemoveSelf(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void TranslateInfoBarDelegate::ReportLanguageDetectionError() { | 133 void TranslateInfoBarDelegate::ReportLanguageDetectionError() { |
| 134 TranslateManager::GetInstance()->ReportLanguageDetectionError( | 134 TranslateTabHelper::GetManagerFromWebContents(web_contents()) |
|
blundell
2014/02/18 09:21:46
You should either DCHECK the manager here or short
droger
2014/02/18 10:16:51
I'm doing a short-circuit here (because ReportLang
| |
| 135 web_contents()); | 135 ->ReportLanguageDetectionError(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void TranslateInfoBarDelegate::TranslationDeclined() { | 138 void TranslateInfoBarDelegate::TranslationDeclined() { |
| 139 ui_delegate_.TranslationDeclined(false); | 139 ui_delegate_.TranslationDeclined(false); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { | 142 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { |
| 143 Profile* profile = | 143 Profile* profile = |
| 144 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 144 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 145 Profile* original_profile = profile->GetOriginalProfile(); | 145 Profile* original_profile = profile->GetOriginalProfile(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 return base::string16(); | 243 return base::string16(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { | 246 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { |
| 247 DCHECK_EQ(TranslateTabHelper::TRANSLATE_ERROR, step_); | 247 DCHECK_EQ(TranslateTabHelper::TRANSLATE_ERROR, step_); |
| 248 if (error_type_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { | 248 if (error_type_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { |
| 249 RevertTranslation(); | 249 RevertTranslation(); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 // This is the "Try again..." case. | 252 // This is the "Try again..." case. |
| 253 TranslateManager::GetInstance()->TranslatePage( | 253 TranslateTabHelper::GetManagerFromWebContents(web_contents()) |
|
blundell
2014/02/18 09:21:46
Same question as above.
droger
2014/02/18 10:16:51
I'm DCHECKing here, because TranslatePage() assume
| |
| 254 web_contents(), original_language_code(), target_language_code()); | 254 ->TranslatePage(original_language_code(), target_language_code()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { | 257 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { |
| 258 return !GetMessageInfoBarButtonText().empty(); | 258 return !GetMessageInfoBarButtonText().empty(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() { | 261 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() { |
| 262 DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_); | 262 DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_); |
| 263 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && | 263 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && |
| 264 (prefs_->GetTranslationDeniedCount(original_language_code()) >= | 264 (prefs_->GetTranslationDeniedCount(original_language_code()) >= |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 if (!details.is_navigation_to_different_page() && !details.is_main_frame) | 362 if (!details.is_navigation_to_different_page() && !details.is_main_frame) |
| 363 return false; | 363 return false; |
| 364 | 364 |
| 365 return InfoBarDelegate::ShouldExpireInternal(details); | 365 return InfoBarDelegate::ShouldExpireInternal(details); |
| 366 } | 366 } |
| 367 | 367 |
| 368 TranslateInfoBarDelegate* | 368 TranslateInfoBarDelegate* |
| 369 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 369 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 370 return this; | 370 return this; |
| 371 } | 371 } |
| OLD | NEW |