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

Unified Diff: components/autofill/core/browser/autofill_cc_infobar_delegate.cc

Issue 710453002: [Autofill] Componentize AutofillCCInfoBarDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove infobar if its associated page content is destroyed. Created 5 years, 12 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: components/autofill/core/browser/autofill_cc_infobar_delegate.cc
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/components/autofill/core/browser/autofill_cc_infobar_delegate.cc
similarity index 55%
rename from chrome/browser/autofill/autofill_cc_infobar_delegate.cc
rename to components/autofill/core/browser/autofill_cc_infobar_delegate.cc
index 430a79c4ac5b934e9ed38d9c7836eff3a78bcddb..886863968c823b1fc9cb301000befbf8f953bee0 100644
--- a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
+++ b/components/autofill/core/browser/autofill_cc_infobar_delegate.cc
@@ -2,39 +2,83 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
+#include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
+
+#include <map>
#include "base/logging.h"
-#include "chrome/browser/infobars/infobar_service.h"
-#include "chrome/grit/generated_resources.h"
-#include "chrome/grit/google_chrome_strings.h"
+#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/infobars/core/infobar.h"
-#include "content/public/browser/page_navigator.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "components/infobars/core/infobar_manager.h"
+#include "grit/components_scaled_resources.h"
#include "grit/components_strings.h"
-#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace autofill {
+namespace {
+
+std::map<AutofillDriver*, AutofillCCInfoBarDelegate*> driver_to_delegate_map;
+
+void AddPairToMap(AutofillDriver* driver, AutofillCCInfoBarDelegate* delegate) {
+ std::map<AutofillDriver*, AutofillCCInfoBarDelegate*>::iterator it =
+ driver_to_delegate_map.find(driver);
+ if (it == driver_to_delegate_map.end()) {
+ driver_to_delegate_map.insert(
+ std::pair<AutofillDriver*, AutofillCCInfoBarDelegate*>(driver,
+ delegate));
+ } else {
+ it->second = delegate;
+ }
+}
+
+void RemovePairFromMap(AutofillDriver* driver,
+ AutofillCCInfoBarDelegate* delegate) {
+ std::map<AutofillDriver*, AutofillCCInfoBarDelegate*>::iterator it =
+ driver_to_delegate_map.find(driver);
+ if (it != driver_to_delegate_map.end())
+ driver_to_delegate_map.erase(it);
+}
Ilya Sherman 2015/01/06 02:54:59 This all seems needlessly complex. I think we sho
Peter Kasting 2015/01/06 03:01:50 (4) Provide LinkClicked as a method on the client
Pritam Nikam 2015/01/06 12:47:42 Done.
+
+} // namespace
+
// static
void AutofillCCInfoBarDelegate::Create(
- InfoBarService* infobar_service,
+ infobars::InfoBarManager* infobar_manager,
+ AutofillDriver* autofill_driver,
const base::Closure& save_card_callback) {
- infobar_service->AddInfoBar(
- infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
- new AutofillCCInfoBarDelegate(save_card_callback))));
+ infobar_manager->AddInfoBar(
+ infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
+ new AutofillCCInfoBarDelegate(autofill_driver, save_card_callback))));
+}
+
+// static
+AutofillCCInfoBarDelegate* AutofillCCInfoBarDelegate::FromAutofillDriver(
+ AutofillDriver* autofill_driver) {
+ std::map<AutofillDriver*, AutofillCCInfoBarDelegate*>::iterator it =
+ driver_to_delegate_map.find(autofill_driver);
+ if (it != driver_to_delegate_map.end())
+ return it->second;
+
+ return nullptr;
+}
+
+void AutofillCCInfoBarDelegate::CloseInfoBar() {
+ RemovePairFromMap(autofill_driver_, this);
+ infobar()->Hide(true);
}
AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
+ AutofillDriver* autofill_driver,
const base::Closure& save_card_callback)
: ConfirmInfoBarDelegate(),
+ autofill_driver_(autofill_driver),
save_card_callback_(save_card_callback),
had_user_interaction_(false) {
+ AddPairToMap(autofill_driver_, this);
AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
}
@@ -52,6 +96,7 @@ void AutofillCCInfoBarDelegate::LogUserAction(
}
void AutofillCCInfoBarDelegate::InfoBarDismissed() {
+ RemovePairFromMap(autofill_driver_, this);
LogUserAction(AutofillMetrics::INFOBAR_DENIED);
}
@@ -83,6 +128,7 @@ base::string16 AutofillCCInfoBarDelegate::GetButtonLabel(
}
bool AutofillCCInfoBarDelegate::Accept() {
+ RemovePairFromMap(autofill_driver_, this);
save_card_callback_.Run();
save_card_callback_.Reset();
LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
@@ -90,6 +136,7 @@ bool AutofillCCInfoBarDelegate::Accept() {
}
bool AutofillCCInfoBarDelegate::Cancel() {
+ RemovePairFromMap(autofill_driver_, this);
LogUserAction(AutofillMetrics::INFOBAR_DENIED);
return true;
}
@@ -99,11 +146,12 @@ base::string16 AutofillCCInfoBarDelegate::GetLinkText() const {
}
bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
- InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL(
- content::OpenURLParams(
- GURL(autofill::kHelpURL), content::Referrer(),
- (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
- ui::PAGE_TRANSITION_LINK, false));
+ if (autofill_driver_) {
+ autofill_driver_->LinkClicked(
+ GURL(autofill::kHelpURL),
+ (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition);
+ }
+
return false;
}

Powered by Google App Engine
This is Rietveld 408576698