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

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

Issue 1924863002: Rescoping prior profile data in Autofill settings to correct regression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 localized_strings->Set("autofillDefaultCountryComponents", 197 localized_strings->Set("autofillDefaultCountryComponents",
198 default_country_components.release()); 198 default_country_components.release());
199 localized_strings->SetString("autofillDefaultCountryLanguageCode", 199 localized_strings->SetString("autofillDefaultCountryLanguageCode",
200 default_country_language_code); 200 default_country_language_code);
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 204
205 namespace options { 205 namespace options {
206 206
207 AutofillOptionsHandler::AutofillOptionsHandler() 207 AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(nullptr) {}
208 : personal_data_(nullptr), prior_profile_(nullptr) {}
209 208
210 AutofillOptionsHandler::~AutofillOptionsHandler() { 209 AutofillOptionsHandler::~AutofillOptionsHandler() {
211 if (personal_data_) 210 if (personal_data_)
212 personal_data_->RemoveObserver(this); 211 personal_data_->RemoveObserver(this);
213 } 212 }
214 213
215 ///////////////////////////////////////////////////////////////////////////// 214 /////////////////////////////////////////////////////////////////////////////
216 // OptionsPageUIHandler implementation: 215 // OptionsPageUIHandler implementation:
217 void AutofillOptionsHandler::GetLocalizedValues( 216 void AutofillOptionsHandler::GetLocalizedValues(
218 base::DictionaryValue* localized_strings) { 217 base::DictionaryValue* localized_strings) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 383
385 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { 384 void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) {
386 DCHECK(IsPersonalDataLoaded()); 385 DCHECK(IsPersonalDataLoaded());
387 386
388 std::string guid; 387 std::string guid;
389 if (!args->GetString(0, &guid)) { 388 if (!args->GetString(0, &guid)) {
390 NOTREACHED(); 389 NOTREACHED();
391 return; 390 return;
392 } 391 }
393 392
394 prior_profile_ = personal_data_->GetProfileByGUID(guid); 393 const AutofillProfile* prior_profile = personal_data_->GetProfileByGUID(guid);
395 if (!prior_profile_) { 394 if (!prior_profile) {
396 // 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
397 // 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
398 // 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
399 // 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
400 // removed. Do nothing in that case. 399 // removed. Do nothing in that case.
401 return; 400 return;
402 } 401 }
403 402
404 base::DictionaryValue address; 403 base::DictionaryValue address;
405 AutofillProfileToDictionary(*prior_profile_, &address); 404 AutofillProfileToDictionary(*prior_profile, &address);
406 405
407 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); 406 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address);
408 } 407 }
409 408
410 void AutofillOptionsHandler::LoadAddressEditorComponents( 409 void AutofillOptionsHandler::LoadAddressEditorComponents(
411 const base::ListValue* args) { 410 const base::ListValue* args) {
412 std::string country_code; 411 std::string country_code;
413 if (!args->GetString(0, &country_code)) { 412 if (!args->GetString(0, &country_code)) {
414 NOTREACHED(); 413 NOTREACHED();
415 return; 414 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 if (!args->GetString(arg_counter++, &guid)) { 472 if (!args->GetString(arg_counter++, &guid)) {
474 NOTREACHED(); 473 NOTREACHED();
475 return; 474 return;
476 } 475 }
477 476
478 AutofillProfile profile(guid, kSettingsOrigin); 477 AutofillProfile profile(guid, kSettingsOrigin);
479 478
480 base::string16 full_name; 479 base::string16 full_name;
481 if (args->GetString(arg_counter++, &full_name)) { 480 if (args->GetString(arg_counter++, &full_name)) {
482 // Although First/Middle/Last are not displayed on the form, we transfer 481 // Although First/Middle/Last are not displayed on the form, we transfer
483 // this information when they match the full name given. This is because it 482 // this information when they match the full name in the old version of the
484 // may not be possible later to correctly tokenize the concatenated full 483 // profile, if one exists. This is because it may not be possible later to
485 // name; e.g., when the last name contains a space, the first word would be 484 // correctly tokenize the concatenated full name; e.g., when the last name
486 // treated as a middle name. 485 // contains a space, the first word would be treated as a middle name.
487 if (prior_profile_ && autofill::data_util::ProfileMatchesFullName( 486 const AutofillProfile* prior_profile =
488 full_name, *prior_profile_)) { 487 base::IsValidGUID(profile.guid())
488 ? personal_data_->GetProfileByGUID(guid)
489 : nullptr;
490
491 if (prior_profile && autofill::data_util::ProfileMatchesFullName(
492 full_name, *prior_profile)) {
489 profile.SetRawInfo(autofill::NAME_FULL, full_name); 493 profile.SetRawInfo(autofill::NAME_FULL, full_name);
490 494
491 profile.SetRawInfo(autofill::NAME_FIRST, 495 profile.SetRawInfo(autofill::NAME_FIRST,
492 prior_profile_->GetRawInfo(autofill::NAME_FIRST)); 496 prior_profile->GetRawInfo(autofill::NAME_FIRST));
493 profile.SetRawInfo(autofill::NAME_MIDDLE, 497 profile.SetRawInfo(autofill::NAME_MIDDLE,
494 prior_profile_->GetRawInfo(autofill::NAME_MIDDLE)); 498 prior_profile->GetRawInfo(autofill::NAME_MIDDLE));
495 profile.SetRawInfo(autofill::NAME_LAST, 499 profile.SetRawInfo(autofill::NAME_LAST,
496 prior_profile_->GetRawInfo(autofill::NAME_LAST)); 500 prior_profile->GetRawInfo(autofill::NAME_LAST));
497 } else { 501 } else {
498 // In contrast to SetRawInfo, SetInfo will naively attempt to populate the 502 // In contrast to SetRawInfo, SetInfo will naively attempt to populate the
499 // First/Middle/Last fields by tokenization. 503 // First/Middle/Last fields by tokenization.
500 profile.SetInfo(AutofillType(autofill::NAME_FULL), full_name, 504 profile.SetInfo(AutofillType(autofill::NAME_FULL), full_name,
501 g_browser_process->GetApplicationLocale()); 505 g_browser_process->GetApplicationLocale());
502 } 506 }
503 } 507 }
504 508
505 base::string16 value; 509 base::string16 value;
506 if (args->GetString(arg_counter++, &value)) 510 if (args->GetString(arg_counter++, &value))
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 address->SetString(kLanguageCode, profile.language_code()); 627 address->SetString(kLanguageCode, profile.language_code());
624 628
625 std::unique_ptr<base::ListValue> components(new base::ListValue); 629 std::unique_ptr<base::ListValue> components(new base::ListValue);
626 GetAddressComponents( 630 GetAddressComponents(
627 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), 631 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
628 profile.language_code(), components.get(), nullptr); 632 profile.language_code(), components.get(), nullptr);
629 address->Set(kComponents, components.release()); 633 address->Set(kComponents, components.release());
630 } 634 }
631 635
632 } // namespace options 636 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698