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

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: let's try this again, android 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 127706e00e66ec3e4b4e5dff3601c6df10de40d0..27a529db7183b32b28b515d3c0c53fff9213b965 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)
@@ -603,14 +604,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.
@@ -1093,8 +1090,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);
}
}
@@ -1115,7 +1113,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,
@@ -1169,7 +1167,7 @@ void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot(
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)) {
@@ -1691,6 +1689,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;
@@ -1708,6 +1707,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() &&
@@ -1718,6 +1720,9 @@ string16 AutofillDialogControllerImpl::InputValidityMessage(
}
break;
+ case COMPANY_NAME:
+ break;
+
case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section.
break;
@@ -1923,6 +1928,30 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
popup_ids);
}
+void AutofillDialogControllerImpl::ComboboxItemSelected(
+ ui::ComboboxModel* model,
+ DialogSection section,
+ int index) {
+ if (model != &country_combobox_model_ ||
+ country_combobox_model_.IsItemSeparatorAt(index)) {
+ return;
+ }
+
+ std::string country_code =
+ country_combobox_model_.countries()[index]->country_code();
+ if (country_code == GetCountryCodeForSection(section))
+ return;
+
+ ScopedViewUpdates updates(view_.get());
+ const FieldValueMap snapshot = TakeUserInputSnapshot();
+
+ SetCountryCodeForSection(section, country_code);
+
+ ResetSectionInput(section);
+ RestoreUserInputFromSnapshot(snapshot);
+ UpdateSection(section);
+}
+
void AutofillDialogControllerImpl::FocusMoved() {
HidePopup();
}
@@ -2164,7 +2193,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_);
}
@@ -2763,7 +2793,6 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
std::vector<base::string16> labels;
AutofillProfile::CreateDifferentiatingLabels(profiles, &labels);
DCHECK_EQ(labels.size(), profiles.size());
- 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_) ||
@@ -2849,11 +2878,10 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
DialogSection section,
const InputFieldComparator& compare) {
- const DetailInputs& inputs = RequestedFieldsForSection(section);
-
if (!SectionIsActive(section))
return;
+ const DetailInputs& inputs = RequestedFieldsForSection(section);
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
if (wrapper) {
// Only fill in data that is associated with this section.
@@ -3000,6 +3028,36 @@ 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);
+
+ const std::string& ui_locale = g_browser_process->GetApplicationLocale();
+ base::string16 country_name = AutofillCountry(country_code, ui_locale).name();
+ for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
+ if (AutofillType(it->type).GetStorableType() == ADDRESS_HOME_COUNTRY)
+ it->initial_value = country_name;
+ }
+}
+
void AutofillDialogControllerImpl::HidePopup() {
if (popup_controller_.get())
popup_controller_->Hide();

Powered by Google App Engine
This is Rietveld 408576698