Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill_dialog_i18n_input.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "components/autofill/core/browser/address_i18n.h" | 10 #include "components/autofill/core/browser/address_i18n.h" |
| 11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/field_types.h" | 13 #include "components/autofill/core/browser/field_types.h" |
| 14 #include "grit/component_strings.h" | 14 #include "grit/component_strings.h" |
| 15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | 15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_field.h" | 16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h" |
| 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" | 17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h" |
| 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui_component.h" | 18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui _component.h" |
| 19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 namespace i18ninput { | 23 namespace i18ninput { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 using base::UTF16ToUTF8; | 27 using base::UTF16ToUTF8; |
| 27 using ::i18n::addressinput::AddressData; | 28 using ::i18n::addressinput::AddressData; |
| 28 using ::i18n::addressinput::AddressField; | 29 using ::i18n::addressinput::AddressField; |
| 29 using ::i18n::addressinput::AddressUiComponent; | 30 using ::i18n::addressinput::AddressUiComponent; |
| 30 | 31 |
| 31 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { | 32 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) { |
| 32 if (hint == AddressUiComponent::HINT_SHORT) | 33 if (hint == AddressUiComponent::HINT_SHORT) |
| 33 return DetailInput::SHORT; | 34 return DetailInput::SHORT; |
| 34 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); | 35 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG); |
| 35 return DetailInput::LONG; | 36 return DetailInput::LONG; |
| 36 } | 37 } |
| 37 | 38 |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| 40 void BuildAddressInputs(common::AddressType address_type, | 41 void BuildAddressInputs(common::AddressType address_type, |
| 41 const std::string& country_code, | 42 const std::string& country_code, |
| 42 DetailInputs* inputs, | 43 DetailInputs* inputs, |
| 43 std::string* language_code) { | 44 std::string* language_code) { |
| 45 DCHECK(inputs); | |
| 46 DCHECK(language_code); | |
| 47 | |
| 48 ::i18n::addressinput::Localization localization; | |
| 49 localization.SetGetter( | |
| 50 l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); | |
| 44 std::vector<AddressUiComponent> components( | 51 std::vector<AddressUiComponent> components( |
| 45 ::i18n::addressinput::BuildComponents( | 52 ::i18n::addressinput::BuildComponents( |
| 46 country_code, g_browser_process->GetApplicationLocale(), | 53 country_code, localization, language_code)); |
| 47 language_code)); | |
| 48 | 54 |
| 49 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; | 55 const bool billing = address_type == common::ADDRESS_TYPE_BILLING; |
| 50 | 56 |
| 51 for (size_t i = 0; i < components.size(); ++i) { | 57 for (size_t i = 0; i < components.size(); ++i) { |
| 52 const AddressUiComponent& component = components[i]; | 58 const AddressUiComponent& component = components[i]; |
| 53 if (component.field == ::i18n::addressinput::ORGANIZATION) { | |
| 54 // TODO(dbeam): figure out when we actually need this. | |
| 55 continue; | |
| 56 } | |
| 57 | |
| 58 ServerFieldType server_type = TypeForField(component.field, address_type); | 59 ServerFieldType server_type = TypeForField(component.field, address_type); |
| 59 DetailInput::Length length = LengthFromHint(component.length_hint); | 60 DetailInput::Length length = LengthFromHint(component.length_hint); |
| 60 base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id); | 61 base::string16 placeholder = base::UTF8ToUTF16(component.name); |
| 61 DetailInput input = { length, server_type, placeholder }; | 62 DetailInput input = { length, server_type, placeholder }; |
| 62 inputs->push_back(input); | 63 inputs->push_back(input); |
| 63 } | 64 } |
| 64 | 65 |
| 65 ServerFieldType server_type = | 66 ServerFieldType server_type = |
| 66 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; | 67 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
| 67 base::string16 placeholder_text = | 68 base::string16 placeholder_text = |
| 68 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); | 69 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY); |
| 69 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; | 70 DetailInput input = { DetailInput::LONG, server_type, placeholder_text }; |
| 70 inputs->push_back(input); | 71 inputs->push_back(input); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 86 } | 87 } |
| 87 | 88 |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile, | 92 bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile, |
| 92 const std::string& app_locale) { | 93 const std::string& app_locale) { |
| 93 if (!profile.IsVerified()) | 94 if (!profile.IsVerified()) |
| 94 return false; | 95 return false; |
| 95 | 96 |
| 96 if (!i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)-> | 97 if (i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)-> |
| 97 HasAllRequiredFields()) { | 98 region_code.empty()) { |
| 99 // if (!i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)-> | |
| 100 // HasAllRequiredFields()) { | |
|
please use gerrit instead
2014/05/23 14:44:54
Need David's code to get required fields from stat
| |
| 98 return false; | 101 return false; |
| 99 } | 102 } |
| 100 | 103 |
| 101 const ServerFieldType more_required_fields[] = { | 104 const ServerFieldType more_required_fields[] = { |
| 102 NAME_FULL, | 105 NAME_FULL, |
| 103 PHONE_HOME_WHOLE_NUMBER | 106 PHONE_HOME_WHOLE_NUMBER |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 for (size_t i = 0; i < arraysize(more_required_fields); ++i) { | 109 for (size_t i = 0; i < arraysize(more_required_fields); ++i) { |
| 107 if (profile.GetRawInfo(more_required_fields[i]).empty()) | 110 if (profile.GetRawInfo(more_required_fields[i]).empty()) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 126 ADDRESS_HOME_DEPENDENT_LOCALITY; | 129 ADDRESS_HOME_DEPENDENT_LOCALITY; |
| 127 case ::i18n::addressinput::POSTAL_CODE: | 130 case ::i18n::addressinput::POSTAL_CODE: |
| 128 return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP; | 131 return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP; |
| 129 case ::i18n::addressinput::SORTING_CODE: | 132 case ::i18n::addressinput::SORTING_CODE: |
| 130 return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE; | 133 return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE; |
| 131 case ::i18n::addressinput::STREET_ADDRESS: | 134 case ::i18n::addressinput::STREET_ADDRESS: |
| 132 return billing ? ADDRESS_BILLING_STREET_ADDRESS : | 135 return billing ? ADDRESS_BILLING_STREET_ADDRESS : |
| 133 ADDRESS_HOME_STREET_ADDRESS; | 136 ADDRESS_HOME_STREET_ADDRESS; |
| 134 case ::i18n::addressinput::RECIPIENT: | 137 case ::i18n::addressinput::RECIPIENT: |
| 135 return billing ? NAME_BILLING_FULL : NAME_FULL; | 138 return billing ? NAME_BILLING_FULL : NAME_FULL; |
| 136 case ::i18n::addressinput::ORGANIZATION: | |
| 137 return COMPANY_NAME; | |
| 138 } | 139 } |
| 139 NOTREACHED(); | 140 NOTREACHED(); |
| 140 return UNKNOWN_TYPE; | 141 return UNKNOWN_TYPE; |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool FieldForType(ServerFieldType server_type, | 144 bool FieldForType(ServerFieldType server_type, |
| 144 ::i18n::addressinput::AddressField* field) { | 145 ::i18n::addressinput::AddressField* field) { |
| 145 switch (server_type) { | 146 switch (server_type) { |
| 146 case ADDRESS_BILLING_COUNTRY: | 147 case ADDRESS_BILLING_COUNTRY: |
| 147 case ADDRESS_HOME_COUNTRY: | 148 case ADDRESS_HOME_COUNTRY: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 176 case ADDRESS_BILLING_STREET_ADDRESS: | 177 case ADDRESS_BILLING_STREET_ADDRESS: |
| 177 case ADDRESS_BILLING_LINE1: | 178 case ADDRESS_BILLING_LINE1: |
| 178 case ADDRESS_BILLING_LINE2: | 179 case ADDRESS_BILLING_LINE2: |
| 179 case ADDRESS_HOME_STREET_ADDRESS: | 180 case ADDRESS_HOME_STREET_ADDRESS: |
| 180 case ADDRESS_HOME_LINE1: | 181 case ADDRESS_HOME_LINE1: |
| 181 case ADDRESS_HOME_LINE2: | 182 case ADDRESS_HOME_LINE2: |
| 182 if (field) | 183 if (field) |
| 183 *field = ::i18n::addressinput::STREET_ADDRESS; | 184 *field = ::i18n::addressinput::STREET_ADDRESS; |
| 184 return true; | 185 return true; |
| 185 case COMPANY_NAME: | 186 case COMPANY_NAME: |
| 186 if (field) | 187 // Ignored. |
| 187 *field = ::i18n::addressinput::ORGANIZATION; | |
| 188 return true; | 188 return true; |
| 189 case NAME_BILLING_FULL: | 189 case NAME_BILLING_FULL: |
| 190 case NAME_FULL: | 190 case NAME_FULL: |
| 191 if (field) | 191 if (field) |
| 192 *field = ::i18n::addressinput::RECIPIENT; | 192 *field = ::i18n::addressinput::RECIPIENT; |
| 193 return true; | 193 return true; |
| 194 default: | 194 default: |
| 195 return false; | 195 return false; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool CountryIsFullySupported(const std::string& country_code) { | 199 bool CountryIsFullySupported(const std::string& country_code) { |
| 200 DCHECK_EQ(2U, country_code.size()); | 200 DCHECK_EQ(2U, country_code.size()); |
| 201 ::i18n::addressinput::Localization localization; | |
| 202 localization.SetGetter( | |
| 203 l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); | |
| 204 std::string best_address_language; | |
| 201 std::vector< ::i18n::addressinput::AddressUiComponent> components = | 205 std::vector< ::i18n::addressinput::AddressUiComponent> components = |
| 202 ::i18n::addressinput::BuildComponents( | 206 ::i18n::addressinput::BuildComponents( |
| 203 country_code, g_browser_process->GetApplicationLocale(), NULL); | 207 country_code, localization, &best_address_language); |
| 204 for (size_t i = 0; i < components.size(); ++i) { | 208 for (size_t i = 0; i < components.size(); ++i) { |
| 205 if (components[i].field == ::i18n::addressinput::DEPENDENT_LOCALITY) | 209 if (components[i].field == ::i18n::addressinput::DEPENDENT_LOCALITY) |
| 206 return false; | 210 return false; |
| 207 } | 211 } |
| 208 return true; | 212 return true; |
| 209 } | 213 } |
| 210 | 214 |
| 211 } // namespace i18ninput | 215 } // namespace i18ninput |
| 212 } // namespace autofill | 216 } // namespace autofill |
| OLD | NEW |