12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/data_model_wrapper.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/bind.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback.h"
94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/strings/string_util.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/browser_process.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/full_wallet.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_address.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_items.h"
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/autofill/core/browser/address_i18n.h"
18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/autofill/core/browser/autofill_country.h"
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_data_model.h"
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "components/autofill/core/browser/autofill_field.h"
21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_profile.h"
22eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_type.h"
23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/credit_card.h"
24eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/form_structure.h"
25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image.h"
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace autofill {
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DataModelWrapper::~DataModelWrapper() {}
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
35c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochvoid DataModelWrapper::FillInputs(DetailInputs* inputs) {
36c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  for (size_t i = 0; i < inputs->size(); ++i) {
37c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    (*inputs)[i].initial_value =
38c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        GetInfoForDisplay(AutofillType((*inputs)[i].type));
39c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  }
40c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch}
41c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type)
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const {
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return GetInfo(type);
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)gfx::Image DataModelWrapper::GetIcon() {
48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return gfx::Image();
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
51c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool DataModelWrapper::GetDisplayText(
52c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* vertically_compact,
53c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* horizontally_compact) {
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 phone =
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER));
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (phone.empty())
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Format the address.
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr< ::i18n::addressinput::AddressData> address_data =
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      i18n::CreateAddressData(
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)          base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)));
63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  address_data->language_code = GetLanguageCode();
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Interactive autofill dialog does not display organization field.
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  address_data->organization.clear();
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<std::string> lines;
67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ::i18n::addressinput::GetFormattedNationalAddress(*address_data, &lines);
68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  std::string single_line;
70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ::i18n::addressinput::GetFormattedNationalAddressLine(
71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch       *address_data, &single_line);
72c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Email and phone number aren't part of address formatting.
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 non_address_info;
754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS));
7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (!email.empty())
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    non_address_info += base::ASCIIToUTF16("\n") + email;
78c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  non_address_info += base::ASCIIToUTF16("\n") + phone;
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  *vertically_compact = base::UTF8ToUTF16(single_line) + non_address_info;
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) +
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      non_address_info;
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DataModelWrapper::FillFormStructure(
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::vector<ServerFieldType>& types,
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const FormStructure::InputFieldComparator& compare,
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FormStructure* form_structure) const {
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return form_structure->FillFields(
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      types,
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      compare,
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      GetLanguageCode(),
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->GetApplicationLocale());
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DataModelWrapper::DataModelWrapper() {}
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// AutofillProfileWrapper
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile)
105d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : profile_(profile),
106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      variant_group_(NO_GROUP),
107d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      variant_(0) {}
108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AutofillProfileWrapper::AutofillProfileWrapper(
110d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const AutofillProfile* profile,
111d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const AutofillType& type,
112d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    size_t variant)
113d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : profile_(profile),
114d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      variant_group_(type.group()),
115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      variant_(variant) {}
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AutofillProfileWrapper::~AutofillProfileWrapper() {}
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)base::string16 AutofillProfileWrapper::GetInfo(const AutofillType& type) const {
1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Requests for the user's credit card are filled from the billing address,
1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // but the AutofillProfile class doesn't know how to fill credit card
1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // fields. So, request for the corresponding profile type instead.
1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  AutofillType effective_type = type;
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (type.GetStorableType() == CREDIT_CARD_NAME)
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    effective_type = AutofillType(NAME_BILLING_FULL);
1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  size_t variant = GetVariantForType(effective_type);
128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const std::string& app_locale = g_browser_process->GetApplicationLocale();
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return profile_->GetInfoForVariant(effective_type, variant, app_locale);
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)base::string16 AutofillProfileWrapper::GetInfoForDisplay(
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const AutofillType& type) const {
1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // We display the "raw" phone number which contains user-defined formatting.
1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) {
1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    std::vector<base::string16> values;
1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    profile_->GetRawMultiInfo(type.GetStorableType(), &values);
1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const base::string16& phone_number = values[GetVariantForType(type)];
1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // If there is no user-defined formatting at all, add some standard
1414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // formatting.
142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (base::ContainsOnlyChars(phone_number,
143116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                base::ASCIIToUTF16("+0123456789"))) {
144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      std::string region = base::UTF16ToASCII(
1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE)));
1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      i18n::PhoneObject phone(phone_number, region);
1475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      base::string16 formatted_number = phone.GetFormattedNumber();
1485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Formatting may fail.
1495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      if (!formatted_number.empty())
1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        return formatted_number;
1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return phone_number;
1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return DataModelWrapper::GetInfoForDisplay(type);
1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
159a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& AutofillProfileWrapper::GetLanguageCode() const {
160a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return profile_->language_code();
161a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
162a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)size_t AutofillProfileWrapper::GetVariantForType(const AutofillType& type)
164d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const {
165d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (type.group() == variant_group_)
166d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return variant_;
167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
168d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return 0;
169d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
171d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// AutofillShippingAddressWrapper
172d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
17358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)AutofillShippingAddressWrapper::AutofillShippingAddressWrapper(
174d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const AutofillProfile* profile)
175d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : AutofillProfileWrapper(profile) {}
17658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
17758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)AutofillShippingAddressWrapper::~AutofillShippingAddressWrapper() {}
17858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
17958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)base::string16 AutofillShippingAddressWrapper::GetInfo(
18058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const AutofillType& type) const {
18158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Shipping addresses don't have email addresses associated with them.
18258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (type.GetStorableType() == EMAIL_ADDRESS)
18358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return base::string16();
18458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
18558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return AutofillProfileWrapper::GetInfo(type);
18658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
18758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// AutofillCreditCardWrapper
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card)
191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : card_(card) {}
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {}
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
195c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbase::string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type)
196c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const {
197424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  if (type.group() != CREDIT_CARD)
198424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    return base::string16();
199424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
200bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return MonthComboboxModel::FormatMonth(card_->expiration_month());
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
203d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return card_->GetInfo(type, g_browser_process->GetApplicationLocale());
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Image AutofillCreditCardWrapper::GetIcon() {
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
2087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
211c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool AutofillCreditCardWrapper::GetDisplayText(
212c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* vertically_compact,
213c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* horizontally_compact) {
214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!card_->IsValid())
215c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    return false;
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
217c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  *vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits();
218c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  return true;
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
221a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& AutofillCreditCardWrapper::GetLanguageCode() const {
222a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Formatting a credit card for display does not depend on language code.
223a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return base::EmptyString();
224a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
225a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WalletAddressWrapper
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletAddressWrapper::WalletAddressWrapper(
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const wallet::Address* address) : address_(address) {}
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletAddressWrapper::~WalletAddressWrapper() {}
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
233c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbase::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const {
23458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Reachable from DataModelWrapper::GetDisplayText().
23558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (type.GetStorableType() == EMAIL_ADDRESS)
23658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return base::string16();
23758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return address_->GetInfo(type, g_browser_process->GetApplicationLocale());
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type)
2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const {
2434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER)
2444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return address_->DisplayPhoneNumber();
2454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return DataModelWrapper::GetInfoForDisplay(type);
2474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
249c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool WalletAddressWrapper::GetDisplayText(
250c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* vertically_compact,
251c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* horizontally_compact) {
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!address_->is_complete_address())
253c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    return false;
25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
255c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  return DataModelWrapper::GetDisplayText(vertically_compact,
256c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                                          horizontally_compact);
25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
259a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& WalletAddressWrapper::GetLanguageCode() const {
260a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return address_->language_code();
261a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
262a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WalletInstrumentWrapper
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletInstrumentWrapper::WalletInstrumentWrapper(
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const wallet::WalletItems::MaskedInstrument* instrument)
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : instrument_(instrument) {}
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
271c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbase::string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type)
272c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const {
27358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Reachable from DataModelWrapper::GetDisplayText().
27458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (type.GetStorableType() == EMAIL_ADDRESS)
27558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return base::string16();
27658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
277bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return MonthComboboxModel::FormatMonth(instrument_->expiration_month());
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale());
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)base::string16 WalletInstrumentWrapper::GetInfoForDisplay(
2844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const AutofillType& type) const {
2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER)
2864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return instrument_->address().DisplayPhoneNumber();
2874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return DataModelWrapper::GetInfoForDisplay(type);
2894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Image WalletInstrumentWrapper::GetIcon() {
2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return instrument_->CardIcon();
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
295c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool WalletInstrumentWrapper::GetDisplayText(
296c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* vertically_compact,
297c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* horizontally_compact) {
298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048
29990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED ||
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      !instrument_->address().is_complete_address()) {
3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!DataModelWrapper::GetDisplayText(vertically_compact,
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                        horizontally_compact)) {
306c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    return false;
30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(estade): descriptive_name() is user-provided. Should we use it or
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // just type + last 4 digits?
311a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::string16 line1 =
312a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      instrument_->descriptive_name() + base::ASCIIToUTF16("\n");
313c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  *vertically_compact = line1 + *vertically_compact;
314c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  *horizontally_compact = line1 + *horizontally_compact;
315c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  return true;
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
318a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& WalletInstrumentWrapper::GetLanguageCode() const {
319a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return instrument_->address().language_code();
320a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
321a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// FullWalletBillingWrapper
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)FullWalletBillingWrapper::FullWalletBillingWrapper(
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    wallet::FullWallet* full_wallet)
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : full_wallet_(full_wallet) {
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(full_wallet_);
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
332c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbase::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type)
333c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const {
334f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return full_wallet_->GetInfo(g_browser_process->GetApplicationLocale(), type);
335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
337c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool FullWalletBillingWrapper::GetDisplayText(
338c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* vertically_compact,
339c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    base::string16* horizontally_compact) {
340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(dbeam): handle other required actions? http://crbug.com/163508
341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE))
342c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    return false;
343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
344c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  return DataModelWrapper::GetDisplayText(vertically_compact,
345c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch                                          horizontally_compact);
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
348a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& FullWalletBillingWrapper::GetLanguageCode() const {
349a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Can be NULL if there are required actions.
350a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return full_wallet_->billing_address() ?
351a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      full_wallet_->billing_address()->language_code() : base::EmptyString();
352a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
353a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// FullWalletShippingWrapper
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)FullWalletShippingWrapper::FullWalletShippingWrapper(
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    wallet::FullWallet* full_wallet)
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : full_wallet_(full_wallet) {
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(full_wallet_);
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)FullWalletShippingWrapper::~FullWalletShippingWrapper() {}
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
364c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbase::string16 FullWalletShippingWrapper::GetInfo(
365c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const AutofillType& type) const {
366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return full_wallet_->shipping_address()->GetInfo(
367c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      type, g_browser_process->GetApplicationLocale());
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
370a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& FullWalletShippingWrapper::GetLanguageCode() const {
371a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Can be NULL if there are required actions or shipping address is not
372a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // required.
373a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return full_wallet_->shipping_address() ?
374a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      full_wallet_->shipping_address()->language_code() : base::EmptyString();
375a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
376a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
377a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// I18nAddressDataWrapper
378a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
379effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochI18nAddressDataWrapper::I18nAddressDataWrapper(
380effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    const ::i18n::addressinput::AddressData* address)
381effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    : address_(address) {}
382effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
383effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochI18nAddressDataWrapper::~I18nAddressDataWrapper() {}
384effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
385effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochbase::string16 I18nAddressDataWrapper::GetInfo(const AutofillType& type) const {
386effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ::i18n::addressinput::AddressField field;
387116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (!i18n::FieldForType(type.GetStorableType(), &field))
388effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return base::string16();
389effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
390effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (field == ::i18n::addressinput::STREET_ADDRESS)
391effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return base::string16();
392effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
393effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (field == ::i18n::addressinput::COUNTRY) {
394116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return AutofillCountry(address_->region_code,
395effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                           g_browser_process->GetApplicationLocale()).name();
396effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
397effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
398effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return base::UTF8ToUTF16(address_->GetFieldValue(field));
399effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
400effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
401a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst std::string& I18nAddressDataWrapper::GetLanguageCode() const {
402a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return address_->language_code;
403a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
404a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace autofill
406