Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 localized_strings->Set("autofillDefaultCountryComponents", | 201 localized_strings->Set("autofillDefaultCountryComponents", |
| 202 default_country_components.release()); | 202 default_country_components.release()); |
| 203 localized_strings->SetString("autofillDefaultCountryLanguageCode", | 203 localized_strings->SetString("autofillDefaultCountryLanguageCode", |
| 204 default_country_language_code); | 204 default_country_language_code); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace | 207 } // namespace |
| 208 | 208 |
| 209 namespace options { | 209 namespace options { |
| 210 | 210 |
| 211 AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(NULL) {} | 211 AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(NULL) {} |
|
Mathieu
2016/04/11 15:01:21
nit: NULL -> nullptr
everywhere in this file.
tmartino
2016/04/12 20:48:27
Done.
| |
| 212 | 212 |
| 213 AutofillOptionsHandler::~AutofillOptionsHandler() { | 213 AutofillOptionsHandler::~AutofillOptionsHandler() { |
| 214 if (personal_data_) | 214 if (personal_data_) |
| 215 personal_data_->RemoveObserver(this); | 215 personal_data_->RemoveObserver(this); |
| 216 } | 216 } |
| 217 | 217 |
| 218 ///////////////////////////////////////////////////////////////////////////// | 218 ///////////////////////////////////////////////////////////////////////////// |
| 219 // OptionsPageUIHandler implementation: | 219 // OptionsPageUIHandler implementation: |
| 220 void AutofillOptionsHandler::GetLocalizedValues( | 220 void AutofillOptionsHandler::GetLocalizedValues( |
| 221 base::DictionaryValue* localized_strings) { | 221 base::DictionaryValue* localized_strings) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 | 387 |
| 388 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { | 388 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { |
| 389 DCHECK(IsPersonalDataLoaded()); | 389 DCHECK(IsPersonalDataLoaded()); |
| 390 | 390 |
| 391 std::string guid; | 391 std::string guid; |
| 392 if (!args->GetString(0, &guid)) { | 392 if (!args->GetString(0, &guid)) { |
| 393 NOTREACHED(); | 393 NOTREACHED(); |
| 394 return; | 394 return; |
| 395 } | 395 } |
| 396 | 396 |
| 397 AutofillProfile* profile = personal_data_->GetProfileByGUID(guid); | 397 prior_profile_ = personal_data_->GetProfileByGUID(guid); |
| 398 if (!profile) { | 398 if (!prior_profile_) { |
| 399 // There is a race where a user can click once on the close button and | 399 // 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 | 400 // 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 | 401 // 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 | 402 // removed). This will activate the editor for a profile that has been |
| 403 // removed. Do nothing in that case. | 403 // removed. Do nothing in that case. |
| 404 return; | 404 return; |
| 405 } | 405 } |
| 406 | 406 |
| 407 base::DictionaryValue address; | 407 base::DictionaryValue address; |
| 408 AutofillProfileToDictionary(*profile, &address); | 408 AutofillProfileToDictionary(*prior_profile_, &address); |
| 409 | 409 |
| 410 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); | 410 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void AutofillOptionsHandler::LoadAddressEditorComponents( | 413 void AutofillOptionsHandler::LoadAddressEditorComponents( |
| 414 const base::ListValue* args) { | 414 const base::ListValue* args) { |
| 415 std::string country_code; | 415 std::string country_code; |
| 416 if (!args->GetString(0, &country_code)) { | 416 if (!args->GetString(0, &country_code)) { |
| 417 NOTREACHED(); | 417 NOTREACHED(); |
| 418 return; | 418 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 std::string guid; | 475 std::string guid; |
| 476 if (!args->GetString(arg_counter++, &guid)) { | 476 if (!args->GetString(arg_counter++, &guid)) { |
| 477 NOTREACHED(); | 477 NOTREACHED(); |
| 478 return; | 478 return; |
| 479 } | 479 } |
| 480 | 480 |
| 481 AutofillProfile profile(guid, kSettingsOrigin); | 481 AutofillProfile profile(guid, kSettingsOrigin); |
| 482 | 482 |
| 483 base::string16 value; | 483 base::string16 value; |
| 484 if (args->GetString(arg_counter++, &value)) { | 484 if (args->GetString(arg_counter++, &value)) { |
| 485 profile.SetInfo(AutofillType(autofill::NAME_FULL), value, | 485 profile.SetInfo(AutofillType(autofill::NAME_FULL), value, |
|
Mathieu
2016/04/11 15:01:21
The origin of this bug is here. When profile.SetIn
tmartino
2016/04/12 20:48:27
With the new flow I don't think it should be neces
| |
| 486 g_browser_process->GetApplicationLocale()); | 486 g_browser_process->GetApplicationLocale()); |
| 487 } | 487 } |
| 488 | 488 |
| 489 if (args->GetString(arg_counter++, &value)) | 489 if (args->GetString(arg_counter++, &value)) |
| 490 profile.SetRawInfo(autofill::COMPANY_NAME, value); | 490 profile.SetRawInfo(autofill::COMPANY_NAME, value); |
| 491 | 491 |
| 492 if (args->GetString(arg_counter++, &value)) | 492 if (args->GetString(arg_counter++, &value)) |
| 493 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); | 493 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); |
| 494 | 494 |
| 495 if (args->GetString(arg_counter++, &value)) | 495 if (args->GetString(arg_counter++, &value)) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 512 | 512 |
| 513 if (args->GetString(arg_counter++, &value)) | 513 if (args->GetString(arg_counter++, &value)) |
| 514 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, value); | 514 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, value); |
| 515 | 515 |
| 516 if (args->GetString(arg_counter++, &value)) | 516 if (args->GetString(arg_counter++, &value)) |
| 517 profile.SetRawInfo(autofill::EMAIL_ADDRESS, value); | 517 profile.SetRawInfo(autofill::EMAIL_ADDRESS, value); |
| 518 | 518 |
| 519 if (args->GetString(arg_counter++, &value)) | 519 if (args->GetString(arg_counter++, &value)) |
| 520 profile.set_language_code(base::UTF16ToUTF8(value)); | 520 profile.set_language_code(base::UTF16ToUTF8(value)); |
| 521 | 521 |
| 522 // Although First/Middle/Last are not displayed on the form, we transfer this | |
| 523 // information when they match the full name given. This is because it may not | |
| 524 // be possible later to correctly tokenize the concatenated full name--e.g., | |
| 525 // when the last name contains a space, the first word would be treated as a | |
| 526 // middle name. | |
| 527 if (prior_profile_ && | |
| 528 ShouldTransferNameComponents(profile, *prior_profile_)) { | |
| 529 profile.SetRawInfo(autofill::NAME_FIRST, | |
| 530 prior_profile_->GetRawInfo(autofill::NAME_FIRST)); | |
| 531 profile.SetRawInfo(autofill::NAME_MIDDLE, | |
| 532 prior_profile_->GetRawInfo(autofill::NAME_MIDDLE)); | |
| 533 profile.SetRawInfo(autofill::NAME_LAST, | |
| 534 prior_profile_->GetRawInfo(autofill::NAME_LAST)); | |
| 535 profile.SetRawInfo( | |
| 536 autofill::NAME_MIDDLE_INITIAL, | |
|
Mathieu
2016/04/11 15:01:21
curious: I'm not familiar with middle initial. In
tmartino
2016/04/12 20:48:27
It appears that it's not stored anywhere:
https:/
| |
| 537 prior_profile_->GetRawInfo(autofill::NAME_MIDDLE_INITIAL)); | |
| 538 } | |
| 539 | |
| 522 if (!base::IsValidGUID(profile.guid())) { | 540 if (!base::IsValidGUID(profile.guid())) { |
| 523 profile.set_guid(base::GenerateGUID()); | 541 profile.set_guid(base::GenerateGUID()); |
| 524 personal_data_->AddProfile(profile); | 542 personal_data_->AddProfile(profile); |
| 525 } else { | 543 } else { |
| 526 personal_data_->UpdateProfile(profile); | 544 personal_data_->UpdateProfile(profile); |
| 527 } | 545 } |
| 528 } | 546 } |
| 529 | 547 |
| 530 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { | 548 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { |
| 531 if (!IsPersonalDataLoaded()) | 549 if (!IsPersonalDataLoaded()) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 625 |
| 608 scoped_ptr<base::ListValue> components(new base::ListValue); | 626 scoped_ptr<base::ListValue> components(new base::ListValue); |
| 609 GetAddressComponents( | 627 GetAddressComponents( |
| 610 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 628 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
| 611 profile.language_code(), | 629 profile.language_code(), |
| 612 components.get(), | 630 components.get(), |
| 613 NULL); | 631 NULL); |
| 614 address->Set(kComponents, components.release()); | 632 address->Set(kComponents, components.release()); |
| 615 } | 633 } |
| 616 | 634 |
| 635 // Concatenates two strings, adding a space and, optionally, a period. | |
| 636 base::string16 StringConcatenationHelper(base::string16 first, | |
| 637 base::string16 second, | |
| 638 bool period) { | |
| 639 base::string16 delimiter = | |
| 640 period ? base::UTF8ToUTF16(". ") : base::UTF8ToUTF16(" "); | |
| 641 return first + delimiter + second; | |
| 642 } | |
| 643 | |
| 644 // static | |
| 645 bool AutofillOptionsHandler::ShouldTransferNameComponents( | |
|
Mathieu
2016/04/11 15:01:21
How about renaming this to ProfileExpressesFullNam
tmartino
2016/04/12 20:48:27
Done.
| |
| 646 const autofill::AutofillProfile& profile, | |
| 647 const autofill::AutofillProfile& prior_profile) { | |
| 648 base::string16 full_name = | |
| 649 profile.GetInfo(AutofillType(autofill::NAME_FULL), | |
| 650 g_browser_process->GetApplicationLocale()); | |
| 651 base::string16 first_last = StringConcatenationHelper( | |
|
Mathieu
2016/04/11 15:01:21
should probably return early if the comparison is
tmartino
2016/04/12 20:48:27
Done.
| |
| 652 prior_profile.GetRawInfo(autofill::NAME_FIRST), | |
| 653 prior_profile.GetRawInfo(autofill::NAME_LAST), false); | |
| 654 base::string16 first_middle_last = StringConcatenationHelper( | |
| 655 StringConcatenationHelper(prior_profile.GetRawInfo(autofill::NAME_FIRST), | |
| 656 prior_profile.GetRawInfo(autofill::NAME_MIDDLE), | |
| 657 false), | |
| 658 prior_profile.GetRawInfo(autofill::NAME_LAST), false); | |
| 659 base::string16 first_m_last = StringConcatenationHelper( | |
| 660 StringConcatenationHelper( | |
| 661 prior_profile.GetRawInfo(autofill::NAME_FIRST), | |
| 662 prior_profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL), false), | |
| 663 prior_profile.GetRawInfo(autofill::NAME_LAST), false); | |
| 664 base::string16 first_m_period_last = StringConcatenationHelper( | |
| 665 StringConcatenationHelper( | |
| 666 prior_profile.GetRawInfo(autofill::NAME_FIRST), | |
| 667 prior_profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL), false), | |
| 668 prior_profile.GetRawInfo(autofill::NAME_LAST), true); | |
| 669 return !(full_name.compare(first_last) && | |
| 670 full_name.compare(first_middle_last) && | |
| 671 full_name.compare(first_m_last) && | |
| 672 full_name.compare(first_m_period_last)); | |
| 673 } | |
| 674 | |
| 617 } // namespace options | 675 } // namespace options |
| OLD | NEW |