OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" | 5 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "components/autofill/core/browser/credit_card.h" | 9 #include "components/autofill/core/browser/credit_card.h" |
10 #include "components/autofill/core/browser/personal_data_manager.h" | 10 #include "components/autofill/core/browser/personal_data_manager.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // static | 31 // static |
32 void AutofillCCInfoBarDelegate::CreateForUpload( | 32 void AutofillCCInfoBarDelegate::CreateForUpload( |
33 infobars::InfoBarManager* infobar_manager, | 33 infobars::InfoBarManager* infobar_manager, |
34 const base::Closure& save_card_callback) { | 34 const base::Closure& save_card_callback) { |
35 infobar_manager->AddInfoBar( | 35 infobar_manager->AddInfoBar( |
36 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 36 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
37 new AutofillCCInfoBarDelegate(true, save_card_callback)))); | 37 new AutofillCCInfoBarDelegate(true, save_card_callback)))); |
38 } | 38 } |
39 | 39 |
| 40 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { |
| 41 if (!had_user_interaction_) |
| 42 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); |
| 43 } |
| 44 |
| 45 int AutofillCCInfoBarDelegate::GetIconId() const { |
| 46 return IDR_INFOBAR_AUTOFILL_CC; |
| 47 } |
| 48 |
| 49 base::string16 AutofillCCInfoBarDelegate::GetMessageText() const { |
| 50 return l10n_util::GetStringUTF16( |
| 51 upload_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD |
| 52 : IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL); |
| 53 } |
| 54 |
| 55 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { |
| 56 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 57 } |
| 58 |
40 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | 59 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( |
41 bool upload, | 60 bool upload, |
42 const base::Closure& save_card_callback) | 61 const base::Closure& save_card_callback) |
43 : ConfirmInfoBarDelegate(), | 62 : ConfirmInfoBarDelegate(), |
44 upload_(upload), | 63 upload_(upload), |
45 save_card_callback_(save_card_callback), | 64 save_card_callback_(save_card_callback), |
46 had_user_interaction_(false) { | 65 had_user_interaction_(false) { |
47 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | 66 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); |
48 } | 67 } |
49 | 68 |
50 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | |
51 if (!had_user_interaction_) | |
52 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | |
53 } | |
54 | |
55 void AutofillCCInfoBarDelegate::LogUserAction( | 69 void AutofillCCInfoBarDelegate::LogUserAction( |
56 AutofillMetrics::InfoBarMetric user_action) { | 70 AutofillMetrics::InfoBarMetric user_action) { |
57 DCHECK(!had_user_interaction_); | 71 DCHECK(!had_user_interaction_); |
58 | 72 |
59 AutofillMetrics::LogCreditCardInfoBarMetric(user_action); | 73 AutofillMetrics::LogCreditCardInfoBarMetric(user_action); |
60 had_user_interaction_ = true; | 74 had_user_interaction_ = true; |
61 } | 75 } |
62 | 76 |
63 infobars::InfoBarDelegate::InfoBarIdentifier | 77 infobars::InfoBarDelegate::InfoBarIdentifier |
64 AutofillCCInfoBarDelegate::GetIdentifier() const { | 78 AutofillCCInfoBarDelegate::GetIdentifier() const { |
65 return AUTOFILL_CC_INFOBAR_DELEGATE; | 79 return AUTOFILL_CC_INFOBAR_DELEGATE; |
66 } | 80 } |
67 | 81 |
68 infobars::InfoBarDelegate::Type | 82 infobars::InfoBarDelegate::Type |
69 AutofillCCInfoBarDelegate::GetInfoBarType() const { | 83 AutofillCCInfoBarDelegate::GetInfoBarType() const { |
70 return PAGE_ACTION_TYPE; | 84 return PAGE_ACTION_TYPE; |
71 } | 85 } |
72 | 86 |
73 int AutofillCCInfoBarDelegate::GetIconId() const { | |
74 return IDR_INFOBAR_AUTOFILL_CC; | |
75 } | |
76 | |
77 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const { | 87 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const { |
78 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID) | 88 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID) |
79 return gfx::VectorIconId::AUTOFILL; | 89 return gfx::VectorIconId::AUTOFILL; |
80 #else | 90 #else |
81 return gfx::VectorIconId::VECTOR_ICON_NONE; | 91 return gfx::VectorIconId::VECTOR_ICON_NONE; |
82 #endif | 92 #endif |
83 } | 93 } |
84 | 94 |
85 bool AutofillCCInfoBarDelegate::ShouldExpire( | 95 bool AutofillCCInfoBarDelegate::ShouldExpire( |
86 const NavigationDetails& details) const { | 96 const NavigationDetails& details) const { |
87 // The user has submitted a form, causing the page to navigate elsewhere. We | 97 // The user has submitted a form, causing the page to navigate elsewhere. We |
88 // don't want the infobar to be expired at this point, because the user won't | 98 // don't want the infobar to be expired at this point, because the user won't |
89 // get a chance to answer the question. | 99 // get a chance to answer the question. |
90 return false; | 100 return false; |
91 } | 101 } |
92 | 102 |
93 void AutofillCCInfoBarDelegate::InfoBarDismissed() { | 103 void AutofillCCInfoBarDelegate::InfoBarDismissed() { |
94 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 104 LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
95 } | 105 } |
96 | 106 |
97 base::string16 AutofillCCInfoBarDelegate::GetMessageText() const { | |
98 return l10n_util::GetStringUTF16( | |
99 upload_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD | |
100 : IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL); | |
101 } | |
102 | |
103 base::string16 AutofillCCInfoBarDelegate::GetButtonLabel( | 107 base::string16 AutofillCCInfoBarDelegate::GetButtonLabel( |
104 InfoBarButton button) const { | 108 InfoBarButton button) const { |
105 return l10n_util::GetStringUTF16(button == BUTTON_OK | 109 return l10n_util::GetStringUTF16(button == BUTTON_OK |
106 ? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT | 110 ? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT |
107 : IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY); | 111 : IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY); |
108 } | 112 } |
109 | 113 |
110 bool AutofillCCInfoBarDelegate::Accept() { | 114 bool AutofillCCInfoBarDelegate::Accept() { |
111 save_card_callback_.Run(); | 115 save_card_callback_.Run(); |
112 save_card_callback_.Reset(); | 116 save_card_callback_.Reset(); |
113 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | 117 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); |
114 return true; | 118 return true; |
115 } | 119 } |
116 | 120 |
117 bool AutofillCCInfoBarDelegate::Cancel() { | 121 bool AutofillCCInfoBarDelegate::Cancel() { |
118 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 122 LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
119 return true; | 123 return true; |
120 } | 124 } |
121 | 125 |
122 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { | |
123 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
124 } | |
125 | |
126 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { | 126 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { |
127 return GURL(kHelpURL); | 127 return GURL(kHelpURL); |
128 } | 128 } |
129 | 129 |
130 } // namespace autofill | 130 } // namespace autofill |
OLD | NEW |