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

Side by Side Diff: chrome/browser/autofill/wallet_infobar_delegate.cc

Issue 11539003: Pop up requestAutocomplete UI when autofill server hints chrome client that it is in a multipage au… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address initial comments Created 8 years 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
(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(const std::string& autocomplete_attribute) {
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() {
ahutter 2012/12/17 17:35:39 Should probably be static.
Raman Kakilate 2013/01/10 00:54:40 These are utility functions outside any object's s
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"));
ahutter 2012/12/17 17:35:39 Where's address line 2?
Raman Kakilate 2013/01/10 00:54:40 changed to street-address.
ahutter 2013/01/10 15:58:54 Not sure if it matters but Sugar expects address l
Albert Bodenhamer 2013/01/10 17:54:27 Autofill also handles Address line 1 and line 2 as
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 }
52
53 WalletInfoBarDelegate::WalletInfoBarDelegate(
54 InfoBarService* infobar_service,
55 AutofillManager* autofill_manager,
56 const AutofillMetrics* metric_logger,
57 const GURL& source_url,
58 const content::SSLStatus& ssl_status)
59 : ConfirmInfoBarDelegate(infobar_service),
60 metric_logger_(metric_logger),
61 autofill_manager_(autofill_manager),
62 source_url_(source_url),
63 ssl_status_(ssl_status),
64 had_user_interaction_(false) {
65 metric_logger_->LogWalletInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
66 }
67
68 WalletInfoBarDelegate::~WalletInfoBarDelegate() {
69 if (!had_user_interaction_)
70 LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
71 }
72
73 void WalletInfoBarDelegate::LogUserAction(
74 AutofillMetrics::InfoBarMetric user_action) {
75 DCHECK(!had_user_interaction_);
76 metric_logger_->LogWalletInfoBarMetric(user_action);
77 had_user_interaction_ = true;
78 }
79
80 bool WalletInfoBarDelegate::ShouldExpire(
81 const content::LoadCommittedDetails& details) const {
82 // The user has submitted a form, causing the page to navigate elsewhere. We
83 // want the infobar to be expired at this point, because the user has
84 // potentially started the checkout flow manually.
85 return true;
86 }
87
88 void WalletInfoBarDelegate::InfoBarDismissed() {
89 LogUserAction(AutofillMetrics::INFOBAR_DENIED);
90 }
91
92 gfx::Image* WalletInfoBarDelegate::GetIcon() const {
93 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
94 IDR_INFOBAR_AUTOFILL);
95 }
96
97 InfoBarDelegate::Type WalletInfoBarDelegate::GetInfoBarType() const {
98 return PAGE_ACTION_TYPE;
99 }
100
101 string16 WalletInfoBarDelegate::GetMessageText() const {
102 return l10n_util::GetStringUTF16(IDS_WALLET_AUTOFILL_INFOBAR_TEXT);
103 }
104
105 string16 WalletInfoBarDelegate::GetButtonLabel(InfoBarButton button) const {
106 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
107 IDS_WALLET_AUTOFILL_INFOBAR_ACCEPT : IDS_WALLET_AUTOFILL_INFOBAR_DENY);
108 }
109
110 bool WalletInfoBarDelegate::Accept() {
111 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
112 GURL frame_url;
113 content::SSLStatus ssl_status;
114
115 autofill_manager_->ShowWalletDialog(BuildWalletFormData(),
116 source_url_, ssl_status_);
117 return true;
118 }
119
120 bool WalletInfoBarDelegate::Cancel() {
121 LogUserAction(AutofillMetrics::INFOBAR_DENIED);
122 return true;
123 }
124
125 string16 WalletInfoBarDelegate::GetLinkText() const {
126 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
127 }
128
129 bool WalletInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
130 // TODO(ramankk): Fix the help URL when we have one.
131 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab(
132 owner()->GetWebContents(),
133 content::OpenURLParams(GURL(chrome::kAutofillHelpURL),
134 content::Referrer(),
135 NEW_FOREGROUND_TAB,
136 content::PAGE_TRANSITION_LINK,
137 false));
138 return false;
139 }
140
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698