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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 799a8c4f039834db6a05432dc3e82e44b4b2d47b..5b84f24a0574abe61b2aadcb7ac5e89277af3b74 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/autofill/autofill_dialog_common.h"
+#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
#include "chrome/browser/ui/autofill/data_model_wrapper.h"
#if !defined(OS_ANDROID)
@@ -615,14 +616,10 @@ void AutofillDialogControllerImpl::Show() {
return;
}
- common::BuildInputsForSection(SECTION_CC,
- &requested_cc_fields_);
- common::BuildInputsForSection(SECTION_BILLING,
- &requested_billing_fields_);
- common::BuildInputsForSection(SECTION_CC_BILLING,
- &requested_cc_billing_fields_);
- common::BuildInputsForSection(SECTION_SHIPPING,
- &requested_shipping_fields_);
+ std::string guess = i18ninput::GuessCountry();
+ for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) {
+ SetCountryCodeForSection(static_cast<DialogSection>(section), guess);
+ }
// Test whether we need to show the shipping section. If filling that section
// would be a no-op, don't show it.
@@ -1102,8 +1099,9 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) {
SetEditingExistingData(section, false);
DetailInputs* inputs = MutableRequestedFieldsForSection(section);
+ std::string country_code = GetCountryCodeForSection(section);
for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
- it->initial_value = common::GetHardcodedValueForType(it->type);
+ it->initial_value = common::GetInitialValueForType(it->type, country_code);
}
}
@@ -1124,7 +1122,7 @@ void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion(
DetailInputs* inputs = MutableRequestedFieldsForSection(section);
if (wrapper && IsEditingExistingData(section))
- wrapper->FillInputs(inputs);
+ wrapper->FillInputs(inputs, GetCountryCodeForSection(section));
}
bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type,
@@ -1140,8 +1138,8 @@ bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type,
return true;
}
-DetailOutputMap AutofillDialogControllerImpl::TakeUserInputSnapshot() {
- DetailOutputMap snapshot;
+UserInputSnapshot AutofillDialogControllerImpl::TakeUserInputSnapshot() {
+ UserInputSnapshot snapshot;
if (!view_)
return snapshot;
@@ -1158,7 +1156,7 @@ DetailOutputMap AutofillDialogControllerImpl::TakeUserInputSnapshot() {
++it) {
if (InputWasEdited(it->first->type, it->second) &&
InputValidityMessage(section, it->first->type, it->second).empty()) {
- snapshot.insert(std::make_pair(it->first, it->second));
+ snapshot.insert(std::make_pair(it->first->type, it->second));
}
}
}
@@ -1167,18 +1165,18 @@ DetailOutputMap AutofillDialogControllerImpl::TakeUserInputSnapshot() {
}
void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot(
- const DetailOutputMap& snapshot) {
+ const UserInputSnapshot& snapshot) {
if (snapshot.empty())
return;
- DetailOutputWrapper wrapper(snapshot);
+ SnapshotWrapper wrapper(snapshot);
for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
DialogSection section = static_cast<DialogSection>(i);
if (!SectionIsActive(section))
continue;
DetailInputs* inputs = MutableRequestedFieldsForSection(section);
- wrapper.FillInputs(inputs);
+ wrapper.FillInputs(inputs, GetCountryCodeForSection(section));
for (size_t i = 0; i < inputs->size(); ++i) {
if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) {
@@ -1700,6 +1698,7 @@ string16 AutofillDialogControllerImpl::InputValidityMessage(
return base::string16(); // Line 2 is optional - always valid.
case ADDRESS_HOME_CITY:
+ case ADDRESS_HOME_DEPENDENT_LOCALITY:
case ADDRESS_HOME_COUNTRY:
break;
@@ -1717,6 +1716,9 @@ string16 AutofillDialogControllerImpl::InputValidityMessage(
}
break;
+ case ADDRESS_HOME_SORTING_CODE:
+ break;
+
case NAME_FULL:
// Wallet requires a first and last billing name.
if (section == SECTION_CC_BILLING && !value.empty() &&
@@ -1727,6 +1729,9 @@ string16 AutofillDialogControllerImpl::InputValidityMessage(
}
break;
+ case COMPANY_NAME:
+ break;
+
case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section.
break;
@@ -1817,9 +1822,7 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
field_values.count(PHONE_HOME_WHOLE_NUMBER)) {
i18n::PhoneObject phone_object(
field_values[PHONE_HOME_WHOLE_NUMBER],
- AutofillCountry::GetCountryCode(
- field_values[ADDRESS_HOME_COUNTRY],
- g_browser_process->GetApplicationLocale()));
+ common::GetCountryCode(field_values[ADDRESS_HOME_COUNTRY]));
ValidityMessage phone_message(base::string16(), true);
if (!phone_object.IsValidNumber()) {
phone_message.text = l10n_util::GetStringUTF16(
@@ -1833,9 +1836,7 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
field_values.count(PHONE_BILLING_WHOLE_NUMBER)) {
i18n::PhoneObject phone_object(
field_values[PHONE_BILLING_WHOLE_NUMBER],
- AutofillCountry::GetCountryCode(
- field_values[ADDRESS_BILLING_COUNTRY],
- g_browser_process->GetApplicationLocale()));
+ common::GetCountryCode(field_values[ADDRESS_BILLING_COUNTRY]));
ValidityMessage phone_message(base::string16(), true);
if (!phone_object.IsValidNumber()) {
phone_message.text = l10n_util::GetStringUTF16(
@@ -1923,6 +1924,23 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
popup_ids);
}
+void AutofillDialogControllerImpl::ComboboxItemSelected(
+ ui::ComboboxModel* model,
+ DialogSection section,
+ int index) {
+ if (model != &country_combobox_model_)
+ return;
+
+ const UserInputSnapshot snapshot = TakeUserInputSnapshot();
+
+ base::string16 country = model->GetItemAt(index);
Evan Stade 2013/11/25 19:52:06 country_combobox_model_.countries()[index].country
Dan Beam 2013/11/28 02:52:45 Done.
+ SetCountryCodeForSection(section, common::GetCountryCode(country));
+
+ ResetSectionInput(section);
+ RestoreUserInputFromSnapshot(snapshot);
+ UpdateSection(section);
+}
+
void AutofillDialogControllerImpl::FocusMoved() {
HidePopup();
}
@@ -2164,7 +2182,8 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value,
for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
DialogSection section = static_cast<DialogSection>(i);
- wrapper->FillInputs(MutableRequestedFieldsForSection(section));
+ wrapper->FillInputs(MutableRequestedFieldsForSection(section),
+ GetCountryCodeForSection(section));
view_->FillSection(section, *input_showing_popup_);
}
@@ -2440,6 +2459,7 @@ void AutofillDialogControllerImpl::UpdateAccountChooserView() {
////////////////////////////////////////////////////////////////////////////////
+
Evan Stade 2013/11/25 19:52:06 intentional?
Dan Beam 2013/11/28 02:52:45 nope, removed
bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
const content::NativeWebKeyboardEvent& event) {
if (popup_controller_.get())
@@ -2641,7 +2661,7 @@ void AutofillDialogControllerImpl::DisableWallet(
void AutofillDialogControllerImpl::SuggestionsUpdated() {
ScopedViewUpdates updates(view_.get());
- const DetailOutputMap snapshot = TakeUserInputSnapshot();
+ const UserInputSnapshot snapshot = TakeUserInputSnapshot();
suggested_cc_.Reset();
suggested_billing_.Reset();
@@ -2741,7 +2761,6 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
}
const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
- const std::string app_locale = g_browser_process->GetApplicationLocale();
for (size_t i = 0; i < profiles.size(); ++i) {
const AutofillProfile& profile = *profiles[i];
if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) ||
@@ -2978,6 +2997,34 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
}
+std::string AutofillDialogControllerImpl::GetCountryCodeForSection(
+ DialogSection section) const {
+ if (section == SECTION_BILLING || section == SECTION_CC_BILLING)
+ return billing_country_code_;
+ if (section == SECTION_SHIPPING)
+ return shipping_country_code_;
+ return "US";
+}
+
+void AutofillDialogControllerImpl::SetCountryCodeForSection(
+ DialogSection section,
+ const std::string& country_code) {
+ if (section == SECTION_BILLING || section == SECTION_CC_BILLING)
+ billing_country_code_ = country_code;
+ else if (section == SECTION_SHIPPING)
+ shipping_country_code_ = country_code;
+
+ DetailInputs* inputs = MutableRequestedFieldsForSection(section);
+ inputs->clear();
+
+ common::BuildInputsForSection(section, inputs, country_code);
+
+ for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
+ if (AutofillType(it->type).GetStorableType() == ADDRESS_HOME_COUNTRY)
+ it->initial_value = common::GetCountryName(country_code);
+ }
+}
+
void AutofillDialogControllerImpl::HidePopup() {
if (popup_controller_.get())
popup_controller_->Hide();

Powered by Google App Engine
This is Rietveld 408576698