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

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 1868003003: Preserving first/middle/last names when an Autofill profile is submitted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing stevenjb nits Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/autofill/personal_data_manager_factory.h" 22 #include "chrome/browser/autofill/personal_data_manager_factory.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/autofill/country_combobox_model.h" 25 #include "chrome/browser/ui/autofill/country_combobox_model.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/grit/chromium_strings.h" 27 #include "chrome/grit/chromium_strings.h"
28 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
29 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 29 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
30 #include "components/autofill/core/browser/autofill_country.h" 30 #include "components/autofill/core/browser/autofill_country.h"
31 #include "components/autofill/core/browser/autofill_data_util.h"
31 #include "components/autofill/core/browser/autofill_profile.h" 32 #include "components/autofill/core/browser/autofill_profile.h"
32 #include "components/autofill/core/browser/credit_card.h" 33 #include "components/autofill/core/browser/credit_card.h"
33 #include "components/autofill/core/browser/personal_data_manager.h" 34 #include "components/autofill/core/browser/personal_data_manager.h"
34 #include "components/autofill/core/browser/phone_number_i18n.h" 35 #include "components/autofill/core/browser/phone_number_i18n.h"
35 #include "components/autofill/core/common/autofill_constants.h" 36 #include "components/autofill/core/common/autofill_constants.h"
36 #include "components/autofill/core/common/autofill_switches.h" 37 #include "components/autofill/core/common/autofill_switches.h"
37 #include "content/public/browser/web_ui.h" 38 #include "content/public/browser/web_ui.h"
38 #include "grit/components_strings.h" 39 #include "grit/components_strings.h"
39 #include "third_party/libaddressinput/messages.h" 40 #include "third_party/libaddressinput/messages.h"
40 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h" 41 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 const std::string& ui_language_code, 91 const std::string& ui_language_code,
91 base::ListValue* address_components, 92 base::ListValue* address_components,
92 std::string* components_language_code) { 93 std::string* components_language_code) {
93 DCHECK(address_components); 94 DCHECK(address_components);
94 95
95 i18n::addressinput::Localization localization; 96 i18n::addressinput::Localization localization;
96 localization.SetGetter(l10n_util::GetStringUTF8); 97 localization.SetGetter(l10n_util::GetStringUTF8);
97 std::string not_used; 98 std::string not_used;
98 std::vector<AddressUiComponent> components = 99 std::vector<AddressUiComponent> components =
99 i18n::addressinput::BuildComponents( 100 i18n::addressinput::BuildComponents(
100 country_code, 101 country_code, localization, ui_language_code,
101 localization, 102 components_language_code ? components_language_code : &not_used);
102 ui_language_code,
103 components_language_code == NULL ?
104 &not_used : components_language_code);
105 if (components.empty()) { 103 if (components.empty()) {
106 static const char kDefaultCountryCode[] = "US"; 104 static const char kDefaultCountryCode[] = "US";
107 components = i18n::addressinput::BuildComponents( 105 components = i18n::addressinput::BuildComponents(
108 kDefaultCountryCode, 106 kDefaultCountryCode, localization, ui_language_code,
109 localization, 107 components_language_code ? components_language_code : &not_used);
110 ui_language_code,
111 components_language_code == NULL ?
112 &not_used : components_language_code);
113 } 108 }
114 DCHECK(!components.empty()); 109 DCHECK(!components.empty());
115 110
116 base::ListValue* line = NULL; 111 base::ListValue* line = nullptr;
117 static const char kField[] = "field"; 112 static const char kField[] = "field";
118 static const char kLength[] = "length"; 113 static const char kLength[] = "length";
119 for (size_t i = 0; i < components.size(); ++i) { 114 for (size_t i = 0; i < components.size(); ++i) {
120 if (i == 0 || 115 if (i == 0 ||
121 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || 116 components[i - 1].length_hint == AddressUiComponent::HINT_LONG ||
122 components[i].length_hint == AddressUiComponent::HINT_LONG) { 117 components[i].length_hint == AddressUiComponent::HINT_LONG) {
123 line = new base::ListValue; 118 line = new base::ListValue;
124 address_components->Append(line); 119 address_components->Append(line);
125 } 120 }
126 121
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 localized_strings->Set("autofillDefaultCountryComponents", 196 localized_strings->Set("autofillDefaultCountryComponents",
202 default_country_components.release()); 197 default_country_components.release());
203 localized_strings->SetString("autofillDefaultCountryLanguageCode", 198 localized_strings->SetString("autofillDefaultCountryLanguageCode",
204 default_country_language_code); 199 default_country_language_code);
205 } 200 }
206 201
207 } // namespace 202 } // namespace
208 203
209 namespace options { 204 namespace options {
210 205
211 AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(NULL) {} 206 AutofillOptionsHandler::AutofillOptionsHandler()
207 : personal_data_(nullptr), prior_profile_(nullptr) {}
212 208
213 AutofillOptionsHandler::~AutofillOptionsHandler() { 209 AutofillOptionsHandler::~AutofillOptionsHandler() {
214 if (personal_data_) 210 if (personal_data_)
215 personal_data_->RemoveObserver(this); 211 personal_data_->RemoveObserver(this);
216 } 212 }
217 213
218 ///////////////////////////////////////////////////////////////////////////// 214 /////////////////////////////////////////////////////////////////////////////
219 // OptionsPageUIHandler implementation: 215 // OptionsPageUIHandler implementation:
220 void AutofillOptionsHandler::GetLocalizedValues( 216 void AutofillOptionsHandler::GetLocalizedValues(
221 base::DictionaryValue* localized_strings) { 217 base::DictionaryValue* localized_strings) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 383
388 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { 384 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) {
389 DCHECK(IsPersonalDataLoaded()); 385 DCHECK(IsPersonalDataLoaded());
390 386
391 std::string guid; 387 std::string guid;
392 if (!args->GetString(0, &guid)) { 388 if (!args->GetString(0, &guid)) {
393 NOTREACHED(); 389 NOTREACHED();
394 return; 390 return;
395 } 391 }
396 392
397 AutofillProfile* profile = personal_data_->GetProfileByGUID(guid); 393 prior_profile_ = personal_data_->GetProfileByGUID(guid);
398 if (!profile) { 394 if (!prior_profile_) {
399 // There is a race where a user can click once on the close button and 395 // There is a race where a user can click once on the close button and
400 // quickly click again on the list item before the item is removed (since 396 // quickly click again on the list item before the item is removed (since
401 // the list is not updated until the model tells the list an item has been 397 // the list is not updated until the model tells the list an item has been
402 // removed). This will activate the editor for a profile that has been 398 // removed). This will activate the editor for a profile that has been
403 // removed. Do nothing in that case. 399 // removed. Do nothing in that case.
404 return; 400 return;
405 } 401 }
406 402
407 base::DictionaryValue address; 403 base::DictionaryValue address;
408 AutofillProfileToDictionary(*profile, &address); 404 AutofillProfileToDictionary(*prior_profile_, &address);
409 405
410 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); 406 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address);
411 } 407 }
412 408
413 void AutofillOptionsHandler::LoadAddressEditorComponents( 409 void AutofillOptionsHandler::LoadAddressEditorComponents(
414 const base::ListValue* args) { 410 const base::ListValue* args) {
415 std::string country_code; 411 std::string country_code;
416 if (!args->GetString(0, &country_code)) { 412 if (!args->GetString(0, &country_code)) {
417 NOTREACHED(); 413 NOTREACHED();
418 return; 414 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 469
474 int arg_counter = 0; 470 int arg_counter = 0;
475 std::string guid; 471 std::string guid;
476 if (!args->GetString(arg_counter++, &guid)) { 472 if (!args->GetString(arg_counter++, &guid)) {
477 NOTREACHED(); 473 NOTREACHED();
478 return; 474 return;
479 } 475 }
480 476
481 AutofillProfile profile(guid, kSettingsOrigin); 477 AutofillProfile profile(guid, kSettingsOrigin);
482 478
483 base::string16 value; 479 base::string16 full_name;
484 if (args->GetString(arg_counter++, &value)) { 480 if (args->GetString(arg_counter++, &full_name)) {
485 profile.SetInfo(AutofillType(autofill::NAME_FULL), value, 481 // Although First/Middle/Last are not displayed on the form, we transfer
486 g_browser_process->GetApplicationLocale()); 482 // this information when they match the full name given. This is because it
483 // may not be possible later to correctly tokenize the concatenated full
484 // name; e.g., when the last name contains a space, the first word would be
485 // treated as a middle name.
486 if (prior_profile_ && autofill::data_util::ProfileMatchesFullName(
487 full_name, *prior_profile_)) {
488 profile.SetRawInfo(autofill::NAME_FULL, full_name);
489
490 profile.SetRawInfo(autofill::NAME_FIRST,
491 prior_profile_->GetRawInfo(autofill::NAME_FIRST));
492 profile.SetRawInfo(autofill::NAME_MIDDLE,
493 prior_profile_->GetRawInfo(autofill::NAME_MIDDLE));
494 profile.SetRawInfo(autofill::NAME_LAST,
495 prior_profile_->GetRawInfo(autofill::NAME_LAST));
496 } else {
497 // In contrast to SetRawInfo, SetInfo will naively attempt to populate the
498 // First/Middle/Last fields by tokenization.
499 profile.SetInfo(AutofillType(autofill::NAME_FULL), full_name,
500 g_browser_process->GetApplicationLocale());
501 }
487 } 502 }
488 503
504 base::string16 value;
489 if (args->GetString(arg_counter++, &value)) 505 if (args->GetString(arg_counter++, &value))
490 profile.SetRawInfo(autofill::COMPANY_NAME, value); 506 profile.SetRawInfo(autofill::COMPANY_NAME, value);
491 507
492 if (args->GetString(arg_counter++, &value)) 508 if (args->GetString(arg_counter++, &value))
493 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); 509 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value);
494 510
495 if (args->GetString(arg_counter++, &value)) 511 if (args->GetString(arg_counter++, &value))
496 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value); 512 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value);
497 513
498 if (args->GetString(arg_counter++, &value)) 514 if (args->GetString(arg_counter++, &value))
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 address->SetString(kCountryField, 617 address->SetString(kCountryField,
602 profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 618 profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
603 address->SetString("phone", 619 address->SetString("phone",
604 profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); 620 profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER));
605 address->SetString("email", profile.GetRawInfo(autofill::EMAIL_ADDRESS)); 621 address->SetString("email", profile.GetRawInfo(autofill::EMAIL_ADDRESS));
606 address->SetString(kLanguageCode, profile.language_code()); 622 address->SetString(kLanguageCode, profile.language_code());
607 623
608 scoped_ptr<base::ListValue> components(new base::ListValue); 624 scoped_ptr<base::ListValue> components(new base::ListValue);
609 GetAddressComponents( 625 GetAddressComponents(
610 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), 626 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
611 profile.language_code(), 627 profile.language_code(), components.get(), nullptr);
612 components.get(),
613 NULL);
614 address->Set(kComponents, components.release()); 628 address->Set(kComponents, components.release());
615 } 629 }
616 630
617 } // namespace options 631 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | components/autofill/core/browser/autofill_data_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698