1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "components/autofill/core/browser/autofill_metrics.h"
14 #include "components/infobars/core/confirm_infobar_delegate.h"
15 #include "ui/base/window_open_disposition.h"
25 // An InfoBar delegate that enables the user to allow or deny storing credit
26 // card information gathered from a form submission.
27 class AutofillCCInfoBarDelegate
: public ConfirmInfoBarDelegate
{
29 // Creates an autofill credit card infobar and delegate and adds the infobar
30 // to |infobar_manager|. The |autofill_client| must outlive the infobar.
31 static void Create(infobars::InfoBarManager
* infobar_manager
,
32 AutofillClient
* autofill_client
,
33 const base::Closure
& save_card_callback
);
35 #if defined(UNIT_TEST)
36 static scoped_ptr
<ConfirmInfoBarDelegate
> Create(
37 AutofillClient
* autofill_client
,
38 const base::Closure
& save_card_callback
) {
39 return scoped_ptr
<ConfirmInfoBarDelegate
>(
40 new AutofillCCInfoBarDelegate(autofill_client
, save_card_callback
));
45 AutofillCCInfoBarDelegate(AutofillClient
* autofill_client
,
46 const base::Closure
& save_card_callback
);
47 ~AutofillCCInfoBarDelegate() override
;
49 void LogUserAction(AutofillMetrics::InfoBarMetric user_action
);
51 // ConfirmInfoBarDelegate:
52 Type
GetInfoBarType() const override
;
53 int GetIconId() const override
;
54 gfx::VectorIconId
GetVectorIconId() const override
;
55 bool ShouldExpire(const NavigationDetails
& details
) const override
;
56 void InfoBarDismissed() override
;
57 base::string16
GetMessageText() const override
;
58 base::string16
GetButtonLabel(InfoBarButton button
) const override
;
59 bool Accept() override
;
60 bool Cancel() override
;
61 base::string16
GetLinkText() const override
;
62 bool LinkClicked(WindowOpenDisposition disposition
) override
;
64 // Performs navigation to handle any link click. Guaranteed to outlive us.
65 AutofillClient
* const autofill_client_
;
67 // The callback to save credit card if the user accepts the infobar.
68 base::Closure save_card_callback_
;
70 // Did the user ever explicitly accept or dismiss this infobar?
71 bool had_user_interaction_
;
73 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest
, CreditCardInfoBar
);
75 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate
);
78 } // namespace autofill
80 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_