OLD | NEW |
---|---|
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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 void GetBillingInfoFromOutputs(const DetailOutputMap& output, | 158 void GetBillingInfoFromOutputs(const DetailOutputMap& output, |
159 CreditCard* card, | 159 CreditCard* card, |
160 string16* cvc, | 160 string16* cvc, |
161 AutofillProfile* profile) { | 161 AutofillProfile* profile) { |
162 for (DetailOutputMap::const_iterator it = output.begin(); | 162 for (DetailOutputMap::const_iterator it = output.begin(); |
163 it != output.end(); ++it) { | 163 it != output.end(); ++it) { |
164 string16 trimmed; | 164 string16 trimmed; |
165 TrimWhitespace(it->second, TRIM_ALL, &trimmed); | 165 TrimWhitespace(it->second, TRIM_ALL, &trimmed); |
166 | 166 |
167 // Special case CVC as CreditCard just swallows it. | 167 // Special case CVC as CreditCard just swallows it. |
168 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { | 168 if (cvc && it->first->type == CREDIT_CARD_VERIFICATION_CODE) { |
Evan Stade
2013/03/13 01:54:10
shouldn't you put the if (cvc) check inside this b
Dan Beam
2013/03/13 03:05:47
Done.
| |
169 *cvc = trimmed; | 169 cvc->assign(trimmed); |
170 } else { | 170 } else { |
171 // Copy the credit card name to |profile| in addition to |card| as | 171 // Copy the credit card name to |profile| in addition to |card| as |
172 // wallet::Instrument requires a recipient name for its billing address. | 172 // wallet::Instrument requires a recipient name for its billing address. |
173 if (it->first->type == CREDIT_CARD_NAME) | 173 if (profile && it->first->type == CREDIT_CARD_NAME) |
174 profile->SetRawInfo(NAME_FULL, trimmed); | 174 profile->SetRawInfo(NAME_FULL, trimmed); |
175 | 175 |
176 if (AutofillType(it->first->type).group() == AutofillType::CREDIT_CARD) | 176 if (AutofillType(it->first->type).group() == AutofillType::CREDIT_CARD) { |
177 card->SetRawInfo(it->first->type, trimmed); | 177 if (card) |
178 else | 178 card->SetRawInfo(it->first->type, trimmed); |
179 profile->SetRawInfo(it->first->type, trimmed); | 179 } else { |
Evan Stade
2013/03/13 01:54:10
merge else { if into else if
Dan Beam
2013/03/13 03:05:47
Done.
| |
180 if (profile) | |
181 profile->SetRawInfo(it->first->type, trimmed); | |
182 } | |
180 } | 183 } |
181 } | 184 } |
182 } | 185 } |
183 | 186 |
184 // Returns the containing window for the given |web_contents|. The containing | 187 // Returns the containing window for the given |web_contents|. The containing |
185 // window might be a browser window for a Chrome tab, or it might be a shell | 188 // window might be a browser window for a Chrome tab, or it might be a shell |
186 // window for a platform app. | 189 // window for a platform app. |
187 BaseWindow* GetBaseWindowForWebContents( | 190 BaseWindow* GetBaseWindowForWebContents( |
188 const content::WebContents* web_contents) { | 191 const content::WebContents* web_contents) { |
189 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 192 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1323 return true; | 1326 return true; |
1324 } | 1327 } |
1325 | 1328 |
1326 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 1329 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
1327 DialogSection section, | 1330 DialogSection section, |
1328 const InputFieldComparator& compare) { | 1331 const InputFieldComparator& compare) { |
1329 if (!SectionIsActive(section)) | 1332 if (!SectionIsActive(section)) |
1330 return; | 1333 return; |
1331 | 1334 |
1332 if (!IsManuallyEditingSection(section)) { | 1335 if (!IsManuallyEditingSection(section)) { |
1333 if (section == SECTION_CC_BILLING) { | 1336 if (IsPayingWithWallet()) { |
1334 // TODO(dbeam): implement. | 1337 bool is_billing = section == SECTION_SHIPPING || |
1338 section == SECTION_CC_BILLING; | |
1339 const DetailInputs& inputs = RequestedFieldsForSection(section); | |
1340 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | |
1341 AutofillField* field = form_structure_.field(i); | |
1342 for (size_t j = 0; j < inputs.size(); ++j) { | |
1343 if (compare.Run(inputs[j], *field)) { | |
1344 field->value = full_wallet_->GetInfo(field->type(), is_billing); | |
1345 break; | |
1346 } | |
1347 } | |
1348 } | |
1335 } else { | 1349 } else { |
1336 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 1350 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
1337 // Only fill in data that is associated with this section. | 1351 // Only fill in data that is associated with this section. |
1338 const DetailInputs& inputs = RequestedFieldsForSection(section); | 1352 const DetailInputs& inputs = RequestedFieldsForSection(section); |
1339 model->FillFormStructure(inputs, compare, &form_structure_); | 1353 model->FillFormStructure(inputs, compare, &form_structure_); |
1340 | 1354 |
1341 // CVC needs special-casing because the CreditCard class doesn't store | 1355 // CVC needs special-casing because the CreditCard class doesn't store |
1342 // or handle them. | 1356 // or handle them. |
1343 if (section == SECTION_CC) | 1357 if (section == SECTION_CC) |
1344 SetCvcResult(view_->GetCvc()); | 1358 SetCvcResult(view_->GetCvc()); |
1345 } | 1359 } |
1346 } else { | 1360 } else { |
1347 // The user manually input data. | 1361 // The user manually input data. |
1348 DetailOutputMap output; | 1362 DetailOutputMap output; |
1349 view_->GetUserInput(section, &output); | 1363 view_->GetUserInput(section, &output); |
1350 | 1364 |
1351 if (IsPayingWithWallet()) { | 1365 scoped_ptr<CreditCard> card; |
1352 // TODO(dbeam): implement. | 1366 scoped_ptr<string16> cvc; |
1353 } else { | 1367 if (section == SECTION_CC || section == SECTION_CC_BILLING) { |
1354 // Save the info as new or edited data and fill it into |form_structure_|. | 1368 card.reset(new CreditCard()); |
1355 if (section == SECTION_CC) { | 1369 cvc.reset(new string16()); |
1356 CreditCard card; | 1370 } |
1357 FillFormGroupFromOutputs(output, &card); | |
1358 | 1371 |
1359 if (view_->SaveDetailsLocally()) | 1372 AutofillProfile profile; |
1360 GetManager()->SaveImportedCreditCard(card); | 1373 GetBillingInfoFromOutputs(output, card.get(), cvc.get(), &profile); |
1361 | 1374 |
1362 FillFormStructureForSection(card, 0, section, compare); | 1375 // TODO(estade): we should probably edit the existing profile in the cases |
1376 // where the input data is based on an existing profile (user clicked "Edit" | |
1377 // or autofill popup filled in the form). | |
1378 if (card.get()) { | |
1379 if (view_->SaveDetailsLocally()) | |
1380 GetManager()->SaveImportedCreditCard(*card); | |
1363 | 1381 |
1364 // Again, CVC needs special-casing. Fill it in directly from |output|. | 1382 FillFormStructureForSection(*card, 0, section, compare); |
1365 SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | 1383 } |
1366 } else { | |
1367 AutofillProfile profile; | |
1368 FillFormGroupFromOutputs(output, &profile); | |
1369 | 1384 |
1370 // TODO(estade): we should probably edit the existing profile in the | 1385 if (cvc.get() && !cvc->empty()) |
1371 // cases where the input data is based on an existing profile (user | 1386 SetCvcResult(*cvc); |
1372 // clicked "Edit" or autofill popup filled in the form). | |
1373 if (view_->SaveDetailsLocally()) | |
1374 GetManager()->SaveImportedProfile(profile); | |
1375 | 1387 |
1376 FillFormStructureForSection(profile, 0, section, compare); | 1388 if (view_->SaveDetailsLocally()) |
1377 } | 1389 GetManager()->SaveImportedProfile(profile); |
1378 } | 1390 |
1391 FillFormStructureForSection(profile, 0, section, compare); | |
1379 } | 1392 } |
1380 } | 1393 } |
1381 | 1394 |
1382 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 1395 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
1383 FillOutputForSectionWithComparator(section, | 1396 FillOutputForSectionWithComparator(section, |
1384 base::Bind(DetailInputMatchesField)); | 1397 base::Bind(DetailInputMatchesField)); |
1385 } | 1398 } |
1386 | 1399 |
1387 void AutofillDialogControllerImpl::FillFormStructureForSection( | 1400 void AutofillDialogControllerImpl::FillFormStructureForSection( |
1388 const FormGroup& form_group, | 1401 const FormGroup& form_group, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1630 callback_.Run(&form_structure_); | 1643 callback_.Run(&form_structure_); |
1631 callback_ = base::Callback<void(const FormStructure*)>(); | 1644 callback_ = base::Callback<void(const FormStructure*)>(); |
1632 | 1645 |
1633 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { | 1646 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { |
1634 // This may delete us. | 1647 // This may delete us. |
1635 Hide(); | 1648 Hide(); |
1636 } | 1649 } |
1637 } | 1650 } |
1638 | 1651 |
1639 } // namespace autofill | 1652 } // namespace autofill |
OLD | NEW |