Index: components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.cc |
diff --git a/components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.cc b/components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2cc5bd003a1d4b325e880e0399203d257fb09798 |
--- /dev/null |
+++ b/components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.cc |
@@ -0,0 +1,111 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/autofill/core/browser/autofill_credit_card_filling_infobar_delegate_mobile.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "components/autofill/core/browser/autofill_client.h" |
+#include "components/autofill/core/browser/credit_card.h" |
+#include "components/autofill/core/common/autofill_constants.h" |
+#include "components/infobars/core/infobar.h" |
+#include "components/infobars/core/infobar_delegate.h" |
+#include "components/infobars/core/infobar_manager.h" |
+#include "grit/components_scaled_resources.h" |
+#include "grit/components_strings.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace autofill { |
+ |
+AutofillCreditCardFillingInfoBarDelegateMobile:: |
+ ~AutofillCreditCardFillingInfoBarDelegateMobile() { |
+ if (!had_user_interaction_ && was_shown_) |
+ LogUserAction(AutofillMetrics::INFOBAR_IGNORED); |
+} |
+ |
+// static |
+void AutofillCreditCardFillingInfoBarDelegateMobile::Create( |
+ infobars::InfoBarManager* infobar_manager, |
+ const base::WeakPtr<AutofillClient>& autofill_client, |
+ const CreditCard& card, |
+ const base::Closure& card_filling_callback) { |
+ std::unique_ptr<infobars::InfoBar> infobar( |
+ autofill_client->CreateCreditCardFillingInfoBar( |
+ base::WrapUnique(new AutofillCreditCardFillingInfoBarDelegateMobile( |
+ card, card_filling_callback)))); |
+ if (infobar) { |
+ infobars::InfoBar* added_infobar = |
+ infobar_manager->AddInfoBar(std::move(infobar)); |
+ if (added_infobar) { |
+ static_cast<AutofillCreditCardFillingInfoBarDelegateMobile*>( |
+ added_infobar->delegate()) |
+ ->was_shown_ = true; |
+ AutofillMetrics::LogCreditCardFillingInfoBarMetric( |
+ AutofillMetrics::INFOBAR_SHOWN); |
+ } |
+ } |
+} |
+ |
+int AutofillCreditCardFillingInfoBarDelegateMobile::GetIconId() const { |
+ return IDR_INFOBAR_AUTOFILL_CC; |
+} |
+ |
+base::string16 AutofillCreditCardFillingInfoBarDelegateMobile::GetMessageText() |
+ const { |
+ return l10n_util::GetStringUTF16( |
+ IDS_AUTOFILL_CREDIT_CARD_FILLING_INFOBAR_TITLE); |
+} |
+ |
+AutofillCreditCardFillingInfoBarDelegateMobile:: |
+ AutofillCreditCardFillingInfoBarDelegateMobile( |
+ const CreditCard& card, |
+ const base::Closure& card_filling_callback) |
+ : ConfirmInfoBarDelegate(), |
+ card_filling_callback_(card_filling_callback), |
+ had_user_interaction_(false), |
+ was_shown_(false), |
+ issuer_icon_id_(CreditCard::IconResourceId(card.type())), |
+ card_label_(base::string16(kMidlineEllipsis) + card.LastFourDigits()), |
+ card_sub_label_(card.AbbreviatedExpirationDateForDisplay()) {} |
+ |
+infobars::InfoBarDelegate::Type |
+AutofillCreditCardFillingInfoBarDelegateMobile::GetInfoBarType() const { |
+ return PAGE_ACTION_TYPE; |
+} |
+ |
+infobars::InfoBarDelegate::InfoBarIdentifier |
+AutofillCreditCardFillingInfoBarDelegateMobile::GetIdentifier() const { |
+ return AUTOFILL_CREDIT_CARD_FILLING_INFOBAR_DELEGATE_ANDROID; |
+} |
+ |
+void AutofillCreditCardFillingInfoBarDelegateMobile::InfoBarDismissed() { |
+ LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
+} |
+ |
+base::string16 AutofillCreditCardFillingInfoBarDelegateMobile::GetButtonLabel( |
+ InfoBarButton button) const { |
+ return l10n_util::GetStringUTF16( |
+ button == BUTTON_OK ? IDS_AUTOFILL_CREDIT_CARD_FILLING_INFOBAR_ACCEPT |
+ : IDS_AUTOFILL_INFOBAR_PROMPT_DENY); |
+} |
+ |
+bool AutofillCreditCardFillingInfoBarDelegateMobile::Accept() { |
+ card_filling_callback_.Run(); |
+ LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); |
+ return true; |
+} |
+ |
+bool AutofillCreditCardFillingInfoBarDelegateMobile::Cancel() { |
+ LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
+ return true; |
+} |
+ |
+void AutofillCreditCardFillingInfoBarDelegateMobile::LogUserAction( |
+ AutofillMetrics::InfoBarMetric user_action) { |
+ DCHECK(!had_user_interaction_); |
+ |
+ AutofillMetrics::LogCreditCardFillingInfoBarMetric(user_action); |
+ had_user_interaction_ = true; |
+} |
+ |
+} // namespace autofill |