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

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

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test 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 (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 "chrome/browser/ui/autofill/data_model_wrapper.h" 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const std::string app_locale = g_browser_process->GetApplicationLocale(); 116 const std::string app_locale = g_browser_process->GetApplicationLocale();
117 for (size_t j = 0; j < inputs->size(); ++j) { 117 for (size_t j = 0; j < inputs->size(); ++j) {
118 std::vector<string16> values; 118 std::vector<string16> values;
119 profile_->GetMultiInfo( 119 profile_->GetMultiInfo(
120 AutofillType((*inputs)[j].type), app_locale, &values); 120 AutofillType((*inputs)[j].type), app_locale, &values);
121 (*inputs)[j].initial_value = values[variant()]; 121 (*inputs)[j].initial_value = values[variant()];
122 } 122 }
123 } 123 }
124 124
125 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { 125 void AutofillProfileWrapper::FillFormField(AutofillField* field) const {
126 AutofillType field_type = field->Type(); 126 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) {
127 // Cache the field's true type.
128 HtmlFieldType original_type = field->html_type();
127 129
128 if (field_type.server_type() == CREDIT_CARD_NAME) {
129 // Requests for the user's credit card are filled from the billing address, 130 // Requests for the user's credit card are filled from the billing address,
130 // but the AutofillProfile class doesn't know how to fill credit card 131 // but the AutofillProfile class doesn't know how to fill credit card
131 // fields. So, temporarily set the type to the corresponding profile type. 132 // fields. So, temporarily set the type to the corresponding profile type.
132 field->set_heuristic_type(NAME_FULL); 133 field->SetHtmlType(HTML_TYPE_NAME, field->html_mode());
134 AutofillDataModelWrapper::FillFormField(field);
135
136 // Restore the field's true type.
137 field->SetHtmlType(original_type, field->html_mode());
138 } else {
139 AutofillDataModelWrapper::FillFormField(field);
133 } 140 }
134
135 AutofillDataModelWrapper::FillFormField(field);
136
137 field->set_heuristic_type(field_type.server_type());
138 } 141 }
139 142
140 // AutofillCreditCardWrapper 143 // AutofillCreditCardWrapper
141 144
142 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) 145 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card)
143 : AutofillDataModelWrapper(card, 0), 146 : AutofillDataModelWrapper(card, 0),
144 card_(card) {} 147 card_(card) {}
145 148
146 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} 149 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {}
147 150
148 string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type) const { 151 string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type) const {
149 if (type.server_type() == CREDIT_CARD_EXP_MONTH) 152 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
150 return MonthComboboxModel::FormatMonth(card_->expiration_month()); 153 return MonthComboboxModel::FormatMonth(card_->expiration_month());
151 154
152 return AutofillDataModelWrapper::GetInfo(type); 155 return AutofillDataModelWrapper::GetInfo(type);
153 } 156 }
154 157
155 gfx::Image AutofillCreditCardWrapper::GetIcon() { 158 gfx::Image AutofillCreditCardWrapper::GetIcon() {
156 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 159 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
157 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type())); 160 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
158 } 161 }
159 162
(...skipping 26 matching lines...) Expand all
186 189
187 // WalletInstrumentWrapper 190 // WalletInstrumentWrapper
188 191
189 WalletInstrumentWrapper::WalletInstrumentWrapper( 192 WalletInstrumentWrapper::WalletInstrumentWrapper(
190 const wallet::WalletItems::MaskedInstrument* instrument) 193 const wallet::WalletItems::MaskedInstrument* instrument)
191 : instrument_(instrument) {} 194 : instrument_(instrument) {}
192 195
193 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} 196 WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
194 197
195 string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type) const { 198 string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type) const {
196 if (type.server_type() == CREDIT_CARD_EXP_MONTH) 199 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
197 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); 200 return MonthComboboxModel::FormatMonth(instrument_->expiration_month());
198 201
199 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); 202 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale());
200 } 203 }
201 204
202 gfx::Image WalletInstrumentWrapper::GetIcon() { 205 gfx::Image WalletInstrumentWrapper::GetIcon() {
203 return instrument_->CardIcon(); 206 return instrument_->CardIcon();
204 } 207 }
205 208
206 string16 WalletInstrumentWrapper::GetDisplayText() { 209 string16 WalletInstrumentWrapper::GetDisplayText() {
(...skipping 14 matching lines...) Expand all
221 224
222 FullWalletBillingWrapper::FullWalletBillingWrapper( 225 FullWalletBillingWrapper::FullWalletBillingWrapper(
223 wallet::FullWallet* full_wallet) 226 wallet::FullWallet* full_wallet)
224 : full_wallet_(full_wallet) { 227 : full_wallet_(full_wallet) {
225 DCHECK(full_wallet_); 228 DCHECK(full_wallet_);
226 } 229 }
227 230
228 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} 231 FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
229 232
230 string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) const { 233 string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) const {
231 if (type.server_type() == CREDIT_CARD_EXP_MONTH) 234 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
232 return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month()); 235 return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month());
233 236
234 if (type.group() == CREDIT_CARD) 237 if (type.group() == CREDIT_CARD)
235 return full_wallet_->GetInfo(type); 238 return full_wallet_->GetInfo(type);
236 239
237 return full_wallet_->billing_address()->GetInfo( 240 return full_wallet_->billing_address()->GetInfo(
238 type, g_browser_process->GetApplicationLocale()); 241 type, g_browser_process->GetApplicationLocale());
239 } 242 }
240 243
241 string16 FullWalletBillingWrapper::GetDisplayText() { 244 string16 FullWalletBillingWrapper::GetDisplayText() {
(...skipping 18 matching lines...) Expand all
260 return full_wallet_->shipping_address()->GetInfo( 263 return full_wallet_->shipping_address()->GetInfo(
261 type, g_browser_process->GetApplicationLocale()); 264 type, g_browser_process->GetApplicationLocale());
262 } 265 }
263 266
264 DetailOutputWrapper::DetailOutputWrapper(const DetailOutputMap& outputs) 267 DetailOutputWrapper::DetailOutputWrapper(const DetailOutputMap& outputs)
265 : outputs_(outputs) {} 268 : outputs_(outputs) {}
266 269
267 DetailOutputWrapper::~DetailOutputWrapper() {} 270 DetailOutputWrapper::~DetailOutputWrapper() {}
268 271
269 base::string16 DetailOutputWrapper::GetInfo(const AutofillType& type) const { 272 base::string16 DetailOutputWrapper::GetInfo(const AutofillType& type) const {
273 ServerFieldType storable_type = type.GetStorableType();
270 for (DetailOutputMap::const_iterator it = outputs_.begin(); 274 for (DetailOutputMap::const_iterator it = outputs_.begin();
271 it != outputs_.end(); ++it) { 275 it != outputs_.end(); ++it) {
272 if (type.server_type() == it->first->type) 276 if (storable_type == AutofillType(it->first->type).GetStorableType())
273 return it->second; 277 return it->second;
274 } 278 }
275 return base::string16(); 279 return base::string16();
276 } 280 }
277 281
278 } // namespace autofill 282 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698