| 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 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) | 1934 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) |
| 1935 DeemphasizeRenderView(); | 1935 DeemphasizeRenderView(); |
| 1936 | 1936 |
| 1937 SetIsSubmitting(true); | 1937 SetIsSubmitting(true); |
| 1938 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1938 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1939 DCHECK(!active_instrument_id_.empty()); | 1939 DCHECK(!active_instrument_id_.empty()); |
| 1940 GetWalletClient()->AuthenticateInstrument( | 1940 GetWalletClient()->AuthenticateInstrument( |
| 1941 active_instrument_id_, | 1941 active_instrument_id_, |
| 1942 UTF16ToUTF8(view_->GetCvc()), | 1942 UTF16ToUTF8(view_->GetCvc())); |
| 1943 wallet_items_->obfuscated_gaia_id()); | |
| 1944 } else if (IsPayingWithWallet()) { | 1943 } else if (IsPayingWithWallet()) { |
| 1945 // TODO(dbeam): disallow interacting with the dialog while submitting. | 1944 // TODO(dbeam): disallow interacting with the dialog while submitting. |
| 1946 // http://crbug.com/230932 | 1945 // http://crbug.com/230932 |
| 1947 AcceptLegalDocuments(); | 1946 AcceptLegalDocuments(); |
| 1948 } else { | 1947 } else { |
| 1949 FinishSubmit(); | 1948 FinishSubmit(); |
| 1950 } | 1949 } |
| 1951 } | 1950 } |
| 1952 | 1951 |
| 1953 Profile* AutofillDialogControllerImpl::profile() { | 1952 Profile* AutofillDialogControllerImpl::profile() { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 2183 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| 2185 scoped_ptr<wallet::WalletItems> wallet_items) { | 2184 scoped_ptr<wallet::WalletItems> wallet_items) { |
| 2186 legal_documents_text_.clear(); | 2185 legal_documents_text_.clear(); |
| 2187 legal_document_link_ranges_.clear(); | 2186 legal_document_link_ranges_.clear(); |
| 2188 has_accepted_legal_documents_ = false; | 2187 has_accepted_legal_documents_ = false; |
| 2189 | 2188 |
| 2190 wallet_items_ = wallet_items.Pass(); | 2189 wallet_items_ = wallet_items.Pass(); |
| 2191 OnWalletOrSigninUpdate(); | 2190 OnWalletOrSigninUpdate(); |
| 2192 } | 2191 } |
| 2193 | 2192 |
| 2194 void AutofillDialogControllerImpl::OnDidSaveAddress( | 2193 void AutofillDialogControllerImpl::OnDidSaveToWallet( |
| 2194 const std::string& instrument_id, |
| 2195 const std::string& address_id, | 2195 const std::string& address_id, |
| 2196 const std::vector<wallet::RequiredAction>& required_actions, | 2196 const std::vector<wallet::RequiredAction>& required_actions, |
| 2197 const std::vector<wallet::FormFieldError>& form_field_errors) { | 2197 const std::vector<wallet::FormFieldError>& form_field_errors) { |
| 2198 DCHECK(is_submitting_ && IsPayingWithWallet()); | 2198 DCHECK(is_submitting_ && IsPayingWithWallet()); |
| 2199 | 2199 |
| 2200 if (required_actions.empty()) { | 2200 if (required_actions.empty()) { |
| 2201 active_address_id_ = address_id; | 2201 if (!address_id.empty()) |
| 2202 GetFullWalletIfReady(); | 2202 active_address_id_ = address_id; |
| 2203 if (!instrument_id.empty()) |
| 2204 active_instrument_id_ = instrument_id; |
| 2205 GetFullWallet(); |
| 2203 } else { | 2206 } else { |
| 2204 OnWalletFormFieldError(form_field_errors); | 2207 OnWalletFormFieldError(form_field_errors); |
| 2205 HandleSaveOrUpdateRequiredActions(required_actions); | 2208 HandleSaveOrUpdateRequiredActions(required_actions); |
| 2206 } | 2209 } |
| 2207 } | 2210 } |
| 2208 | 2211 |
| 2209 void AutofillDialogControllerImpl::OnDidSaveInstrument( | |
| 2210 const std::string& instrument_id, | |
| 2211 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2212 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2213 DCHECK(is_submitting_ && IsPayingWithWallet()); | |
| 2214 | |
| 2215 if (required_actions.empty()) { | |
| 2216 active_instrument_id_ = instrument_id; | |
| 2217 GetFullWalletIfReady(); | |
| 2218 } else { | |
| 2219 OnWalletFormFieldError(form_field_errors); | |
| 2220 HandleSaveOrUpdateRequiredActions(required_actions); | |
| 2221 } | |
| 2222 } | |
| 2223 | |
| 2224 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( | |
| 2225 const std::string& instrument_id, | |
| 2226 const std::string& address_id, | |
| 2227 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2228 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2229 OnDidSaveInstrument(instrument_id, required_actions, form_field_errors); | |
| 2230 // |is_submitting_| can change while in |OnDidSaveInstrument()|. | |
| 2231 if (is_submitting_) | |
| 2232 OnDidSaveAddress(address_id, required_actions, form_field_errors); | |
| 2233 } | |
| 2234 | |
| 2235 void AutofillDialogControllerImpl::OnDidUpdateAddress( | |
| 2236 const std::string& address_id, | |
| 2237 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2238 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2239 OnDidSaveAddress(address_id, required_actions, form_field_errors); | |
| 2240 } | |
| 2241 | |
| 2242 void AutofillDialogControllerImpl::OnDidUpdateInstrument( | |
| 2243 const std::string& instrument_id, | |
| 2244 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2245 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2246 OnDidSaveInstrument(instrument_id, required_actions, form_field_errors); | |
| 2247 } | |
| 2248 | |
| 2249 void AutofillDialogControllerImpl::OnWalletError( | 2212 void AutofillDialogControllerImpl::OnWalletError( |
| 2250 wallet::WalletClient::ErrorType error_type) { | 2213 wallet::WalletClient::ErrorType error_type) { |
| 2251 DisableWallet(error_type); | 2214 DisableWallet(error_type); |
| 2252 } | 2215 } |
| 2253 | 2216 |
| 2254 //////////////////////////////////////////////////////////////////////////////// | 2217 //////////////////////////////////////////////////////////////////////////////// |
| 2255 // PersonalDataManagerObserver implementation. | 2218 // PersonalDataManagerObserver implementation. |
| 2256 | 2219 |
| 2257 void AutofillDialogControllerImpl::OnPersonalDataChanged() { | 2220 void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
| 2258 if (is_submitting_) | 2221 if (is_submitting_) |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3018 DCHECK(!active_address_id_.empty()); | 2981 DCHECK(!active_address_id_.empty()); |
| 3019 } | 2982 } |
| 3020 | 2983 |
| 3021 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { | 2984 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { |
| 3022 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); | 2985 DCHECK_EQ(AUTOCHECKOUT_NOT_STARTED, autocheckout_state_); |
| 3023 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); | 2986 SetAutocheckoutState(AUTOCHECKOUT_IN_PROGRESS); |
| 3024 } | 2987 } |
| 3025 | 2988 |
| 3026 scoped_ptr<wallet::Instrument> inputted_instrument = | 2989 scoped_ptr<wallet::Instrument> inputted_instrument = |
| 3027 CreateTransientInstrument(); | 2990 CreateTransientInstrument(); |
| 3028 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> update_request = | 2991 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { |
| 3029 CreateUpdateInstrumentRequest( | 2992 inputted_instrument->set_object_id(active_instrument->object_id()); |
| 3030 inputted_instrument.get(), | 2993 DCHECK(!inputted_instrument->object_id().empty()); |
| 3031 !IsEditingExistingData(SECTION_CC_BILLING) ? std::string() : | 2994 } |
| 3032 active_instrument->object_id()); | |
| 3033 | 2995 |
| 3034 scoped_ptr<wallet::Address> inputted_address; | 2996 scoped_ptr<wallet::Address> inputted_address; |
| 3035 if (active_address_id_.empty()) { | 2997 if (active_address_id_.empty()) { |
| 3036 if (ShouldUseBillingForShipping()) { | 2998 if (ShouldUseBillingForShipping()) { |
| 3037 const wallet::Address& address = inputted_instrument ? | 2999 const wallet::Address& address = inputted_instrument ? |
| 3038 inputted_instrument->address() : active_instrument->address(); | 3000 *inputted_instrument->address() : active_instrument->address(); |
| 3039 // Try to find an exact matched shipping address and use it for shipping, | 3001 // 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 | 3002 // otherwise save it as a new shipping address. http://crbug.com/225442 |
| 3041 const wallet::Address* duplicated_address = | 3003 const wallet::Address* duplicated_address = |
| 3042 FindDuplicateAddress(wallet_items_->addresses(), address); | 3004 FindDuplicateAddress(wallet_items_->addresses(), address); |
| 3043 if (duplicated_address) { | 3005 if (duplicated_address) { |
| 3044 active_address_id_ = duplicated_address->object_id(); | 3006 active_address_id_ = duplicated_address->object_id(); |
| 3045 DCHECK(!active_address_id_.empty()); | 3007 DCHECK(!active_address_id_.empty()); |
| 3046 } else { | 3008 } else { |
| 3047 inputted_address.reset(new wallet::Address(address)); | 3009 inputted_address.reset(new wallet::Address(address)); |
| 3048 DCHECK(inputted_address->object_id().empty()); | 3010 DCHECK(inputted_address->object_id().empty()); |
| 3049 } | 3011 } |
| 3050 } else { | 3012 } else { |
| 3051 inputted_address = CreateTransientAddress(); | 3013 inputted_address = CreateTransientAddress(); |
| 3052 if (IsEditingExistingData(SECTION_SHIPPING)) { | 3014 if (IsEditingExistingData(SECTION_SHIPPING)) { |
| 3053 inputted_address->set_object_id(active_address->object_id()); | 3015 inputted_address->set_object_id(active_address->object_id()); |
| 3054 DCHECK(!inputted_address->object_id().empty()); | 3016 DCHECK(!inputted_address->object_id().empty()); |
| 3055 } | 3017 } |
| 3056 } | 3018 } |
| 3057 } | 3019 } |
| 3058 | 3020 |
| 3059 // If there's neither an address nor instrument to save, |GetFullWallet()| | 3021 // If there's neither an address nor instrument to save, |GetFullWallet()| |
| 3060 // is called when the risk fingerprint is loaded. | 3022 // is called when the risk fingerprint is loaded. |
| 3061 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { | 3023 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { |
| 3062 GetFullWallet(); | 3024 GetFullWallet(); |
| 3063 return; | 3025 return; |
| 3064 } | 3026 } |
| 3065 | 3027 |
| 3066 // If instrument and address aren't based off of any existing data, save both. | 3028 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(), |
| 3067 if (inputted_instrument && inputted_address && !update_request && | 3029 inputted_address.Pass(), |
| 3068 inputted_address->object_id().empty()) { | 3030 source_url_); |
| 3069 GetWalletClient()->SaveInstrumentAndAddress( | |
| 3070 *inputted_instrument, | |
| 3071 *inputted_address, | |
| 3072 wallet_items_->obfuscated_gaia_id(), | |
| 3073 source_url_); | |
| 3074 return; | |
| 3075 } | |
| 3076 | |
| 3077 if (inputted_instrument) { | |
| 3078 if (update_request) { | |
| 3079 scoped_ptr<wallet::Address> billing_address( | |
| 3080 new wallet::Address(inputted_instrument->address())); | |
| 3081 GetWalletClient()->UpdateInstrument(*update_request, | |
| 3082 billing_address.Pass()); | |
| 3083 } else { | |
| 3084 GetWalletClient()->SaveInstrument(*inputted_instrument, | |
| 3085 wallet_items_->obfuscated_gaia_id(), | |
| 3086 source_url_); | |
| 3087 } | |
| 3088 } | |
| 3089 | |
| 3090 if (inputted_address) { | |
| 3091 if (!inputted_address->object_id().empty()) | |
| 3092 GetWalletClient()->UpdateAddress(*inputted_address, source_url_); | |
| 3093 else | |
| 3094 GetWalletClient()->SaveAddress(*inputted_address, source_url_); | |
| 3095 } | |
| 3096 } | 3031 } |
| 3097 | 3032 |
| 3098 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: | 3033 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: |
| 3099 CreateTransientInstrument() { | 3034 CreateTransientInstrument() { |
| 3100 if (!active_instrument_id_.empty()) | 3035 if (!active_instrument_id_.empty()) |
| 3101 return scoped_ptr<wallet::Instrument>(); | 3036 return scoped_ptr<wallet::Instrument>(); |
| 3102 | 3037 |
| 3103 DetailOutputMap output; | 3038 DetailOutputMap output; |
| 3104 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3039 view_->GetUserInput(SECTION_CC_BILLING, &output); |
| 3105 | 3040 |
| 3106 CreditCard card; | 3041 CreditCard card; |
| 3107 AutofillProfile profile; | 3042 AutofillProfile profile; |
| 3108 string16 cvc; | 3043 string16 cvc; |
| 3109 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); | 3044 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); |
| 3110 | 3045 |
| 3111 return scoped_ptr<wallet::Instrument>( | 3046 return scoped_ptr<wallet::Instrument>( |
| 3112 new wallet::Instrument(card, cvc, profile)); | 3047 new wallet::Instrument(card, cvc, profile)); |
| 3113 } | 3048 } |
| 3114 | 3049 |
| 3115 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> | |
| 3116 AutofillDialogControllerImpl::CreateUpdateInstrumentRequest( | |
| 3117 const wallet::Instrument* instrument, | |
| 3118 const std::string& instrument_id) { | |
| 3119 if (!instrument || instrument_id.empty()) | |
| 3120 return scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest>(); | |
| 3121 | |
| 3122 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> update_request( | |
| 3123 new wallet::WalletClient::UpdateInstrumentRequest( | |
| 3124 instrument_id, source_url_)); | |
| 3125 update_request->expiration_month = instrument->expiration_month(); | |
| 3126 update_request->expiration_year = instrument->expiration_year(); | |
| 3127 update_request->card_verification_number = | |
| 3128 UTF16ToUTF8(instrument->card_verification_number()); | |
| 3129 update_request->obfuscated_gaia_id = wallet_items_->obfuscated_gaia_id(); | |
| 3130 return update_request.Pass(); | |
| 3131 } | |
| 3132 | |
| 3133 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: | 3050 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: |
| 3134 CreateTransientAddress() { | 3051 CreateTransientAddress() { |
| 3135 // If not using billing for shipping, just scrape the view. | 3052 // If not using billing for shipping, just scrape the view. |
| 3136 DetailOutputMap output; | 3053 DetailOutputMap output; |
| 3137 view_->GetUserInput(SECTION_SHIPPING, &output); | 3054 view_->GetUserInput(SECTION_SHIPPING, &output); |
| 3138 | 3055 |
| 3139 AutofillProfile profile; | 3056 AutofillProfile profile; |
| 3140 FillFormGroupFromOutputs(output, &profile); | 3057 FillFormGroupFromOutputs(output, &profile); |
| 3141 | 3058 |
| 3142 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); | 3059 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3156 AUTOCHECKOUT_STEP_STARTED); | 3073 AUTOCHECKOUT_STEP_STARTED); |
| 3157 | 3074 |
| 3158 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( | 3075 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( |
| 3159 active_instrument_id_, | 3076 active_instrument_id_, |
| 3160 active_address_id_, | 3077 active_address_id_, |
| 3161 source_url_, | 3078 source_url_, |
| 3162 wallet_items_->google_transaction_id(), | 3079 wallet_items_->google_transaction_id(), |
| 3163 capabilities)); | 3080 capabilities)); |
| 3164 } | 3081 } |
| 3165 | 3082 |
| 3166 void AutofillDialogControllerImpl::GetFullWalletIfReady() { | |
| 3167 DCHECK(is_submitting_); | |
| 3168 DCHECK(IsPayingWithWallet()); | |
| 3169 | |
| 3170 if (!active_instrument_id_.empty() && !active_address_id_.empty()) | |
| 3171 GetFullWallet(); | |
| 3172 } | |
| 3173 | |
| 3174 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions( | 3083 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions( |
| 3175 const std::vector<wallet::RequiredAction>& required_actions) { | 3084 const std::vector<wallet::RequiredAction>& required_actions) { |
| 3176 DCHECK(!required_actions.empty()); | 3085 DCHECK(!required_actions.empty()); |
| 3177 | 3086 |
| 3178 // TODO(ahutter): Invesitigate if we need to support more generic actions on | 3087 // TODO(ahutter): Invesitigate if we need to support more generic actions on |
| 3179 // this call such as GAIA_AUTH. See crbug.com/243457. | 3088 // this call such as GAIA_AUTH. See crbug.com/243457. |
| 3180 for (std::vector<wallet::RequiredAction>::const_iterator iter = | 3089 for (std::vector<wallet::RequiredAction>::const_iterator iter = |
| 3181 required_actions.begin(); | 3090 required_actions.begin(); |
| 3182 iter != required_actions.end(); ++iter) { | 3091 iter != required_actions.end(); ++iter) { |
| 3183 if (*iter != wallet::INVALID_FORM_FIELD) { | 3092 if (*iter != wallet::INVALID_FORM_FIELD) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3484 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3393 view_->GetUserInput(SECTION_CC_BILLING, &output); |
| 3485 CreditCard card; | 3394 CreditCard card; |
| 3486 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3395 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
| 3487 backing_last_four = card.TypeAndLastFourDigits(); | 3396 backing_last_four = card.TypeAndLastFourDigits(); |
| 3488 } | 3397 } |
| 3489 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( | 3398 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( |
| 3490 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3399 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
| 3491 } | 3400 } |
| 3492 | 3401 |
| 3493 } // namespace autofill | 3402 } // namespace autofill |
| OLD | NEW |