OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "components/autofill/core/browser/autofill_metrics.h" | 13 #include "components/autofill/core/browser/autofill_metrics.h" |
| 14 #include "components/autofill/core/browser/legal_message_line.h" |
14 #include "components/infobars/core/confirm_infobar_delegate.h" | 15 #include "components/infobars/core/confirm_infobar_delegate.h" |
15 #include "ui/base/window_open_disposition.h" | 16 #include "ui/base/window_open_disposition.h" |
16 | 17 |
| 18 namespace base { |
| 19 class DictionaryValue; |
| 20 } |
| 21 |
17 namespace infobars { | 22 namespace infobars { |
18 class InfoBarManager; | 23 class InfoBarManager; |
19 } | 24 } |
20 | 25 |
21 namespace autofill { | 26 namespace autofill { |
22 | 27 |
| 28 class CreditCard; |
| 29 |
23 // An InfoBar delegate that enables the user to allow or deny storing credit | 30 // An InfoBar delegate that enables the user to allow or deny storing credit |
24 // card information gathered from a form submission. | 31 // card information gathered from a form submission. |
25 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { | 32 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { |
26 public: | 33 public: |
27 // Creates an autofill credit card infobar and delegate and adds the infobar | 34 // Creates an autofill credit card infobar and delegate and adds the infobar |
28 // to |infobar_manager|. | 35 // to |infobar_manager|. |
29 static void CreateForLocalSave(infobars::InfoBarManager* infobar_manager, | 36 static void CreateForLocalSave(infobars::InfoBarManager* infobar_manager, |
| 37 const CreditCard& card, |
30 const base::Closure& save_card_callback); | 38 const base::Closure& save_card_callback); |
31 static void CreateForUpload(infobars::InfoBarManager* infobar_manager, | 39 static void CreateForUpload(infobars::InfoBarManager* infobar_manager, |
| 40 const CreditCard& card, |
| 41 scoped_ptr<base::DictionaryValue> legal_message, |
32 const base::Closure& save_card_callback); | 42 const base::Closure& save_card_callback); |
33 | 43 |
34 #if defined(UNIT_TEST) | 44 #if defined(UNIT_TEST) |
35 static scoped_ptr<ConfirmInfoBarDelegate> Create( | 45 static scoped_ptr<ConfirmInfoBarDelegate> Create( |
36 const base::Closure& save_card_callback) { | 46 const base::Closure& save_card_callback) { |
37 return scoped_ptr<ConfirmInfoBarDelegate>( | 47 return scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate( |
38 new AutofillCCInfoBarDelegate(false, save_card_callback)); | 48 false, CreditCard(), scoped_ptr<base::DictionaryValue>(nullptr), |
| 49 save_card_callback)); |
39 } | 50 } |
40 #endif | 51 #endif |
41 | 52 |
| 53 ~AutofillCCInfoBarDelegate() override; |
| 54 |
| 55 int issuer_icon_id() const { return issuer_icon_id_; } |
| 56 const base::string16& card_label() const { return card_label_; } |
| 57 const base::string16& card_sub_label() const { return card_sub_label_; } |
| 58 const LegalMessageLines& legal_messages() const { return legal_messages_; } |
| 59 |
| 60 // Called when a link in the legal message text was clicked. |
| 61 void OnLegalMessageLinkClicked(GURL url); |
| 62 |
42 private: | 63 private: |
43 AutofillCCInfoBarDelegate(bool upload, | 64 AutofillCCInfoBarDelegate(bool upload, |
| 65 const CreditCard& card, |
| 66 scoped_ptr<base::DictionaryValue> legal_message, |
44 const base::Closure& save_card_callback); | 67 const base::Closure& save_card_callback); |
45 ~AutofillCCInfoBarDelegate() override; | |
46 | 68 |
47 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); | 69 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); |
48 | 70 |
49 // ConfirmInfoBarDelegate: | 71 // ConfirmInfoBarDelegate: |
50 Type GetInfoBarType() const override; | 72 Type GetInfoBarType() const override; |
51 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 73 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
52 int GetIconId() const override; | 74 int GetIconId() const override; |
53 gfx::VectorIconId GetVectorIconId() const override; | 75 gfx::VectorIconId GetVectorIconId() const override; |
54 bool ShouldExpire(const NavigationDetails& details) const override; | 76 bool ShouldExpire(const NavigationDetails& details) const override; |
55 void InfoBarDismissed() override; | 77 void InfoBarDismissed() override; |
56 base::string16 GetMessageText() const override; | 78 base::string16 GetMessageText() const override; |
57 base::string16 GetButtonLabel(InfoBarButton button) const override; | 79 base::string16 GetButtonLabel(InfoBarButton button) const override; |
58 bool Accept() override; | 80 bool Accept() override; |
59 bool Cancel() override; | 81 bool Cancel() override; |
60 base::string16 GetLinkText() const override; | 82 base::string16 GetLinkText() const override; |
61 GURL GetLinkURL() const override; | 83 GURL GetLinkURL() const override; |
62 | 84 |
| 85 // Whether the infobar is for uploading the credit card. |
63 bool upload_; | 86 bool upload_; |
64 | 87 |
| 88 // The resource ID for the icon that identifies the issuer of the card. |
| 89 int issuer_icon_id_; |
| 90 |
| 91 // The label for the card to show in the content of the infobar. |
| 92 base::string16 card_label_; |
| 93 |
| 94 // The sub-label for the card to show in the content onf the infobar. |
| 95 base::string16 card_sub_label_; |
| 96 |
| 97 // The legal messages to show in the content of the infobar. |
| 98 LegalMessageLines legal_messages_; |
| 99 |
65 // The callback to save credit card if the user accepts the infobar. | 100 // The callback to save credit card if the user accepts the infobar. |
66 base::Closure save_card_callback_; | 101 base::Closure save_card_callback_; |
67 | 102 |
68 // Did the user ever explicitly accept or dismiss this infobar? | 103 // Did the user ever explicitly accept or dismiss this infobar? |
69 bool had_user_interaction_; | 104 bool had_user_interaction_; |
70 | 105 |
71 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); | 106 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); |
72 | 107 |
73 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); |
74 }; | 109 }; |
75 | 110 |
76 } // namespace autofill | 111 } // namespace autofill |
77 | 112 |
78 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 113 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
OLD | NEW |