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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 22009003: [Autofill] Distinguish between native field types and potentially HTML field types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 // Returns true if |card_type| is supported by Wallet. 106 // Returns true if |card_type| is supported by Wallet.
107 bool IsWalletSupportedCard(const std::string& card_type) { 107 bool IsWalletSupportedCard(const std::string& card_type) {
108 return card_type == autofill::kVisaCard || 108 return card_type == autofill::kVisaCard ||
109 card_type == autofill::kMasterCard || 109 card_type == autofill::kMasterCard ||
110 card_type == autofill::kDiscoverCard; 110 card_type == autofill::kDiscoverCard;
111 } 111 }
112 112
113 // Returns true if |input| should be shown when |field_type| has been requested. 113 // Returns true if |input| should be shown when |field_type| has been requested.
114 bool InputTypeMatchesFieldType(const DetailInput& input, 114 bool InputTypeMatchesFieldType(const DetailInput& input,
115 AutofillFieldType field_type) { 115 const AutofillType& field_type) {
116 // If any credit card expiration info is asked for, show both month and year 116 // If any credit card expiration info is asked for, show both month and year
117 // inputs. 117 // inputs.
118 if (field_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || 118 if (field_type.server_type() == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
119 field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || 119 field_type.server_type() == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
120 field_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || 120 field_type.server_type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
121 field_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || 121 field_type.server_type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
122 field_type == CREDIT_CARD_EXP_MONTH) { 122 field_type.server_type() == CREDIT_CARD_EXP_MONTH) {
123 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || 123 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
124 input.type == CREDIT_CARD_EXP_MONTH; 124 input.type == CREDIT_CARD_EXP_MONTH;
125 } 125 }
126 126
127 if (field_type == CREDIT_CARD_TYPE) 127 if (field_type.server_type() == CREDIT_CARD_TYPE)
128 return input.type == CREDIT_CARD_NUMBER; 128 return input.type == CREDIT_CARD_NUMBER;
129 129
130 return input.type == field_type; 130 return input.type == field_type.server_type();
131 } 131 }
132 132
133 // Returns true if |input| in the given |section| should be used for a 133 // Returns true if |input| in the given |section| should be used for a
134 // site-requested |field|. 134 // site-requested |field|.
135 bool DetailInputMatchesField(DialogSection section, 135 bool DetailInputMatchesField(DialogSection section,
136 const DetailInput& input, 136 const DetailInput& input,
137 const AutofillField& field) { 137 const AutofillField& field) {
138 AutofillType field_type = field.Type();
139
138 // The credit card name is filled from the billing section's data. 140 // The credit card name is filled from the billing section's data.
139 if (field.type() == CREDIT_CARD_NAME && 141 if (field_type.server_type() == CREDIT_CARD_NAME &&
140 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) { 142 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
141 return input.type == NAME_BILLING_FULL; 143 return input.type == NAME_BILLING_FULL;
142 } 144 }
143 145
144 return InputTypeMatchesFieldType(input, field.type()); 146 return InputTypeMatchesFieldType(input, field_type);
145 } 147 }
146 148
147 bool IsCreditCardType(AutofillFieldType type) { 149 bool IsCreditCardType(ServerFieldType type) {
148 return AutofillType(type).group() == CREDIT_CARD; 150 return AutofillType(type).group() == CREDIT_CARD;
149 } 151 }
150 152
151 // Returns true if |input| should be used to fill a site-requested |field| which 153 // Returns true if |input| should be used to fill a site-requested |field| which
152 // is notated with a "shipping" tag, for use when the user has decided to use 154 // is notated with a "shipping" tag, for use when the user has decided to use
153 // the billing address as the shipping address. 155 // the billing address as the shipping address.
154 bool DetailInputMatchesShippingField(const DetailInput& input, 156 bool DetailInputMatchesShippingField(const DetailInput& input,
155 const AutofillField& field) { 157 const AutofillField& field) {
156 // Equivalent billing field type is used to support UseBillingAsShipping 158 // Equivalent billing field type is used to support UseBillingAsShipping
157 // usecase. 159 // usecase.
158 AutofillFieldType field_type = 160 ServerFieldType field_type =
159 AutofillType::GetEquivalentBillingFieldType(field.type()); 161 AutofillType::GetEquivalentBillingFieldType(field.Type().server_type());
160 162
161 return InputTypeMatchesFieldType(input, field_type); 163 return InputTypeMatchesFieldType(input, AutofillType(field_type));
162 } 164 }
163 165
164 // Constructs |inputs| from template data. 166 // Constructs |inputs| from template data.
165 void BuildInputs(const DetailInput* input_template, 167 void BuildInputs(const DetailInput* input_template,
166 size_t template_size, 168 size_t template_size,
167 DetailInputs* inputs) { 169 DetailInputs* inputs) {
168 for (size_t i = 0; i < template_size; ++i) { 170 for (size_t i = 0; i < template_size; ++i) {
169 const DetailInput* input = &input_template[i]; 171 const DetailInput* input = &input_template[i];
170 inputs->push_back(*input); 172 inputs->push_back(*input);
171 } 173 }
172 } 174 }
173 175
174 // Initializes |form_group| from user-entered data. 176 // Initializes |form_group| from user-entered data.
175 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, 177 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs,
176 FormGroup* form_group) { 178 FormGroup* form_group) {
177 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); 179 for (DetailOutputMap::const_iterator iter = detail_outputs.begin();
178 iter != detail_outputs.end(); ++iter) { 180 iter != detail_outputs.end(); ++iter) {
181 ServerFieldType type = iter->first->type;
179 if (!iter->second.empty()) { 182 if (!iter->second.empty()) {
180 AutofillFieldType type = iter->first->type;
181 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { 183 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) {
182 form_group->SetInfo(type, 184 form_group->SetInfo(AutofillType(type),
183 iter->second, 185 iter->second,
184 g_browser_process->GetApplicationLocale()); 186 g_browser_process->GetApplicationLocale());
185 } else { 187 } else {
186 form_group->SetRawInfo(iter->first->type, iter->second); 188 form_group->SetRawInfo(type, iter->second);
187 } 189 }
188 } 190 }
189 } 191 }
190 } 192 }
191 193
192 // Get billing info from |output| and put it into |card|, |cvc|, and |profile|. 194 // Get billing info from |output| and put it into |card|, |cvc|, and |profile|.
193 // These outparams are required because |card|/|profile| accept different types 195 // These outparams are required because |card|/|profile| accept different types
194 // of raw info, and CreditCard doesn't save CVCs. 196 // of raw info, and CreditCard doesn't save CVCs.
195 void GetBillingInfoFromOutputs(const DetailOutputMap& output, 197 void GetBillingInfoFromOutputs(const DetailOutputMap& output,
196 CreditCard* card, 198 CreditCard* card,
197 string16* cvc, 199 string16* cvc,
198 AutofillProfile* profile) { 200 AutofillProfile* profile) {
199 for (DetailOutputMap::const_iterator it = output.begin(); 201 for (DetailOutputMap::const_iterator it = output.begin();
200 it != output.end(); ++it) { 202 it != output.end(); ++it) {
201 string16 trimmed; 203 string16 trimmed;
202 TrimWhitespace(it->second, TRIM_ALL, &trimmed); 204 TrimWhitespace(it->second, TRIM_ALL, &trimmed);
203 205
204 // Special case CVC as CreditCard just swallows it. 206 // Special case CVC as CreditCard just swallows it.
205 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { 207 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) {
206 if (cvc) 208 if (cvc)
207 cvc->assign(trimmed); 209 cvc->assign(trimmed);
208 } else if (it->first->type == ADDRESS_HOME_COUNTRY || 210 } else if (it->first->type == ADDRESS_HOME_COUNTRY ||
209 it->first->type == ADDRESS_BILLING_COUNTRY) { 211 it->first->type == ADDRESS_BILLING_COUNTRY) {
210 if (profile) { 212 if (profile) {
211 profile->SetInfo(it->first->type, 213 profile->SetInfo(AutofillType(it->first->type),
212 trimmed, 214 trimmed,
213 g_browser_process->GetApplicationLocale()); 215 g_browser_process->GetApplicationLocale());
214 } 216 }
215 } else { 217 } else {
216 // Copy the credit card name to |profile| in addition to |card| as 218 // Copy the credit card name to |profile| in addition to |card| as
217 // wallet::Instrument requires a recipient name for its billing address. 219 // wallet::Instrument requires a recipient name for its billing address.
218 if (card && it->first->type == NAME_FULL) 220 if (card && it->first->type == NAME_FULL)
219 card->SetRawInfo(CREDIT_CARD_NAME, trimmed); 221 card->SetRawInfo(CREDIT_CARD_NAME, trimmed);
220 222
221 if (IsCreditCardType(it->first->type)) { 223 if (IsCreditCardType(it->first->type)) {
(...skipping 19 matching lines...) Expand all
241 web_contents->GetView()->GetTopLevelNativeWindow(); 243 web_contents->GetView()->GetTopLevelNativeWindow();
242 apps::ShellWindow* shell_window = 244 apps::ShellWindow* shell_window =
243 extensions::ShellWindowRegistry:: 245 extensions::ShellWindowRegistry::
244 GetShellWindowForNativeWindowAnyProfile(native_window); 246 GetShellWindowForNativeWindowAnyProfile(native_window);
245 return shell_window->GetBaseWindow(); 247 return shell_window->GetBaseWindow();
246 } 248 }
247 249
248 // Extracts the string value of a field with |type| from |output|. This is 250 // Extracts the string value of a field with |type| from |output|. This is
249 // useful when you only need the value of 1 input from a section of view inputs. 251 // useful when you only need the value of 1 input from a section of view inputs.
250 string16 GetValueForType(const DetailOutputMap& output, 252 string16 GetValueForType(const DetailOutputMap& output,
251 AutofillFieldType type) { 253 ServerFieldType type) {
252 for (DetailOutputMap::const_iterator it = output.begin(); 254 for (DetailOutputMap::const_iterator it = output.begin();
253 it != output.end(); ++it) { 255 it != output.end(); ++it) {
254 if (it->first->type == type) 256 if (it->first->type == type)
255 return it->second; 257 return it->second;
256 } 258 }
257 NOTREACHED(); 259 NOTREACHED();
258 return string16(); 260 return string16();
259 } 261 }
260 262
261 // Returns a string descriptor for a DialogSection, for use with prefs (do not 263 // Returns a string descriptor for a DialogSection, for use with prefs (do not
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 309 }
308 310
309 // Returns whether |data_model| is complete, i.e. can fill out all the 311 // Returns whether |data_model| is complete, i.e. can fill out all the
310 // |requested_fields|, and verified, i.e. not just automatically aggregated. 312 // |requested_fields|, and verified, i.e. not just automatically aggregated.
311 // Incomplete or unverifed data will not be displayed in the dropdown menu. 313 // Incomplete or unverifed data will not be displayed in the dropdown menu.
312 bool HasCompleteAndVerifiedData(const AutofillDataModel& data_model, 314 bool HasCompleteAndVerifiedData(const AutofillDataModel& data_model,
313 const DetailInputs& requested_fields) { 315 const DetailInputs& requested_fields) {
314 if (!data_model.IsVerified()) 316 if (!data_model.IsVerified())
315 return false; 317 return false;
316 318
317 const std::string app_locale = g_browser_process->GetApplicationLocale();
318 for (size_t i = 0; i < requested_fields.size(); ++i) { 319 for (size_t i = 0; i < requested_fields.size(); ++i) {
319 AutofillFieldType type = requested_fields[i].type; 320 ServerFieldType type = requested_fields[i].type;
320 if (type != ADDRESS_HOME_LINE2 && 321 if (type != ADDRESS_HOME_LINE2 &&
321 type != CREDIT_CARD_VERIFICATION_CODE && 322 type != CREDIT_CARD_VERIFICATION_CODE &&
322 data_model.GetInfo(type, app_locale).empty()) { 323 data_model.GetRawInfo(type).empty()) {
323 return false; 324 return false;
324 } 325 }
325 } 326 }
326 327
327 return true; 328 return true;
328 } 329 }
329 330
330 // Returns true if |profile| has an invalid address, i.e. an invalid state, zip 331 // Returns true if |profile| has an invalid address, i.e. an invalid state, zip
331 // code, or phone number. Otherwise returns false. Profiles with invalid 332 // code, or phone number. Otherwise returns false. Profiles with invalid
332 // addresses are not suggested in the dropdown menu for billing and shipping 333 // addresses are not suggested in the dropdown menu for billing and shipping
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 843
843 state.strings.push_back(DialogOverlayString()); 844 state.strings.push_back(DialogOverlayString());
844 DialogOverlayString& string = state.strings.back(); 845 DialogOverlayString& string = state.strings.back();
845 #if !defined(OS_ANDROID) 846 #if !defined(OS_ANDROID)
846 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref. 847 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref.
847 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); 848 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4);
848 #endif 849 #endif
849 850
850 // First-run, post-submit, Wallet expository page. 851 // First-run, post-submit, Wallet expository page.
851 if (full_wallet_ && full_wallet_->required_actions().empty()) { 852 if (full_wallet_ && full_wallet_->required_actions().empty()) {
852 string16 cc_number = full_wallet_->GetInfo(CREDIT_CARD_NUMBER); 853 string16 cc_number =
854 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER));
853 DCHECK_EQ(16U, cc_number.size()); 855 DCHECK_EQ(16U, cc_number.size());
854 state.image = GetGeneratedCardImage( 856 state.image = GetGeneratedCardImage(
855 ASCIIToUTF16("xxxx xxxx xxxx ") + 857 ASCIIToUTF16("xxxx xxxx xxxx ") +
856 cc_number.substr(cc_number.size() - 4)); 858 cc_number.substr(cc_number.size() - 4));
857 string.text = l10n_util::GetStringUTF16( 859 string.text = l10n_util::GetStringUTF16(
858 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE); 860 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE);
859 string.text_color = SK_ColorBLACK; 861 string.text_color = SK_ColorBLACK;
860 string.alignment = gfx::ALIGN_CENTER; 862 string.alignment = gfx::ALIGN_CENTER;
861 863
862 state.strings.push_back(DialogOverlayString()); 864 state.strings.push_back(DialogOverlayString());
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 return requested_cc_billing_fields_; 1192 return requested_cc_billing_fields_;
1191 case SECTION_SHIPPING: 1193 case SECTION_SHIPPING:
1192 return requested_shipping_fields_; 1194 return requested_shipping_fields_;
1193 } 1195 }
1194 1196
1195 NOTREACHED(); 1197 NOTREACHED();
1196 return requested_billing_fields_; 1198 return requested_billing_fields_;
1197 } 1199 }
1198 1200
1199 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( 1201 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
1200 AutofillFieldType type) { 1202 ServerFieldType type) {
1201 switch (AutofillType::GetEquivalentFieldType(type)) { 1203 switch (AutofillType::GetEquivalentFieldType(type)) {
1202 case CREDIT_CARD_EXP_MONTH: 1204 case CREDIT_CARD_EXP_MONTH:
1203 return &cc_exp_month_combobox_model_; 1205 return &cc_exp_month_combobox_model_;
1204 1206
1205 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1207 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1206 return &cc_exp_year_combobox_model_; 1208 return &cc_exp_year_combobox_model_;
1207 1209
1208 case ADDRESS_HOME_COUNTRY: 1210 case ADDRESS_HOME_COUNTRY:
1209 return &country_combobox_model_; 1211 return &country_combobox_model_;
1210 1212
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 GetDialogType(), DialogSectionToUiEditEvent(section)); 1499 GetDialogType(), DialogSectionToUiEditEvent(section));
1498 } 1500 }
1499 1501
1500 void AutofillDialogControllerImpl::EditCancelledForSection( 1502 void AutofillDialogControllerImpl::EditCancelledForSection(
1501 DialogSection section) { 1503 DialogSection section) {
1502 ResetSectionInput(section); 1504 ResetSectionInput(section);
1503 UpdateSection(section); 1505 UpdateSection(section);
1504 } 1506 }
1505 1507
1506 gfx::Image AutofillDialogControllerImpl::IconForField( 1508 gfx::Image AutofillDialogControllerImpl::IconForField(
1507 AutofillFieldType type, const string16& user_input) const { 1509 ServerFieldType type, const string16& user_input) const {
1508 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1510 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1509 if (type == CREDIT_CARD_VERIFICATION_CODE) 1511 if (type == CREDIT_CARD_VERIFICATION_CODE)
1510 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 1512 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
1511 1513
1512 // For the credit card, we show a few grayscale images, and possibly one 1514 // For the credit card, we show a few grayscale images, and possibly one
1513 // color image if |user_input| is a valid card number. 1515 // color image if |user_input| is a valid card number.
1514 if (type == CREDIT_CARD_NUMBER) { 1516 if (type == CREDIT_CARD_NUMBER) {
1515 const int card_idrs[] = { 1517 const int card_idrs[] = {
1516 IDR_AUTOFILL_CC_VISA, 1518 IDR_AUTOFILL_CC_VISA,
1517 IDR_AUTOFILL_CC_MASTERCARD, 1519 IDR_AUTOFILL_CC_MASTERCARD,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 return gfx::Image(skia); 1551 return gfx::Image(skia);
1550 } 1552 }
1551 1553
1552 return gfx::Image(); 1554 return gfx::Image();
1553 } 1555 }
1554 1556
1555 // TODO(estade): Replace all the error messages here with more helpful and 1557 // TODO(estade): Replace all the error messages here with more helpful and
1556 // translateable ones. TODO(groby): Also add tests. 1558 // translateable ones. TODO(groby): Also add tests.
1557 string16 AutofillDialogControllerImpl::InputValidityMessage( 1559 string16 AutofillDialogControllerImpl::InputValidityMessage(
1558 DialogSection section, 1560 DialogSection section,
1559 AutofillFieldType type, 1561 ServerFieldType type,
1560 const string16& value) { 1562 const string16& value) {
1561 // If the field is edited, clear any Wallet errors. 1563 // If the field is edited, clear any Wallet errors.
1562 if (IsPayingWithWallet()) { 1564 if (IsPayingWithWallet()) {
1563 WalletValidationErrors::iterator it = wallet_errors_.find(section); 1565 WalletValidationErrors::iterator it = wallet_errors_.find(section);
1564 if (it != wallet_errors_.end()) { 1566 if (it != wallet_errors_.end()) {
1565 TypeErrorInputMap::const_iterator iter = it->second.find(type); 1567 TypeErrorInputMap::const_iterator iter = it->second.find(type);
1566 if (iter != it->second.end()) { 1568 if (iter != it->second.end()) {
1567 if (iter->second.second == value) 1569 if (iter->second.second == value)
1568 return iter->second.first; 1570 return iter->second.first;
1569 it->second.erase(type); 1571 it->second.erase(type);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 base::string16(); 1651 base::string16();
1650 } 1652 }
1651 1653
1652 // TODO(estade): Replace all the error messages here with more helpful and 1654 // TODO(estade): Replace all the error messages here with more helpful and
1653 // translateable ones. TODO(groby): Also add tests. 1655 // translateable ones. TODO(groby): Also add tests.
1654 ValidityData AutofillDialogControllerImpl::InputsAreValid( 1656 ValidityData AutofillDialogControllerImpl::InputsAreValid(
1655 DialogSection section, 1657 DialogSection section,
1656 const DetailOutputMap& inputs, 1658 const DetailOutputMap& inputs,
1657 ValidationType validation_type) { 1659 ValidationType validation_type) {
1658 ValidityData invalid_messages; 1660 ValidityData invalid_messages;
1659 std::map<AutofillFieldType, string16> field_values; 1661 std::map<ServerFieldType, string16> field_values;
1660 for (DetailOutputMap::const_iterator iter = inputs.begin(); 1662 for (DetailOutputMap::const_iterator iter = inputs.begin();
1661 iter != inputs.end(); ++iter) { 1663 iter != inputs.end(); ++iter) {
1662 // Skip empty fields in edit mode. 1664 // Skip empty fields in edit mode.
1663 if (validation_type == VALIDATE_EDIT && iter->second.empty()) 1665 if (validation_type == VALIDATE_EDIT && iter->second.empty())
1664 continue; 1666 continue;
1665 1667
1666 const AutofillFieldType type = iter->first->type; 1668 const ServerFieldType type = iter->first->type;
1667 string16 message = InputValidityMessage(section, type, iter->second); 1669 string16 message = InputValidityMessage(section, type, iter->second);
1668 if (!message.empty()) 1670 if (!message.empty())
1669 invalid_messages[type] = message; 1671 invalid_messages[type] = message;
1670 else 1672 else
1671 field_values[type] = iter->second; 1673 field_values[type] = iter->second;
1672 } 1674 }
1673 1675
1674 // Validate the date formed by month and year field. (Autofill dialog is 1676 // Validate the date formed by month and year field. (Autofill dialog is
1675 // never supposed to have 2-digit years, so not checked). 1677 // never supposed to have 2-digit years, so not checked).
1676 if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) && 1678 if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) &&
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 1744
1743 // If the user clicks while the popup is already showing, be sure to hide 1745 // If the user clicks while the popup is already showing, be sure to hide
1744 // it. 1746 // it.
1745 if (!was_edit && popup_controller_.get()) { 1747 if (!was_edit && popup_controller_.get()) {
1746 HidePopup(); 1748 HidePopup();
1747 return; 1749 return;
1748 } 1750 }
1749 1751
1750 std::vector<string16> popup_values, popup_labels, popup_icons; 1752 std::vector<string16> popup_values, popup_labels, popup_icons;
1751 if (IsCreditCardType(input->type)) { 1753 if (IsCreditCardType(input->type)) {
1752 GetManager()->GetCreditCardSuggestions(input->type, 1754 GetManager()->GetCreditCardSuggestions(AutofillType(input->type),
1753 field_contents, 1755 field_contents,
1754 &popup_values, 1756 &popup_values,
1755 &popup_labels, 1757 &popup_labels,
1756 &popup_icons, 1758 &popup_icons,
1757 &popup_guids_); 1759 &popup_guids_);
1758 } else { 1760 } else {
1759 std::vector<AutofillFieldType> field_types; 1761 std::vector<ServerFieldType> field_types;
1760 field_types.push_back(EMAIL_ADDRESS); 1762 field_types.push_back(EMAIL_ADDRESS);
1761 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); 1763 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin();
1762 iter != requested_shipping_fields_.end(); ++iter) { 1764 iter != requested_shipping_fields_.end(); ++iter) {
1763 field_types.push_back(iter->type); 1765 field_types.push_back(iter->type);
1764 } 1766 }
1765 GetManager()->GetProfileSuggestions(input->type, 1767 GetManager()->GetProfileSuggestions(AutofillType(input->type),
1766 field_contents, 1768 field_contents,
1767 false, 1769 false,
1768 field_types, 1770 field_types,
1769 &popup_values, 1771 &popup_values,
1770 &popup_labels, 1772 &popup_labels,
1771 &popup_icons, 1773 &popup_icons,
1772 &popup_guids_); 1774 &popup_guids_);
1773 } 1775 }
1774 1776
1775 if (popup_values.empty()) { 1777 if (popup_values.empty()) {
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 if (popup_controller_.get()) 2319 if (popup_controller_.get())
2318 return popup_controller_->HandleKeyPressEvent(event); 2320 return popup_controller_->HandleKeyPressEvent(event);
2319 2321
2320 return false; 2322 return false;
2321 } 2323 }
2322 2324
2323 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { 2325 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
2324 DCHECK_GT(form_structure_.field_count(), 0U); 2326 DCHECK_GT(form_structure_.field_count(), 0U);
2325 2327
2326 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2328 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2327 if (IsCreditCardType(form_structure_.field(i)->type())) 2329 if (IsCreditCardType(form_structure_.field(i)->Type().server_type()))
2328 return true; 2330 return true;
2329 } 2331 }
2330 2332
2331 return false; 2333 return false;
2332 } 2334 }
2333 2335
2334 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { 2336 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const {
2335 return source_url_.SchemeIs(chrome::kHttpsScheme); 2337 return source_url_.SchemeIs(chrome::kHttpsScheme);
2336 } 2338 }
2337 2339
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 const std::string app_locale = g_browser_process->GetApplicationLocale(); 2597 const std::string app_locale = g_browser_process->GetApplicationLocale();
2596 for (size_t i = 0; i < profiles.size(); ++i) { 2598 for (size_t i = 0; i < profiles.size(); ++i) {
2597 if (!HasCompleteAndVerifiedData(*profiles[i], 2599 if (!HasCompleteAndVerifiedData(*profiles[i],
2598 requested_shipping_fields_) || 2600 requested_shipping_fields_) ||
2599 HasInvalidAddress(*profiles[i])) { 2601 HasInvalidAddress(*profiles[i])) {
2600 continue; 2602 continue;
2601 } 2603 }
2602 2604
2603 // Add all email addresses. 2605 // Add all email addresses.
2604 std::vector<string16> values; 2606 std::vector<string16> values;
2605 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); 2607 profiles[i]->GetMultiInfo(
2608 AutofillType(EMAIL_ADDRESS), app_locale, &values);
2606 for (size_t j = 0; j < values.size(); ++j) { 2609 for (size_t j = 0; j < values.size(); ++j) {
2607 if (IsValidEmailAddress(values[j])) 2610 if (IsValidEmailAddress(values[j]))
2608 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); 2611 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]);
2609 } 2612 }
2610 2613
2611 // Don't add variants for addresses: the email variants are handled above, 2614 // Don't add variants for addresses: the email variants are handled above,
2612 // name is part of credit card and we'll just ignore phone number 2615 // name is part of credit card and we'll just ignore phone number
2613 // variants. 2616 // variants.
2614 suggested_billing_.AddKeyedItem(profiles[i]->guid(), 2617 suggested_billing_.AddKeyedItem(profiles[i]->guid(),
2615 profiles[i]->Label()); 2618 profiles[i]->Label());
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 // any of the fields. 2779 // any of the fields.
2777 if (section == SECTION_SHIPPING) 2780 if (section == SECTION_SHIPPING)
2778 return cares_about_shipping_; 2781 return cares_about_shipping_;
2779 2782
2780 return true; 2783 return true;
2781 } 2784 }
2782 2785
2783 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { 2786 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) {
2784 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2787 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2785 AutofillField* field = form_structure_.field(i); 2788 AutofillField* field = form_structure_.field(i);
2786 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { 2789 if (field->Type().server_type() == CREDIT_CARD_VERIFICATION_CODE) {
2787 field->value = cvc; 2790 field->value = cvc;
2788 break; 2791 break;
2789 } 2792 }
2790 } 2793 }
2791 } 2794 }
2792 2795
2793 string16 AutofillDialogControllerImpl::GetValueFromSection( 2796 string16 AutofillDialogControllerImpl::GetValueFromSection(
2794 DialogSection section, 2797 DialogSection section,
2795 AutofillFieldType type) { 2798 ServerFieldType type) {
2796 DCHECK(SectionIsActive(section)); 2799 DCHECK(SectionIsActive(section));
2797 2800
2798 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 2801 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
2799 if (wrapper) 2802 if (wrapper)
2800 return wrapper->GetInfo(type); 2803 return wrapper->GetInfo(AutofillType(type));
2801 2804
2802 DetailOutputMap output; 2805 DetailOutputMap output;
2803 view_->GetUserInput(section, &output); 2806 view_->GetUserInput(section, &output);
2804 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); 2807 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end();
2805 ++iter) { 2808 ++iter) {
2806 if (iter->first->type == type) 2809 if (iter->first->type == type)
2807 return iter->second; 2810 return iter->second;
2808 } 2811 }
2809 2812
2810 return string16(); 2813 return string16();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 return false; 2970 return false;
2968 2971
2969 if (IsPayingWithWallet() && IsEditingExistingData(SECTION_CC_BILLING)) { 2972 if (IsPayingWithWallet() && IsEditingExistingData(SECTION_CC_BILLING)) {
2970 const wallet::WalletItems::MaskedInstrument* instrument = 2973 const wallet::WalletItems::MaskedInstrument* instrument =
2971 ActiveInstrument(); 2974 ActiveInstrument();
2972 const std::string& locale = g_browser_process->GetApplicationLocale(); 2975 const std::string& locale = g_browser_process->GetApplicationLocale();
2973 int month_int; 2976 int month_int;
2974 if (base::StringToInt(month, &month_int) && 2977 if (base::StringToInt(month, &month_int) &&
2975 instrument->status() == 2978 instrument->status() ==
2976 wallet::WalletItems::MaskedInstrument::EXPIRED && 2979 wallet::WalletItems::MaskedInstrument::EXPIRED &&
2977 year == instrument->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, locale) && 2980 year ==
2981 instrument->GetInfo(
2982 AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), locale) &&
2978 month_int == instrument->expiration_month()) { 2983 month_int == instrument->expiration_month()) {
2979 // Otherwise, if the user is editing an instrument that's deemed expired 2984 // Otherwise, if the user is editing an instrument that's deemed expired
2980 // by the Online Wallet server, mark it invalid on selection. 2985 // by the Online Wallet server, mark it invalid on selection.
2981 return false; 2986 return false;
2982 } 2987 }
2983 } 2988 }
2984 2989
2985 return true; 2990 return true;
2986 } 2991 }
2987 2992
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3468 view_->GetUserInput(SECTION_CC_BILLING, &output); 3473 view_->GetUserInput(SECTION_CC_BILLING, &output);
3469 CreditCard card; 3474 CreditCard card;
3470 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 3475 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
3471 backing_last_four = card.TypeAndLastFourDigits(); 3476 backing_last_four = card.TypeAndLastFourDigits();
3472 } 3477 }
3473 AutofillCreditCardBubbleController::ShowGeneratedCardUI( 3478 AutofillCreditCardBubbleController::ShowGeneratedCardUI(
3474 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); 3479 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits());
3475 } 3480 }
3476 3481
3477 } // namespace autofill 3482 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698