Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: components/autofill/core/browser/autofill_cc_infobar_delegate.cc

Issue 1540423004: Add card details and legal message to Android save credit card infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial draft Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
17 #include "ui/gfx/vector_icons_public.h" 21 #include "ui/gfx/vector_icons_public.h"
18 #include "url/gurl.h" 22 #include "url/gurl.h"
19 23
20 namespace autofill { 24 namespace autofill {
25 namespace {
26
27 // Number of card details to show in the details section of the infobar.
28 const int kNumberOfCards = 1;
29
30 } // namespace
21 31
22 // static 32 // static
23 void AutofillCCInfoBarDelegate::CreateForLocalSave( 33 void AutofillCCInfoBarDelegate::CreateForLocalSave(
24 infobars::InfoBarManager* infobar_manager, 34 infobars::InfoBarManager* infobar_manager,
25 const base::Closure& save_card_callback) { 35 const base::Closure& save_card_callback,
26 infobar_manager->AddInfoBar( 36 const CreditCard& card) {
27 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( 37 scoped_ptr<base::DictionaryValue> no_legal_message;
28 new AutofillCCInfoBarDelegate(false, save_card_callback)))); 38 infobar_manager->AddInfoBar(infobar_manager->CreateConfirmInfoBar(
39 scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate(
40 false, save_card_callback, card, std::move(no_legal_message)))));
29 } 41 }
30 42
31 // static 43 // static
32 void AutofillCCInfoBarDelegate::CreateForUpload( 44 void AutofillCCInfoBarDelegate::CreateForUpload(
33 infobars::InfoBarManager* infobar_manager, 45 infobars::InfoBarManager* infobar_manager,
34 const base::Closure& save_card_callback) { 46 const base::Closure& save_card_callback,
35 infobar_manager->AddInfoBar( 47 const CreditCard& card,
36 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( 48 scoped_ptr<base::DictionaryValue> legal_message) {
37 new AutofillCCInfoBarDelegate(true, save_card_callback)))); 49 infobar_manager->AddInfoBar(infobar_manager->CreateConfirmInfoBar(
50 scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate(
51 true, save_card_callback, card, std::move(legal_message)))));
38 } 52 }
39 53
40 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( 54 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
41 bool upload, 55 bool upload,
42 const base::Closure& save_card_callback) 56 const base::Closure& save_card_callback,
57 const CreditCard& card,
58 scoped_ptr<base::DictionaryValue> legal_message)
43 : ConfirmInfoBarDelegate(), 59 : ConfirmInfoBarDelegate(),
44 upload_(upload), 60 upload_(upload),
45 save_card_callback_(save_card_callback), 61 save_card_callback_(save_card_callback),
62 card_details_(kNumberOfCards),
46 had_user_interaction_(false) { 63 had_user_interaction_(false) {
64 #if !defined(OS_IOS)
65 // TODO(rouslan): Use credit card issuer images on iOS.
66 // http://crbug.com/535784
67 card_details_.front().icon_id = CreditCard::IconResourceId(
68 CreditCard::GetCreditCardType(card.GetRawInfo(CREDIT_CARD_NUMBER)));
69 #endif
70
71 card_details_.front().label = card.LastFourDigitsForDisplay();
72 card_details_.front().sub_label = card.AbbreviatedExpirationDateForDisplay();
73
74 if (legal_message) {
75 LegalMessageLines parsed_legal_message;
76 LegalMessageLine::Parse(*legal_message, &parsed_legal_message);
77 for (const auto& line : parsed_legal_message) {
78 legal_messages_.push_back(Description());
79 legal_messages_.back().text = line.text();
Justin Donnelly 2015/12/30 18:06:37 When we discussed copying LegalMessage into anothe
please use gerrit instead 2016/01/07 01:39:25 Done.
80 for (const auto& link : line.links()) {
81 legal_messages_.back().links.push_back(Description::Link());
82 legal_messages_.back().links.back().start = link.range.start();
83 legal_messages_.back().links.back().end = link.range.end();
84 legal_messages_.back().links.back().url = link.url;
85 }
86 }
87 }
88
47 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); 89 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
48 } 90 }
49 91
50 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { 92 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() {
51 if (!had_user_interaction_) 93 if (!had_user_interaction_)
52 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); 94 LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
53 } 95 }
54 96
55 void AutofillCCInfoBarDelegate::LogUserAction( 97 void AutofillCCInfoBarDelegate::LogUserAction(
56 AutofillMetrics::InfoBarMetric user_action) { 98 AutofillMetrics::InfoBarMetric user_action) {
(...skipping 13 matching lines...) Expand all
70 } 112 }
71 113
72 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const { 114 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const {
73 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID) 115 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID)
74 return gfx::VectorIconId::AUTOFILL; 116 return gfx::VectorIconId::AUTOFILL;
75 #else 117 #else
76 return gfx::VectorIconId::VECTOR_ICON_NONE; 118 return gfx::VectorIconId::VECTOR_ICON_NONE;
77 #endif 119 #endif
78 } 120 }
79 121
122 const std::vector<infobars::InfoBarDelegate::Detail>&
123 AutofillCCInfoBarDelegate::GetDetails() const {
124 return card_details_;
125 }
126
127 const std::vector<infobars::InfoBarDelegate::Description>&
128 AutofillCCInfoBarDelegate::GetDescriptions() const {
129 return legal_messages_;
130 }
131
80 bool AutofillCCInfoBarDelegate::ShouldExpire( 132 bool AutofillCCInfoBarDelegate::ShouldExpire(
81 const NavigationDetails& details) const { 133 const NavigationDetails& details) const {
82 // The user has submitted a form, causing the page to navigate elsewhere. We 134 // The user has submitted a form, causing the page to navigate elsewhere. We
83 // don't want the infobar to be expired at this point, because the user won't 135 // don't want the infobar to be expired at this point, because the user won't
84 // get a chance to answer the question. 136 // get a chance to answer the question.
85 return false; 137 return false;
86 } 138 }
87 139
88 void AutofillCCInfoBarDelegate::InfoBarDismissed() { 140 void AutofillCCInfoBarDelegate::InfoBarDismissed() {
89 LogUserAction(AutofillMetrics::INFOBAR_DENIED); 141 LogUserAction(AutofillMetrics::INFOBAR_DENIED);
(...skipping 26 matching lines...) Expand all
116 168
117 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { 169 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const {
118 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 170 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
119 } 171 }
120 172
121 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { 173 GURL AutofillCCInfoBarDelegate::GetLinkURL() const {
122 return GURL(kHelpURL); 174 return GURL(kHelpURL);
123 } 175 }
124 176
125 } // namespace autofill 177 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698