OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 const GURL& source_url, | 127 const GURL& source_url, |
128 const content::SSLStatus& ssl_status, | 128 const content::SSLStatus& ssl_status, |
129 const base::Callback<void(const FormStructure*)>& callback) | 129 const base::Callback<void(const FormStructure*)>& callback) |
130 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 130 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
131 contents_(contents), | 131 contents_(contents), |
132 form_structure_(form), | 132 form_structure_(form), |
133 source_url_(source_url), | 133 source_url_(source_url), |
134 ssl_status_(ssl_status), | 134 ssl_status_(ssl_status), |
135 callback_(callback), | 135 callback_(callback), |
136 wallet_client_(profile_->GetRequestContext()), | 136 wallet_client_(profile_->GetRequestContext()), |
137 refresh_wallet_items_queued_(false), | |
138 had_wallet_error_(false), | |
137 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), | 139 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), |
138 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), | 140 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), |
139 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), | 141 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), |
140 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), | 142 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), |
141 section_showing_popup_(SECTION_BILLING) { | 143 section_showing_popup_(SECTION_BILLING) { |
142 // TODO(estade): |this| should observe PersonalDataManager. | 144 // TODO(estade): |this| should observe PersonalDataManager. |
143 // TODO(estade): remove duplicates from |form|? | 145 // TODO(estade): remove duplicates from |form|? |
144 | 146 |
145 content::NavigationEntry* entry = contents->GetController().GetActiveEntry(); | 147 content::NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
146 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); | 148 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 &requested_shipping_fields_); | 218 &requested_shipping_fields_); |
217 | 219 |
218 GenerateSuggestionsModels(); | 220 GenerateSuggestionsModels(); |
219 | 221 |
220 // TODO(estade): don't show the dialog if the site didn't specify the right | 222 // TODO(estade): don't show the dialog if the site didn't specify the right |
221 // fields. First we must figure out what the "right" fields are. | 223 // fields. First we must figure out what the "right" fields are. |
222 view_.reset(AutofillDialogView::Create(this)); | 224 view_.reset(AutofillDialogView::Create(this)); |
223 view_->Show(); | 225 view_->Show(); |
224 | 226 |
225 // Request sugar info after the view is showing to simplify code for now. | 227 // Request sugar info after the view is showing to simplify code for now. |
226 wallet_client_.GetWalletItems(this); | 228 ScheduleRefreshWalletItems(); |
227 } | 229 } |
228 | 230 |
229 void AutofillDialogControllerImpl::Hide() { | 231 void AutofillDialogControllerImpl::Hide() { |
230 if (view_) | 232 if (view_) |
231 view_->Hide(); | 233 view_->Hide(); |
232 } | 234 } |
233 | 235 |
234 //////////////////////////////////////////////////////////////////////////////// | 236 //////////////////////////////////////////////////////////////////////////////// |
235 // AutofillDialogController implementation. | 237 // AutofillDialogController implementation. |
236 | 238 |
(...skipping 16 matching lines...) Expand all Loading... | |
253 } | 255 } |
254 | 256 |
255 string16 AutofillDialogControllerImpl::CancelButtonText() const { | 257 string16 AutofillDialogControllerImpl::CancelButtonText() const { |
256 return l10n_util::GetStringUTF16(IDS_CANCEL); | 258 return l10n_util::GetStringUTF16(IDS_CANCEL); |
257 } | 259 } |
258 | 260 |
259 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { | 261 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { |
260 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); | 262 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); |
261 } | 263 } |
262 | 264 |
263 string16 AutofillDialogControllerImpl::SignInText() const { | |
264 // TODO(abodenha): real strings and l10n. | |
265 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); | |
266 } | |
267 | |
268 string16 AutofillDialogControllerImpl::CancelSignInText() const { | 265 string16 AutofillDialogControllerImpl::CancelSignInText() const { |
269 // TODO(abodenha): real strings and l10n. | 266 // TODO(abodenha): real strings and l10n. |
270 return string16(ASCIIToUTF16("Don't sign in.")); | 267 return ASCIIToUTF16("Don't sign in."); |
268 } | |
269 | |
270 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | |
271 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | |
272 } | |
273 | |
274 string16 AutofillDialogControllerImpl::ProgressBarText() const { | |
275 return l10n_util::GetStringUTF16( | |
276 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); | |
271 } | 277 } |
272 | 278 |
273 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { | 279 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { |
274 if (!wallet_items_) | 280 if (!wallet_items_) |
275 return REQUIRES_RESPONSE; | 281 return REQUIRES_RESPONSE; |
276 | 282 |
277 if (HasRequiredAction(wallet::GAIA_AUTH)) | 283 if (HasRequiredAction(wallet::GAIA_AUTH)) |
278 return REQUIRES_SIGN_IN; | 284 return REQUIRES_SIGN_IN; |
279 | 285 |
280 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 286 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
281 return REQUIRES_PASSIVE_SIGN_IN; | 287 return REQUIRES_PASSIVE_SIGN_IN; |
282 | 288 |
283 return SIGNED_IN; | 289 return SIGNED_IN; |
284 } | 290 } |
285 | 291 |
286 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | 292 bool AutofillDialogControllerImpl::CanPayWithWallet() const { |
287 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | 293 return !had_wallet_error_; |
288 } | 294 } |
289 | 295 |
290 string16 AutofillDialogControllerImpl::ProgressBarText() const { | 296 string16 AutofillDialogControllerImpl::AccountChooserText() const { |
291 return l10n_util::GetStringUTF16( | 297 if (!CanPayWithWallet()) |
292 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); | 298 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); |
299 | |
300 // TODO(dbeam): real strings and l10n. | |
301 const DialogSignedInState& state = SignedInState(); | |
302 return state != SIGNED_IN ? ASCIIToUTF16("Sign in to use Google Wallet") : | |
303 ASCIIToUTF16("user@example.com"); | |
304 } | |
305 | |
306 bool AutofillDialogControllerImpl::AccountChooserEnabled() const { | |
307 if (!CanPayWithWallet()) | |
308 return false; | |
309 | |
310 const DialogSignedInState& state = SignedInState(); | |
Ilya Sherman
2013/02/11 06:07:01
nit: No need to store a const-ref to an enumerated
Dan Beam
2013/02/11 21:53:54
Done.
| |
311 return state != REQUIRES_RESPONSE && state != SIGNED_IN; | |
293 } | 312 } |
294 | 313 |
295 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 314 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
296 DialogSection section) const { | 315 DialogSection section) const { |
297 switch (section) { | 316 switch (section) { |
298 case SECTION_EMAIL: | 317 case SECTION_EMAIL: |
299 return requested_email_fields_; | 318 return requested_email_fields_; |
300 case SECTION_CC: | 319 case SECTION_CC: |
301 return requested_cc_fields_; | 320 return requested_cc_fields_; |
302 case SECTION_BILLING: | 321 case SECTION_BILLING: |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); | 573 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); |
555 } | 574 } |
556 | 575 |
557 if (!invoked_from_same_origin_) { | 576 if (!invoked_from_same_origin_) { |
558 return DialogNotification( | 577 return DialogNotification( |
559 DialogNotification::SECURITY_WARNING, | 578 DialogNotification::SECURITY_WARNING, |
560 l10n_util::GetStringFUTF16( | 579 l10n_util::GetStringFUTF16( |
561 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); | 580 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); |
562 } | 581 } |
563 | 582 |
583 if (!CanPayWithWallet()) { | |
584 // TODO(dbeam): pass along the Wallet error or remove from the translation. | |
585 return DialogNotification( | |
586 DialogNotification::WALLET_ERROR, | |
587 l10n_util::GetStringFUTF16( | |
588 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, | |
589 ASCIIToUTF16("[Wallet-Error]."))); | |
590 } | |
591 | |
564 return DialogNotification(); | 592 return DialogNotification(); |
565 } | 593 } |
566 | 594 |
567 void AutofillDialogControllerImpl::StartSignInFlow() { | 595 void AutofillDialogControllerImpl::StartSignInFlow() { |
568 DCHECK(registrar_.IsEmpty()); | 596 DCHECK(registrar_.IsEmpty()); |
569 | 597 |
570 content::Source<content::NavigationController> source( | 598 content::Source<content::NavigationController> source(&view_->ShowSignIn()); |
571 &view_->ShowSignIn()); | |
572 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | 599 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); |
573 } | 600 } |
574 | 601 |
575 void AutofillDialogControllerImpl::EndSignInFlow() { | 602 void AutofillDialogControllerImpl::EndSignInFlow() { |
576 DCHECK(!registrar_.IsEmpty()); | 603 DCHECK(!registrar_.IsEmpty()); |
577 registrar_.RemoveAll(); | 604 registrar_.RemoveAll(); |
578 view_->HideSignIn(); | 605 view_->HideSignIn(); |
579 } | 606 } |
580 | 607 |
581 Profile* AutofillDialogControllerImpl::profile() { | 608 Profile* AutofillDialogControllerImpl::profile() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 | 662 |
636 void AutofillDialogControllerImpl::Observe( | 663 void AutofillDialogControllerImpl::Observe( |
637 int type, | 664 int type, |
638 const content::NotificationSource& source, | 665 const content::NotificationSource& source, |
639 const content::NotificationDetails& details) { | 666 const content::NotificationDetails& details) { |
640 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 667 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
641 content::LoadCommittedDetails* load_details = | 668 content::LoadCommittedDetails* load_details = |
642 content::Details<content::LoadCommittedDetails>(details).ptr(); | 669 content::Details<content::LoadCommittedDetails>(details).ptr(); |
643 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 670 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
644 EndSignInFlow(); | 671 EndSignInFlow(); |
645 // TODO(dbeam): the fetcher can't handle being called multiple times. | 672 ScheduleRefreshWalletItems(); |
646 // Address this soon as we will be re-fetching wallet items after every | |
647 // required action is resolved. | |
648 wallet_client_.GetWalletItems(this); | |
649 } | 673 } |
650 } | 674 } |
651 | 675 |
652 //////////////////////////////////////////////////////////////////////////////// | 676 //////////////////////////////////////////////////////////////////////////////// |
653 // SuggestionsMenuModelDelegate | 677 // SuggestionsMenuModelDelegate |
654 | 678 |
655 void AutofillDialogControllerImpl::SuggestionItemSelected( | 679 void AutofillDialogControllerImpl::SuggestionItemSelected( |
656 const SuggestionsMenuModel& model) { | 680 const SuggestionsMenuModel& model) { |
657 DialogSection section = SectionForSuggestionsMenuModel(model); | 681 DialogSection section = SectionForSuggestionsMenuModel(model); |
658 section_editing_state_[section] = false; | 682 section_editing_state_[section] = false; |
(...skipping 14 matching lines...) Expand all Loading... | |
673 } | 697 } |
674 | 698 |
675 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation( | 699 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation( |
676 const std::string& escrow_handle) { | 700 const std::string& escrow_handle) { |
677 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle; | 701 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle; |
678 } | 702 } |
679 | 703 |
680 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 704 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
681 scoped_ptr<wallet::FullWallet> full_wallet) { | 705 scoped_ptr<wallet::FullWallet> full_wallet) { |
682 NOTIMPLEMENTED(); | 706 NOTIMPLEMENTED(); |
707 WalletRequestCompleted(true); | |
683 } | 708 } |
684 | 709 |
685 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 710 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
686 scoped_ptr<wallet::WalletItems> wallet_items) { | 711 scoped_ptr<wallet::WalletItems> wallet_items) { |
712 bool items_changed = !wallet_items_ || *wallet_items != *wallet_items_; | |
687 wallet_items_ = wallet_items.Pass(); | 713 wallet_items_ = wallet_items.Pass(); |
688 view_->UpdateAccountChooser(); | 714 WalletRequestCompleted(true); |
689 view_->UpdateNotificationArea(); | 715 |
716 if (items_changed) { | |
717 view_->UpdateAccountChooser(); | |
718 view_->UpdateNotificationArea(); | |
719 } | |
690 } | 720 } |
691 | 721 |
692 void AutofillDialogControllerImpl::OnDidSaveAddress( | 722 void AutofillDialogControllerImpl::OnDidSaveAddress( |
693 const std::string& address_id) { | 723 const std::string& address_id) { |
694 NOTIMPLEMENTED() << " address_id=" << address_id; | 724 NOTIMPLEMENTED() << " address_id=" << address_id; |
725 WalletRequestCompleted(true); | |
695 } | 726 } |
696 | 727 |
697 void AutofillDialogControllerImpl::OnDidSaveInstrument( | 728 void AutofillDialogControllerImpl::OnDidSaveInstrument( |
698 const std::string& instrument_id) { | 729 const std::string& instrument_id) { |
699 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; | 730 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; |
731 WalletRequestCompleted(true); | |
700 } | 732 } |
701 | 733 |
702 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( | 734 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( |
703 const std::string& instrument_id, const std::string& address_id) { | 735 const std::string& instrument_id, const std::string& address_id) { |
704 NOTIMPLEMENTED() << " instrument_id=" << instrument_id | 736 NOTIMPLEMENTED() << " instrument_id=" << instrument_id |
705 << ", address_id=" << address_id; | 737 << ", address_id=" << address_id; |
738 WalletRequestCompleted(true); | |
706 } | 739 } |
707 | 740 |
708 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() { | 741 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() { |
709 NOTIMPLEMENTED(); | 742 NOTIMPLEMENTED(); |
743 WalletRequestCompleted(true); | |
710 } | 744 } |
711 | 745 |
712 void AutofillDialogControllerImpl::OnWalletError() { | 746 void AutofillDialogControllerImpl::OnWalletError() { |
713 NOTIMPLEMENTED(); | 747 WalletRequestCompleted(false); |
714 wallet_items_.reset(); | |
715 } | 748 } |
716 | 749 |
717 void AutofillDialogControllerImpl::OnMalformedResponse() { | 750 void AutofillDialogControllerImpl::OnMalformedResponse() { |
718 NOTIMPLEMENTED(); | 751 WalletRequestCompleted(false); |
719 wallet_items_.reset(); | |
720 } | 752 } |
721 | 753 |
722 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { | 754 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { |
723 NOTIMPLEMENTED() << " response_code=" << response_code; | 755 WalletRequestCompleted(false); |
724 wallet_items_.reset(); | |
725 } | 756 } |
726 | 757 |
727 //////////////////////////////////////////////////////////////////////////////// | 758 //////////////////////////////////////////////////////////////////////////////// |
728 | 759 |
729 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 760 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
730 const content::NativeWebKeyboardEvent& event) { | 761 const content::NativeWebKeyboardEvent& event) { |
731 if (popup_controller_) | 762 if (popup_controller_) |
732 return popup_controller_->HandleKeyPressEvent(event); | 763 return popup_controller_->HandleKeyPressEvent(event); |
733 | 764 |
734 return false; | 765 return false; |
(...skipping 21 matching lines...) Expand all Loading... | |
756 bool AutofillDialogControllerImpl::HasRequiredAction( | 787 bool AutofillDialogControllerImpl::HasRequiredAction( |
757 wallet::RequiredAction action) const { | 788 wallet::RequiredAction action) const { |
758 if (!wallet_items_) | 789 if (!wallet_items_) |
759 return false; | 790 return false; |
760 | 791 |
761 const std::vector<wallet::RequiredAction>& actions = | 792 const std::vector<wallet::RequiredAction>& actions = |
762 wallet_items_->required_actions(); | 793 wallet_items_->required_actions(); |
763 return std::find(actions.begin(), actions.end(), action) != actions.end(); | 794 return std::find(actions.begin(), actions.end(), action) != actions.end(); |
764 } | 795 } |
765 | 796 |
797 void AutofillDialogControllerImpl::ScheduleRefreshWalletItems() { | |
798 if (!CanPayWithWallet()) | |
Ilya Sherman
2013/02/11 06:07:01
nit: Maybe add a comment for why this block is hel
Dan Beam
2013/02/11 21:53:54
Instead I've changed this to wrap each call with t
| |
799 return; | |
800 | |
801 if (wallet_client_.IsRequestInProgress()) { | |
802 refresh_wallet_items_queued_ = true; | |
803 return; | |
804 } | |
805 | |
806 wallet_client_.GetWalletItems(this); | |
807 refresh_wallet_items_queued_ = false; | |
808 } | |
809 | |
810 void AutofillDialogControllerImpl::WalletRequestCompleted(bool success) { | |
811 if (!success) { | |
812 had_wallet_error_ = true; | |
813 wallet_items_.reset(); | |
814 view_->UpdateAccountChooser(); | |
815 view_->UpdateNotificationArea(); | |
816 return; | |
817 } | |
818 | |
819 if (refresh_wallet_items_queued_) | |
820 ScheduleRefreshWalletItems(); | |
821 } | |
822 | |
766 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { | 823 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { |
767 PersonalDataManager* manager = GetManager(); | 824 PersonalDataManager* manager = GetManager(); |
768 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 825 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
769 for (size_t i = 0; i < cards.size(); ++i) { | 826 for (size_t i = 0; i < cards.size(); ++i) { |
770 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label()); | 827 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label()); |
771 } | 828 } |
772 // TODO(estade): real strings and i18n. | 829 // TODO(estade): real strings and i18n. |
773 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card")); | 830 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card")); |
774 | 831 |
775 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 832 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 DialogSection section) { | 1005 DialogSection section) { |
949 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 1006 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
950 } | 1007 } |
951 | 1008 |
952 void AutofillDialogControllerImpl::HidePopup() { | 1009 void AutofillDialogControllerImpl::HidePopup() { |
953 if (popup_controller_) | 1010 if (popup_controller_) |
954 popup_controller_->Hide(); | 1011 popup_controller_->Hide(); |
955 } | 1012 } |
956 | 1013 |
957 } // namespace autofill | 1014 } // namespace autofill |
OLD | NEW |