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/ui/autofill/data_model_wrapper.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autofill/autofill_country.h" |
| 9 #include "chrome/browser/autofill/credit_card.h" |
| 10 #include "chrome/browser/autofill/form_group.h" |
| 11 #include "chrome/browser/autofill/form_structure.h" |
| 12 #include "chrome/browser/autofill/wallet/wallet_address.h" |
| 13 #include "chrome/browser/autofill/wallet/wallet_address.h" |
| 14 #include "chrome/browser/autofill/wallet/wallet_items.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image.h" |
| 17 |
| 18 namespace autofill { |
| 19 |
| 20 DataModelWrapper::~DataModelWrapper() {} |
| 21 |
| 22 // AutofillDataModelWrapper |
| 23 |
| 24 AutofillDataModelWrapper::AutofillDataModelWrapper(const FormGroup* form_group, |
| 25 size_t variant) |
| 26 : form_group_(form_group), |
| 27 variant_(variant) {} |
| 28 |
| 29 AutofillDataModelWrapper::~AutofillDataModelWrapper() {} |
| 30 |
| 31 string16 AutofillDataModelWrapper::GetInfo(AutofillFieldType type) { |
| 32 return form_group_->GetInfo(type, AutofillCountry::ApplicationLocale()); |
| 33 } |
| 34 |
| 35 gfx::Image AutofillDataModelWrapper::GetIcon() { |
| 36 return gfx::Image(); |
| 37 } |
| 38 |
| 39 void AutofillDataModelWrapper::FillInputs(DetailInputs* inputs) { |
| 40 // TODO(estade): use |variant_|? |
| 41 const std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 42 for (size_t j = 0; j < inputs->size(); ++j) { |
| 43 (*inputs)[j].autofilled_value = |
| 44 form_group_->GetInfo((*inputs)[j].type, app_locale); |
| 45 } |
| 46 } |
| 47 |
| 48 void AutofillDataModelWrapper::FillFormStructure( |
| 49 const DetailInputs& inputs, |
| 50 const InputFieldComparator& compare, |
| 51 FormStructure* form_structure) { |
| 52 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 53 AutofillField* field = form_structure->field(i); |
| 54 for (size_t j = 0; j < inputs.size(); ++j) { |
| 55 if (compare.Run(inputs[j], *field)) { |
| 56 form_group_->FillFormField(*field, variant_, field); |
| 57 break; |
| 58 } |
| 59 } |
| 60 } |
| 61 } |
| 62 |
| 63 // AutofillCreditCardWrapper |
| 64 |
| 65 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) |
| 66 : AutofillDataModelWrapper(card, 0), |
| 67 card_(card) {} |
| 68 |
| 69 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} |
| 70 |
| 71 gfx::Image AutofillCreditCardWrapper::GetIcon() { |
| 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 73 return rb.GetImageNamed(card_->IconResourceId()); |
| 74 } |
| 75 |
| 76 // WalletInstrumentWrapper |
| 77 |
| 78 WalletInstrumentWrapper::WalletInstrumentWrapper( |
| 79 const wallet::WalletItems::MaskedInstrument* instrument) |
| 80 : instrument_(instrument) {} |
| 81 |
| 82 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} |
| 83 |
| 84 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { |
| 85 // TODO(estade): implement. |
| 86 return string16(ASCIIToUTF16("foo")); |
| 87 } |
| 88 |
| 89 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 90 // TODO(estade): implement. |
| 91 return gfx::Image(); |
| 92 } |
| 93 |
| 94 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { |
| 95 // TODO(estade): implement. |
| 96 } |
| 97 |
| 98 void WalletInstrumentWrapper::FillFormStructure( |
| 99 const DetailInputs& inputs, |
| 100 const InputFieldComparator& compare, |
| 101 FormStructure* form_structure) { |
| 102 // TODO(estade): implement. |
| 103 } |
| 104 |
| 105 // WalletAddressWrapper |
| 106 |
| 107 WalletAddressWrapper::WalletAddressWrapper( |
| 108 const wallet::Address* address) : address_(address) {} |
| 109 |
| 110 WalletAddressWrapper::~WalletAddressWrapper() {} |
| 111 |
| 112 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { |
| 113 return address_->GetInfo(type); |
| 114 } |
| 115 |
| 116 gfx::Image WalletAddressWrapper::GetIcon() { |
| 117 return gfx::Image(); |
| 118 } |
| 119 |
| 120 void WalletAddressWrapper::FillInputs(DetailInputs* inputs) { |
| 121 for (size_t j = 0; j < inputs->size(); ++j) |
| 122 (*inputs)[j].autofilled_value = address_->GetInfo((*inputs)[j].type); |
| 123 } |
| 124 |
| 125 void WalletAddressWrapper::FillFormStructure( |
| 126 const DetailInputs& inputs, |
| 127 const InputFieldComparator& compare, |
| 128 FormStructure* form_structure) { |
| 129 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 130 AutofillField* field = form_structure->field(i); |
| 131 for (size_t j = 0; j < inputs.size(); ++j) { |
| 132 if (compare.Run(inputs[j], *field)) { |
| 133 field->value = GetInfo(field->type()); |
| 134 break; |
| 135 } |
| 136 } |
| 137 } |
| 138 } |
| 139 |
| 140 } // namespace autofill |
OLD | NEW |