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

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

Issue 137723008: Remove DataModelWrapper from android build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | 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/bind.h"
7 #include "base/callback.h" 8 #include "base/callback.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 13 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
13 #include "components/autofill/content/browser/wallet/full_wallet.h" 14 #include "components/autofill/content/browser/wallet/full_wallet.h"
14 #include "components/autofill/content/browser/wallet/wallet_address.h" 15 #include "components/autofill/content/browser/wallet/wallet_address.h"
15 #include "components/autofill/content/browser/wallet/wallet_items.h" 16 #include "components/autofill/content/browser/wallet/wallet_items.h"
16 #include "components/autofill/core/browser/autofill_data_model.h" 17 #include "components/autofill/core/browser/autofill_data_model.h"
17 #include "components/autofill/core/browser/autofill_field.h" 18 #include "components/autofill/core/browser/autofill_field.h"
18 #include "components/autofill/core/browser/autofill_profile.h" 19 #include "components/autofill/core/browser/autofill_profile.h"
19 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
20 #include "components/autofill/core/browser/credit_card.h" 21 #include "components/autofill/core/browser/credit_card.h"
21 #include "components/autofill/core/browser/form_structure.h" 22 #include "components/autofill/core/browser/form_structure.h"
23 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h"
24 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h"
22 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
24 27
25 #if !defined(OS_ANDROID)
26 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h"
27 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h"
28 #endif
29
30 namespace autofill { 28 namespace autofill {
31 29
32 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
33 using base::UTF16ToUTF8; 31 using base::UTF16ToUTF8;
34 32
35 DataModelWrapper::~DataModelWrapper() {} 33 DataModelWrapper::~DataModelWrapper() {}
36 34
37 void DataModelWrapper::FillInputs(DetailInputs* inputs) { 35 void DataModelWrapper::FillInputs(DetailInputs* inputs) {
38 for (size_t i = 0; i < inputs->size(); ++i) { 36 for (size_t i = 0; i < inputs->size(); ++i) {
39 DetailInput* input = &(*inputs)[i]; 37 DetailInput* input = &(*inputs)[i];
40 input->initial_value = common::GetHardcodedValueForType(input->type); 38 input->initial_value = common::GetHardcodedValueForType(input->type);
41 if (input->initial_value.empty()) 39 if (input->initial_value.empty())
42 input->initial_value = GetInfo(AutofillType(input->type)); 40 input->initial_value = GetInfo(AutofillType(input->type));
43 } 41 }
44 } 42 }
45 43
46 base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type) 44 base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type)
47 const { 45 const {
48 return GetInfo(type); 46 return GetInfo(type);
49 } 47 }
50 48
51 gfx::Image DataModelWrapper::GetIcon() { 49 gfx::Image DataModelWrapper::GetIcon() {
52 return gfx::Image(); 50 return gfx::Image();
53 } 51 }
54 52
55 #if !defined(OS_ANDROID)
56 bool DataModelWrapper::GetDisplayText( 53 bool DataModelWrapper::GetDisplayText(
57 base::string16* vertically_compact, 54 base::string16* vertically_compact,
58 base::string16* horizontally_compact) { 55 base::string16* horizontally_compact) {
59 // Format the address. 56 // Format the address.
60 ::i18n::addressinput::AddressData address_data; 57 ::i18n::addressinput::AddressData address_data;
61 address_data.recipient = UTF16ToUTF8( 58 address_data.recipient = UTF16ToUTF8(
62 GetInfoForDisplay(AutofillType(NAME_FULL))); 59 GetInfoForDisplay(AutofillType(NAME_FULL)));
63 address_data.country_code = UTF16ToUTF8( 60 address_data.country_code = UTF16ToUTF8(
64 GetInfoForDisplay(AutofillType(ADDRESS_HOME_COUNTRY))); 61 GetInfoForDisplay(AutofillType(ADDRESS_HOME_COUNTRY)));
65 address_data.administrative_area = UTF16ToUTF8( 62 address_data.administrative_area = UTF16ToUTF8(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 g_browser_process->GetApplicationLocale(), 94 g_browser_process->GetApplicationLocale(),
98 address_data.country_code); 95 address_data.country_code);
99 *vertically_compact = 96 *vertically_compact =
100 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + 97 base::UTF8ToUTF16(JoinString(lines, compact_separator)) +
101 non_address_info; 98 non_address_info;
102 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + 99 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) +
103 non_address_info; 100 non_address_info;
104 101
105 return true; 102 return true;
106 } 103 }
107 #endif
108 104
109 bool DataModelWrapper::FillFormStructure( 105 bool DataModelWrapper::FillFormStructure(
110 const DetailInputs& inputs, 106 const std::vector<ServerFieldType>& types,
111 const InputFieldComparator& compare, 107 const FormStructure::InputFieldComparator& compare,
112 FormStructure* form_structure) const { 108 FormStructure* form_structure) const {
113 bool filled_something = false; 109 return form_structure->FillFields(
114 for (size_t i = 0; i < form_structure->field_count(); ++i) { 110 types,
115 AutofillField* field = form_structure->field(i); 111 compare,
116 for (size_t j = 0; j < inputs.size(); ++j) { 112 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
117 if (compare.Run(inputs[j].type, *field)) { 113 g_browser_process->GetApplicationLocale());
118 AutofillField::FillFormField(*field, GetInfo(field->Type()),
119 g_browser_process->GetApplicationLocale(),
120 field);
121 filled_something = true;
122 break;
123 }
124 }
125 }
126 return filled_something;
127 } 114 }
128 115
129 DataModelWrapper::DataModelWrapper() {} 116 DataModelWrapper::DataModelWrapper() {}
130 117
131 // EmptyDataModelWrapper
132
133 EmptyDataModelWrapper::EmptyDataModelWrapper() {}
134 EmptyDataModelWrapper::~EmptyDataModelWrapper() {}
135
136 base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const {
137 return base::string16();
138 }
139
140 // AutofillProfileWrapper 118 // AutofillProfileWrapper
141 119
142 AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile) 120 AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile)
143 : profile_(profile), 121 : profile_(profile),
144 variant_group_(NO_GROUP), 122 variant_group_(NO_GROUP),
145 variant_(0) {} 123 variant_(0) {}
146 124
147 AutofillProfileWrapper::AutofillProfileWrapper( 125 AutofillProfileWrapper::AutofillProfileWrapper(
148 const AutofillProfile* profile, 126 const AutofillProfile* profile,
149 const AutofillType& type, 127 const AutofillType& type,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return MonthComboboxModel::FormatMonth(card_->expiration_month()); 209 return MonthComboboxModel::FormatMonth(card_->expiration_month());
232 210
233 return card_->GetInfo(type, g_browser_process->GetApplicationLocale()); 211 return card_->GetInfo(type, g_browser_process->GetApplicationLocale());
234 } 212 }
235 213
236 gfx::Image AutofillCreditCardWrapper::GetIcon() { 214 gfx::Image AutofillCreditCardWrapper::GetIcon() {
237 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 215 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
238 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type())); 216 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
239 } 217 }
240 218
241 #if !defined(OS_ANDROID)
242 bool AutofillCreditCardWrapper::GetDisplayText( 219 bool AutofillCreditCardWrapper::GetDisplayText(
243 base::string16* vertically_compact, 220 base::string16* vertically_compact,
244 base::string16* horizontally_compact) { 221 base::string16* horizontally_compact) {
245 if (!card_->IsValid()) 222 if (!card_->IsValid())
246 return false; 223 return false;
247 224
248 *vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits(); 225 *vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits();
249 return true; 226 return true;
250 } 227 }
251 #endif
252 228
253 // WalletAddressWrapper 229 // WalletAddressWrapper
254 230
255 WalletAddressWrapper::WalletAddressWrapper( 231 WalletAddressWrapper::WalletAddressWrapper(
256 const wallet::Address* address) : address_(address) {} 232 const wallet::Address* address) : address_(address) {}
257 233
258 WalletAddressWrapper::~WalletAddressWrapper() {} 234 WalletAddressWrapper::~WalletAddressWrapper() {}
259 235
260 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { 236 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const {
261 // Reachable from DataModelWrapper::GetDisplayText(). 237 // Reachable from DataModelWrapper::GetDisplayText().
262 if (type.GetStorableType() == EMAIL_ADDRESS) 238 if (type.GetStorableType() == EMAIL_ADDRESS)
263 return base::string16(); 239 return base::string16();
264 240
265 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); 241 return address_->GetInfo(type, g_browser_process->GetApplicationLocale());
266 } 242 }
267 243
268 base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type) 244 base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type)
269 const { 245 const {
270 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) 246 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER)
271 return address_->DisplayPhoneNumber(); 247 return address_->DisplayPhoneNumber();
272 248
273 return DataModelWrapper::GetInfoForDisplay(type); 249 return DataModelWrapper::GetInfoForDisplay(type);
274 } 250 }
275 251
276 #if !defined(OS_ANDROID)
277 bool WalletAddressWrapper::GetDisplayText( 252 bool WalletAddressWrapper::GetDisplayText(
278 base::string16* vertically_compact, 253 base::string16* vertically_compact,
279 base::string16* horizontally_compact) { 254 base::string16* horizontally_compact) {
280 if (!address_->is_complete_address() || 255 if (!address_->is_complete_address() ||
281 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { 256 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
282 return false; 257 return false;
283 } 258 }
284 259
285 return DataModelWrapper::GetDisplayText(vertically_compact, 260 return DataModelWrapper::GetDisplayText(vertically_compact,
286 horizontally_compact); 261 horizontally_compact);
287 } 262 }
288 #endif
289 263
290 // WalletInstrumentWrapper 264 // WalletInstrumentWrapper
291 265
292 WalletInstrumentWrapper::WalletInstrumentWrapper( 266 WalletInstrumentWrapper::WalletInstrumentWrapper(
293 const wallet::WalletItems::MaskedInstrument* instrument) 267 const wallet::WalletItems::MaskedInstrument* instrument)
294 : instrument_(instrument) {} 268 : instrument_(instrument) {}
295 269
296 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} 270 WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
297 271
298 base::string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type) 272 base::string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type)
(...skipping 13 matching lines...) Expand all
312 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) 286 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER)
313 return instrument_->address().DisplayPhoneNumber(); 287 return instrument_->address().DisplayPhoneNumber();
314 288
315 return DataModelWrapper::GetInfoForDisplay(type); 289 return DataModelWrapper::GetInfoForDisplay(type);
316 } 290 }
317 291
318 gfx::Image WalletInstrumentWrapper::GetIcon() { 292 gfx::Image WalletInstrumentWrapper::GetIcon() {
319 return instrument_->CardIcon(); 293 return instrument_->CardIcon();
320 } 294 }
321 295
322 #if !defined(OS_ANDROID)
323 bool WalletInstrumentWrapper::GetDisplayText( 296 bool WalletInstrumentWrapper::GetDisplayText(
324 base::string16* vertically_compact, 297 base::string16* vertically_compact,
325 base::string16* horizontally_compact) { 298 base::string16* horizontally_compact) {
326 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 299 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048
327 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || 300 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED ||
328 !instrument_->address().is_complete_address() || 301 !instrument_->address().is_complete_address() ||
329 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { 302 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
330 return false; 303 return false;
331 } 304 }
332 305
333 DataModelWrapper::GetDisplayText(vertically_compact, horizontally_compact); 306 DataModelWrapper::GetDisplayText(vertically_compact, horizontally_compact);
334 // TODO(estade): descriptive_name() is user-provided. Should we use it or 307 // TODO(estade): descriptive_name() is user-provided. Should we use it or
335 // just type + last 4 digits? 308 // just type + last 4 digits?
336 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n"); 309 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n");
337 *vertically_compact = line1 + *vertically_compact; 310 *vertically_compact = line1 + *vertically_compact;
338 *horizontally_compact = line1 + *horizontally_compact; 311 *horizontally_compact = line1 + *horizontally_compact;
339 return true; 312 return true;
340 } 313 }
341 #endif
342 314
343 // FullWalletBillingWrapper 315 // FullWalletBillingWrapper
344 316
345 FullWalletBillingWrapper::FullWalletBillingWrapper( 317 FullWalletBillingWrapper::FullWalletBillingWrapper(
346 wallet::FullWallet* full_wallet) 318 wallet::FullWallet* full_wallet)
347 : full_wallet_(full_wallet) { 319 : full_wallet_(full_wallet) {
348 DCHECK(full_wallet_); 320 DCHECK(full_wallet_);
349 } 321 }
350 322
351 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} 323 FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
352 324
353 base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) 325 base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type)
354 const { 326 const {
355 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) 327 return full_wallet_->GetBillingInfo(
356 return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month()); 328 g_browser_process->GetApplicationLocale(), type);
Dan Beam 2014/01/27 19:37:50 i prefer the old API. why have 2 different method
Evan Stade 2014/01/27 19:45:41 because sometimes we're using the billing address
Dan Beam 2014/01/27 20:18:23 GetEquivalentBillingFieldType()/AutofillType().Get
357
358 if (type.group() == CREDIT_CARD)
359 return full_wallet_->GetInfo(type);
360
361 return full_wallet_->billing_address()->GetInfo(
362 type, g_browser_process->GetApplicationLocale());
363 } 329 }
364 330
365 #if !defined(OS_ANDROID)
366 bool FullWalletBillingWrapper::GetDisplayText( 331 bool FullWalletBillingWrapper::GetDisplayText(
367 base::string16* vertically_compact, 332 base::string16* vertically_compact,
368 base::string16* horizontally_compact) { 333 base::string16* horizontally_compact) {
369 // TODO(dbeam): handle other required actions? http://crbug.com/163508 334 // TODO(dbeam): handle other required actions? http://crbug.com/163508
370 if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE)) 335 if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE))
371 return false; 336 return false;
372 337
373 return DataModelWrapper::GetDisplayText(vertically_compact, 338 return DataModelWrapper::GetDisplayText(vertically_compact,
374 horizontally_compact); 339 horizontally_compact);
375 } 340 }
376 #endif
377 341
378 // FullWalletShippingWrapper 342 // FullWalletShippingWrapper
379 343
380 FullWalletShippingWrapper::FullWalletShippingWrapper( 344 FullWalletShippingWrapper::FullWalletShippingWrapper(
381 wallet::FullWallet* full_wallet) 345 wallet::FullWallet* full_wallet)
382 : full_wallet_(full_wallet) { 346 : full_wallet_(full_wallet) {
383 DCHECK(full_wallet_); 347 DCHECK(full_wallet_);
384 } 348 }
385 349
386 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} 350 FullWalletShippingWrapper::~FullWalletShippingWrapper() {}
387 351
388 base::string16 FullWalletShippingWrapper::GetInfo( 352 base::string16 FullWalletShippingWrapper::GetInfo(
389 const AutofillType& type) const { 353 const AutofillType& type) const {
390 return full_wallet_->shipping_address()->GetInfo( 354 return full_wallet_->GetShippingInfo(
391 type, g_browser_process->GetApplicationLocale()); 355 g_browser_process->GetApplicationLocale(), type);
392 } 356 }
393 357
394 FieldMapWrapper::FieldMapWrapper(const FieldValueMap& field_map) 358 FieldMapWrapper::FieldMapWrapper(const FieldValueMap& field_map)
395 : field_map_(field_map) {} 359 : field_map_(field_map) {}
396 360
397 FieldMapWrapper::~FieldMapWrapper() {} 361 FieldMapWrapper::~FieldMapWrapper() {}
398 362
399 base::string16 FieldMapWrapper::GetInfo(const AutofillType& type) const { 363 base::string16 FieldMapWrapper::GetInfo(const AutofillType& type) const {
400 FieldValueMap::const_iterator it = field_map_.find(type.server_type()); 364 FieldValueMap::const_iterator it = field_map_.find(type.server_type());
401 return it != field_map_.end() ? it->second : base::string16(); 365 return it != field_map_.end() ? it->second : base::string16();
402 } 366 }
403 367
404 } // namespace autofill 368 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698