| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| 2137 bool AutofillDialogControllerImpl::IsMinimalAddressAccepted() const { |
| 2138 // TODO(ahutter): Make this care about |form_structure_|. |
| 2139 return false; |
| 2140 } |
| 2141 |
| 2142 bool AutofillDialogControllerImpl::IsPhoneNumberRequired() const { |
| 2143 // TODO(ahutter): Make this care about |form_structure_|. |
| 2144 return true; |
| 2145 } |
| 2146 |
| 2133 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { | 2147 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { |
| 2134 DCHECK(is_submitting_ && IsPayingWithWallet()); | 2148 DCHECK(is_submitting_ && IsPayingWithWallet()); |
| 2135 has_accepted_legal_documents_ = true; | 2149 has_accepted_legal_documents_ = true; |
| 2136 LoadRiskFingerprintData(); | 2150 LoadRiskFingerprintData(); |
| 2137 } | 2151 } |
| 2138 | 2152 |
| 2139 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { | 2153 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { |
| 2140 DCHECK(is_submitting_ && IsPayingWithWallet()); | 2154 DCHECK(is_submitting_ && IsPayingWithWallet()); |
| 2141 | 2155 |
| 2142 // TODO(dbeam): use the returned full wallet. b/8332329 | 2156 // TODO(dbeam): use the returned full wallet. b/8332329 |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2735 | 2749 |
| 2736 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2750 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
| 2737 FillOutputForSectionWithComparator( | 2751 FillOutputForSectionWithComparator( |
| 2738 section, base::Bind(DetailInputMatchesField, section)); | 2752 section, base::Bind(DetailInputMatchesField, section)); |
| 2739 } | 2753 } |
| 2740 | 2754 |
| 2741 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2755 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
| 2742 DialogSection section) const { | 2756 DialogSection section) const { |
| 2743 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for | 2757 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for |
| 2744 // any of the fields. | 2758 // any of the fields. |
| 2745 // TODO(estade): remove !IsPayingWithWallet() check once WalletClient support | 2759 if (section == SECTION_SHIPPING) |
| 2746 // is added. http://crbug.com/243514 | |
| 2747 if (section == SECTION_SHIPPING && !IsPayingWithWallet()) | |
| 2748 return cares_about_shipping_; | 2760 return cares_about_shipping_; |
| 2749 | 2761 |
| 2750 return true; | 2762 return true; |
| 2751 } | 2763 } |
| 2752 | 2764 |
| 2753 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 2765 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { |
| 2754 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2766 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
| 2755 AutofillField* field = form_structure_.field(i); | 2767 AutofillField* field = form_structure_.field(i); |
| 2756 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { | 2768 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { |
| 2757 field->value = cvc; | 2769 field->value = cvc; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3007 | 3019 |
| 3008 const wallet::WalletItems::MaskedInstrument* active_instrument = | 3020 const wallet::WalletItems::MaskedInstrument* active_instrument = |
| 3009 ActiveInstrument(); | 3021 ActiveInstrument(); |
| 3010 if (!IsManuallyEditingSection(SECTION_CC_BILLING)) { | 3022 if (!IsManuallyEditingSection(SECTION_CC_BILLING)) { |
| 3011 active_instrument_id_ = active_instrument->object_id(); | 3023 active_instrument_id_ = active_instrument->object_id(); |
| 3012 DCHECK(!active_instrument_id_.empty()); | 3024 DCHECK(!active_instrument_id_.empty()); |
| 3013 } | 3025 } |
| 3014 | 3026 |
| 3015 const wallet::Address* active_address = ActiveShippingAddress(); | 3027 const wallet::Address* active_address = ActiveShippingAddress(); |
| 3016 if (!IsManuallyEditingSection(SECTION_SHIPPING) && | 3028 if (!IsManuallyEditingSection(SECTION_SHIPPING) && |
| 3017 !ShouldUseBillingForShipping()) { | 3029 !ShouldUseBillingForShipping() && |
| 3030 IsShippingAddressRequired()) { |
| 3018 active_address_id_ = active_address->object_id(); | 3031 active_address_id_ = active_address->object_id(); |
| 3019 DCHECK(!active_address_id_.empty()); | 3032 DCHECK(!active_address_id_.empty()); |
| 3020 } | 3033 } |
| 3021 | 3034 |
| 3022 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { | 3035 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { |
| 3023 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); | 3036 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); |
| 3024 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); | 3037 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); |
| 3025 } | 3038 } |
| 3026 | 3039 |
| 3027 scoped_ptr<wallet::Instrument> inputted_instrument = | 3040 scoped_ptr<wallet::Instrument> inputted_instrument = |
| 3028 CreateTransientInstrument(); | 3041 CreateTransientInstrument(); |
| 3029 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { | 3042 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { |
| 3030 inputted_instrument->set_object_id(active_instrument->object_id()); | 3043 inputted_instrument->set_object_id(active_instrument->object_id()); |
| 3031 DCHECK(!inputted_instrument->object_id().empty()); | 3044 DCHECK(!inputted_instrument->object_id().empty()); |
| 3032 } | 3045 } |
| 3033 | 3046 |
| 3034 scoped_ptr<wallet::Address> inputted_address; | 3047 scoped_ptr<wallet::Address> inputted_address; |
| 3035 if (active_address_id_.empty()) { | 3048 if (active_address_id_.empty() && IsShippingAddressRequired()) { |
| 3036 if (ShouldUseBillingForShipping()) { | 3049 if (ShouldUseBillingForShipping()) { |
| 3037 const wallet::Address& address = inputted_instrument ? | 3050 const wallet::Address& address = inputted_instrument ? |
| 3038 *inputted_instrument->address() : active_instrument->address(); | 3051 *inputted_instrument->address() : active_instrument->address(); |
| 3039 // Try to find an exact matched shipping address and use it for shipping, | 3052 // 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 | 3053 // otherwise save it as a new shipping address. http://crbug.com/225442 |
| 3041 const wallet::Address* duplicated_address = | 3054 const wallet::Address* duplicated_address = |
| 3042 FindDuplicateAddress(wallet_items_->addresses(), address); | 3055 FindDuplicateAddress(wallet_items_->addresses(), address); |
| 3043 if (duplicated_address) { | 3056 if (duplicated_address) { |
| 3044 active_address_id_ = duplicated_address->object_id(); | 3057 active_address_id_ = duplicated_address->object_id(); |
| 3045 DCHECK(!active_address_id_.empty()); | 3058 DCHECK(!active_address_id_.empty()); |
| 3046 } else { | 3059 } else { |
| 3047 inputted_address.reset(new wallet::Address(address)); | 3060 inputted_address.reset(new wallet::Address(address)); |
| 3048 DCHECK(inputted_address->object_id().empty()); | 3061 DCHECK(inputted_address->object_id().empty()); |
| 3049 } | 3062 } |
| 3050 } else { | 3063 } else { |
| 3051 inputted_address = CreateTransientAddress(); | 3064 inputted_address = CreateTransientAddress(); |
| 3052 if (IsEditingExistingData(SECTION_SHIPPING)) { | 3065 if (IsEditingExistingData(SECTION_SHIPPING)) { |
| 3053 inputted_address->set_object_id(active_address->object_id()); | 3066 inputted_address->set_object_id(active_address->object_id()); |
| 3054 DCHECK(!inputted_address->object_id().empty()); | 3067 DCHECK(!inputted_address->object_id().empty()); |
| 3055 } | 3068 } |
| 3056 } | 3069 } |
| 3057 } | 3070 } |
| 3058 | 3071 |
| 3059 // If there's neither an address nor instrument to save, |GetFullWallet()| | 3072 // If there's neither an address nor instrument to save, |GetFullWallet()| |
| 3060 // is called when the risk fingerprint is loaded. | 3073 // is called when the risk fingerprint is loaded. |
| 3061 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { | 3074 if (!active_instrument_id_.empty() && |
| 3075 (!active_address_id_.empty() || !IsShippingAddressRequired())) { |
| 3062 GetFullWallet(); | 3076 GetFullWallet(); |
| 3063 return; | 3077 return; |
| 3064 } | 3078 } |
| 3065 | 3079 |
| 3066 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(), | 3080 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(), |
| 3067 inputted_address.Pass(), | 3081 inputted_address.Pass(), |
| 3068 source_url_); | 3082 source_url_); |
| 3069 } | 3083 } |
| 3070 | 3084 |
| 3071 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: | 3085 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3095 FillFormGroupFromOutputs(output, &profile); | 3109 FillFormGroupFromOutputs(output, &profile); |
| 3096 | 3110 |
| 3097 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); | 3111 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); |
| 3098 } | 3112 } |
| 3099 | 3113 |
| 3100 void AutofillDialogControllerImpl::GetFullWallet() { | 3114 void AutofillDialogControllerImpl::GetFullWallet() { |
| 3101 DCHECK(is_submitting_); | 3115 DCHECK(is_submitting_); |
| 3102 DCHECK(IsPayingWithWallet()); | 3116 DCHECK(IsPayingWithWallet()); |
| 3103 DCHECK(wallet_items_); | 3117 DCHECK(wallet_items_); |
| 3104 DCHECK(!active_instrument_id_.empty()); | 3118 DCHECK(!active_instrument_id_.empty()); |
| 3105 DCHECK(!active_address_id_.empty()); | 3119 DCHECK(!active_address_id_.empty() || !IsShippingAddressRequired()); |
| 3106 | 3120 |
| 3107 std::vector<wallet::WalletClient::RiskCapability> capabilities; | 3121 std::vector<wallet::WalletClient::RiskCapability> capabilities; |
| 3108 capabilities.push_back(wallet::WalletClient::VERIFY_CVC); | 3122 capabilities.push_back(wallet::WalletClient::VERIFY_CVC); |
| 3109 | 3123 |
| 3110 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, | 3124 UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, |
| 3111 AUTOCHECKOUT_STEP_STARTED); | 3125 AUTOCHECKOUT_STEP_STARTED); |
| 3112 | 3126 |
| 3113 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( | 3127 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( |
| 3114 active_instrument_id_, | 3128 active_instrument_id_, |
| 3115 active_address_id_, | 3129 active_address_id_, |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3431 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3445 view_->GetUserInput(SECTION_CC_BILLING, &output); |
| 3432 CreditCard card; | 3446 CreditCard card; |
| 3433 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3447 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
| 3434 backing_last_four = card.TypeAndLastFourDigits(); | 3448 backing_last_four = card.TypeAndLastFourDigits(); |
| 3435 } | 3449 } |
| 3436 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( | 3450 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( |
| 3437 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3451 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
| 3438 } | 3452 } |
| 3439 | 3453 |
| 3440 } // namespace autofill | 3454 } // namespace autofill |
| OLD | NEW |