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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 } | 60 } |
61 | 61 |
62 // Find any existing translate infobar delegate. | 62 // Find any existing translate infobar delegate. |
63 TranslateInfoBarDelegate* old_delegate = NULL; | 63 TranslateInfoBarDelegate* old_delegate = NULL; |
64 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 64 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
65 old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate(); | 65 old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate(); |
66 if (old_delegate) | 66 if (old_delegate) |
67 break; | 67 break; |
68 } | 68 } |
69 | 69 |
70 // Do not create the after translate infobar if we are auto translating. | |
71 if (infobar_type == TranslateInfoBarDelegate::AFTER_TRANSLATE || | |
72 infobar_type == TranslateInfoBarDelegate::TRANSLATING) { | |
73 TranslateTabHelper* translate_tab_helper = | |
74 TranslateTabHelper::FromWebContents(infobar_service->web_contents()); | |
75 if (!translate_tab_helper || | |
76 translate_tab_helper->language_state().InTranslateNavigation()) { | |
77 DCHECK(!old_delegate); | |
Takashi Toyoshima
2013/07/17 17:02:08
I agreed this DCHECK is always correct.
But I'd li
Peter Kasting
2013/07/17 18:06:19
I don't know whether the DCHECK here is important.
| |
78 return; | |
79 } | |
80 } | |
81 | |
70 // Create the new delegate. | 82 // Create the new delegate. |
71 scoped_ptr<TranslateInfoBarDelegate> infobar( | 83 scoped_ptr<TranslateInfoBarDelegate> infobar( |
72 new TranslateInfoBarDelegate(infobar_type, error_type, infobar_service, | 84 new TranslateInfoBarDelegate(infobar_type, error_type, infobar_service, |
73 prefs, shortcut_config, | 85 prefs, shortcut_config, |
74 original_language, target_language)); | 86 original_language, target_language)); |
75 infobar->UpdateBackgroundAnimation(old_delegate); | 87 infobar->UpdateBackgroundAnimation(old_delegate); |
76 | 88 |
77 // Do not create the after translate infobar if we are auto translating. | |
78 if (infobar_type == TranslateInfoBarDelegate::AFTER_TRANSLATE || | |
79 infobar_type == TranslateInfoBarDelegate::TRANSLATING) { | |
80 TranslateTabHelper* translate_tab_helper = | |
81 TranslateTabHelper::FromWebContents(infobar_service->web_contents()); | |
82 if (!translate_tab_helper || | |
83 translate_tab_helper->language_state().InTranslateNavigation()) | |
84 return; | |
85 } | |
86 | |
87 // Add the new delegate if necessary. | 89 // Add the new delegate if necessary. |
88 if (!old_delegate) { | 90 if (!old_delegate) { |
89 infobar_service->AddInfoBar(infobar.PassAs<InfoBarDelegate>()); | 91 infobar_service->AddInfoBar(infobar.PassAs<InfoBarDelegate>()); |
90 } else if (replace_existing_infobar) { | 92 } else if (replace_existing_infobar) { |
91 infobar_service->ReplaceInfoBar(old_delegate, | 93 infobar_service->ReplaceInfoBar(old_delegate, |
92 infobar.PassAs<InfoBarDelegate>()); | 94 infobar.PassAs<InfoBarDelegate>()); |
93 } | 95 } |
94 } | 96 } |
95 | 97 |
96 void TranslateInfoBarDelegate::Translate() { | 98 void TranslateInfoBarDelegate::Translate() { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 | 415 |
414 TranslateInfoBarDelegate* | 416 TranslateInfoBarDelegate* |
415 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 417 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
416 return this; | 418 return this; |
417 } | 419 } |
418 | 420 |
419 std::string TranslateInfoBarDelegate::GetPageHost() { | 421 std::string TranslateInfoBarDelegate::GetPageHost() { |
420 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 422 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
421 return entry ? entry->GetURL().HostNoBrackets() : std::string(); | 423 return entry ? entry->GetURL().HostNoBrackets() : std::string(); |
422 } | 424 } |
OLD | NEW |