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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // access checks. 597 // access checks.
598 const GURL& current_url = web_contents()->GetLastCommittedURL(); 598 const GURL& current_url = web_contents()->GetLastCommittedURL();
599 invoked_from_same_origin_ = 599 invoked_from_same_origin_ =
600 current_url.GetOrigin() == source_url_.GetOrigin(); 600 current_url.GetOrigin() == source_url_.GetOrigin();
601 601
602 if (!invoked_from_same_origin_) { 602 if (!invoked_from_same_origin_) {
603 GetMetricLogger().LogDialogSecurityMetric( 603 GetMetricLogger().LogDialogSecurityMetric(
604 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); 604 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
605 } 605 }
606 606
607 // TODO(dbeam): use GetManager()->GetDefaultCountryCodeForNewAddress()
608 // instead when the country combobox is visible. http://crbug.com/331544
609 std::string country_code = "US";
610 common::BuildInputsForSection(SECTION_CC, 607 common::BuildInputsForSection(SECTION_CC,
611 country_code, 608 std::string(),
612 &requested_cc_fields_); 609 &requested_cc_fields_);
613 common::BuildInputsForSection(SECTION_BILLING, 610 OnComboboxModelChanged(&billing_country_combobox_model_);
614 country_code, 611 OnComboboxModelChanged(&shipping_country_combobox_model_);
615 &requested_billing_fields_);
616 common::BuildInputsForSection(SECTION_CC_BILLING,
617 country_code,
618 &requested_cc_billing_fields_);
619 common::BuildInputsForSection(SECTION_SHIPPING,
620 country_code,
621 &requested_shipping_fields_);
622 612
623 // Test whether we need to show the shipping section. If filling that section 613 // Test whether we need to show the shipping section. If filling that section
624 // would be a no-op, don't show it. 614 // would be a no-op, don't show it.
625 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); 615 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING);
626 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( 616 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure(
627 inputs, 617 inputs,
628 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), 618 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING),
629 &form_structure_); 619 &form_structure_);
630 620
631 account_chooser_model_.reset( 621 account_chooser_model_.reset(
632 new AccountChooserModel(this, 622 new AccountChooserModel(this,
633 profile_, 623 profile_,
634 !ShouldShowAccountChooser(), 624 !ShouldShowAccountChooser(),
635 metric_logger_)); 625 metric_logger_));
636 626
637 if (account_chooser_model_->WalletIsSelected()) 627 if (account_chooser_model_->WalletIsSelected())
638 FetchWalletCookie(); 628 FetchWalletCookie();
639 629
640 // TODO(estade): don't show the dialog if the site didn't specify the right 630 // TODO(estade): don't show the dialog if the site didn't specify the right
641 // fields. First we must figure out what the "right" fields are. 631 // fields. First we must figure out what the "right" fields are.
642 SuggestionsUpdated(); 632 SuggestionsUpdated();
643 SubmitButtonDelayBegin(); 633 SubmitButtonDelayBegin();
644 view_.reset(CreateView()); 634 view_.reset(CreateView());
645 view_->Show(); 635 view_->Show();
636
646 GetManager()->AddObserver(this); 637 GetManager()->AddObserver(this);
638 observer_.Add(&billing_country_combobox_model_);
639 observer_.Add(&shipping_country_combobox_model_);
647 640
648 if (!account_chooser_model_->WalletIsSelected()) 641 if (!account_chooser_model_->WalletIsSelected())
649 LogDialogLatencyToShow(); 642 LogDialogLatencyToShow();
650 } 643 }
651 644
652 void AutofillDialogControllerImpl::Hide() { 645 void AutofillDialogControllerImpl::Hide() {
653 if (view_) 646 if (view_)
654 view_->Hide(); 647 view_->Hide();
655 } 648 }
656 649
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1156 }
1164 1157
1165 return snapshot; 1158 return snapshot;
1166 } 1159 }
1167 1160
1168 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( 1161 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot(
1169 const FieldValueMap& snapshot) { 1162 const FieldValueMap& snapshot) {
1170 if (snapshot.empty()) 1163 if (snapshot.empty())
1171 return; 1164 return;
1172 1165
1166 FieldValueMap::const_iterator it = snapshot.find(ADDRESS_BILLING_COUNTRY);
1167 if (it != snapshot.end()) {
1168 billing_country_combobox_model_.SetDefaultCountry(
1169 AutofillCountry::GetCountryCode(
1170 it->second, g_browser_process->GetApplicationLocale()));
1171 }
1172
1173 FieldValueMap::const_iterator ship_it = snapshot.find(ADDRESS_HOME_COUNTRY);
1174 if (ship_it != snapshot.end()) {
1175 shipping_country_combobox_model_.SetDefaultCountry(
1176 AutofillCountry::GetCountryCode(
1177 ship_it->second, g_browser_process->GetApplicationLocale()));
1178 }
1179
1173 FieldMapWrapper wrapper(snapshot); 1180 FieldMapWrapper wrapper(snapshot);
1174 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 1181 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
1175 DialogSection section = static_cast<DialogSection>(i); 1182 DialogSection section = static_cast<DialogSection>(i);
1176 if (!SectionIsActive(section)) 1183 if (!SectionIsActive(section))
1177 continue; 1184 continue;
1178 1185
1179 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1186 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1180 wrapper.FillInputs(inputs); 1187 wrapper.FillInputs(inputs);
1181 1188
1182 for (size_t i = 0; i < inputs->size(); ++i) { 1189 for (size_t i = 0; i < inputs->size(); ++i) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1303
1297 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( 1304 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
1298 ServerFieldType type) { 1305 ServerFieldType type) {
1299 switch (type) { 1306 switch (type) {
1300 case CREDIT_CARD_EXP_MONTH: 1307 case CREDIT_CARD_EXP_MONTH:
1301 return &cc_exp_month_combobox_model_; 1308 return &cc_exp_month_combobox_model_;
1302 1309
1303 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1310 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1304 return &cc_exp_year_combobox_model_; 1311 return &cc_exp_year_combobox_model_;
1305 1312
1313 case ADDRESS_BILLING_COUNTRY:
1314 return &billing_country_combobox_model_;
1315
1306 case ADDRESS_HOME_COUNTRY: 1316 case ADDRESS_HOME_COUNTRY:
1307 case ADDRESS_BILLING_COUNTRY: 1317 return &shipping_country_combobox_model_;
1308 return &country_combobox_model_;
1309 1318
1310 default: 1319 default:
1311 return NULL; 1320 return NULL;
1312 } 1321 }
1313 } 1322 }
1314 1323
1315 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( 1324 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection(
1316 DialogSection section) { 1325 DialogSection section) {
1317 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1326 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
1318 // The shipping section menu is special. It will always show because there is 1327 // The shipping section menu is special. It will always show because there is
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { 1698 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) {
1690 return l10n_util::GetStringUTF16( 1699 return l10n_util::GetStringUTF16(
1691 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); 1700 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE);
1692 } 1701 }
1693 break; 1702 break;
1694 1703
1695 case ADDRESS_HOME_LINE1: 1704 case ADDRESS_HOME_LINE1:
1696 break; 1705 break;
1697 1706
1698 case ADDRESS_HOME_LINE2: 1707 case ADDRESS_HOME_LINE2:
1699 return base::string16(); // Line 2 is optional - always valid. 1708 case ADDRESS_HOME_DEPENDENT_LOCALITY:
1709 case ADDRESS_HOME_SORTING_CODE:
1710 return base::string16(); // Optional until we have better validation.
1700 1711
1701 case ADDRESS_HOME_CITY: 1712 case ADDRESS_HOME_CITY:
1702 case ADDRESS_HOME_COUNTRY: 1713 case ADDRESS_HOME_COUNTRY:
1703 break; 1714 break;
1704 1715
1705 case ADDRESS_HOME_STATE: 1716 case ADDRESS_HOME_STATE:
1706 if (!value.empty() && !autofill::IsValidState(value)) { 1717 if (!value.empty() && !autofill::IsValidState(value) &&
1718 CountryCodeForSection(section) == "US") {
1707 return l10n_util::GetStringUTF16( 1719 return l10n_util::GetStringUTF16(
1708 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); 1720 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION);
1709 } 1721 }
1710 break; 1722 break;
1711 1723
1712 case ADDRESS_HOME_ZIP: 1724 case ADDRESS_HOME_ZIP:
1713 if (!value.empty() && !autofill::IsValidZip(value)) { 1725 if (!value.empty() && !autofill::IsValidZip(value) &&
1726 CountryCodeForSection(section) == "US") {
1714 return l10n_util::GetStringUTF16( 1727 return l10n_util::GetStringUTF16(
1715 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); 1728 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE);
1716 } 1729 }
1717 break; 1730 break;
1718 1731
1719 case NAME_FULL: 1732 case NAME_FULL:
1720 // Wallet requires a first and last billing name. 1733 // Wallet requires a first and last billing name.
1721 if (section == SECTION_CC_BILLING && !value.empty() && 1734 if (section == SECTION_CC_BILLING && !value.empty() &&
1722 !IsCardHolderNameValidForWallet(value)) { 1735 !IsCardHolderNameValidForWallet(value)) {
1723 DCHECK(IsPayingWithWallet()); 1736 DCHECK(IsPayingWithWallet());
(...skipping 16 matching lines...) Expand all
1740 return value.empty() ? 1753 return value.empty() ?
1741 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : 1754 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) :
1742 base::string16(); 1755 base::string16();
1743 } 1756 }
1744 1757
1745 // TODO(groby): Also add tests. 1758 // TODO(groby): Also add tests.
1746 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( 1759 ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
1747 DialogSection section, 1760 DialogSection section,
1748 const FieldValueMap& inputs) { 1761 const FieldValueMap& inputs) {
1749 ValidityMessages messages; 1762 ValidityMessages messages;
1750 std::map<ServerFieldType, base::string16> field_values; 1763 FieldValueMap field_values;
1751 for (FieldValueMap::const_iterator iter = inputs.begin(); 1764 for (FieldValueMap::const_iterator iter = inputs.begin();
1752 iter != inputs.end(); ++iter) { 1765 iter != inputs.end(); ++iter) {
1753 const ServerFieldType type = iter->first; 1766 const ServerFieldType type = iter->first;
1754 1767
1755 base::string16 text = InputValidityMessage(section, type, iter->second); 1768 base::string16 text = InputValidityMessage(section, type, iter->second);
1756 1769
1757 // Skip empty/unchanged fields in edit mode. Ignore country code as it 1770 // Skip empty/unchanged fields in edit mode. Ignore country as it always has
1758 // always has a value. If the individual field does not have validation 1771 // a value. If the individual field does not have validation errors, assume
1759 // errors, assume it to be valid unless later proven otherwise. 1772 // it to be valid unless later proven otherwise.
1760 bool sure = InputWasEdited(type, iter->second) || 1773 bool sure = InputWasEdited(type, iter->second) ||
1761 ComboboxModelForAutofillType(type) == &country_combobox_model_; 1774 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY;
1762 1775
1763 // Consider only individually valid fields for inter-field validation. 1776 // Consider only individually valid fields for inter-field validation.
1764 if (text.empty()) { 1777 if (text.empty()) {
1765 field_values[type] = iter->second; 1778 field_values[type] = iter->second;
1766 // If the field is valid but can be invalidated by inter-field validation, 1779 // If the field is valid but can be invalidated by inter-field validation,
1767 // assume it to be unsure. 1780 // assume it to be unsure.
1768 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || 1781 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
1769 type == CREDIT_CARD_EXP_MONTH || 1782 type == CREDIT_CARD_EXP_MONTH ||
1770 type == CREDIT_CARD_VERIFICATION_CODE || 1783 type == CREDIT_CARD_VERIFICATION_CODE ||
1771 type == PHONE_HOME_WHOLE_NUMBER || 1784 type == PHONE_HOME_WHOLE_NUMBER ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 return messages; 1859 return messages;
1847 } 1860 }
1848 1861
1849 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( 1862 void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
1850 DialogSection section, 1863 DialogSection section,
1851 ServerFieldType type, 1864 ServerFieldType type,
1852 gfx::NativeView parent_view, 1865 gfx::NativeView parent_view,
1853 const gfx::Rect& content_bounds, 1866 const gfx::Rect& content_bounds,
1854 const base::string16& field_contents, 1867 const base::string16& field_contents,
1855 bool was_edit) { 1868 bool was_edit) {
1869 ScopedViewUpdates updates(view_.get());
1870
1871 if (type == ADDRESS_BILLING_COUNTRY || type == ADDRESS_HOME_COUNTRY) {
1872 FieldValueMap snapshot = TakeUserInputSnapshot();
1873 snapshot[type] = field_contents;
1874 RestoreUserInputFromSnapshot(snapshot);
1875 const bool is_billing = type == ADDRESS_BILLING_COUNTRY;
1876 UpdateSection(is_billing ? ActiveBillingSection() : SECTION_SHIPPING);
1877 }
1878
1879 // The rest of this method applies only to textfields. If a combobox, bail.
1880 if (ComboboxModelForAutofillType(type))
1881 return;
1882
1856 // If the field is edited down to empty, don't show a popup. 1883 // If the field is edited down to empty, don't show a popup.
1857 if (was_edit && field_contents.empty()) { 1884 if (was_edit && field_contents.empty()) {
1858 HidePopup(); 1885 HidePopup();
1859 return; 1886 return;
1860 } 1887 }
1861 1888
1862 // If the user clicks while the popup is already showing, be sure to hide 1889 // If the user clicks while the popup is already showing, be sure to hide
1863 // it. 1890 // it.
1864 if (!was_edit && popup_controller_.get()) { 1891 if (!was_edit && popup_controller_.get()) {
1865 HidePopup(); 1892 HidePopup();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 return !view_->HitTestInput(popup_input_type_, event.location()); 2164 return !view_->HitTestInput(popup_input_type_, event.location());
2138 } 2165 }
2139 2166
2140 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { 2167 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) {
2141 // TODO(estade): implement. 2168 // TODO(estade): implement.
2142 } 2169 }
2143 2170
2144 void AutofillDialogControllerImpl::DidAcceptSuggestion( 2171 void AutofillDialogControllerImpl::DidAcceptSuggestion(
2145 const base::string16& value, 2172 const base::string16& value,
2146 int identifier) { 2173 int identifier) {
2174 DCHECK_NE(UNKNOWN_TYPE, popup_input_type_);
2175 // Because |HidePopup()| can be called from |UpdateSection()|, remember the
2176 // type of the input for later here.
2177 const ServerFieldType popup_input_type = popup_input_type_;
2178
2147 ScopedViewUpdates updates(view_.get()); 2179 ScopedViewUpdates updates(view_.get());
2148 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; 2180 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier];
2149 2181
2150 scoped_ptr<DataModelWrapper> wrapper; 2182 scoped_ptr<DataModelWrapper> wrapper;
2151 if (common::IsCreditCardType(popup_input_type_)) { 2183 if (common::IsCreditCardType(popup_input_type)) {
2152 wrapper.reset(new AutofillCreditCardWrapper( 2184 wrapper.reset(new AutofillCreditCardWrapper(
2153 GetManager()->GetCreditCardByGUID(pair.first))); 2185 GetManager()->GetCreditCardByGUID(pair.first)));
2154 } else { 2186 } else {
2155 wrapper.reset(new AutofillProfileWrapper( 2187 wrapper.reset(new AutofillProfileWrapper(
2156 GetManager()->GetProfileByGUID(pair.first), 2188 GetManager()->GetProfileByGUID(pair.first),
2157 AutofillType(popup_input_type_), 2189 AutofillType(popup_input_type),
2158 pair.second)); 2190 pair.second));
2159 } 2191 }
2160 2192
2193 if (i18ninput::Enabled()) {
2194 base::string16 billing_country =
2195 wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY));
2196 base::string16 shipping_country =
2197 wrapper->GetInfo(AutofillType(ADDRESS_HOME_COUNTRY));
2198
2199 if (!billing_country.empty() || !shipping_country.empty()) {
2200 FieldValueMap snapshot = TakeUserInputSnapshot();
2201 if (!billing_country.empty())
2202 snapshot[ADDRESS_BILLING_COUNTRY] = billing_country;
2203 if (!shipping_country.empty())
2204 snapshot[ADDRESS_HOME_COUNTRY] = shipping_country;
2205
2206 RestoreUserInputFromSnapshot(snapshot);
2207
2208 if (!billing_country.empty())
2209 UpdateSection(ActiveBillingSection());
2210 if (!shipping_country.empty())
2211 UpdateSection(SECTION_SHIPPING);
2212 }
2213 }
2214
2161 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 2215 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2162 DialogSection section = static_cast<DialogSection>(i); 2216 DialogSection section = static_cast<DialogSection>(i);
2217 if (!SectionIsActive(section))
2218 continue;
2219
2163 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); 2220 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
2164 view_->FillSection(section, popup_input_type_); 2221 view_->FillSection(section, popup_input_type);
2165 } 2222 }
2166 2223
2167 GetMetricLogger().LogDialogPopupEvent( 2224 GetMetricLogger().LogDialogPopupEvent(
2168 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); 2225 AutofillMetrics::DIALOG_POPUP_FORM_FILLED);
2169 2226
2170 // TODO(estade): not sure why it's necessary to do this explicitly. 2227 // TODO(estade): not sure why it's necessary to do this explicitly.
2171 HidePopup(); 2228 HidePopup();
2172 } 2229 }
2173 2230
2174 void AutofillDialogControllerImpl::RemoveSuggestion( 2231 void AutofillDialogControllerImpl::RemoveSuggestion(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 wallet::GetManageAddressesUrl(user_index) : 2288 wallet::GetManageAddressesUrl(user_index) :
2232 wallet::GetManageInstrumentsUrl(user_index); 2289 wallet::GetManageInstrumentsUrl(user_index);
2233 } 2290 }
2234 2291
2235 OpenTabWithUrl(url); 2292 OpenTabWithUrl(url);
2236 return; 2293 return;
2237 } 2294 }
2238 2295
2239 model->SetCheckedIndex(index); 2296 model->SetCheckedIndex(index);
2240 DialogSection section = SectionForSuggestionsMenuModel(*model); 2297 DialogSection section = SectionForSuggestionsMenuModel(*model);
2298
2299 if (i18ninput::Enabled()) {
2300 CountryComboboxModel* model = CountryComboboxModelForSection(section);
2301 if (model)
2302 model->ResetDefault();
2303 }
2304
2241 ResetSectionInput(section); 2305 ResetSectionInput(section);
2242 ShowEditUiIfBadSuggestion(section); 2306 ShowEditUiIfBadSuggestion(section);
2243 UpdateSection(section); 2307 UpdateSection(section);
2244 view_->UpdateNotificationArea(); 2308 view_->UpdateNotificationArea();
2245 UpdateForErrors(); 2309 UpdateForErrors();
2246 2310
2247 LogSuggestionItemSelectedMetric(*model); 2311 LogSuggestionItemSelectedMetric(*model);
2248 } 2312 }
2249 2313
2250 //////////////////////////////////////////////////////////////////////////////// 2314 ////////////////////////////////////////////////////////////////////////////////
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), 2578 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
2515 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 2579 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
2516 form_structure_(form_structure), 2580 form_structure_(form_structure),
2517 invoked_from_same_origin_(true), 2581 invoked_from_same_origin_(true),
2518 source_url_(source_url), 2582 source_url_(source_url),
2519 callback_(callback), 2583 callback_(callback),
2520 wallet_client_(profile_->GetRequestContext(), this, source_url), 2584 wallet_client_(profile_->GetRequestContext(), this, source_url),
2521 wallet_items_requested_(false), 2585 wallet_items_requested_(false),
2522 handling_use_wallet_link_click_(false), 2586 handling_use_wallet_link_click_(false),
2523 passive_failed_(false), 2587 passive_failed_(false),
2524 country_combobox_model_(*GetManager()), 2588 billing_country_combobox_model_(*GetManager()),
2589 shipping_country_combobox_model_(*GetManager()),
2525 suggested_cc_(this), 2590 suggested_cc_(this),
2526 suggested_billing_(this), 2591 suggested_billing_(this),
2527 suggested_cc_billing_(this), 2592 suggested_cc_billing_(this),
2528 suggested_shipping_(this), 2593 suggested_shipping_(this),
2529 cares_about_shipping_(true), 2594 cares_about_shipping_(true),
2530 popup_input_type_(UNKNOWN_TYPE), 2595 popup_input_type_(UNKNOWN_TYPE),
2531 weak_ptr_factory_(this), 2596 weak_ptr_factory_(this),
2532 waiting_for_explicit_sign_in_response_(false), 2597 waiting_for_explicit_sign_in_response_(false),
2533 has_accepted_legal_documents_(false), 2598 has_accepted_legal_documents_(false),
2534 is_submitting_(false), 2599 is_submitting_(false),
2535 choose_another_instrument_or_address_(false), 2600 choose_another_instrument_or_address_(false),
2536 wallet_server_validation_recoverable_(true), 2601 wallet_server_validation_recoverable_(true),
2537 data_was_passed_back_(false), 2602 data_was_passed_back_(false),
2538 was_ui_latency_logged_(false), 2603 was_ui_latency_logged_(false),
2539 card_generated_animation_(2000, 60, this) { 2604 card_generated_animation_(2000, 60, this),
2605 observer_(this) {
2540 // TODO(estade): remove duplicates from |form_structure|? 2606 // TODO(estade): remove duplicates from |form_structure|?
2541 DCHECK(!callback_.is_null()); 2607 DCHECK(!callback_.is_null());
2542 } 2608 }
2543 2609
2544 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { 2610 AutofillDialogView* AutofillDialogControllerImpl::CreateView() {
2545 return AutofillDialogView::Create(this); 2611 return AutofillDialogView::Create(this);
2546 } 2612 }
2547 2613
2548 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { 2614 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const {
2549 return PersonalDataManagerFactory::GetForProfile(profile_); 2615 return PersonalDataManagerFactory::GetForProfile(profile_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 2668
2603 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { 2669 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) {
2604 chrome::NavigateParams params( 2670 chrome::NavigateParams params(
2605 chrome::FindBrowserWithWebContents(web_contents()), 2671 chrome::FindBrowserWithWebContents(web_contents()),
2606 url, 2672 url,
2607 content::PAGE_TRANSITION_LINK); 2673 content::PAGE_TRANSITION_LINK);
2608 params.disposition = NEW_FOREGROUND_TAB; 2674 params.disposition = NEW_FOREGROUND_TAB;
2609 chrome::Navigate(&params); 2675 chrome::Navigate(&params);
2610 } 2676 }
2611 2677
2678 DialogSection AutofillDialogControllerImpl::ActiveBillingSection() const {
2679 return IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING;
2680 }
2681
2612 bool AutofillDialogControllerImpl::IsEditingExistingData( 2682 bool AutofillDialogControllerImpl::IsEditingExistingData(
2613 DialogSection section) const { 2683 DialogSection section) const {
2614 return section_editing_state_.count(section) > 0; 2684 return section_editing_state_.count(section) > 0;
2615 } 2685 }
2616 2686
2617 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 2687 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
2618 DialogSection section) const { 2688 DialogSection section) const {
2619 return IsEditingExistingData(section) || 2689 return IsEditingExistingData(section) ||
2620 SuggestionsMenuModelForSection(section)-> 2690 SuggestionsMenuModelForSection(section)->
2621 GetItemKeyForCheckedItem() == kAddNewItemKey; 2691 GetItemKeyForCheckedItem() == kAddNewItemKey;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 2907
2838 UpdateForErrors(); 2908 UpdateForErrors();
2839 } 2909 }
2840 2910
2841 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( 2911 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
2842 DialogSection section, 2912 DialogSection section,
2843 const InputFieldComparator& compare) { 2913 const InputFieldComparator& compare) {
2844 if (!SectionIsActive(section)) 2914 if (!SectionIsActive(section))
2845 return; 2915 return;
2846 2916
2847 const DetailInputs& inputs = RequestedFieldsForSection(section); 2917 DetailInputs inputs;
2918 std::string country_code = CountryCodeForSection(section);
2919 common::BuildInputsForSection(section, country_code, &inputs);
2920
2848 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 2921 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
2849 if (wrapper) { 2922 if (wrapper) {
2850 // Only fill in data that is associated with this section. 2923 // Only fill in data that is associated with this section.
2851 const DetailInputs& inputs = RequestedFieldsForSection(section);
2852 wrapper->FillFormStructure(inputs, compare, &form_structure_); 2924 wrapper->FillFormStructure(inputs, compare, &form_structure_);
2853 2925
2854 // CVC needs special-casing because the CreditCard class doesn't store or 2926 // CVC needs special-casing because the CreditCard class doesn't store or
2855 // handle them. This isn't necessary when filling the combined CC and 2927 // handle them. This isn't necessary when filling the combined CC and
2856 // billing section as CVC comes from |full_wallet_| in this case. 2928 // billing section as CVC comes from |full_wallet_| in this case.
2857 if (section == SECTION_CC) 2929 if (section == SECTION_CC)
2858 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); 2930 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc());
2859 2931
2860 // When filling from Wallet data, use the email address associated with the 2932 // When filling from Wallet data, use the email address associated with the
2861 // account. There is no other email address stored as part of a Wallet 2933 // account. There is no other email address stored as part of a Wallet
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 if (&model == &suggested_billing_) 3051 if (&model == &suggested_billing_)
2980 return SECTION_BILLING; 3052 return SECTION_BILLING;
2981 3053
2982 if (&model == &suggested_cc_billing_) 3054 if (&model == &suggested_cc_billing_)
2983 return SECTION_CC_BILLING; 3055 return SECTION_CC_BILLING;
2984 3056
2985 DCHECK_EQ(&model, &suggested_shipping_); 3057 DCHECK_EQ(&model, &suggested_shipping_);
2986 return SECTION_SHIPPING; 3058 return SECTION_SHIPPING;
2987 } 3059 }
2988 3060
3061 CountryComboboxModel* AutofillDialogControllerImpl::
3062 CountryComboboxModelForSection(DialogSection section) {
3063 switch (section) {
3064 case SECTION_CC:
3065 return NULL;
3066 case SECTION_BILLING:
3067 case SECTION_CC_BILLING:
3068 return &billing_country_combobox_model_;
3069 case SECTION_SHIPPING:
3070 return &shipping_country_combobox_model_;
3071 }
3072
3073 NOTREACHED();
3074 return NULL;
3075 }
3076
2989 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 3077 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
2990 DialogSection section) { 3078 DialogSection section) {
2991 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 3079 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
2992 } 3080 }
2993 3081
3082 void AutofillDialogControllerImpl::OnComboboxModelChanged(
3083 ui::ComboboxModel* model) {
3084 DCHECK(model == &billing_country_combobox_model_ ||
3085 model == &shipping_country_combobox_model_);
3086
3087 const std::string country_code = AutofillCountry::GetCountryCode(
3088 model->GetItemAt(model->GetDefaultIndex()),
3089 g_browser_process->GetApplicationLocale());
3090
3091 const bool is_billing = model == &billing_country_combobox_model_;
3092 DialogSection section = is_billing ? SECTION_BILLING : SECTION_SHIPPING;
3093
3094 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
3095 inputs->clear();
3096 common::BuildInputsForSection(section, country_code, inputs);
3097
3098 if (is_billing) {
3099 // Also rebuild inputs for the combined credit card + billing section.
3100 DetailInputs* inputs = MutableRequestedFieldsForSection(SECTION_CC_BILLING);
3101 inputs->clear();
3102 common::BuildInputsForSection(SECTION_CC_BILLING, country_code, inputs);
3103 }
3104 }
3105
3106 std::string AutofillDialogControllerImpl::CountryCodeForSection(
3107 DialogSection section) {
3108 if (section == SECTION_CC)
3109 return std::string();
3110
3111 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
3112 if (wrapper) {
3113 ServerFieldType type = section == SECTION_SHIPPING ?
3114 ADDRESS_HOME_COUNTRY : ADDRESS_BILLING_COUNTRY;
3115 return AutofillCountry::GetCountryCode(
3116 wrapper->GetInfo(AutofillType(type)),
3117 g_browser_process->GetApplicationLocale());
3118 }
3119
3120 CountryComboboxModel* model = CountryComboboxModelForSection(section);
3121 return model->countries()[model->GetDefaultIndex()]->country_code();
3122 }
3123
2994 void AutofillDialogControllerImpl::HidePopup() { 3124 void AutofillDialogControllerImpl::HidePopup() {
2995 if (popup_controller_.get()) 3125 if (popup_controller_.get())
2996 popup_controller_->Hide(); 3126 popup_controller_->Hide();
2997 popup_input_type_ = UNKNOWN_TYPE; 3127 popup_input_type_ = UNKNOWN_TYPE;
2998 } 3128 }
2999 3129
3000 void AutofillDialogControllerImpl::SetEditingExistingData( 3130 void AutofillDialogControllerImpl::SetEditingExistingData(
3001 DialogSection section, bool editing) { 3131 DialogSection section, bool editing) {
3002 if (editing) 3132 if (editing)
3003 section_editing_state_.insert(section); 3133 section_editing_state_.insert(section);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 view_->UpdateButtonStrip(); 3663 view_->UpdateButtonStrip();
3534 } 3664 }
3535 3665
3536 void AutofillDialogControllerImpl::FetchWalletCookie() { 3666 void AutofillDialogControllerImpl::FetchWalletCookie() {
3537 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3667 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3538 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3668 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3539 signin_helper_->StartWalletCookieValueFetch(); 3669 signin_helper_->StartWalletCookieValueFetch();
3540 } 3670 }
3541 3671
3542 } // namespace autofill 3672 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698