OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/autofill/wallet_infobar_delegate.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/api/infobars/infobar_service.h" | |
10 #include "chrome/browser/autofill/autofill_manager.h" | |
11 #include "chrome/browser/autofill/personal_data_manager.h" | |
12 #include "chrome/common/form_data.h" | |
13 #include "chrome/common/url_constants.h" | |
14 #include "content/public/browser/page_navigator.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/browser/web_contents_delegate.h" | |
17 #include "grit/generated_resources.h" | |
18 #include "grit/theme_resources.h" | |
19 #include "ui/base/l10n/l10n_util.h" | |
20 #include "ui/base/resource/resource_bundle.h" | |
21 | |
22 | |
23 FormFieldData BuildField(std::string autocomplete_attribute) { | |
Ilya Sherman
2012/12/13 02:29:23
nit: Pass by const reference
Raman Kakilate
2012/12/13 21:34:34
Done.
| |
24 FormFieldData field; | |
25 field.name = string16(); | |
26 field.value = string16(); | |
27 field.autocomplete_attribute = autocomplete_attribute; | |
28 field.form_control_type = "text"; | |
29 return field; | |
30 } | |
31 | |
32 FormData BuildWalletFormData() { | |
33 FormData formdata; | |
34 formdata.fields.push_back(BuildField("name")); | |
35 formdata.fields.push_back(BuildField("email")); | |
36 formdata.fields.push_back(BuildField("cc-name")); | |
37 formdata.fields.push_back(BuildField("cc-number")); | |
38 formdata.fields.push_back(BuildField("cc-exp")); | |
39 formdata.fields.push_back(BuildField("cc-csc")); | |
40 formdata.fields.push_back(BuildField("billing address-line1")); | |
Ilya Sherman
2012/12/13 23:23:18
This should be street-address; or else you should
| |
41 formdata.fields.push_back(BuildField("billing locality")); | |
42 formdata.fields.push_back(BuildField("billing region")); | |
43 formdata.fields.push_back(BuildField("billing country")); | |
44 formdata.fields.push_back(BuildField("billing postal-code")); | |
45 formdata.fields.push_back(BuildField("shipping address-line1")); | |
46 formdata.fields.push_back(BuildField("shipping locality")); | |
47 formdata.fields.push_back(BuildField("shipping region")); | |
48 formdata.fields.push_back(BuildField("shipping country")); | |
49 formdata.fields.push_back(BuildField("shipping postal-code")); | |
50 return formdata; | |
51 } | |
Ilya Sherman
2012/12/13 02:29:23
These functions have nothing to do with the infoba
Raman Kakilate
2012/12/13 21:34:34
Given that this infobar will be close to wallet, I
Ilya Sherman
2012/12/13 23:23:18
I am strongly inclined for the code not to live in
| |
52 | |
53 WalletInfoBarDelegate::WalletInfoBarDelegate( | |
54 InfoBarService* infobar_service, | |
55 PersonalDataManager* personal_data, | |
56 AutofillManager* autofill_mgr, | |
57 const AutofillMetrics* metric_logger, | |
58 const GURL& source_url, | |
59 const content::SSLStatus& ssl_status) | |
60 : ConfirmInfoBarDelegate(infobar_service), | |
61 personal_data_(personal_data), | |
62 metric_logger_(metric_logger), | |
63 autofill_mgr_(autofill_mgr), | |
64 source_url_(source_url), | |
65 ssl_status_(ssl_status), | |
66 had_user_interaction_(false) { | |
67 metric_logger_->LogWalletInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
68 } | |
69 | |
70 WalletInfoBarDelegate::~WalletInfoBarDelegate() { | |
71 if (!had_user_interaction_) | |
72 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | |
73 } | |
74 | |
75 void WalletInfoBarDelegate::LogUserAction( | |
76 AutofillMetrics::InfoBarMetric user_action) { | |
77 DCHECK(!had_user_interaction_); | |
78 metric_logger_->LogWalletInfoBarMetric(user_action); | |
79 had_user_interaction_ = true; | |
80 } | |
81 | |
82 bool WalletInfoBarDelegate::ShouldExpire( | |
83 const content::LoadCommittedDetails& details) const { | |
84 // The user has submitted a form, causing the page to navigate elsewhere. We | |
85 // want the infobar to be expired at this point, because the user has | |
86 // potentially started the checkout flow manually. | |
87 return true; | |
88 } | |
89 | |
90 void WalletInfoBarDelegate::InfoBarDismissed() { | |
91 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
92 } | |
93 | |
94 gfx::Image* WalletInfoBarDelegate::GetIcon() const { | |
95 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
96 IDR_INFOBAR_AUTOFILL); | |
97 } | |
98 | |
99 InfoBarDelegate::Type WalletInfoBarDelegate::GetInfoBarType() const { | |
100 return PAGE_ACTION_TYPE; | |
101 } | |
102 | |
103 string16 WalletInfoBarDelegate::GetMessageText() const { | |
104 return l10n_util::GetStringUTF16(IDS_WALLET_AUTOFILL_INFOBAR_TEXT); | |
105 } | |
106 | |
107 string16 WalletInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { | |
108 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
109 IDS_WALLET_AUTOFILL_INFOBAR_ACCEPT : IDS_WALLET_AUTOFILL_INFOBAR_DENY); | |
110 } | |
111 | |
112 bool WalletInfoBarDelegate::Accept() { | |
113 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | |
114 GURL frame_url; | |
115 content::SSLStatus ssl_status; | |
116 | |
117 autofill_mgr_->ShowWalletDialog(BuildWalletFormData(), | |
118 source_url_, ssl_status_); | |
119 return true; | |
120 } | |
121 | |
122 bool WalletInfoBarDelegate::Cancel() { | |
123 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
124 return true; | |
125 } | |
126 | |
127 string16 WalletInfoBarDelegate::GetLinkText() const { | |
128 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
129 } | |
130 | |
131 bool WalletInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | |
132 // TODO(ramankk): Fix the help URL when we have one. | |
133 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( | |
134 owner()->GetWebContents(), | |
135 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), | |
136 content::Referrer(), | |
137 NEW_FOREGROUND_TAB, | |
138 content::PAGE_TRANSITION_LINK, | |
139 false)); | |
140 return false; | |
141 } | |
142 | |
OLD | NEW |