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

Unified Diff: chrome/browser/translate/translate_infobar_delegate.cc

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/translate/translate_infobar_delegate.cc
diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc
index bafb6f14797c55169cca704d8c8a359865721c55..d7e3439697dc23b1bb65742849ba1f695ba9e032 100644
--- a/chrome/browser/translate/translate_infobar_delegate.cc
+++ b/chrome/browser/translate/translate_infobar_delegate.cc
@@ -11,6 +11,7 @@
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/infobar.h"
+#include "chrome/browser/infobars/infobar_manager.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/translate/translate_manager.h"
@@ -89,9 +90,10 @@ void TranslateInfoBarDelegate::Create(bool replace_existing_infobar,
InfoBar* old_infobar = NULL;
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
+ InfoBarManager& infobar_manager = infobar_service->infobar_manager();
TranslateInfoBarDelegate* old_delegate = NULL;
- for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
- old_infobar = infobar_service->infobar_at(i);
+ for (size_t i = 0; i < infobar_manager.infobar_count(); ++i) {
+ old_infobar = infobar_manager.infobar_at(i);
old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate();
if (old_delegate) {
if (!replace_existing_infobar)
@@ -134,7 +136,7 @@ void TranslateInfoBarDelegate::RevertTranslation() {
void TranslateInfoBarDelegate::ReportLanguageDetectionError() {
TranslateManager* manager =
- TranslateTabHelper::GetManagerFromWebContents(web_contents());
+ TranslateTabHelper::GetManagerFromWebContents(web_contents_);
if (!manager)
return;
manager->ReportLanguageDetectionError();
@@ -146,7 +148,7 @@ void TranslateInfoBarDelegate::TranslationDeclined() {
bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() {
Profile* profile =
- Profile::FromBrowserContext(web_contents()->GetBrowserContext());
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext());
Profile* original_profile = profile->GetOriginalProfile();
scoped_ptr<TranslatePrefs> translate_prefs(
TranslateTabHelper::CreateTranslatePrefs(original_profile->GetPrefs()));
@@ -256,7 +258,7 @@ void TranslateInfoBarDelegate::MessageInfoBarButtonPressed() {
}
// This is the "Try again..." case.
TranslateManager* manager =
- TranslateTabHelper::GetManagerFromWebContents(web_contents());
+ TranslateTabHelper::GetManagerFromWebContents(web_contents_);
DCHECK(manager);
manager->TranslatePage(
original_language_code(), target_language_code(), false);
@@ -268,15 +270,15 @@ bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() {
bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() {
DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_);
- return !web_contents()->GetBrowserContext()->IsOffTheRecord() &&
- (prefs_->GetTranslationDeniedCount(original_language_code()) >=
+ return !web_contents_->GetBrowserContext()->IsOffTheRecord() &&
+ (prefs_->GetTranslationDeniedCount(original_language_code()) >=
kNeverTranslateMinCount);
}
bool TranslateInfoBarDelegate::ShouldShowAlwaysTranslateShortcut() {
DCHECK_EQ(TranslateTabHelper::BEFORE_TRANSLATE, step_);
- return !web_contents()->GetBrowserContext()->IsOffTheRecord() &&
- (prefs_->GetTranslationAcceptedCount(original_language_code()) >=
+ return !web_contents_->GetBrowserContext()->IsOffTheRecord() &&
+ (prefs_->GetTranslationAcceptedCount(original_language_code()) >=
kAlwaysTranslateMinCount);
}
@@ -333,6 +335,7 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
bool triggered_from_menu)
: InfoBarDelegate(),
step_(step),
+ web_contents_(web_contents),
background_animation_(NONE),
ui_delegate_(web_contents, original_language, target_language),
error_type_(error_type),
@@ -366,10 +369,10 @@ InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const {
}
bool TranslateInfoBarDelegate::ShouldExpire(
- const content::LoadCommittedDetails& details) const {
+ const NavigationDetails& details) const {
// Note: we allow closing this infobar even if the main frame navigation
// was programmatic and not initiated by the user - crbug.com/70261 .
- if (!details.is_navigation_to_different_page() && !details.is_main_frame)
+ if (!details.is_navigation_to_different_page && !details.is_main_frame)
return false;
return InfoBarDelegate::ShouldExpireInternal(details);
@@ -379,3 +382,5 @@ TranslateInfoBarDelegate*
TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
return this;
}
+
+void TranslateInfoBarDelegate::CleanUp() { web_contents_ = NULL; }

Powered by Google App Engine
This is Rietveld 408576698