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 <utility> | |
8 | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | |
8 #include "build/build_config.h" | 11 #include "build/build_config.h" |
9 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
13 #include "components/autofill/core/browser/legal_message_line.h" | |
10 #include "components/autofill/core/browser/personal_data_manager.h" | 14 #include "components/autofill/core/browser/personal_data_manager.h" |
11 #include "components/autofill/core/common/autofill_constants.h" | 15 #include "components/autofill/core/common/autofill_constants.h" |
12 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
13 #include "components/infobars/core/infobar_manager.h" | 17 #include "components/infobars/core/infobar_manager.h" |
14 #include "grit/components_scaled_resources.h" | 18 #include "grit/components_scaled_resources.h" |
15 #include "grit/components_strings.h" | 19 #include "grit/components_strings.h" |
16 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/window_open_disposition.h" | |
17 #include "ui/gfx/vector_icons_public.h" | 22 #include "ui/gfx/vector_icons_public.h" |
18 #include "url/gurl.h" | 23 #include "url/gurl.h" |
19 | 24 |
20 namespace autofill { | 25 namespace autofill { |
21 | 26 |
22 // static | 27 // static |
23 void AutofillCCInfoBarDelegate::CreateForLocalSave( | 28 void AutofillCCInfoBarDelegate::CreateForLocalSave( |
24 infobars::InfoBarManager* infobar_manager, | 29 infobars::InfoBarManager* infobar_manager, |
30 const CreditCard& card, | |
25 const base::Closure& save_card_callback) { | 31 const base::Closure& save_card_callback) { |
26 infobar_manager->AddInfoBar( | 32 infobar_manager->AddInfoBar(infobar_manager->CreateAutofillCCInfoBar( |
27 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 33 make_scoped_ptr(new AutofillCCInfoBarDelegate( |
28 new AutofillCCInfoBarDelegate(false, save_card_callback)))); | 34 false, card, scoped_ptr<base::DictionaryValue>(nullptr), |
35 save_card_callback)))); | |
29 } | 36 } |
30 | 37 |
31 // static | 38 // static |
32 void AutofillCCInfoBarDelegate::CreateForUpload( | 39 void AutofillCCInfoBarDelegate::CreateForUpload( |
33 infobars::InfoBarManager* infobar_manager, | 40 infobars::InfoBarManager* infobar_manager, |
41 const CreditCard& card, | |
42 scoped_ptr<base::DictionaryValue> legal_message, | |
34 const base::Closure& save_card_callback) { | 43 const base::Closure& save_card_callback) { |
35 infobar_manager->AddInfoBar( | 44 infobar_manager->AddInfoBar(infobar_manager->CreateAutofillCCInfoBar( |
36 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 45 make_scoped_ptr(new AutofillCCInfoBarDelegate( |
37 new AutofillCCInfoBarDelegate(true, save_card_callback)))); | 46 true, card, std::move(legal_message), save_card_callback)))); |
38 } | |
39 | |
40 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | |
41 bool upload, | |
42 const base::Closure& save_card_callback) | |
43 : ConfirmInfoBarDelegate(), | |
44 upload_(upload), | |
45 save_card_callback_(save_card_callback), | |
46 had_user_interaction_(false) { | |
47 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
48 } | 47 } |
49 | 48 |
50 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | 49 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { |
51 if (!had_user_interaction_) | 50 if (!had_user_interaction_) |
52 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | 51 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); |
53 } | 52 } |
54 | 53 |
54 void AutofillCCInfoBarDelegate::OnLegalMessageLinkClicked(GURL url) { | |
55 infobar()->owner()->OpenURL(url, NEW_FOREGROUND_TAB); | |
56 } | |
57 | |
58 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | |
59 bool upload, | |
60 const CreditCard& card, | |
61 scoped_ptr<base::DictionaryValue> legal_message, | |
62 const base::Closure& save_card_callback) | |
63 : ConfirmInfoBarDelegate(), | |
64 upload_(upload), | |
65 #if defined(OS_IOS) | |
66 // TODO(rouslan): Use credit card issuer images on iOS. | |
67 // http://crbug.com/535784 | |
68 issuer_icon_id_(kNoIconID), | |
69 #else | |
70 issuer_icon_id_(CreditCard::IconResourceId( | |
71 CreditCard::GetCreditCardType(card.GetRawInfo(CREDIT_CARD_NUMBER)))), | |
72 #endif // defined(OS_IOS) | |
73 card_label_(card.LastFourDigitsForDisplay()), | |
74 card_sub_label_(card.AbbreviatedExpirationDateForDisplay()), | |
75 save_card_callback_(save_card_callback), | |
76 had_user_interaction_(false) { | |
77 if (legal_message) { | |
Peter Kasting
2016/01/08 00:34:31
Nit: {} unnecessary
please use gerrit instead
2016/01/12 00:47:25
Done.
| |
78 LegalMessageLine::Parse(*legal_message, &legal_messages_); | |
79 } | |
80 | |
81 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
82 } | |
83 | |
55 void AutofillCCInfoBarDelegate::LogUserAction( | 84 void AutofillCCInfoBarDelegate::LogUserAction( |
56 AutofillMetrics::InfoBarMetric user_action) { | 85 AutofillMetrics::InfoBarMetric user_action) { |
57 DCHECK(!had_user_interaction_); | 86 DCHECK(!had_user_interaction_); |
58 | 87 |
59 AutofillMetrics::LogCreditCardInfoBarMetric(user_action); | 88 AutofillMetrics::LogCreditCardInfoBarMetric(user_action); |
60 had_user_interaction_ = true; | 89 had_user_interaction_ = true; |
61 } | 90 } |
62 | 91 |
63 infobars::InfoBarDelegate::InfoBarIdentifier | 92 infobars::InfoBarDelegate::InfoBarIdentifier |
64 AutofillCCInfoBarDelegate::GetIdentifier() const { | 93 AutofillCCInfoBarDelegate::GetIdentifier() const { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 | 150 |
122 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { | 151 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { |
123 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 152 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
124 } | 153 } |
125 | 154 |
126 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { | 155 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { |
127 return GURL(kHelpURL); | 156 return GURL(kHelpURL); |
128 } | 157 } |
129 | 158 |
130 } // namespace autofill | 159 } // namespace autofill |
OLD | NEW |