Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc

Issue 261013010: autocomplete: add ability to get full address (hidden behind a flag). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/field_types.h" 13 #include "components/autofill/core/browser/field_types.h"
13 #include "grit/component_strings.h" 14 #include "grit/component_strings.h"
14 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" 15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h"
15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_field.h" 16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_field.h"
16 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h"
17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui_component.h" 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui_component.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 20
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 }; 81 };
81 82
82 for (size_t i = 0; i < arraysize(required_fields); ++i) { 83 for (size_t i = 0; i < arraysize(required_fields); ++i) {
83 if (card.GetRawInfo(required_fields[i]).empty()) 84 if (card.GetRawInfo(required_fields[i]).empty())
84 return false; 85 return false;
85 } 86 }
86 87
87 return true; 88 return true;
88 } 89 }
89 90
90 bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile) { 91 bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile,
92 const std::string& app_locale) {
91 if (!profile.IsVerified()) 93 if (!profile.IsVerified())
92 return false; 94 return false;
93 95
94 base::string16 country_code = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); 96 if (!i18n::CreateAddressDataFromAutofillProfile(profile, app_locale)->
95 if (country_code.empty()) 97 HasAllRequiredFields()) {
96 return false; 98 return false;
97
98 std::vector<AddressField> required_fields =
99 ::i18n::addressinput::GetRequiredFields(base::UTF16ToUTF8(country_code));
100
101 for (size_t i = 0; i < required_fields.size(); ++i) {
102 ServerFieldType type =
103 TypeForField(required_fields[i], common::ADDRESS_TYPE_SHIPPING);
104 if (profile.GetRawInfo(type).empty())
105 return false;
106 } 99 }
107 100
108 const ServerFieldType more_required_fields[] = { 101 const ServerFieldType more_required_fields[] = {
109 NAME_FULL, 102 NAME_FULL,
110 PHONE_HOME_WHOLE_NUMBER 103 PHONE_HOME_WHOLE_NUMBER
111 }; 104 };
112 105
113 for (size_t i = 0; i < arraysize(more_required_fields); ++i) { 106 for (size_t i = 0; i < arraysize(more_required_fields); ++i) {
114 if (profile.GetRawInfo(more_required_fields[i]).empty()) 107 if (profile.GetRawInfo(more_required_fields[i]).empty())
115 return false; 108 return false;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 case NAME_BILLING_FULL: 189 case NAME_BILLING_FULL:
197 case NAME_FULL: 190 case NAME_FULL:
198 if (field) 191 if (field)
199 *field = ::i18n::addressinput::RECIPIENT; 192 *field = ::i18n::addressinput::RECIPIENT;
200 return true; 193 return true;
201 default: 194 default:
202 return false; 195 return false;
203 } 196 }
204 } 197 }
205 198
206 void CreateAddressData(
207 const base::Callback<base::string16(const AutofillType&)>& get_info,
208 AddressData* address_data) {
209 address_data->recipient = UTF16ToUTF8(get_info.Run(AutofillType(NAME_FULL)));
210 address_data->country_code = UTF16ToUTF8(
211 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_SHIPPING)));
212 DCHECK_EQ(2U, address_data->country_code.size());
213 address_data->administrative_area = UTF16ToUTF8(
214 get_info.Run(AutofillType(ADDRESS_HOME_STATE)));
215 address_data->locality = UTF16ToUTF8(
216 get_info.Run(AutofillType(ADDRESS_HOME_CITY)));
217 address_data->dependent_locality = UTF16ToUTF8(
218 get_info.Run(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY)));
219 address_data->sorting_code = UTF16ToUTF8(
220 get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE)));
221 address_data->postal_code = UTF16ToUTF8(
222 get_info.Run(AutofillType(ADDRESS_HOME_ZIP)));
223 base::SplitString(
224 UTF16ToUTF8(get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))),
225 '\n',
226 &address_data->address_lines);
227 }
228
229 bool CountryIsFullySupported(const std::string& country_code) { 199 bool CountryIsFullySupported(const std::string& country_code) {
230 DCHECK_EQ(2U, country_code.size()); 200 DCHECK_EQ(2U, country_code.size());
231 std::vector< ::i18n::addressinput::AddressUiComponent> components = 201 std::vector< ::i18n::addressinput::AddressUiComponent> components =
232 ::i18n::addressinput::BuildComponents( 202 ::i18n::addressinput::BuildComponents(
233 country_code, g_browser_process->GetApplicationLocale(), NULL); 203 country_code, g_browser_process->GetApplicationLocale(), NULL);
234 for (size_t i = 0; i < components.size(); ++i) { 204 for (size_t i = 0; i < components.size(); ++i) {
235 if (components[i].field == ::i18n::addressinput::DEPENDENT_LOCALITY) 205 if (components[i].field == ::i18n::addressinput::DEPENDENT_LOCALITY)
236 return false; 206 return false;
237 } 207 }
238 return true; 208 return true;
239 } 209 }
240 210
241 } // namespace i18ninput 211 } // namespace i18ninput
242 } // namespace autofill 212 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_i18n_input.h ('k') | chrome/browser/ui/autofill/data_model_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698