Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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/callback.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 8 | #include "base/strings/utf_string_conversions.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 11 | #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 12 | #include "components/autofill/content/browser/wallet/wallet_address.h" |
| 13 | #include "components/autofill/content/browser/wallet/wallet_items.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 14 | #include "components/autofill/core/browser/autofill_data_model.h" |
| 15 | #include "components/autofill/core/browser/autofill_profile.h" |
| 16 | #include "components/autofill/core/browser/autofill_type.h" |
| 17 | #include "components/autofill/core/browser/credit_card.h" |
| 18 | #include "components/autofill/core/browser/form_structure.h" |
| 19 | #include "components/autofill/core/browser/validation.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 20 | #include "ui/base/resource/resource_bundle.h" |
| 21 | #include "ui/gfx/image/image.h" |
| 22 | |
| 23 | namespace autofill { |
| 24 | |
| 25 | DataModelWrapper::~DataModelWrapper() {} |
| 26 | |
| 27 | string16 DataModelWrapper::GetDisplayText() { |
| 28 | string16 comma = ASCIIToUTF16(", "); |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 29 | string16 label = |
| 30 | GetInfo(AutofillType(NAME_FULL)) + comma + |
| 31 | GetInfo(AutofillType(ADDRESS_HOME_LINE1)); |
| 32 | string16 address2 = GetInfo(AutofillType(ADDRESS_HOME_LINE2)); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 33 | if (!address2.empty()) |
| 34 | label += comma + address2; |
| 35 | label += ASCIIToUTF16("\n") + |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 36 | GetInfo(AutofillType(ADDRESS_HOME_CITY)) + comma + |
| 37 | GetInfo(AutofillType(ADDRESS_HOME_STATE)) + ASCIIToUTF16(" ") + |
| 38 | GetInfo(AutofillType(ADDRESS_HOME_ZIP)); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | return label; |
| 40 | } |
| 41 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 42 | bool DataModelWrapper::FillFormStructure( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 43 | const DetailInputs& inputs, |
| 44 | const InputFieldComparator& compare, |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 45 | FormStructure* form_structure) const { |
| 46 | bool filled_something = false; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 48 | AutofillField* field = form_structure->field(i); |
| 49 | for (size_t j = 0; j < inputs.size(); ++j) { |
| 50 | if (compare.Run(inputs[j], *field)) { |
| 51 | FillFormField(field); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 52 | filled_something = true; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 53 | break; |
| 54 | } |
| 55 | } |
| 56 | } |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 57 | return filled_something; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void DataModelWrapper::FillInputs(DetailInputs* inputs) { |
| 61 | for (size_t i = 0; i < inputs->size(); ++i) { |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 62 | (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 66 | void DataModelWrapper::FillFormField(AutofillField* field) const { |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 67 | field->value = GetInfo(field->Type()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 70 | DataModelWrapper::DataModelWrapper() {} |
| 71 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 72 | gfx::Image DataModelWrapper::GetIcon() { |
| 73 | return gfx::Image(); |
| 74 | } |
| 75 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 76 | // EmptyDataModelWrapper |
| 77 | |
| 78 | EmptyDataModelWrapper::EmptyDataModelWrapper() {} |
| 79 | EmptyDataModelWrapper::~EmptyDataModelWrapper() {} |
| 80 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 81 | string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const { |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 82 | return string16(); |
| 83 | } |
| 84 | |
| 85 | void EmptyDataModelWrapper::FillFormField(AutofillField* field) const {} |
| 86 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 87 | // AutofillDataModelWrapper |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 88 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 89 | AutofillDataModelWrapper::AutofillDataModelWrapper( |
| 90 | const AutofillDataModel* data_model, |
| 91 | size_t variant) |
| 92 | : data_model_(data_model), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 93 | variant_(variant) {} |
| 94 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 95 | AutofillDataModelWrapper::~AutofillDataModelWrapper() {} |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 96 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 97 | string16 AutofillDataModelWrapper::GetInfo(const AutofillType& type) const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 98 | return data_model_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 101 | void AutofillDataModelWrapper::FillFormField(AutofillField* field) const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 102 | data_model_->FillFormField( |
| 103 | *field, variant_, g_browser_process->GetApplicationLocale(), field); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // AutofillProfileWrapper |
| 107 | |
| 108 | AutofillProfileWrapper::AutofillProfileWrapper( |
| 109 | const AutofillProfile* profile, size_t variant) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 110 | : AutofillDataModelWrapper(profile, variant), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 111 | profile_(profile) {} |
| 112 | |
| 113 | AutofillProfileWrapper::~AutofillProfileWrapper() {} |
| 114 | |
| 115 | void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 116 | const std::string app_locale = g_browser_process->GetApplicationLocale(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 117 | for (size_t j = 0; j < inputs->size(); ++j) { |
| 118 | std::vector<string16> values; |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 119 | profile_->GetMultiInfo( |
| 120 | AutofillType((*inputs)[j].type), app_locale, &values); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 121 | (*inputs)[j].initial_value = values[variant()]; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 125 | void AutofillProfileWrapper::FillFormField(AutofillField* field) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 126 | if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { |
| 127 | // Cache the field's true type. |
| 128 | HtmlFieldType original_type = field->html_type(); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 129 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 130 | // Requests for the user's credit card are filled from the billing address, |
| 131 | // but the AutofillProfile class doesn't know how to fill credit card |
| 132 | // fields. So, temporarily set the type to the corresponding profile type. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 140 | } |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 143 | // AutofillCreditCardWrapper |
| 144 | |
| 145 | AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 146 | : AutofillDataModelWrapper(card, 0), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 147 | card_(card) {} |
| 148 | |
| 149 | AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} |
| 150 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 151 | string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 152 | if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 153 | return MonthComboboxModel::FormatMonth(card_->expiration_month()); |
| 154 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 155 | return AutofillDataModelWrapper::GetInfo(type); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | gfx::Image AutofillCreditCardWrapper::GetIcon() { |
| 159 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 160 | return rb.GetImageNamed(CreditCard::IconResourceId(card_->type())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | string16 AutofillCreditCardWrapper::GetDisplayText() { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 164 | if (!card_->IsValid()) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 165 | return string16(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 166 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 167 | return card_->TypeAndLastFourDigits(); |
| 168 | } |
| 169 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 170 | // WalletAddressWrapper |
| 171 | |
| 172 | WalletAddressWrapper::WalletAddressWrapper( |
| 173 | const wallet::Address* address) : address_(address) {} |
| 174 | |
| 175 | WalletAddressWrapper::~WalletAddressWrapper() {} |
| 176 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 177 | string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 178 | return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 181 | string16 WalletAddressWrapper::GetDisplayText() { |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 182 | if (!address_->is_complete_address() || |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 183 | GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 184 | return string16(); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 185 | } |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 186 | |
| 187 | return DataModelWrapper::GetDisplayText(); |
| 188 | } |
| 189 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 190 | // WalletInstrumentWrapper |
| 191 | |
| 192 | WalletInstrumentWrapper::WalletInstrumentWrapper( |
| 193 | const wallet::WalletItems::MaskedInstrument* instrument) |
| 194 | : instrument_(instrument) {} |
| 195 | |
| 196 | WalletInstrumentWrapper::~WalletInstrumentWrapper() {} |
| 197 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 198 | string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 199 | if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 200 | return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); |
| 201 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 202 | return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 206 | return instrument_->CardIcon(); |
| 207 | } |
| 208 | |
| 209 | string16 WalletInstrumentWrapper::GetDisplayText() { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 210 | // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 211 | if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 212 | !instrument_->address().is_complete_address() || |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 213 | GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 214 | return string16(); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 215 | } |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 216 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 217 | // TODO(estade): descriptive_name() is user-provided. Should we use it or |
| 218 | // just type + last 4 digits? |
| 219 | string16 line1 = instrument_->descriptive_name(); |
| 220 | return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
| 221 | } |
| 222 | |
| 223 | // FullWalletBillingWrapper |
| 224 | |
| 225 | FullWalletBillingWrapper::FullWalletBillingWrapper( |
| 226 | wallet::FullWallet* full_wallet) |
| 227 | : full_wallet_(full_wallet) { |
| 228 | DCHECK(full_wallet_); |
| 229 | } |
| 230 | |
| 231 | FullWalletBillingWrapper::~FullWalletBillingWrapper() {} |
| 232 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 233 | string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 234 | if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 235 | return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month()); |
| 236 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 237 | if (type.group() == CREDIT_CARD) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 238 | return full_wallet_->GetInfo(type); |
| 239 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 240 | return full_wallet_->billing_address()->GetInfo( |
| 241 | type, g_browser_process->GetApplicationLocale()); |
| 242 | } |
| 243 | |
| 244 | string16 FullWalletBillingWrapper::GetDisplayText() { |
| 245 | // TODO(dbeam): handle other required actions? http://crbug.com/163508 |
| 246 | if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE)) |
| 247 | return string16(); |
| 248 | |
| 249 | return DataModelWrapper::GetDisplayText(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // FullWalletShippingWrapper |
| 253 | |
| 254 | FullWalletShippingWrapper::FullWalletShippingWrapper( |
| 255 | wallet::FullWallet* full_wallet) |
| 256 | : full_wallet_(full_wallet) { |
| 257 | DCHECK(full_wallet_); |
| 258 | } |
| 259 | |
| 260 | FullWalletShippingWrapper::~FullWalletShippingWrapper() {} |
| 261 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 262 | string16 FullWalletShippingWrapper::GetInfo(const AutofillType& type) const { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 263 | return full_wallet_->shipping_address()->GetInfo( |
| 264 | type, g_browser_process->GetApplicationLocale()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 267 | DetailOutputWrapper::DetailOutputWrapper(const DetailOutputMap& outputs) |
| 268 | : outputs_(outputs) {} |
| 269 | |
| 270 | DetailOutputWrapper::~DetailOutputWrapper() {} |
| 271 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 272 | base::string16 DetailOutputWrapper::GetInfo(const AutofillType& type) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 273 | ServerFieldType storable_type = type.GetStorableType(); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 274 | for (DetailOutputMap::const_iterator it = outputs_.begin(); |
| 275 | it != outputs_.end(); ++it) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 276 | if (storable_type == AutofillType(it->first->type).GetStorableType()) |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 277 | return it->second; |
| 278 | } |
| 279 | return base::string16(); |
| 280 | } |
| 281 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 282 | } // namespace autofill |