| 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 if (!possible_values.empty() && | 660 if (!possible_values.empty() && |
| 661 !possible_values.count(base::ASCIIToUTF16(country_code))) { | 661 !possible_values.count(base::ASCIIToUTF16(country_code))) { |
| 662 return false; | 662 return false; |
| 663 } | 663 } |
| 664 | 664 |
| 665 return true; | 665 return true; |
| 666 } | 666 } |
| 667 | 667 |
| 668 // static | 668 // static |
| 669 base::WeakPtr<AutofillDialogControllerImpl> | 669 base::WeakPtr<AutofillDialogControllerImpl> |
| 670 AutofillDialogControllerImpl::Create( | 670 AutofillDialogControllerImpl::Create( |
| 671 content::WebContents* contents, | 671 content::WebContents* contents, |
| 672 const FormData& form_structure, | 672 const FormData& form_structure, |
| 673 const GURL& source_url, | 673 const GURL& source_url, |
| 674 const AutofillManagerDelegate::ResultCallback& callback) { | 674 const AutofillClient::ResultCallback& callback) { |
| 675 // AutofillDialogControllerImpl owns itself. | 675 // AutofillDialogControllerImpl owns itself. |
| 676 AutofillDialogControllerImpl* autofill_dialog_controller = | 676 AutofillDialogControllerImpl* autofill_dialog_controller = |
| 677 new AutofillDialogControllerImpl(contents, | 677 new AutofillDialogControllerImpl(contents, |
| 678 form_structure, | 678 form_structure, |
| 679 source_url, | 679 source_url, |
| 680 callback); | 680 callback); |
| 681 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); | 681 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); |
| 682 } | 682 } |
| 683 | 683 |
| 684 // static | 684 // static |
| (...skipping 19 matching lines...) Expand all Loading... |
| 704 ::prefs::kAutofillDialogWalletShippingSameAsBilling, | 704 ::prefs::kAutofillDialogWalletShippingSameAsBilling, |
| 705 false, | 705 false, |
| 706 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 706 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 707 } | 707 } |
| 708 | 708 |
| 709 // static | 709 // static |
| 710 base::WeakPtr<AutofillDialogController> AutofillDialogController::Create( | 710 base::WeakPtr<AutofillDialogController> AutofillDialogController::Create( |
| 711 content::WebContents* contents, | 711 content::WebContents* contents, |
| 712 const FormData& form_structure, | 712 const FormData& form_structure, |
| 713 const GURL& source_url, | 713 const GURL& source_url, |
| 714 const AutofillManagerDelegate::ResultCallback& callback) { | 714 const AutofillClient::ResultCallback& callback) { |
| 715 return AutofillDialogControllerImpl::Create(contents, | 715 return AutofillDialogControllerImpl::Create(contents, |
| 716 form_structure, | 716 form_structure, |
| 717 source_url, | 717 source_url, |
| 718 callback); | 718 callback); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void AutofillDialogControllerImpl::Show() { | 721 void AutofillDialogControllerImpl::Show() { |
| 722 dialog_shown_timestamp_ = base::Time::Now(); | 722 dialog_shown_timestamp_ = base::Time::Now(); |
| 723 | 723 |
| 724 // Determine what field types should be included in the dialog. | 724 // Determine what field types should be included in the dialog. |
| 725 bool has_types = false; | 725 bool has_types = false; |
| 726 bool has_sections = false; | 726 bool has_sections = false; |
| 727 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 727 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
| 728 &has_types, &has_sections); | 728 &has_types, &has_sections); |
| 729 | 729 |
| 730 // Fail if the author didn't specify autocomplete types. | 730 // Fail if the author didn't specify autocomplete types. |
| 731 if (!has_types) { | 731 if (!has_types) { |
| 732 callback_.Run( | 732 callback_.Run( |
| 733 AutofillManagerDelegate::AutocompleteResultErrorDisabled, | 733 AutofillClient::AutocompleteResultErrorDisabled, |
| 734 base::ASCIIToUTF16("Form is missing autocomplete attributes."), | 734 base::ASCIIToUTF16("Form is missing autocomplete attributes."), |
| 735 NULL); | 735 NULL); |
| 736 delete this; | 736 delete this; |
| 737 return; | 737 return; |
| 738 } | 738 } |
| 739 | 739 |
| 740 // Fail if the author didn't ask for at least some kind of credit card | 740 // Fail if the author didn't ask for at least some kind of credit card |
| 741 // information. | 741 // information. |
| 742 bool has_credit_card_field = false; | 742 bool has_credit_card_field = false; |
| 743 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 743 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
| 744 AutofillType type = form_structure_.field(i)->Type(); | 744 AutofillType type = form_structure_.field(i)->Type(); |
| 745 if (type.html_type() != HTML_TYPE_UNKNOWN && type.group() == CREDIT_CARD) { | 745 if (type.html_type() != HTML_TYPE_UNKNOWN && type.group() == CREDIT_CARD) { |
| 746 has_credit_card_field = true; | 746 has_credit_card_field = true; |
| 747 break; | 747 break; |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 | 750 |
| 751 if (!has_credit_card_field) { | 751 if (!has_credit_card_field) { |
| 752 callback_.Run( | 752 callback_.Run(AutofillClient::AutocompleteResultErrorDisabled, |
| 753 AutofillManagerDelegate::AutocompleteResultErrorDisabled, | 753 base::ASCIIToUTF16( |
| 754 base::ASCIIToUTF16("Form is not a payment form (must contain " | 754 "Form is not a payment form (must contain " |
| 755 "some autocomplete=\"cc-*\" fields). "), | 755 "some autocomplete=\"cc-*\" fields). "), |
| 756 NULL); | 756 NULL); |
| 757 delete this; | 757 delete this; |
| 758 return; | 758 return; |
| 759 } | 759 } |
| 760 | 760 |
| 761 billing_country_combobox_model_.reset(new CountryComboboxModel( | 761 billing_country_combobox_model_.reset(new CountryComboboxModel( |
| 762 *GetManager(), | 762 *GetManager(), |
| 763 base::Bind(CountryFilter, | 763 base::Bind(CountryFilter, |
| 764 form_structure_.PossibleValues(ADDRESS_BILLING_COUNTRY)))); | 764 form_structure_.PossibleValues(ADDRESS_BILLING_COUNTRY)))); |
| 765 shipping_country_combobox_model_.reset(new CountryComboboxModel( | 765 shipping_country_combobox_model_.reset(new CountryComboboxModel( |
| 766 *GetManager(), | 766 *GetManager(), |
| (...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2277 } | 2277 } |
| 2278 } | 2278 } |
| 2279 | 2279 |
| 2280 NOTREACHED(); | 2280 NOTREACHED(); |
| 2281 } | 2281 } |
| 2282 | 2282 |
| 2283 bool AutofillDialogControllerImpl::OnCancel() { | 2283 bool AutofillDialogControllerImpl::OnCancel() { |
| 2284 HidePopup(); | 2284 HidePopup(); |
| 2285 if (!is_submitting_) | 2285 if (!is_submitting_) |
| 2286 LogOnCancelMetrics(); | 2286 LogOnCancelMetrics(); |
| 2287 callback_.Run(AutofillManagerDelegate::AutocompleteResultErrorCancel, | 2287 callback_.Run( |
| 2288 base::string16(), | 2288 AutofillClient::AutocompleteResultErrorCancel, base::string16(), NULL); |
| 2289 NULL); | |
| 2290 return true; | 2289 return true; |
| 2291 } | 2290 } |
| 2292 | 2291 |
| 2293 bool AutofillDialogControllerImpl::OnAccept() { | 2292 bool AutofillDialogControllerImpl::OnAccept() { |
| 2294 ScopedViewUpdates updates(view_.get()); | 2293 ScopedViewUpdates updates(view_.get()); |
| 2295 choose_another_instrument_or_address_ = false; | 2294 choose_another_instrument_or_address_ = false; |
| 2296 wallet_server_validation_recoverable_ = true; | 2295 wallet_server_validation_recoverable_ = true; |
| 2297 HidePopup(); | 2296 HidePopup(); |
| 2298 | 2297 |
| 2299 // This must come before SetIsSubmitting(). | 2298 // This must come before SetIsSubmitting(). |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 bool AutofillDialogControllerImpl::IsSignInContinueUrl( | 2758 bool AutofillDialogControllerImpl::IsSignInContinueUrl( |
| 2760 const GURL& url, | 2759 const GURL& url, |
| 2761 size_t* user_index) const { | 2760 size_t* user_index) const { |
| 2762 return wallet::IsSignInContinueUrl(url, user_index); | 2761 return wallet::IsSignInContinueUrl(url, user_index); |
| 2763 } | 2762 } |
| 2764 | 2763 |
| 2765 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2764 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| 2766 content::WebContents* contents, | 2765 content::WebContents* contents, |
| 2767 const FormData& form_structure, | 2766 const FormData& form_structure, |
| 2768 const GURL& source_url, | 2767 const GURL& source_url, |
| 2769 const AutofillManagerDelegate::ResultCallback& callback) | 2768 const AutofillClient::ResultCallback& callback) |
| 2770 : WebContentsObserver(contents), | 2769 : WebContentsObserver(contents), |
| 2771 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2770 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2772 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2771 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2773 form_structure_(form_structure), | 2772 form_structure_(form_structure), |
| 2774 invoked_from_same_origin_(true), | 2773 invoked_from_same_origin_(true), |
| 2775 source_url_(source_url), | 2774 source_url_(source_url), |
| 2776 callback_(callback), | 2775 callback_(callback), |
| 2777 wallet_client_(profile_->GetRequestContext(), this, source_url), | 2776 wallet_client_(profile_->GetRequestContext(), this, source_url), |
| 2778 wallet_items_requested_(false), | 2777 wallet_items_requested_(false), |
| 2779 handling_use_wallet_link_click_(false), | 2778 handling_use_wallet_link_click_(false), |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3888 if (!wallet_error_notification_ && | 3887 if (!wallet_error_notification_ && |
| 3889 account_chooser_model_->HasAccountsToChoose()) { | 3888 account_chooser_model_->HasAccountsToChoose()) { |
| 3890 profile_->GetPrefs()->SetBoolean( | 3889 profile_->GetPrefs()->SetBoolean( |
| 3891 ::prefs::kAutofillDialogPayWithoutWallet, | 3890 ::prefs::kAutofillDialogPayWithoutWallet, |
| 3892 !account_chooser_model_->WalletIsSelected()); | 3891 !account_chooser_model_->WalletIsSelected()); |
| 3893 } | 3892 } |
| 3894 | 3893 |
| 3895 LogOnFinishSubmitMetrics(); | 3894 LogOnFinishSubmitMetrics(); |
| 3896 | 3895 |
| 3897 // Callback should be called as late as possible. | 3896 // Callback should be called as late as possible. |
| 3898 callback_.Run(AutofillManagerDelegate::AutocompleteResultSuccess, | 3897 callback_.Run(AutofillClient::AutocompleteResultSuccess, |
| 3899 base::string16(), | 3898 base::string16(), |
| 3900 &form_structure_); | 3899 &form_structure_); |
| 3901 data_was_passed_back_ = true; | 3900 data_was_passed_back_ = true; |
| 3902 | 3901 |
| 3903 // This might delete us. | 3902 // This might delete us. |
| 3904 Hide(); | 3903 Hide(); |
| 3905 } | 3904 } |
| 3906 | 3905 |
| 3907 void AutofillDialogControllerImpl::PersistAutofillChoice( | 3906 void AutofillDialogControllerImpl::PersistAutofillChoice( |
| 3908 DialogSection section, | 3907 DialogSection section, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4096 view_->UpdateButtonStrip(); | 4095 view_->UpdateButtonStrip(); |
| 4097 } | 4096 } |
| 4098 | 4097 |
| 4099 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4098 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 4100 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4099 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 4101 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4100 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 4102 signin_helper_->StartWalletCookieValueFetch(); | 4101 signin_helper_->StartWalletCookieValueFetch(); |
| 4103 } | 4102 } |
| 4104 | 4103 |
| 4105 } // namespace autofill | 4104 } // namespace autofill |
| OLD | NEW |