Chromium Code Reviews| 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 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1809 DialogAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, | 1809 DialogAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD, |
| 1810 AUTOCHECKOUT_STEP_UNSTARTED)); | 1810 AUTOCHECKOUT_STEP_UNSTARTED)); |
| 1811 } | 1811 } |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 SetIsSubmitting(true); | 1814 SetIsSubmitting(true); |
| 1815 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1815 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1816 DCHECK(!active_instrument_id_.empty()); | 1816 DCHECK(!active_instrument_id_.empty()); |
| 1817 GetWalletClient()->AuthenticateInstrument( | 1817 GetWalletClient()->AuthenticateInstrument( |
| 1818 active_instrument_id_, | 1818 active_instrument_id_, |
| 1819 UTF16ToUTF8(view_->GetCvc()), | 1819 UTF16ToUTF8(view_->GetCvc())); |
| 1820 wallet_items_->obfuscated_gaia_id()); | |
| 1821 } else if (IsPayingWithWallet()) { | 1820 } else if (IsPayingWithWallet()) { |
| 1822 // TODO(dbeam): disallow interacting with the dialog while submitting. | 1821 // TODO(dbeam): disallow interacting with the dialog while submitting. |
| 1823 // http://crbug.com/230932 | 1822 // http://crbug.com/230932 |
| 1824 AcceptLegalDocuments(); | 1823 AcceptLegalDocuments(); |
| 1825 } else { | 1824 } else { |
| 1826 FinishSubmit(); | 1825 FinishSubmit(); |
| 1827 } | 1826 } |
| 1828 } | 1827 } |
| 1829 | 1828 |
| 1830 Profile* AutofillDialogControllerImpl::profile() { | 1829 Profile* AutofillDialogControllerImpl::profile() { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2055 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 2054 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| 2056 scoped_ptr<wallet::WalletItems> wallet_items) { | 2055 scoped_ptr<wallet::WalletItems> wallet_items) { |
| 2057 legal_documents_text_.clear(); | 2056 legal_documents_text_.clear(); |
| 2058 legal_document_link_ranges_.clear(); | 2057 legal_document_link_ranges_.clear(); |
| 2059 has_accepted_legal_documents_ = false; | 2058 has_accepted_legal_documents_ = false; |
| 2060 | 2059 |
| 2061 wallet_items_ = wallet_items.Pass(); | 2060 wallet_items_ = wallet_items.Pass(); |
| 2062 OnWalletOrSigninUpdate(); | 2061 OnWalletOrSigninUpdate(); |
| 2063 } | 2062 } |
| 2064 | 2063 |
| 2065 void AutofillDialogControllerImpl::OnDidSaveAddress( | 2064 void AutofillDialogControllerImpl::OnDidSaveToWallet( |
| 2065 const std::string& instrument_id, | |
| 2066 const std::string& address_id, | 2066 const std::string& address_id, |
| 2067 const std::vector<wallet::RequiredAction>& required_actions, | 2067 const std::vector<wallet::RequiredAction>& required_actions, |
| 2068 const std::vector<wallet::FormFieldError>& form_field_errors) { | 2068 const std::vector<wallet::FormFieldError>& form_field_errors) { |
| 2069 DCHECK(is_submitting_ && IsPayingWithWallet()); | |
|
Dan Beam
2013/07/02 01:25:52
why did you remove?
ahutter
2013/07/02 15:44:23
oops
| |
| 2070 | |
| 2071 if (required_actions.empty()) { | 2069 if (required_actions.empty()) { |
| 2072 active_address_id_ = address_id; | 2070 if (!address_id.empty()) |
| 2071 active_address_id_ = address_id; | |
| 2072 if (!instrument_id.empty()) | |
| 2073 active_instrument_id_ = instrument_id; | |
| 2073 GetFullWalletIfReady(); | 2074 GetFullWalletIfReady(); |
|
Dan Beam
2013/07/02 01:25:52
^ shouldn't we always be ready now?
ahutter
2013/07/02 15:44:23
Done.
| |
| 2074 } else { | 2075 } else { |
| 2075 OnWalletFormFieldError(form_field_errors); | 2076 OnWalletFormFieldError(form_field_errors); |
| 2076 HandleSaveOrUpdateRequiredActions(required_actions); | |
| 2077 } | |
| 2078 } | |
| 2079 | |
| 2080 void AutofillDialogControllerImpl::OnDidSaveInstrument( | |
| 2081 const std::string& instrument_id, | |
| 2082 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2083 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2084 DCHECK(is_submitting_ && IsPayingWithWallet()); | |
| 2085 | |
| 2086 if (required_actions.empty()) { | |
| 2087 active_instrument_id_ = instrument_id; | |
| 2088 GetFullWalletIfReady(); | |
| 2089 } else { | |
| 2090 OnWalletFormFieldError(form_field_errors); | |
| 2091 HandleSaveOrUpdateRequiredActions(required_actions); | 2077 HandleSaveOrUpdateRequiredActions(required_actions); |
| 2092 } | 2078 } |
| 2093 } | 2079 } |
| 2094 | 2080 |
| 2095 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( | |
| 2096 const std::string& instrument_id, | |
| 2097 const std::string& address_id, | |
| 2098 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2099 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2100 OnDidSaveInstrument(instrument_id, required_actions, form_field_errors); | |
| 2101 // |is_submitting_| can change while in |OnDidSaveInstrument()|. | |
| 2102 if (is_submitting_) | |
| 2103 OnDidSaveAddress(address_id, required_actions, form_field_errors); | |
| 2104 } | |
| 2105 | |
| 2106 void AutofillDialogControllerImpl::OnDidUpdateAddress( | |
| 2107 const std::string& address_id, | |
| 2108 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2109 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2110 OnDidSaveAddress(address_id, required_actions, form_field_errors); | |
| 2111 } | |
| 2112 | |
| 2113 void AutofillDialogControllerImpl::OnDidUpdateInstrument( | |
| 2114 const std::string& instrument_id, | |
| 2115 const std::vector<wallet::RequiredAction>& required_actions, | |
| 2116 const std::vector<wallet::FormFieldError>& form_field_errors) { | |
| 2117 OnDidSaveInstrument(instrument_id, required_actions, form_field_errors); | |
| 2118 } | |
| 2119 | |
| 2120 void AutofillDialogControllerImpl::OnWalletError( | 2081 void AutofillDialogControllerImpl::OnWalletError( |
| 2121 wallet::WalletClient::ErrorType error_type) { | 2082 wallet::WalletClient::ErrorType error_type) { |
| 2122 DisableWallet(error_type); | 2083 DisableWallet(error_type); |
| 2123 } | 2084 } |
| 2124 | 2085 |
| 2125 //////////////////////////////////////////////////////////////////////////////// | 2086 //////////////////////////////////////////////////////////////////////////////// |
| 2126 // PersonalDataManagerObserver implementation. | 2087 // PersonalDataManagerObserver implementation. |
| 2127 | 2088 |
| 2128 void AutofillDialogControllerImpl::OnPersonalDataChanged() { | 2089 void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
| 2129 if (is_submitting_) | 2090 if (is_submitting_) |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2884 if (view_) { | 2845 if (view_) { |
| 2885 view_->UpdateButtonStrip(); | 2846 view_->UpdateButtonStrip(); |
| 2886 view_->UpdateAutocheckoutStepsArea(); | 2847 view_->UpdateAutocheckoutStepsArea(); |
| 2887 view_->UpdateDetailArea(); | 2848 view_->UpdateDetailArea(); |
| 2888 view_->UpdateAccountChooser(); | 2849 view_->UpdateAccountChooser(); |
| 2889 } | 2850 } |
| 2890 } | 2851 } |
| 2891 | 2852 |
| 2892 scoped_ptr<wallet::Instrument> inputted_instrument = | 2853 scoped_ptr<wallet::Instrument> inputted_instrument = |
| 2893 CreateTransientInstrument(); | 2854 CreateTransientInstrument(); |
| 2894 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> update_request = | 2855 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) { |
| 2895 CreateUpdateInstrumentRequest( | 2856 inputted_instrument->set_object_id(active_instrument->object_id()); |
| 2896 inputted_instrument.get(), | 2857 DCHECK(!inputted_instrument->object_id().empty()); |
| 2897 !IsEditingExistingData(SECTION_CC_BILLING) ? std::string() : | 2858 } |
| 2898 active_instrument->object_id()); | |
| 2899 | 2859 |
| 2900 scoped_ptr<wallet::Address> inputted_address; | 2860 scoped_ptr<wallet::Address> inputted_address; |
| 2901 if (active_address_id_.empty()) { | 2861 if (active_address_id_.empty()) { |
| 2902 if (ShouldUseBillingForShipping()) { | 2862 if (ShouldUseBillingForShipping()) { |
| 2903 const wallet::Address& address = inputted_instrument ? | 2863 const wallet::Address& address = inputted_instrument ? |
| 2904 inputted_instrument->address() : active_instrument->address(); | 2864 *inputted_instrument->address() : active_instrument->address(); |
| 2905 // Try to find an exact matched shipping address and use it for shipping, | 2865 // Try to find an exact matched shipping address and use it for shipping, |
| 2906 // otherwise save it as a new shipping address. http://crbug.com/225442 | 2866 // otherwise save it as a new shipping address. http://crbug.com/225442 |
| 2907 const wallet::Address* duplicated_address = | 2867 const wallet::Address* duplicated_address = |
| 2908 FindDuplicateAddress(wallet_items_->addresses(), address); | 2868 FindDuplicateAddress(wallet_items_->addresses(), address); |
| 2909 if (duplicated_address) { | 2869 if (duplicated_address) { |
| 2910 active_address_id_ = duplicated_address->object_id(); | 2870 active_address_id_ = duplicated_address->object_id(); |
| 2911 DCHECK(!active_address_id_.empty()); | 2871 DCHECK(!active_address_id_.empty()); |
| 2912 } else { | 2872 } else { |
| 2913 inputted_address.reset(new wallet::Address(address)); | 2873 inputted_address.reset(new wallet::Address(address)); |
| 2914 DCHECK(inputted_address->object_id().empty()); | 2874 DCHECK(inputted_address->object_id().empty()); |
| 2915 } | 2875 } |
| 2916 } else { | 2876 } else { |
| 2917 inputted_address = CreateTransientAddress(); | 2877 inputted_address = CreateTransientAddress(); |
| 2918 if (IsEditingExistingData(SECTION_SHIPPING)) { | 2878 if (IsEditingExistingData(SECTION_SHIPPING)) { |
| 2919 inputted_address->set_object_id(active_address->object_id()); | 2879 inputted_address->set_object_id(active_address->object_id()); |
| 2920 DCHECK(!inputted_address->object_id().empty()); | 2880 DCHECK(!inputted_address->object_id().empty()); |
| 2921 } | 2881 } |
| 2922 } | 2882 } |
| 2923 } | 2883 } |
| 2924 | 2884 |
| 2925 // If there's neither an address nor instrument to save, |GetFullWallet()| | 2885 // If there's neither an address nor instrument to save, |GetFullWallet()| |
| 2926 // is called when the risk fingerprint is loaded. | 2886 // is called when the risk fingerprint is loaded. |
| 2927 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { | 2887 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { |
| 2928 GetFullWallet(); | 2888 GetFullWallet(); |
| 2929 return; | 2889 return; |
| 2930 } | 2890 } |
| 2931 | 2891 |
| 2932 // If instrument and address aren't based off of any existing data, save both. | 2892 GetWalletClient()->SaveToWallet( |
| 2933 if (inputted_instrument && inputted_address && !update_request && | 2893 inputted_instrument.Pass(), |
| 2934 inputted_address->object_id().empty()) { | 2894 inputted_address.Pass(), |
| 2935 GetWalletClient()->SaveInstrumentAndAddress( | 2895 source_url_); |
|
Dan Beam
2013/07/02 01:25:52
nit:
GetWalletClient()->SaveToWallet(inputted_i
ahutter
2013/07/02 15:44:23
Done.
| |
| 2936 *inputted_instrument, | |
| 2937 *inputted_address, | |
| 2938 wallet_items_->obfuscated_gaia_id(), | |
| 2939 source_url_); | |
| 2940 return; | |
| 2941 } | |
| 2942 | |
| 2943 if (inputted_instrument) { | |
| 2944 if (update_request) { | |
| 2945 scoped_ptr<wallet::Address> billing_address( | |
| 2946 new wallet::Address(inputted_instrument->address())); | |
| 2947 GetWalletClient()->UpdateInstrument(*update_request, | |
| 2948 billing_address.Pass()); | |
| 2949 } else { | |
| 2950 GetWalletClient()->SaveInstrument(*inputted_instrument, | |
| 2951 wallet_items_->obfuscated_gaia_id(), | |
| 2952 source_url_); | |
| 2953 } | |
| 2954 } | |
| 2955 | |
| 2956 if (inputted_address) { | |
| 2957 if (!inputted_address->object_id().empty()) | |
| 2958 GetWalletClient()->UpdateAddress(*inputted_address, source_url_); | |
| 2959 else | |
| 2960 GetWalletClient()->SaveAddress(*inputted_address, source_url_); | |
| 2961 } | |
| 2962 } | 2896 } |
| 2963 | 2897 |
| 2964 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: | 2898 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: |
| 2965 CreateTransientInstrument() { | 2899 CreateTransientInstrument() { |
| 2966 if (!active_instrument_id_.empty()) | 2900 if (!active_instrument_id_.empty()) |
| 2967 return scoped_ptr<wallet::Instrument>(); | 2901 return scoped_ptr<wallet::Instrument>(); |
| 2968 | 2902 |
| 2969 DetailOutputMap output; | 2903 DetailOutputMap output; |
| 2970 view_->GetUserInput(SECTION_CC_BILLING, &output); | 2904 view_->GetUserInput(SECTION_CC_BILLING, &output); |
| 2971 | 2905 |
| 2972 CreditCard card; | 2906 CreditCard card; |
| 2973 AutofillProfile profile; | 2907 AutofillProfile profile; |
| 2974 string16 cvc; | 2908 string16 cvc; |
| 2975 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); | 2909 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); |
| 2976 | 2910 |
| 2977 return scoped_ptr<wallet::Instrument>( | 2911 return scoped_ptr<wallet::Instrument>( |
| 2978 new wallet::Instrument(card, cvc, profile)); | 2912 new wallet::Instrument(card, cvc, profile)); |
| 2979 } | 2913 } |
| 2980 | 2914 |
| 2981 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> | |
| 2982 AutofillDialogControllerImpl::CreateUpdateInstrumentRequest( | |
| 2983 const wallet::Instrument* instrument, | |
| 2984 const std::string& instrument_id) { | |
| 2985 if (!instrument || instrument_id.empty()) | |
| 2986 return scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest>(); | |
| 2987 | |
| 2988 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> update_request( | |
| 2989 new wallet::WalletClient::UpdateInstrumentRequest( | |
| 2990 instrument_id, source_url_)); | |
| 2991 update_request->expiration_month = instrument->expiration_month(); | |
| 2992 update_request->expiration_year = instrument->expiration_year(); | |
| 2993 update_request->card_verification_number = | |
| 2994 UTF16ToUTF8(instrument->card_verification_number()); | |
| 2995 update_request->obfuscated_gaia_id = wallet_items_->obfuscated_gaia_id(); | |
| 2996 return update_request.Pass(); | |
| 2997 } | |
| 2998 | |
| 2999 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: | 2915 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: |
| 3000 CreateTransientAddress() { | 2916 CreateTransientAddress() { |
| 3001 // If not using billing for shipping, just scrape the view. | 2917 // If not using billing for shipping, just scrape the view. |
| 3002 DetailOutputMap output; | 2918 DetailOutputMap output; |
| 3003 view_->GetUserInput(SECTION_SHIPPING, &output); | 2919 view_->GetUserInput(SECTION_SHIPPING, &output); |
| 3004 | 2920 |
| 3005 AutofillProfile profile; | 2921 AutofillProfile profile; |
| 3006 FillFormGroupFromOutputs(output, &profile); | 2922 FillFormGroupFromOutputs(output, &profile); |
| 3007 | 2923 |
| 3008 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); | 2924 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3287 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 3203 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
| 3288 } | 3204 } |
| 3289 | 3205 |
| 3290 // Has Wallet items. | 3206 // Has Wallet items. |
| 3291 return has_autofill_profiles ? | 3207 return has_autofill_profiles ? |
| 3292 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 3208 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
| 3293 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 3209 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
| 3294 } | 3210 } |
| 3295 | 3211 |
| 3296 } // namespace autofill | 3212 } // namespace autofill |
| OLD | NEW |