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

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

Issue 85863003: Change DetailOutputMap to FieldValueMap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Equivalent billing field type is used to support UseBillingAsShipping 149 // Equivalent billing field type is used to support UseBillingAsShipping
150 // usecase. 150 // usecase.
151 ServerFieldType field_type = 151 ServerFieldType field_type =
152 AutofillType::GetEquivalentBillingFieldType( 152 AutofillType::GetEquivalentBillingFieldType(
153 field.Type().GetStorableType()); 153 field.Type().GetStorableType());
154 154
155 return common::InputTypeMatchesFieldType(input, AutofillType(field_type)); 155 return common::InputTypeMatchesFieldType(input, AutofillType(field_type));
156 } 156 }
157 157
158 // Initializes |form_group| from user-entered data. 158 // Initializes |form_group| from user-entered data.
159 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, 159 void FillFormGroupFromOutputs(const FieldValueMap& detail_outputs,
160 FormGroup* form_group) { 160 FormGroup* form_group) {
161 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); 161 for (FieldValueMap::const_iterator iter = detail_outputs.begin();
162 iter != detail_outputs.end(); ++iter) { 162 iter != detail_outputs.end(); ++iter) {
163 ServerFieldType type = iter->first->type; 163 ServerFieldType type = iter->first;
164 if (!iter->second.empty()) { 164 if (!iter->second.empty()) {
165 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { 165 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) {
166 form_group->SetInfo(AutofillType(type), 166 form_group->SetInfo(AutofillType(type),
167 iter->second, 167 iter->second,
168 g_browser_process->GetApplicationLocale()); 168 g_browser_process->GetApplicationLocale());
169 } else { 169 } else {
170 form_group->SetRawInfo( 170 form_group->SetRawInfo(
171 AutofillType(type).GetStorableType(), iter->second); 171 AutofillType(type).GetStorableType(), iter->second);
172 } 172 }
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 // Get billing info from |output| and put it into |card|, |cvc|, and |profile|. 177 // Get billing info from |output| and put it into |card|, |cvc|, and |profile|.
178 // These outparams are required because |card|/|profile| accept different types 178 // These outparams are required because |card|/|profile| accept different types
179 // of raw info, and CreditCard doesn't save CVCs. 179 // of raw info, and CreditCard doesn't save CVCs.
180 void GetBillingInfoFromOutputs(const DetailOutputMap& output, 180 void GetBillingInfoFromOutputs(const FieldValueMap& output,
181 CreditCard* card, 181 CreditCard* card,
182 string16* cvc, 182 base::string16* cvc,
183 AutofillProfile* profile) { 183 AutofillProfile* profile) {
184 for (DetailOutputMap::const_iterator it = output.begin(); 184 for (FieldValueMap::const_iterator it = output.begin();
185 it != output.end(); ++it) { 185 it != output.end(); ++it) {
186 string16 trimmed; 186 const ServerFieldType type = it->first;
187 base::string16 trimmed;
187 TrimWhitespace(it->second, TRIM_ALL, &trimmed); 188 TrimWhitespace(it->second, TRIM_ALL, &trimmed);
188 189
189 // Special case CVC as CreditCard just swallows it. 190 // Special case CVC as CreditCard just swallows it.
190 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { 191 if (type == CREDIT_CARD_VERIFICATION_CODE) {
191 if (cvc) 192 if (cvc)
192 cvc->assign(trimmed); 193 cvc->assign(trimmed);
193 } else if (it->first->type == ADDRESS_HOME_COUNTRY || 194 } else if (type == ADDRESS_HOME_COUNTRY ||
194 it->first->type == ADDRESS_BILLING_COUNTRY) { 195 type == ADDRESS_BILLING_COUNTRY) {
195 if (profile) { 196 if (profile) {
196 profile->SetInfo(AutofillType(it->first->type), 197 profile->SetInfo(AutofillType(type),
197 trimmed, 198 trimmed,
198 g_browser_process->GetApplicationLocale()); 199 g_browser_process->GetApplicationLocale());
199 } 200 }
200 } else { 201 } else {
201 // Copy the credit card name to |profile| in addition to |card| as 202 // Copy the credit card name to |profile| in addition to |card| as
202 // wallet::Instrument requires a recipient name for its billing address. 203 // wallet::Instrument requires a recipient name for its billing address.
203 if (card && it->first->type == NAME_FULL) 204 if (card && type == NAME_FULL)
204 card->SetRawInfo(CREDIT_CARD_NAME, trimmed); 205 card->SetRawInfo(CREDIT_CARD_NAME, trimmed);
205 206
206 if (common::IsCreditCardType(it->first->type)) { 207 if (common::IsCreditCardType(type)) {
207 if (card) 208 if (card)
208 card->SetRawInfo(it->first->type, trimmed); 209 card->SetRawInfo(type, trimmed);
209 } else if (profile) { 210 } else if (profile) {
210 profile->SetRawInfo( 211 profile->SetRawInfo(AutofillType(type).GetStorableType(), trimmed);
211 AutofillType(it->first->type).GetStorableType(), trimmed);
212 } 212 }
213 } 213 }
214 } 214 }
215 } 215 }
216 216
217 // Returns the containing window for the given |web_contents|. The containing 217 // Returns the containing window for the given |web_contents|. The containing
218 // window might be a browser window for a Chrome tab, or it might be a shell 218 // window might be a browser window for a Chrome tab, or it might be a shell
219 // window for a platform app. 219 // window for a platform app.
220 ui::BaseWindow* GetBaseWindowForWebContents( 220 ui::BaseWindow* GetBaseWindowForWebContents(
221 const content::WebContents* web_contents) { 221 const content::WebContents* web_contents) {
222 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 222 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
223 if (browser) 223 if (browser)
224 return browser->window(); 224 return browser->window();
225 225
226 gfx::NativeWindow native_window = 226 gfx::NativeWindow native_window =
227 web_contents->GetView()->GetTopLevelNativeWindow(); 227 web_contents->GetView()->GetTopLevelNativeWindow();
228 apps::ShellWindow* shell_window = 228 apps::ShellWindow* shell_window =
229 apps::ShellWindowRegistry:: 229 apps::ShellWindowRegistry::
230 GetShellWindowForNativeWindowAnyProfile(native_window); 230 GetShellWindowForNativeWindowAnyProfile(native_window);
231 return shell_window->GetBaseWindow(); 231 return shell_window->GetBaseWindow();
232 } 232 }
233 233
234 // Extracts the string value of a field with |type| from |output|. This is
235 // useful when you only need the value of 1 input from a section of view inputs.
236 string16 GetValueForType(const DetailOutputMap& output,
237 ServerFieldType type) {
238 for (DetailOutputMap::const_iterator it = output.begin();
239 it != output.end(); ++it) {
240 if (it->first->type == type)
241 return it->second;
242 }
243 return string16();
244 }
245
246 // Returns a string descriptor for a DialogSection, for use with prefs (do not 234 // Returns a string descriptor for a DialogSection, for use with prefs (do not
247 // change these values). 235 // change these values).
248 std::string SectionToPrefString(DialogSection section) { 236 std::string SectionToPrefString(DialogSection section) {
249 switch (section) { 237 switch (section) {
250 case SECTION_CC: 238 case SECTION_CC:
251 return "cc"; 239 return "cc";
252 240
253 case SECTION_BILLING: 241 case SECTION_BILLING:
254 return "billing"; 242 return "billing";
255 243
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return false; 1121 return false;
1134 1122
1135 // If this is a combobox at the default value, don't preserve it. 1123 // If this is a combobox at the default value, don't preserve it.
1136 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); 1124 ui::ComboboxModel* model = ComboboxModelForAutofillType(type);
1137 if (model && model->GetItemAt(model->GetDefaultIndex()) == value) 1125 if (model && model->GetItemAt(model->GetDefaultIndex()) == value)
1138 return false; 1126 return false;
1139 1127
1140 return true; 1128 return true;
1141 } 1129 }
1142 1130
1143 DetailOutputMap AutofillDialogControllerImpl::TakeUserInputSnapshot() { 1131 FieldValueMap AutofillDialogControllerImpl::TakeUserInputSnapshot() {
1144 DetailOutputMap snapshot; 1132 FieldValueMap snapshot;
1145 if (!view_) 1133 if (!view_)
1146 return snapshot; 1134 return snapshot;
1147 1135
1148 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 1136 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
1149 DialogSection section = static_cast<DialogSection>(i); 1137 DialogSection section = static_cast<DialogSection>(i);
1150 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1138 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
1151 if (model->GetItemKeyForCheckedItem() != kAddNewItemKey) 1139 if (model->GetItemKeyForCheckedItem() != kAddNewItemKey)
1152 continue; 1140 continue;
1153 1141
1154 DetailOutputMap outputs; 1142 FieldValueMap outputs;
1155 view_->GetUserInput(section, &outputs); 1143 view_->GetUserInput(section, &outputs);
1156 // Remove fields that are empty, at their default values, or invalid. 1144 // Remove fields that are empty, at their default values, or invalid.
1157 for (DetailOutputMap::iterator it = outputs.begin(); it != outputs.end(); 1145 for (FieldValueMap::iterator it = outputs.begin(); it != outputs.end();
1158 ++it) { 1146 ++it) {
1159 if (InputWasEdited(it->first->type, it->second) && 1147 if (InputWasEdited(it->first, it->second) &&
1160 InputValidityMessage(section, it->first->type, it->second).empty()) { 1148 InputValidityMessage(section, it->first, it->second).empty()) {
1161 snapshot.insert(std::make_pair(it->first, it->second)); 1149 snapshot.insert(std::make_pair(it->first, it->second));
1162 } 1150 }
1163 } 1151 }
1164 } 1152 }
1165 1153
1166 return snapshot; 1154 return snapshot;
1167 } 1155 }
1168 1156
1169 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( 1157 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot(
1170 const DetailOutputMap& snapshot) { 1158 const FieldValueMap& snapshot) {
1171 if (snapshot.empty()) 1159 if (snapshot.empty())
1172 return; 1160 return;
1173 1161
1174 DetailOutputWrapper wrapper(snapshot); 1162 FieldMapWrapper wrapper(snapshot);
1175 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 1163 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
1176 DialogSection section = static_cast<DialogSection>(i); 1164 DialogSection section = static_cast<DialogSection>(i);
1177 if (!SectionIsActive(section)) 1165 if (!SectionIsActive(section))
1178 continue; 1166 continue;
1179 1167
1180 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1168 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1181 wrapper.FillInputs(inputs); 1169 wrapper.FillInputs(inputs);
1182 1170
1183 for (size_t i = 0; i < inputs->size(); ++i) { 1171 for (size_t i = 0; i < inputs->size(); ++i) {
1184 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { 1172 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 } 1413 }
1426 1414
1427 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( 1415 string16 AutofillDialogControllerImpl::RequiredActionTextForSection(
1428 DialogSection section) const { 1416 DialogSection section) const {
1429 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { 1417 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1430 const wallet::WalletItems::MaskedInstrument* current_instrument = 1418 const wallet::WalletItems::MaskedInstrument* current_instrument =
1431 wallet_items_->GetInstrumentById(active_instrument_id_); 1419 wallet_items_->GetInstrumentById(active_instrument_id_);
1432 if (current_instrument) 1420 if (current_instrument)
1433 return current_instrument->TypeAndLastFourDigits(); 1421 return current_instrument->TypeAndLastFourDigits();
1434 1422
1435 DetailOutputMap output; 1423 FieldValueMap output;
1436 view_->GetUserInput(section, &output); 1424 view_->GetUserInput(section, &output);
1437 CreditCard card; 1425 CreditCard card;
1438 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 1426 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
1439 return card.TypeAndLastFourDigits(); 1427 return card.TypeAndLastFourDigits();
1440 } 1428 }
1441 1429
1442 return string16(); 1430 return string16();
1443 } 1431 }
1444 1432
1445 string16 AutofillDialogControllerImpl::ExtraSuggestionTextForSection( 1433 string16 AutofillDialogControllerImpl::ExtraSuggestionTextForSection(
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 if (section != SECTION_CC_BILLING) 1596 if (section != SECTION_CC_BILLING)
1609 return true; 1597 return true;
1610 1598
1611 if (input.type == CREDIT_CARD_NUMBER) 1599 if (input.type == CREDIT_CARD_NUMBER)
1612 return !IsEditingExistingData(section); 1600 return !IsEditingExistingData(section);
1613 1601
1614 // For CVC, only require (allow) input if the user has edited some other 1602 // For CVC, only require (allow) input if the user has edited some other
1615 // aspect of the card. 1603 // aspect of the card.
1616 if (input.type == CREDIT_CARD_VERIFICATION_CODE && 1604 if (input.type == CREDIT_CARD_VERIFICATION_CODE &&
1617 IsEditingExistingData(section)) { 1605 IsEditingExistingData(section)) {
1618 DetailOutputMap output; 1606 FieldValueMap output;
1619 view_->GetUserInput(section, &output); 1607 view_->GetUserInput(section, &output);
1620 WalletInstrumentWrapper wrapper(ActiveInstrument()); 1608 WalletInstrumentWrapper wrapper(ActiveInstrument());
1621 1609
1622 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); 1610 for (FieldValueMap::iterator iter = output.begin(); iter != output.end();
1623 ++iter) { 1611 ++iter) {
1624 if (iter->first->type == input.type) 1612 if (iter->first == input.type)
1625 continue; 1613 continue;
1626 1614
1627 AutofillType type(iter->first->type); 1615 AutofillType type(iter->first);
1628 if (type.group() == CREDIT_CARD && 1616 if (type.group() == CREDIT_CARD &&
1629 iter->second != wrapper.GetInfo(type)) { 1617 iter->second != wrapper.GetInfo(type)) {
1630 return true; 1618 return true;
1631 } 1619 }
1632 } 1620 }
1633 1621
1634 return false; 1622 return false;
1635 } 1623 }
1636 1624
1637 return true; 1625 return true;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 } 1727 }
1740 1728
1741 return value.empty() ? 1729 return value.empty() ?
1742 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : 1730 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) :
1743 base::string16(); 1731 base::string16();
1744 } 1732 }
1745 1733
1746 // TODO(groby): Also add tests. 1734 // TODO(groby): Also add tests.
1747 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( 1735 ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
1748 DialogSection section, 1736 DialogSection section,
1749 const DetailOutputMap& inputs) { 1737 const FieldValueMap& inputs) {
1750 ValidityMessages messages; 1738 ValidityMessages messages;
1751 std::map<ServerFieldType, string16> field_values; 1739 std::map<ServerFieldType, string16> field_values;
1752 for (DetailOutputMap::const_iterator iter = inputs.begin(); 1740 for (FieldValueMap::const_iterator iter = inputs.begin();
1753 iter != inputs.end(); ++iter) { 1741 iter != inputs.end(); ++iter) {
1754 const ServerFieldType type = iter->first->type; 1742 const ServerFieldType type = iter->first;
1755 1743
1756 base::string16 text = InputValidityMessage(section, type, iter->second); 1744 base::string16 text = InputValidityMessage(section, type, iter->second);
1757 1745
1758 // Skip empty/unchanged fields in edit mode. Ignore country code as it 1746 // Skip empty/unchanged fields in edit mode. Ignore country code as it
1759 // always has a value. If the individual field does not have validation 1747 // always has a value. If the individual field does not have validation
1760 // errors, assume it to be valid unless later proven otherwise. 1748 // errors, assume it to be valid unless later proven otherwise.
1761 bool sure = InputWasEdited(type, iter->second) || 1749 bool sure = InputWasEdited(type, iter->second) ||
1762 ComboboxModelForAutofillType(type) == &country_combobox_model_; 1750 ComboboxModelForAutofillType(type) == &country_combobox_model_;
1763 1751
1764 // Consider only individually valid fields for inter-field validation. 1752 // Consider only individually valid fields for inter-field validation.
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 // name. 2068 // name.
2081 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { 2069 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
2082 submitted_cardholder_name_ = 2070 submitted_cardholder_name_ =
2083 GetValueFromSection(SECTION_CC_BILLING, NAME_BILLING_FULL); 2071 GetValueFromSection(SECTION_CC_BILLING, NAME_BILLING_FULL);
2084 2072
2085 // Snag the last four digits of the backing card now as it could be wiped 2073 // Snag the last four digits of the backing card now as it could be wiped
2086 // out if a CVC challenge happens. 2074 // out if a CVC challenge happens.
2087 if (ActiveInstrument()) { 2075 if (ActiveInstrument()) {
2088 backing_card_last_four_ = ActiveInstrument()->TypeAndLastFourDigits(); 2076 backing_card_last_four_ = ActiveInstrument()->TypeAndLastFourDigits();
2089 } else { 2077 } else {
2090 DetailOutputMap output; 2078 FieldValueMap output;
2091 view_->GetUserInput(SECTION_CC_BILLING, &output); 2079 view_->GetUserInput(SECTION_CC_BILLING, &output);
2092 CreditCard card; 2080 CreditCard card;
2093 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 2081 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
2094 backing_card_last_four_ = card.TypeAndLastFourDigits(); 2082 backing_card_last_four_ = card.TypeAndLastFourDigits();
2095 } 2083 }
2096 } 2084 }
2097 DCHECK(!submitted_cardholder_name_.empty()); 2085 DCHECK(!submitted_cardholder_name_.empty());
2098 DCHECK(!backing_card_last_four_.empty()); 2086 DCHECK(!backing_card_last_four_.empty());
2099 } 2087 }
2100 2088
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 wallet_errors_.clear(); 2622 wallet_errors_.clear();
2635 GetWalletClient()->CancelRequests(); 2623 GetWalletClient()->CancelRequests();
2636 SetIsSubmitting(false); 2624 SetIsSubmitting(false);
2637 wallet_error_notification_ = GetWalletError(error_type); 2625 wallet_error_notification_ = GetWalletError(error_type);
2638 account_chooser_model_.SetHadWalletError(); 2626 account_chooser_model_.SetHadWalletError();
2639 } 2627 }
2640 2628
2641 void AutofillDialogControllerImpl::SuggestionsUpdated() { 2629 void AutofillDialogControllerImpl::SuggestionsUpdated() {
2642 ScopedViewUpdates updates(view_.get()); 2630 ScopedViewUpdates updates(view_.get());
2643 2631
2644 const DetailOutputMap snapshot = TakeUserInputSnapshot(); 2632 const FieldValueMap snapshot = TakeUserInputSnapshot();
2645 2633
2646 suggested_cc_.Reset(); 2634 suggested_cc_.Reset();
2647 suggested_billing_.Reset(); 2635 suggested_billing_.Reset();
2648 suggested_cc_billing_.Reset(); 2636 suggested_cc_billing_.Reset();
2649 suggested_shipping_.Reset(); 2637 suggested_shipping_.Reset();
2650 HidePopup(); 2638 HidePopup();
2651 2639
2652 suggested_shipping_.AddKeyedItem( 2640 suggested_shipping_.AddKeyedItem(
2653 kSameAsBillingKey, 2641 kSameAsBillingKey,
2654 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); 2642 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 // When filling from Wallet data, use the email address associated with the 2835 // When filling from Wallet data, use the email address associated with the
2848 // account. There is no other email address stored as part of a Wallet 2836 // account. There is no other email address stored as part of a Wallet
2849 // address. 2837 // address.
2850 if (section == SECTION_CC_BILLING) { 2838 if (section == SECTION_CC_BILLING) {
2851 SetOutputForFieldsOfType( 2839 SetOutputForFieldsOfType(
2852 EMAIL_ADDRESS, account_chooser_model_.GetActiveWalletAccountName()); 2840 EMAIL_ADDRESS, account_chooser_model_.GetActiveWalletAccountName());
2853 } 2841 }
2854 } else { 2842 } else {
2855 // The user manually input data. If using Autofill, save the info as new or 2843 // The user manually input data. If using Autofill, save the info as new or
2856 // edited data. Always fill local data into |form_structure_|. 2844 // edited data. Always fill local data into |form_structure_|.
2857 DetailOutputMap output; 2845 FieldValueMap output;
2858 view_->GetUserInput(section, &output); 2846 view_->GetUserInput(section, &output);
2859 2847
2860 if (section == SECTION_CC) { 2848 if (section == SECTION_CC) {
2861 CreditCard card; 2849 CreditCard card;
2862 card.set_origin(kAutofillDialogOrigin); 2850 card.set_origin(kAutofillDialogOrigin);
2863 FillFormGroupFromOutputs(output, &card); 2851 FillFormGroupFromOutputs(output, &card);
2864 2852
2865 // The card holder name comes from the billing address section. 2853 // The card holder name comes from the billing address section.
2866 card.SetRawInfo(CREDIT_CARD_NAME, 2854 card.SetRawInfo(CREDIT_CARD_NAME,
2867 GetValueFromSection(SECTION_BILLING, NAME_BILLING_FULL)); 2855 GetValueFromSection(SECTION_BILLING, NAME_BILLING_FULL));
2868 2856
2869 if (ShouldSaveDetailsLocally()) { 2857 if (ShouldSaveDetailsLocally()) {
2870 std::string guid = GetManager()->SaveImportedCreditCard(card); 2858 std::string guid = GetManager()->SaveImportedCreditCard(card);
2871 newly_saved_data_model_guids_[section] = guid; 2859 newly_saved_data_model_guids_[section] = guid;
2872 DCHECK(!profile()->IsOffTheRecord()); 2860 DCHECK(!profile()->IsOffTheRecord());
2873 newly_saved_card_.reset(new CreditCard(card)); 2861 newly_saved_card_.reset(new CreditCard(card));
2874 } 2862 }
2875 2863
2876 AutofillCreditCardWrapper card_wrapper(&card); 2864 AutofillCreditCardWrapper card_wrapper(&card);
2877 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); 2865 card_wrapper.FillFormStructure(inputs, compare, &form_structure_);
2878 2866
2879 // Again, CVC needs special-casing. Fill it in directly from |output|. 2867 // Again, CVC needs special-casing. Fill it in directly from |output|.
2880 SetOutputForFieldsOfType( 2868 SetOutputForFieldsOfType(
2881 CREDIT_CARD_VERIFICATION_CODE, 2869 CREDIT_CARD_VERIFICATION_CODE,
2882 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); 2870 output[CREDIT_CARD_VERIFICATION_CODE]);
2883 } else { 2871 } else {
2884 AutofillProfile profile; 2872 AutofillProfile profile;
2885 profile.set_origin(kAutofillDialogOrigin); 2873 profile.set_origin(kAutofillDialogOrigin);
2886 FillFormGroupFromOutputs(output, &profile); 2874 FillFormGroupFromOutputs(output, &profile);
2887 2875
2888 if (ShouldSaveDetailsLocally()) { 2876 if (ShouldSaveDetailsLocally()) {
2889 std::string guid = GetManager()->SaveImportedProfile(profile); 2877 std::string guid = GetManager()->SaveImportedProfile(profile);
2890 newly_saved_data_model_guids_[section] = guid; 2878 newly_saved_data_model_guids_[section] = guid;
2891 } 2879 }
2892 2880
(...skipping 30 matching lines...) Expand all
2923 2911
2924 string16 AutofillDialogControllerImpl::GetValueFromSection( 2912 string16 AutofillDialogControllerImpl::GetValueFromSection(
2925 DialogSection section, 2913 DialogSection section,
2926 ServerFieldType type) { 2914 ServerFieldType type) {
2927 DCHECK(SectionIsActive(section)); 2915 DCHECK(SectionIsActive(section));
2928 2916
2929 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 2917 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
2930 if (wrapper) 2918 if (wrapper)
2931 return wrapper->GetInfo(AutofillType(type)); 2919 return wrapper->GetInfo(AutofillType(type));
2932 2920
2933 DetailOutputMap output; 2921 FieldValueMap output;
2934 view_->GetUserInput(section, &output); 2922 view_->GetUserInput(section, &output);
2935 return GetValueForType(output, type); 2923 return output[type];
2936 } 2924 }
2937 2925
2938 SuggestionsMenuModel* AutofillDialogControllerImpl:: 2926 SuggestionsMenuModel* AutofillDialogControllerImpl::
2939 SuggestionsMenuModelForSection(DialogSection section) { 2927 SuggestionsMenuModelForSection(DialogSection section) {
2940 switch (section) { 2928 switch (section) {
2941 case SECTION_CC: 2929 case SECTION_CC:
2942 return &suggested_cc_; 2930 return &suggested_cc_;
2943 case SECTION_BILLING: 2931 case SECTION_BILLING:
2944 return &suggested_billing_; 2932 return &suggested_billing_;
2945 case SECTION_SHIPPING: 2933 case SECTION_SHIPPING:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 return false; 3017 return false;
3030 } 3018 }
3031 return true; 3019 return true;
3032 } 3020 }
3033 3021
3034 bool AutofillDialogControllerImpl::SectionIsValid( 3022 bool AutofillDialogControllerImpl::SectionIsValid(
3035 DialogSection section) { 3023 DialogSection section) {
3036 if (!IsManuallyEditingSection(section)) 3024 if (!IsManuallyEditingSection(section))
3037 return true; 3025 return true;
3038 3026
3039 DetailOutputMap detail_outputs; 3027 FieldValueMap detail_outputs;
3040 view_->GetUserInput(section, &detail_outputs); 3028 view_->GetUserInput(section, &detail_outputs);
3041 return !InputsAreValid(section, detail_outputs).HasSureErrors(); 3029 return !InputsAreValid(section, detail_outputs).HasSureErrors();
3042 } 3030 }
3043 3031
3044 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( 3032 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid(
3045 const base::string16& year, 3033 const base::string16& year,
3046 const base::string16& month) const { 3034 const base::string16& month) const {
3047 // If the expiration is in the past as per the local clock, it's invalid. 3035 // If the expiration is in the past as per the local clock, it's invalid.
3048 base::Time now = base::Time::Now(); 3036 base::Time now = base::Time::Now();
3049 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) 3037 if (!autofill::IsValidCreditCardExpirationDate(year, month, now))
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3184 3172
3185 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(), 3173 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(),
3186 inputted_address.Pass()); 3174 inputted_address.Pass());
3187 } 3175 }
3188 3176
3189 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: 3177 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl::
3190 CreateTransientInstrument() { 3178 CreateTransientInstrument() {
3191 if (!active_instrument_id_.empty()) 3179 if (!active_instrument_id_.empty())
3192 return scoped_ptr<wallet::Instrument>(); 3180 return scoped_ptr<wallet::Instrument>();
3193 3181
3194 DetailOutputMap output; 3182 FieldValueMap output;
3195 view_->GetUserInput(SECTION_CC_BILLING, &output); 3183 view_->GetUserInput(SECTION_CC_BILLING, &output);
3196 3184
3197 CreditCard card; 3185 CreditCard card;
3198 AutofillProfile profile; 3186 AutofillProfile profile;
3199 string16 cvc; 3187 string16 cvc;
3200 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); 3188 GetBillingInfoFromOutputs(output, &card, &cvc, &profile);
3201 3189
3202 return scoped_ptr<wallet::Instrument>( 3190 return scoped_ptr<wallet::Instrument>(
3203 new wallet::Instrument(card, cvc, profile)); 3191 new wallet::Instrument(card, cvc, profile));
3204 } 3192 }
3205 3193
3206 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: 3194 scoped_ptr<wallet::Address>AutofillDialogControllerImpl::
3207 CreateTransientAddress() { 3195 CreateTransientAddress() {
3208 // If not using billing for shipping, just scrape the view. 3196 // If not using billing for shipping, just scrape the view.
3209 DetailOutputMap output; 3197 FieldValueMap output;
3210 view_->GetUserInput(SECTION_SHIPPING, &output); 3198 view_->GetUserInput(SECTION_SHIPPING, &output);
3211 3199
3212 AutofillProfile profile; 3200 AutofillProfile profile;
3213 FillFormGroupFromOutputs(output, &profile); 3201 FillFormGroupFromOutputs(output, &profile);
3214 3202
3215 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); 3203 return scoped_ptr<wallet::Address>(new wallet::Address(profile));
3216 } 3204 }
3217 3205
3218 void AutofillDialogControllerImpl::GetFullWallet() { 3206 void AutofillDialogControllerImpl::GetFullWallet() {
3219 DCHECK(is_submitting_); 3207 DCHECK(is_submitting_);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
3477 } 3465 }
3478 3466
3479 void AutofillDialogControllerImpl::MaybeShowCreditCardBubble() { 3467 void AutofillDialogControllerImpl::MaybeShowCreditCardBubble() {
3480 if (!data_was_passed_back_) 3468 if (!data_was_passed_back_)
3481 return; 3469 return;
3482 3470
3483 if (newly_saved_card_) { 3471 if (newly_saved_card_) {
3484 scoped_ptr<AutofillProfile> billing_profile; 3472 scoped_ptr<AutofillProfile> billing_profile;
3485 if (IsManuallyEditingSection(SECTION_BILLING)) { 3473 if (IsManuallyEditingSection(SECTION_BILLING)) {
3486 // Scrape the view as the user's entering or updating information. 3474 // Scrape the view as the user's entering or updating information.
3487 DetailOutputMap outputs; 3475 FieldValueMap outputs;
3488 view_->GetUserInput(SECTION_BILLING, &outputs); 3476 view_->GetUserInput(SECTION_BILLING, &outputs);
3489 billing_profile.reset(new AutofillProfile); 3477 billing_profile.reset(new AutofillProfile);
3490 FillFormGroupFromOutputs(outputs, billing_profile.get()); 3478 FillFormGroupFromOutputs(outputs, billing_profile.get());
3491 } else { 3479 } else {
3492 // Just snag the currently suggested profile. 3480 // Just snag the currently suggested profile.
3493 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> 3481 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)->
3494 GetItemKeyForCheckedItem(); 3482 GetItemKeyForCheckedItem();
3495 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); 3483 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key);
3496 billing_profile.reset(new AutofillProfile(*profile)); 3484 billing_profile.reset(new AutofillProfile(*profile));
3497 } 3485 }
(...skipping 21 matching lines...) Expand all
3519 view_->UpdateButtonStrip(); 3507 view_->UpdateButtonStrip();
3520 } 3508 }
3521 3509
3522 void AutofillDialogControllerImpl::FetchWalletCookie() { 3510 void AutofillDialogControllerImpl::FetchWalletCookie() {
3523 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3511 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3524 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3512 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3525 signin_helper_->StartWalletCookieValueFetch(); 3513 signin_helper_->StartWalletCookieValueFetch();
3526 } 3514 }
3527 3515
3528 } // namespace autofill 3516 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698