| Index: chrome/browser/translate/translate_infobar_delegate.cc
|
| ===================================================================
|
| --- chrome/browser/translate/translate_infobar_delegate.cc (revision 226624)
|
| +++ chrome/browser/translate/translate_infobar_delegate.cc (working copy)
|
| @@ -10,6 +10,7 @@
|
| #include "base/metrics/histogram.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/infobars/infobar.h"
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/translate/translate_accept_languages.h"
|
| @@ -66,10 +67,22 @@
|
| }
|
| }
|
|
|
| + // Do not create the after translate infobar if we are auto translating.
|
| + if ((infobar_type == TranslateInfoBarDelegate::AFTER_TRANSLATE) ||
|
| + (infobar_type == TranslateInfoBarDelegate::TRANSLATING)) {
|
| + TranslateTabHelper* translate_tab_helper =
|
| + TranslateTabHelper::FromWebContents(infobar_service->web_contents());
|
| + if (!translate_tab_helper ||
|
| + translate_tab_helper->language_state().InTranslateNavigation())
|
| + return;
|
| + }
|
| +
|
| // Find any existing translate infobar delegate.
|
| + InfoBar* old_infobar = NULL;
|
| TranslateInfoBarDelegate* old_delegate = NULL;
|
| for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
|
| - old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate();
|
| + old_infobar = infobar_service->infobar_at(i);
|
| + old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate();
|
| if (old_delegate) {
|
| if (!replace_existing_infobar)
|
| return;
|
| @@ -77,30 +90,15 @@
|
| }
|
| }
|
|
|
| - // Create the new delegate.
|
| - scoped_ptr<TranslateInfoBarDelegate> infobar(
|
| - new TranslateInfoBarDelegate(infobar_service, infobar_type, old_delegate,
|
| - original_language, target_language,
|
| - error_type, prefs, shortcut_config));
|
| -
|
| - // Do not create the after translate infobar if we are auto translating.
|
| - if ((infobar_type == TranslateInfoBarDelegate::AFTER_TRANSLATE) ||
|
| - (infobar_type == TranslateInfoBarDelegate::TRANSLATING)) {
|
| - TranslateTabHelper* translate_tab_helper =
|
| - TranslateTabHelper::FromWebContents(infobar_service->web_contents());
|
| - if (!translate_tab_helper ||
|
| - translate_tab_helper->language_state().InTranslateNavigation())
|
| - return;
|
| - }
|
| -
|
| - // Add the new delegate if necessary.
|
| - if (!old_delegate) {
|
| - infobar_service->AddInfoBar(infobar.PassAs<InfoBarDelegate>());
|
| - } else {
|
| - DCHECK(replace_existing_infobar);
|
| - infobar_service->ReplaceInfoBar(old_delegate,
|
| - infobar.PassAs<InfoBarDelegate>());
|
| - }
|
| + // Add the new delegate.
|
| + scoped_ptr<InfoBar> infobar(CreateInfoBar(
|
| + scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate(
|
| + infobar_type, old_delegate, original_language, target_language,
|
| + error_type, prefs, shortcut_config))));
|
| + if (old_delegate)
|
| + infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass());
|
| + else
|
| + infobar_service->AddInfoBar(infobar.Pass());
|
| }
|
|
|
| void TranslateInfoBarDelegate::Translate() {
|
| @@ -118,7 +116,7 @@
|
|
|
| void TranslateInfoBarDelegate::RevertTranslation() {
|
| TranslateManager::GetInstance()->RevertTranslation(web_contents());
|
| - RemoveSelf();
|
| + infobar()->RemoveSelf();
|
|
|
| UMA_HISTOGRAM_BOOLEAN(kRevertTranslation, true);
|
| }
|
| @@ -159,7 +157,7 @@
|
| prefs_.UnblockLanguage(original_lang);
|
| } else {
|
| prefs_.BlockLanguage(original_lang);
|
| - RemoveSelf();
|
| + infobar()->RemoveSelf();
|
| }
|
|
|
| UMA_HISTOGRAM_BOOLEAN(kNeverTranslateLang, true);
|
| @@ -179,7 +177,7 @@
|
| prefs_.RemoveSiteFromBlacklist(host);
|
| } else {
|
| prefs_.BlacklistSite(host);
|
| - RemoveSelf();
|
| + infobar()->RemoveSelf();
|
| }
|
|
|
| UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, true);
|
| @@ -212,7 +210,7 @@
|
| void TranslateInfoBarDelegate::NeverTranslatePageLanguage() {
|
| std::string original_lang = original_language_code();
|
| prefs_.BlockLanguage(original_lang);
|
| - RemoveSelf();
|
| + infobar()->RemoveSelf();
|
| }
|
|
|
| string16 TranslateInfoBarDelegate::GetMessageInfoBarText() {
|
| @@ -333,7 +331,6 @@
|
| }
|
|
|
| TranslateInfoBarDelegate::TranslateInfoBarDelegate(
|
| - InfoBarService* infobar_service,
|
| Type infobar_type,
|
| TranslateInfoBarDelegate* old_delegate,
|
| const std::string& original_language,
|
| @@ -341,7 +338,7 @@
|
| TranslateErrors::Type error_type,
|
| PrefService* prefs,
|
| ShortcutConfiguration shortcut_config)
|
| - : InfoBarDelegate(infobar_service),
|
| + : InfoBarDelegate(),
|
| infobar_type_(infobar_type),
|
| background_animation_(NONE),
|
| original_language_index_(kNoIndex),
|
| @@ -395,6 +392,9 @@
|
| DCHECK_NE(kNoIndex, target_language_index_);
|
| }
|
|
|
| +// TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific
|
| +// files.
|
| +
|
| void TranslateInfoBarDelegate::InfoBarDismissed() {
|
| if (infobar_type_ != BEFORE_TRANSLATE)
|
| return;
|
|
|