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

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

Issue 20420002: Make Wallet respect whether or not shipping address is required. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wallet client respects delegates shipping preference. Created 7 years, 5 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 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 static_cast<size_t>(index) >= wallet_items_->instruments().size()) { 1360 static_cast<size_t>(index) >= wallet_items_->instruments().size()) {
1361 NOTREACHED(); 1361 NOTREACHED();
1362 return NULL; 1362 return NULL;
1363 } 1363 }
1364 1364
1365 return wallet_items_->instruments()[index]; 1365 return wallet_items_->instruments()[index];
1366 } 1366 }
1367 1367
1368 const wallet::Address* AutofillDialogControllerImpl:: 1368 const wallet::Address* AutofillDialogControllerImpl::
1369 ActiveShippingAddress() const { 1369 ActiveShippingAddress() const {
1370 if (!IsPayingWithWallet()) 1370 if (!IsPayingWithWallet() || !IsShippingAddressRequired())
1371 return NULL; 1371 return NULL;
1372 1372
1373 const SuggestionsMenuModel* model = 1373 const SuggestionsMenuModel* model =
1374 SuggestionsMenuModelForSection(SECTION_SHIPPING); 1374 SuggestionsMenuModelForSection(SECTION_SHIPPING);
1375 const std::string item_key = model->GetItemKeyForCheckedItem(); 1375 const std::string item_key = model->GetItemKeyForCheckedItem();
1376 if (!IsASuggestionItemKey(item_key)) 1376 if (!IsASuggestionItemKey(item_key))
1377 return NULL; 1377 return NULL;
1378 1378
1379 int index; 1379 int index;
1380 if (!base::StringToInt(item_key, &index) || index < 0 || 1380 if (!base::StringToInt(item_key, &index) || index < 0 ||
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 2123
2124 std::string AutofillDialogControllerImpl::GetRiskData() const { 2124 std::string AutofillDialogControllerImpl::GetRiskData() const {
2125 DCHECK(!risk_data_.empty()); 2125 DCHECK(!risk_data_.empty());
2126 return risk_data_; 2126 return risk_data_;
2127 } 2127 }
2128 2128
2129 std::string AutofillDialogControllerImpl::GetWalletCookieValue() const { 2129 std::string AutofillDialogControllerImpl::GetWalletCookieValue() const {
2130 return wallet_cookie_value_; 2130 return wallet_cookie_value_;
2131 } 2131 }
2132 2132
2133 bool AutofillDialogControllerImpl::IsShippingAddressRequired() const {
2134 return cares_about_shipping_;
2135 }
2136
2133 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { 2137 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() {
2134 DCHECK(is_submitting_ && IsPayingWithWallet()); 2138 DCHECK(is_submitting_ && IsPayingWithWallet());
2135 has_accepted_legal_documents_ = true; 2139 has_accepted_legal_documents_ = true;
2136 LoadRiskFingerprintData(); 2140 LoadRiskFingerprintData();
2137 } 2141 }
2138 2142
2139 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { 2143 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) {
2140 DCHECK(is_submitting_ && IsPayingWithWallet()); 2144 DCHECK(is_submitting_ && IsPayingWithWallet());
2141 2145
2142 // TODO(dbeam): use the returned full wallet. b/8332329 2146 // TODO(dbeam): use the returned full wallet. b/8332329
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 2739
2736 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { 2740 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) {
2737 FillOutputForSectionWithComparator( 2741 FillOutputForSectionWithComparator(
2738 section, base::Bind(DetailInputMatchesField, section)); 2742 section, base::Bind(DetailInputMatchesField, section));
2739 } 2743 }
2740 2744
2741 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( 2745 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection(
2742 DialogSection section) const { 2746 DialogSection section) const {
2743 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for 2747 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for
2744 // any of the fields. 2748 // any of the fields.
2745 // TODO(estade): remove !IsPayingWithWallet() check once WalletClient support 2749 if (section == SECTION_SHIPPING)
2746 // is added. http://crbug.com/243514
2747 if (section == SECTION_SHIPPING && !IsPayingWithWallet())
2748 return cares_about_shipping_; 2750 return cares_about_shipping_;
2749 2751
2750 return true; 2752 return true;
2751 } 2753 }
2752 2754
2753 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { 2755 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) {
2754 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2756 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2755 AutofillField* field = form_structure_.field(i); 2757 AutofillField* field = form_structure_.field(i);
2756 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { 2758 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) {
2757 field->value = cvc; 2759 field->value = cvc;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
3007 3009
3008 const wallet::WalletItems::MaskedInstrument* active_instrument = 3010 const wallet::WalletItems::MaskedInstrument* active_instrument =
3009 ActiveInstrument(); 3011 ActiveInstrument();
3010 if (!IsManuallyEditingSection(SECTION_CC_BILLING)) { 3012 if (!IsManuallyEditingSection(SECTION_CC_BILLING)) {
3011 active_instrument_id_ = active_instrument->object_id(); 3013 active_instrument_id_ = active_instrument->object_id();
3012 DCHECK(!active_instrument_id_.empty()); 3014 DCHECK(!active_instrument_id_.empty());
3013 } 3015 }
3014 3016
3015 const wallet::Address* active_address = ActiveShippingAddress(); 3017 const wallet::Address* active_address = ActiveShippingAddress();
3016 if (!IsManuallyEditingSection(SECTION_SHIPPING) && 3018 if (!IsManuallyEditingSection(SECTION_SHIPPING) &&
3017 !ShouldUseBillingForShipping()) { 3019 !ShouldUseBillingForShipping() &&
3020 IsShippingAddressRequired()) {
3018 active_address_id_ = active_address->object_id(); 3021 active_address_id_ = active_address->object_id();
3019 DCHECK(!active_address_id_.empty()); 3022 DCHECK(!active_address_id_.empty());
3020 } 3023 }
3021 3024
3022 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { 3025 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) {
3023 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); 3026 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_);
3024 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); 3027 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS);
3025 } 3028 }
3026 3029
3027 scoped_ptr<wallet::Instrument> inputted_instrument = 3030 scoped_ptr<wallet::Instrument> inputted_instrument =
3028 CreateTransientInstrument(); 3031 CreateTransientInstrument();
3029 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { 3032 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) {
3030 inputted_instrument->set_object_id(active_instrument->object_id()); 3033 inputted_instrument->set_object_id(active_instrument->object_id());
3031 DCHECK(!inputted_instrument->object_id().empty()); 3034 DCHECK(!inputted_instrument->object_id().empty());
3032 } 3035 }
3033 3036
3034 scoped_ptr<wallet::Address> inputted_address; 3037 scoped_ptr<wallet::Address> inputted_address;
3035 if (active_address_id_.empty()) { 3038 if (active_address_id_.empty() && IsShippingAddressRequired()) {
3036 if (ShouldUseBillingForShipping()) { 3039 if (ShouldUseBillingForShipping()) {
3037 const wallet::Address& address = inputted_instrument ? 3040 const wallet::Address& address = inputted_instrument ?
3038 *inputted_instrument->address() : active_instrument->address(); 3041 *inputted_instrument->address() : active_instrument->address();
3039 // Try to find an exact matched shipping address and use it for shipping, 3042 // Try to find an exact matched shipping address and use it for shipping,
3040 // otherwise save it as a new shipping address. http://crbug.com/225442 3043 // otherwise save it as a new shipping address. http://crbug.com/225442
3041 const wallet::Address* duplicated_address = 3044 const wallet::Address* duplicated_address =
3042 FindDuplicateAddress(wallet_items_->addresses(), address); 3045 FindDuplicateAddress(wallet_items_->addresses(), address);
3043 if (duplicated_address) { 3046 if (duplicated_address) {
3044 active_address_id_ = duplicated_address->object_id(); 3047 active_address_id_ = duplicated_address->object_id();
3045 DCHECK(!active_address_id_.empty()); 3048 DCHECK(!active_address_id_.empty());
3046 } else { 3049 } else {
3047 inputted_address.reset(new wallet::Address(address)); 3050 inputted_address.reset(new wallet::Address(address));
3048 DCHECK(inputted_address->object_id().empty()); 3051 DCHECK(inputted_address->object_id().empty());
3049 } 3052 }
3050 } else { 3053 } else {
3051 inputted_address = CreateTransientAddress(); 3054 inputted_address = CreateTransientAddress();
3052 if (IsEditingExistingData(SECTION_SHIPPING)) { 3055 if (IsEditingExistingData(SECTION_SHIPPING)) {
3053 inputted_address->set_object_id(active_address->object_id()); 3056 inputted_address->set_object_id(active_address->object_id());
3054 DCHECK(!inputted_address->object_id().empty()); 3057 DCHECK(!inputted_address->object_id().empty());
3055 } 3058 }
3056 } 3059 }
3057 } 3060 }
3058 3061
3059 // If there's neither an address nor instrument to save, |GetFullWallet()| 3062 // If there's neither an address nor instrument to save, |GetFullWallet()|
3060 // is called when the risk fingerprint is loaded. 3063 // is called when the risk fingerprint is loaded.
3061 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { 3064 if (!active_instrument_id_.empty() &&
3065 (!active_address_id_.empty() || !IsShippingAddressRequired())) {
3062 GetFullWallet(); 3066 GetFullWallet();
3063 return; 3067 return;
3064 } 3068 }
3065 3069
3066 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(), 3070 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(),
3067 inputted_address.Pass(), 3071 inputted_address.Pass(),
3068 source_url_); 3072 source_url_);
3069 } 3073 }
3070 3074
3071 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: 3075 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl::
(...skipping 23 matching lines...) Expand all
3095 FillFormGroupFromOutputs(output, &profile); 3099 FillFormGroupFromOutputs(output, &profile);
3096 3100
3097 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); 3101 return scoped_ptr<wallet::Address>(new wallet::Address(profile));
3098 } 3102 }
3099 3103
3100 void AutofillDialogControllerImpl::GetFullWallet() { 3104 void AutofillDialogControllerImpl::GetFullWallet() {
3101 DCHECK(is_submitting_); 3105 DCHECK(is_submitting_);
3102 DCHECK(IsPayingWithWallet()); 3106 DCHECK(IsPayingWithWallet());
3103 DCHECK(wallet_items_); 3107 DCHECK(wallet_items_);
3104 DCHECK(!active_instrument_id_.empty()); 3108 DCHECK(!active_instrument_id_.empty());
3105 DCHECK(!active_address_id_.empty()); 3109 DCHECK(!active_address_id_.empty() || !IsShippingAddressRequired());
3106 3110
3107 std::vector<wallet::WalletClient::RiskCapability> capabilities; 3111 std::vector<wallet::WalletClient::RiskCapability> capabilities;
3108 capabilities.push_back(wallet::WalletClient::VERIFY_CVC); 3112 capabilities.push_back(wallet::WalletClient::VERIFY_CVC);
3109 3113
3110 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, 3114 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD,
3111 AUTOCHECKOUT_STEP_STARTED); 3115 AUTOCHECKOUT_STEP_STARTED);
3112 3116
3113 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( 3117 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest(
3114 active_instrument_id_, 3118 active_instrument_id_,
3115 active_address_id_, 3119 active_address_id_,
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
3431 view_->GetUserInput(SECTION_CC_BILLING, &output); 3435 view_->GetUserInput(SECTION_CC_BILLING, &output);
3432 CreditCard card; 3436 CreditCard card;
3433 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 3437 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
3434 backing_last_four = card.TypeAndLastFourDigits(); 3438 backing_last_four = card.TypeAndLastFourDigits();
3435 } 3439 }
3436 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( 3440 AutofillCreditCardBubbleController::ShowGeneratedCardBubble(
3437 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); 3441 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits());
3438 } 3442 }
3439 3443
3440 } // namespace autofill 3444 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698