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

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

Issue 12815002: requestAutocomplete: Fill |form_structure_| from Online Wallet data (including (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (it->first->type == CREDIT_CARD_VERIFICATION_CODE) {
169 *cvc = trimmed; 169 if (cvc)
170 cvc->assign(trimmed);
170 } else { 171 } else {
171 // Copy the credit card name to |profile| in addition to |card| as 172 // Copy the credit card name to |profile| in addition to |card| as
172 // wallet::Instrument requires a recipient name for its billing address. 173 // wallet::Instrument requires a recipient name for its billing address.
173 if (it->first->type == CREDIT_CARD_NAME) 174 if (profile && it->first->type == CREDIT_CARD_NAME)
174 profile->SetRawInfo(NAME_FULL, trimmed); 175 profile->SetRawInfo(NAME_FULL, trimmed);
175 176
176 if (AutofillType(it->first->type).group() == AutofillType::CREDIT_CARD) 177 if (AutofillType(it->first->type).group() == AutofillType::CREDIT_CARD) {
177 card->SetRawInfo(it->first->type, trimmed); 178 if (card)
178 else 179 card->SetRawInfo(it->first->type, trimmed);
180 } else if (profile) {
179 profile->SetRawInfo(it->first->type, trimmed); 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 591
589 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( 592 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper(
590 DialogSection section) { 593 DialogSection section) {
591 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 594 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
592 std::string item_key = model->GetItemKeyForCheckedItem(); 595 std::string item_key = model->GetItemKeyForCheckedItem();
593 scoped_ptr<DataModelWrapper> wrapper; 596 scoped_ptr<DataModelWrapper> wrapper;
594 if (item_key.empty()) 597 if (item_key.empty())
595 return wrapper.Pass(); 598 return wrapper.Pass();
596 599
597 if (IsPayingWithWallet()) { 600 if (IsPayingWithWallet()) {
598 int index; 601 if (did_submit_ && full_wallet_.get()) {
599 bool success = base::StringToInt(item_key, &index); 602 if (section == SECTION_CC_BILLING)
600 DCHECK(success); 603 wrapper.reset(new FullWalletBillingWrapper(full_wallet_.get()));
604 else
605 wrapper.reset(new FullWalletShippingWrapper(full_wallet_.get()));
606 } else {
607 int index;
608 bool success = base::StringToInt(item_key, &index);
609 DCHECK(success);
601 610
602 if (section == SECTION_CC_BILLING) { 611 if (section == SECTION_CC_BILLING) {
603 wrapper.reset( 612 wrapper.reset(
604 new WalletInstrumentWrapper(wallet_items_->instruments()[index])); 613 new WalletInstrumentWrapper(wallet_items_->instruments()[index]));
605 } else { 614 } else {
606 wrapper.reset( 615 wrapper.reset(
607 new WalletAddressWrapper(wallet_items_->addresses()[index])); 616 new WalletAddressWrapper(wallet_items_->addresses()[index]));
617 }
608 } 618 }
609 } else if (section == SECTION_CC) { 619 } else if (section == SECTION_CC) {
610 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); 620 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key);
611 DCHECK(card); 621 DCHECK(card);
612 wrapper.reset(new AutofillCreditCardWrapper(card)); 622 wrapper.reset(new AutofillCreditCardWrapper(card));
613 } else { 623 } else {
614 // Calculate the variant by looking at how many items come from the same 624 // Calculate the variant by looking at how many items come from the same
615 // FormGroup. 625 // FormGroup.
616 size_t variant = 0; 626 size_t variant = 0;
617 for (int i = model->checked_item() - 1; i >= 0; --i) { 627 for (int i = model->checked_item() - 1; i >= 0; --i) {
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 return true; 1333 return true;
1324 } 1334 }
1325 1335
1326 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( 1336 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
1327 DialogSection section, 1337 DialogSection section,
1328 const InputFieldComparator& compare) { 1338 const InputFieldComparator& compare) {
1329 if (!SectionIsActive(section)) 1339 if (!SectionIsActive(section))
1330 return; 1340 return;
1331 1341
1332 if (!IsManuallyEditingSection(section)) { 1342 if (!IsManuallyEditingSection(section)) {
1333 if (section == SECTION_CC_BILLING) { 1343 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
1334 // TODO(dbeam): implement. 1344 // Only fill in data that is associated with this section.
1335 } else { 1345 const DetailInputs& inputs = RequestedFieldsForSection(section);
1336 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 1346 model->FillFormStructure(inputs, compare, &form_structure_);
1337 // Only fill in data that is associated with this section.
1338 const DetailInputs& inputs = RequestedFieldsForSection(section);
1339 model->FillFormStructure(inputs, compare, &form_structure_);
1340 1347
1341 // CVC needs special-casing because the CreditCard class doesn't store 1348 // CVC needs special-casing because the CreditCard class doesn't store
1342 // or handle them. 1349 // or handle them.
1343 if (section == SECTION_CC) 1350 if (section == SECTION_CC)
1344 SetCvcResult(view_->GetCvc()); 1351 SetCvcResult(view_->GetCvc());
1345 }
1346 } else { 1352 } else {
1347 // The user manually input data. 1353 // The user manually input data.
1348 DetailOutputMap output; 1354 DetailOutputMap output;
1349 view_->GetUserInput(section, &output); 1355 view_->GetUserInput(section, &output);
1350 1356
1351 if (IsPayingWithWallet()) { 1357 scoped_ptr<CreditCard> card;
1352 // TODO(dbeam): implement. 1358 scoped_ptr<string16> cvc;
1353 } else { 1359 if (section == SECTION_CC || section == SECTION_CC_BILLING) {
1354 // Save the info as new or edited data and fill it into |form_structure_|. 1360 card.reset(new CreditCard());
1355 if (section == SECTION_CC) { 1361 cvc.reset(new string16());
1356 CreditCard card; 1362 }
1357 FillFormGroupFromOutputs(output, &card);
1358 1363
1359 if (view_->SaveDetailsLocally()) 1364 AutofillProfile profile;
1360 GetManager()->SaveImportedCreditCard(card); 1365 GetBillingInfoFromOutputs(output, card.get(), cvc.get(), &profile);
1361 1366
1362 FillFormStructureForSection(card, 0, section, compare); 1367 // TODO(estade): we should probably edit the existing profile in the cases
1368 // where the input data is based on an existing profile (user clicked "Edit"
1369 // or autofill popup filled in the form).
1370 if (card.get()) {
1371 if (SaveDetailsLocally())
1372 GetManager()->SaveImportedCreditCard(*card);
1363 1373
1364 // Again, CVC needs special-casing. Fill it in directly from |output|. 1374 FillFormStructureForSection(*card, 0, section, compare);
1365 SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); 1375 }
1366 } else {
1367 AutofillProfile profile;
1368 FillFormGroupFromOutputs(output, &profile);
1369 1376
1370 // TODO(estade): we should probably edit the existing profile in the 1377 if (cvc.get() && !cvc->empty())
1371 // cases where the input data is based on an existing profile (user 1378 SetCvcResult(*cvc);
1372 // clicked "Edit" or autofill popup filled in the form).
1373 if (view_->SaveDetailsLocally())
1374 GetManager()->SaveImportedProfile(profile);
1375 1379
1376 FillFormStructureForSection(profile, 0, section, compare); 1380 if (SaveDetailsLocally())
1377 } 1381 GetManager()->SaveImportedProfile(profile);
1378 } 1382
1383 FillFormStructureForSection(profile, 0, section, compare);
1379 } 1384 }
1380 } 1385 }
1381 1386
1382 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { 1387 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) {
1383 FillOutputForSectionWithComparator(section, 1388 FillOutputForSectionWithComparator(section,
1384 base::Bind(DetailInputMatchesField)); 1389 base::Bind(DetailInputMatchesField));
1385 } 1390 }
1386 1391
1387 void AutofillDialogControllerImpl::FillFormStructureForSection( 1392 void AutofillDialogControllerImpl::FillFormStructureForSection(
1388 const FormGroup& form_group, 1393 const FormGroup& form_group,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 bool AutofillDialogControllerImpl::UseBillingForShipping() { 1506 bool AutofillDialogControllerImpl::UseBillingForShipping() {
1502 // If the user is editing or inputting data, ask the view. 1507 // If the user is editing or inputting data, ask the view.
1503 if (IsManuallyEditingSection(SECTION_SHIPPING)) 1508 if (IsManuallyEditingSection(SECTION_SHIPPING))
1504 return view_->UseBillingForShipping(); 1509 return view_->UseBillingForShipping();
1505 1510
1506 // Otherwise, the checkbox should be hidden so its state is irrelevant. 1511 // Otherwise, the checkbox should be hidden so its state is irrelevant.
1507 // Always use the shipping suggestion model. 1512 // Always use the shipping suggestion model.
1508 return false; 1513 return false;
1509 } 1514 }
1510 1515
1516 bool AutofillDialogControllerImpl::SaveDetailsLocally() {
1517 return !IsPayingWithWallet() && view_->SaveDetailsLocally();
1518 }
1519
1511 void AutofillDialogControllerImpl::SubmitWithWallet() { 1520 void AutofillDialogControllerImpl::SubmitWithWallet() {
1512 // TODO(dbeam): disallow interacting with the dialog while submitting. 1521 // TODO(dbeam): disallow interacting with the dialog while submitting.
1513 1522
1514 active_instrument_id_.clear(); 1523 active_instrument_id_.clear();
1515 active_address_id_.clear(); 1524 active_address_id_.clear();
1516 1525
1517 if (!section_editing_state_[SECTION_CC_BILLING]) { 1526 if (!section_editing_state_[SECTION_CC_BILLING]) {
1518 SuggestionsMenuModel* billing = 1527 SuggestionsMenuModel* billing =
1519 SuggestionsMenuModelForSection(SECTION_CC_BILLING); 1528 SuggestionsMenuModelForSection(SECTION_CC_BILLING);
1520 if (!billing->GetItemKeyForCheckedItem().empty() && 1529 if (!billing->GetItemKeyForCheckedItem().empty() &&
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 callback_.Run(&form_structure_); 1639 callback_.Run(&form_structure_);
1631 callback_ = base::Callback<void(const FormStructure*)>(); 1640 callback_ = base::Callback<void(const FormStructure*)>();
1632 1641
1633 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { 1642 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {
1634 // This may delete us. 1643 // This may delete us.
1635 Hide(); 1644 Hide();
1636 } 1645 }
1637 } 1646 }
1638 1647
1639 } // namespace autofill 1648 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698