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 TranslateManager* manager = |
135 web_contents()); | 135 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
136 if (!manager) | |
MAD
2014/02/18 20:29:12
Why an if here and DCHECK elsewhere?
droger
2014/02/19 09:17:29
The logic I used is the following:
- if the funct
MAD
2014/02/19 16:22:07
OK, good point... I wonder if we should add a comm
droger
2014/02/19 16:40:08
I don't know if this actually happen.
I'll make a
| |
137 return; | |
138 manager->ReportLanguageDetectionError(); | |
136 } | 139 } |
137 | 140 |
138 void TranslateInfoBarDelegate::TranslationDeclined() { | 141 void TranslateInfoBarDelegate::TranslationDeclined() { |
139 ui_delegate_.TranslationDeclined(false); | 142 ui_delegate_.TranslationDeclined(false); |
140 } | 143 } |
141 | 144 |
142 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { | 145 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { |
143 Profile* profile = | 146 Profile* profile = |
144 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 147 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
145 Profile* original_profile = profile->GetOriginalProfile(); | 148 Profile* original_profile = profile->GetOriginalProfile(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 return base::string16(); | 246 return base::string16(); |
244 } | 247 } |
245 | 248 |
246 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { | 249 void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() { |
247 DCHECK_EQ(TranslateTabHelper::TRANSLATE_ERROR, step_); | 250 DCHECK_EQ(TranslateTabHelper::TRANSLATE_ERROR, step_); |
248 if (error_type_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { | 251 if (error_type_ == TranslateErrors::UNSUPPORTED_LANGUAGE) { |
249 RevertTranslation(); | 252 RevertTranslation(); |
250 return; | 253 return; |
251 } | 254 } |
252 // This is the "Try again..." case. | 255 // This is the "Try again..." case. |
253 TranslateManager::GetInstance()->TranslatePage( | 256 TranslateManager* manager = |
254 web_contents(), original_language_code(), target_language_code()); | 257 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
258 DCHECK(manager); | |
259 manager->TranslatePage(original_language_code(), target_language_code()); | |
255 } | 260 } |
256 | 261 |
257 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { | 262 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { |
258 return !GetMessageInfoBarButtonText().empty(); | 263 return !GetMessageInfoBarButtonText().empty(); |
259 } | 264 } |
260 | 265 |
261 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() { | 266 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() { |
262 DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_); | 267 DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_); |
263 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && | 268 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && |
264 (prefs_->GetTranslationDeniedCount(original_language_code()) >= | 269 (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) | 367 if (!details.is_navigation_to_different_page() && !details.is_main_frame) |
363 return false; | 368 return false; |
364 | 369 |
365 return InfoBarDelegate::ShouldExpireInternal(details); | 370 return InfoBarDelegate::ShouldExpireInternal(details); |
366 } | 371 } |
367 | 372 |
368 TranslateInfoBarDelegate* | 373 TranslateInfoBarDelegate* |
369 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 374 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
370 return this; | 375 return this; |
371 } | 376 } |
OLD | NEW |