| 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/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 15 #include "ui/base/window_open_disposition.h" | 15 #include "ui/base/window_open_disposition.h" |
| 16 | 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 } |
| 20 |
| 17 namespace infobars { | 21 namespace infobars { |
| 18 class InfoBarManager; | 22 class InfoBarManager; |
| 19 } | 23 } |
| 20 | 24 |
| 21 namespace autofill { | 25 namespace autofill { |
| 22 | 26 |
| 27 class CreditCard; |
| 28 class LegalMessageLine; |
| 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 std::vector<scoped_ptr<LegalMessageLine>>& legal_messages() const { |
| 59 return legal_messages_; |
| 60 } |
| 61 |
| 62 // Called when a link in the legal message text was clicked. |
| 63 void OnLegalMessageLinkClicked(GURL url); |
| 64 |
| 42 private: | 65 private: |
| 43 AutofillCCInfoBarDelegate(bool upload, | 66 AutofillCCInfoBarDelegate(bool upload, |
| 67 const CreditCard& card, |
| 68 scoped_ptr<base::DictionaryValue> legal_message, |
| 44 const base::Closure& save_card_callback); | 69 const base::Closure& save_card_callback); |
| 45 ~AutofillCCInfoBarDelegate() override; | |
| 46 | 70 |
| 47 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); | 71 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); |
| 48 | 72 |
| 49 // ConfirmInfoBarDelegate: | 73 // ConfirmInfoBarDelegate: |
| 50 Type GetInfoBarType() const override; | 74 Type GetInfoBarType() const override; |
| 51 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 75 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 52 int GetIconId() const override; | 76 int GetIconId() const override; |
| 53 gfx::VectorIconId GetVectorIconId() const override; | 77 gfx::VectorIconId GetVectorIconId() const override; |
| 54 bool ShouldExpire(const NavigationDetails& details) const override; | 78 bool ShouldExpire(const NavigationDetails& details) const override; |
| 55 void InfoBarDismissed() override; | 79 void InfoBarDismissed() override; |
| 56 base::string16 GetMessageText() const override; | 80 base::string16 GetMessageText() const override; |
| 57 base::string16 GetButtonLabel(InfoBarButton button) const override; | 81 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 58 bool Accept() override; | 82 bool Accept() override; |
| 59 bool Cancel() override; | 83 bool Cancel() override; |
| 60 base::string16 GetLinkText() const override; | 84 base::string16 GetLinkText() const override; |
| 61 GURL GetLinkURL() const override; | 85 GURL GetLinkURL() const override; |
| 62 | 86 |
| 87 // Whether the infobar is for uploading the credit card. |
| 63 bool upload_; | 88 bool upload_; |
| 64 | 89 |
| 90 // The resource ID for the icon that identifies the issuer of the card. |
| 91 int issuer_icon_id_; |
| 92 |
| 93 // The label for the card to show in the content of the infobar. |
| 94 base::string16 card_label_; |
| 95 |
| 96 // The sub-label for the card to show in the content onf the infobar. |
| 97 base::string16 card_sub_label_; |
| 98 |
| 99 // The legal messages to show in the content of the infobar. |
| 100 std::vector<scoped_ptr<LegalMessageLine>> legal_messages_; |
| 101 |
| 65 // The callback to save credit card if the user accepts the infobar. | 102 // The callback to save credit card if the user accepts the infobar. |
| 66 base::Closure save_card_callback_; | 103 base::Closure save_card_callback_; |
| 67 | 104 |
| 68 // Did the user ever explicitly accept or dismiss this infobar? | 105 // Did the user ever explicitly accept or dismiss this infobar? |
| 69 bool had_user_interaction_; | 106 bool had_user_interaction_; |
| 70 | 107 |
| 71 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); | 108 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); |
| 72 | 109 |
| 73 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); | 110 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); |
| 74 }; | 111 }; |
| 75 | 112 |
| 76 } // namespace autofill | 113 } // namespace autofill |
| 77 | 114 |
| 78 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 115 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
| OLD | NEW |