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

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

Issue 17970003: New encryption/escrow endpoints for Wallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No !! 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 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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()); 2069 DCHECK(is_submitting_ && IsPayingWithWallet());
2070 2070
2071 if (required_actions.empty()) { 2071 if (required_actions.empty()) {
2072 active_address_id_ = address_id; 2072 if (!address_id.empty())
2073 GetFullWalletIfReady(); 2073 active_address_id_ = address_id;
2074 if (!instrument_id.empty())
2075 active_instrument_id_ = instrument_id;
2076 GetFullWallet();
2074 } else { 2077 } else {
2075 OnWalletFormFieldError(form_field_errors); 2078 OnWalletFormFieldError(form_field_errors);
2076 HandleSaveOrUpdateRequiredActions(required_actions); 2079 HandleSaveOrUpdateRequiredActions(required_actions);
2077 } 2080 }
2078 } 2081 }
2079 2082
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);
2092 }
2093 }
2094
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( 2083 void AutofillDialogControllerImpl::OnWalletError(
2121 wallet::WalletClient::ErrorType error_type) { 2084 wallet::WalletClient::ErrorType error_type) {
2122 DisableWallet(error_type); 2085 DisableWallet(error_type);
2123 } 2086 }
2124 2087
2125 //////////////////////////////////////////////////////////////////////////////// 2088 ////////////////////////////////////////////////////////////////////////////////
2126 // PersonalDataManagerObserver implementation. 2089 // PersonalDataManagerObserver implementation.
2127 2090
2128 void AutofillDialogControllerImpl::OnPersonalDataChanged() { 2091 void AutofillDialogControllerImpl::OnPersonalDataChanged() {
2129 if (is_submitting_) 2092 if (is_submitting_)
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 if (view_) { 2847 if (view_) {
2885 view_->UpdateButtonStrip(); 2848 view_->UpdateButtonStrip();
2886 view_->UpdateAutocheckoutStepsArea(); 2849 view_->UpdateAutocheckoutStepsArea();
2887 view_->UpdateDetailArea(); 2850 view_->UpdateDetailArea();
2888 view_->UpdateAccountChooser(); 2851 view_->UpdateAccountChooser();
2889 } 2852 }
2890 } 2853 }
2891 2854
2892 scoped_ptr<wallet::Instrument> inputted_instrument = 2855 scoped_ptr<wallet::Instrument> inputted_instrument =
2893 CreateTransientInstrument(); 2856 CreateTransientInstrument();
2894 scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest> update_request = 2857 if (inputted_instrument && IsEditingExistingData(SECTION_CC_BILLING)) {
2895 CreateUpdateInstrumentRequest( 2858 inputted_instrument->set_object_id(active_instrument->object_id());
2896 inputted_instrument.get(), 2859 DCHECK(!inputted_instrument->object_id().empty());
2897 !IsEditingExistingData(SECTION_CC_BILLING) ? std::string() : 2860 }
2898 active_instrument->object_id());
2899 2861
2900 scoped_ptr<wallet::Address> inputted_address; 2862 scoped_ptr<wallet::Address> inputted_address;
2901 if (active_address_id_.empty()) { 2863 if (active_address_id_.empty()) {
2902 if (ShouldUseBillingForShipping()) { 2864 if (ShouldUseBillingForShipping()) {
2903 const wallet::Address& address = inputted_instrument ? 2865 const wallet::Address& address = inputted_instrument ?
2904 inputted_instrument->address() : active_instrument->address(); 2866 *inputted_instrument->address() : active_instrument->address();
2905 // Try to find an exact matched shipping address and use it for shipping, 2867 // 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 2868 // otherwise save it as a new shipping address. http://crbug.com/225442
2907 const wallet::Address* duplicated_address = 2869 const wallet::Address* duplicated_address =
2908 FindDuplicateAddress(wallet_items_->addresses(), address); 2870 FindDuplicateAddress(wallet_items_->addresses(), address);
2909 if (duplicated_address) { 2871 if (duplicated_address) {
2910 active_address_id_ = duplicated_address->object_id(); 2872 active_address_id_ = duplicated_address->object_id();
2911 DCHECK(!active_address_id_.empty()); 2873 DCHECK(!active_address_id_.empty());
2912 } else { 2874 } else {
2913 inputted_address.reset(new wallet::Address(address)); 2875 inputted_address.reset(new wallet::Address(address));
2914 DCHECK(inputted_address->object_id().empty()); 2876 DCHECK(inputted_address->object_id().empty());
2915 } 2877 }
2916 } else { 2878 } else {
2917 inputted_address = CreateTransientAddress(); 2879 inputted_address = CreateTransientAddress();
2918 if (IsEditingExistingData(SECTION_SHIPPING)) { 2880 if (IsEditingExistingData(SECTION_SHIPPING)) {
2919 inputted_address->set_object_id(active_address->object_id()); 2881 inputted_address->set_object_id(active_address->object_id());
2920 DCHECK(!inputted_address->object_id().empty()); 2882 DCHECK(!inputted_address->object_id().empty());
2921 } 2883 }
2922 } 2884 }
2923 } 2885 }
2924 2886
2925 // If there's neither an address nor instrument to save, |GetFullWallet()| 2887 // If there's neither an address nor instrument to save, |GetFullWallet()|
2926 // is called when the risk fingerprint is loaded. 2888 // is called when the risk fingerprint is loaded.
2927 if (!active_instrument_id_.empty() && !active_address_id_.empty()) { 2889 if (!active_instrument_id_.empty() && !active_address_id_.empty()) {
2928 GetFullWallet(); 2890 GetFullWallet();
2929 return; 2891 return;
2930 } 2892 }
2931 2893
2932 // If instrument and address aren't based off of any existing data, save both. 2894 GetWalletClient()->SaveToWallet(inputted_instrument.Pass(),
2933 if (inputted_instrument && inputted_address && !update_request && 2895 inputted_address.Pass(),
2934 inputted_address->object_id().empty()) { 2896 source_url_);
2935 GetWalletClient()->SaveInstrumentAndAddress(
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 } 2897 }
2963 2898
2964 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl:: 2899 scoped_ptr<wallet::Instrument> AutofillDialogControllerImpl::
2965 CreateTransientInstrument() { 2900 CreateTransientInstrument() {
2966 if (!active_instrument_id_.empty()) 2901 if (!active_instrument_id_.empty())
2967 return scoped_ptr<wallet::Instrument>(); 2902 return scoped_ptr<wallet::Instrument>();
2968 2903
2969 DetailOutputMap output; 2904 DetailOutputMap output;
2970 view_->GetUserInput(SECTION_CC_BILLING, &output); 2905 view_->GetUserInput(SECTION_CC_BILLING, &output);
2971 2906
2972 CreditCard card; 2907 CreditCard card;
2973 AutofillProfile profile; 2908 AutofillProfile profile;
2974 string16 cvc; 2909 string16 cvc;
2975 GetBillingInfoFromOutputs(output, &card, &cvc, &profile); 2910 GetBillingInfoFromOutputs(output, &card, &cvc, &profile);
2976 2911
2977 return scoped_ptr<wallet::Instrument>( 2912 return scoped_ptr<wallet::Instrument>(
2978 new wallet::Instrument(card, cvc, profile)); 2913 new wallet::Instrument(card, cvc, profile));
2979 } 2914 }
2980 2915
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:: 2916 scoped_ptr<wallet::Address>AutofillDialogControllerImpl::
3000 CreateTransientAddress() { 2917 CreateTransientAddress() {
3001 // If not using billing for shipping, just scrape the view. 2918 // If not using billing for shipping, just scrape the view.
3002 DetailOutputMap output; 2919 DetailOutputMap output;
3003 view_->GetUserInput(SECTION_SHIPPING, &output); 2920 view_->GetUserInput(SECTION_SHIPPING, &output);
3004 2921
3005 AutofillProfile profile; 2922 AutofillProfile profile;
3006 FillFormGroupFromOutputs(output, &profile); 2923 FillFormGroupFromOutputs(output, &profile);
3007 2924
3008 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); 2925 return scoped_ptr<wallet::Address>(new wallet::Address(profile));
(...skipping 13 matching lines...) Expand all
3022 AUTOCHECKOUT_STEP_STARTED); 2939 AUTOCHECKOUT_STEP_STARTED);
3023 2940
3024 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( 2941 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest(
3025 active_instrument_id_, 2942 active_instrument_id_,
3026 active_address_id_, 2943 active_address_id_,
3027 source_url_, 2944 source_url_,
3028 wallet_items_->google_transaction_id(), 2945 wallet_items_->google_transaction_id(),
3029 capabilities)); 2946 capabilities));
3030 } 2947 }
3031 2948
3032 void AutofillDialogControllerImpl::GetFullWalletIfReady() {
3033 DCHECK(is_submitting_);
3034 DCHECK(IsPayingWithWallet());
3035
3036 if (!active_instrument_id_.empty() && !active_address_id_.empty())
3037 GetFullWallet();
3038 }
3039
3040 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions( 2949 void AutofillDialogControllerImpl::HandleSaveOrUpdateRequiredActions(
3041 const std::vector<wallet::RequiredAction>& required_actions) { 2950 const std::vector<wallet::RequiredAction>& required_actions) {
3042 DCHECK(!required_actions.empty()); 2951 DCHECK(!required_actions.empty());
3043 2952
3044 // TODO(ahutter): Invesitigate if we need to support more generic actions on 2953 // TODO(ahutter): Invesitigate if we need to support more generic actions on
3045 // this call such as GAIA_AUTH. See crbug.com/243457. 2954 // this call such as GAIA_AUTH. See crbug.com/243457.
3046 for (std::vector<wallet::RequiredAction>::const_iterator iter = 2955 for (std::vector<wallet::RequiredAction>::const_iterator iter =
3047 required_actions.begin(); 2956 required_actions.begin();
3048 iter != required_actions.end(); ++iter) { 2957 iter != required_actions.end(); ++iter) {
3049 if (*iter != wallet::INVALID_FORM_FIELD) { 2958 if (*iter != wallet::INVALID_FORM_FIELD) {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 3196 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
3288 } 3197 }
3289 3198
3290 // Has Wallet items. 3199 // Has Wallet items.
3291 return has_autofill_profiles ? 3200 return has_autofill_profiles ?
3292 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 3201 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
3293 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 3202 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
3294 } 3203 }
3295 3204
3296 } // namespace autofill 3205 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698