Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / autofill / data_model_wrapper.cc
index 7c0b9df..1293a9f 100644 (file)
@@ -32,7 +32,8 @@ DataModelWrapper::~DataModelWrapper() {}
 
 void DataModelWrapper::FillInputs(DetailInputs* inputs) {
   for (size_t i = 0; i < inputs->size(); ++i) {
-    (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type));
+    (*inputs)[i].initial_value =
+        GetInfoForDisplay(AutofillType((*inputs)[i].type));
   }
 }
 
@@ -58,6 +59,7 @@ bool DataModelWrapper::GetDisplayText(
   i18ninput::CreateAddressData(
       base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
       &address_data);
+  address_data.language_code = GetLanguageCode();
   std::vector<std::string> lines;
   address_data.FormatForDisplay(&lines);
 
@@ -71,8 +73,7 @@ bool DataModelWrapper::GetDisplayText(
 
   // The separator is locale-specific.
   std::string compact_separator =
-      ::i18n::addressinput::GetCompactAddressLinesSeparator(
-          g_browser_process->GetApplicationLocale());
+      ::i18n::addressinput::GetCompactAddressLinesSeparator(GetLanguageCode());
   *vertically_compact =
       base::UTF8ToUTF16(JoinString(lines, compact_separator)) +
           non_address_info;
@@ -140,7 +141,10 @@ base::string16 AutofillProfileWrapper::GetInfoForDisplay(
       std::string region = base::UTF16ToASCII(
           GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE)));
       i18n::PhoneObject phone(phone_number, region);
-      return phone.GetFormattedNumber();
+      base::string16 formatted_number = phone.GetFormattedNumber();
+      // Formatting may fail.
+      if (!formatted_number.empty())
+        return formatted_number;
     }
 
     return phone_number;
@@ -149,6 +153,10 @@ base::string16 AutofillProfileWrapper::GetInfoForDisplay(
   return DataModelWrapper::GetInfoForDisplay(type);
 }
 
+const std::string& AutofillProfileWrapper::GetLanguageCode() const {
+  return profile_->language_code();
+}
+
 size_t AutofillProfileWrapper::GetVariantForType(const AutofillType& type)
     const {
   if (type.group() == variant_group_)
@@ -207,6 +215,11 @@ bool AutofillCreditCardWrapper::GetDisplayText(
   return true;
 }
 
+const std::string& AutofillCreditCardWrapper::GetLanguageCode() const {
+  // Formatting a credit card for display does not depend on language code.
+  return base::EmptyString();
+}
+
 // WalletAddressWrapper
 
 WalletAddressWrapper::WalletAddressWrapper(
@@ -240,6 +253,10 @@ bool WalletAddressWrapper::GetDisplayText(
                                           horizontally_compact);
 }
 
+const std::string& WalletAddressWrapper::GetLanguageCode() const {
+  return address_->language_code();
+}
+
 // WalletInstrumentWrapper
 
 WalletInstrumentWrapper::WalletInstrumentWrapper(
@@ -295,6 +312,10 @@ bool WalletInstrumentWrapper::GetDisplayText(
   return true;
 }
 
+const std::string& WalletInstrumentWrapper::GetLanguageCode() const {
+  return instrument_->address().language_code();
+}
+
 // FullWalletBillingWrapper
 
 FullWalletBillingWrapper::FullWalletBillingWrapper(
@@ -324,6 +345,12 @@ bool FullWalletBillingWrapper::GetDisplayText(
                                           horizontally_compact);
 }
 
+const std::string& FullWalletBillingWrapper::GetLanguageCode() const {
+  // Can be NULL if there are required actions.
+  return full_wallet_->billing_address() ?
+      full_wallet_->billing_address()->language_code() : base::EmptyString();
+}
+
 // FullWalletShippingWrapper
 
 FullWalletShippingWrapper::FullWalletShippingWrapper(
@@ -340,6 +367,15 @@ base::string16 FullWalletShippingWrapper::GetInfo(
       type, g_browser_process->GetApplicationLocale());
 }
 
+const std::string& FullWalletShippingWrapper::GetLanguageCode() const {
+  // Can be NULL if there are required actions or shipping address is not
+  // required.
+  return full_wallet_->shipping_address() ?
+      full_wallet_->shipping_address()->language_code() : base::EmptyString();
+}
+
+// I18nAddressDataWrapper
+
 I18nAddressDataWrapper::I18nAddressDataWrapper(
     const ::i18n::addressinput::AddressData* address)
     : address_(address) {}
@@ -362,4 +398,8 @@ base::string16 I18nAddressDataWrapper::GetInfo(const AutofillType& type) const {
   return base::UTF8ToUTF16(address_->GetFieldValue(field));
 }
 
+const std::string& I18nAddressDataWrapper::GetLanguageCode() const {
+  return address_->language_code;
+}
+
 }  // namespace autofill