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

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

Issue 12221040: Interactive autofill: Handle Online Wallet being unavailable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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 (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
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 &requested_shipping_fields_); 216 &requested_shipping_fields_);
215 217
216 GenerateSuggestionsModels(); 218 GenerateSuggestionsModels();
217 219
218 // TODO(estade): don't show the dialog if the site didn't specify the right 220 // TODO(estade): don't show the dialog if the site didn't specify the right
219 // fields. First we must figure out what the "right" fields are. 221 // fields. First we must figure out what the "right" fields are.
220 view_.reset(AutofillDialogView::Create(this)); 222 view_.reset(AutofillDialogView::Create(this));
221 view_->Show(); 223 view_->Show();
222 224
223 // Request sugar info after the view is showing to simplify code for now. 225 // Request sugar info after the view is showing to simplify code for now.
224 wallet_client_.GetWalletItems(this); 226 if (CanPayWithWallet())
227 ScheduleRefreshWalletItems();
225 } 228 }
226 229
227 void AutofillDialogControllerImpl::Hide() { 230 void AutofillDialogControllerImpl::Hide() {
228 if (view_) 231 if (view_)
229 view_->Hide(); 232 view_->Hide();
230 } 233 }
231 234
232 //////////////////////////////////////////////////////////////////////////////// 235 ////////////////////////////////////////////////////////////////////////////////
233 // AutofillDialogController implementation. 236 // AutofillDialogController implementation.
234 237
(...skipping 16 matching lines...) Expand all
251 } 254 }
252 255
253 string16 AutofillDialogControllerImpl::CancelButtonText() const { 256 string16 AutofillDialogControllerImpl::CancelButtonText() const {
254 return l10n_util::GetStringUTF16(IDS_CANCEL); 257 return l10n_util::GetStringUTF16(IDS_CANCEL);
255 } 258 }
256 259
257 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { 260 string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
258 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); 261 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
259 } 262 }
260 263
261 string16 AutofillDialogControllerImpl::SignInText() const {
262 // TODO(abodenha): real strings and l10n.
263 return string16(ASCIIToUTF16("Sign in to use Google Wallet"));
264 }
265
266 string16 AutofillDialogControllerImpl::CancelSignInText() const { 264 string16 AutofillDialogControllerImpl::CancelSignInText() const {
267 // TODO(abodenha): real strings and l10n. 265 // TODO(abodenha): real strings and l10n.
268 return string16(ASCIIToUTF16("Don't sign in.")); 266 return ASCIIToUTF16("Don't sign in.");
267 }
268
269 string16 AutofillDialogControllerImpl::SaveLocallyText() const {
270 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
271 }
272
273 string16 AutofillDialogControllerImpl::ProgressBarText() const {
274 return l10n_util::GetStringUTF16(
275 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR);
269 } 276 }
270 277
271 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { 278 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const {
272 if (!wallet_items_) 279 if (!wallet_items_)
273 return REQUIRES_RESPONSE; 280 return REQUIRES_RESPONSE;
274 281
275 if (HasRequiredAction(wallet::GAIA_AUTH)) 282 if (HasRequiredAction(wallet::GAIA_AUTH))
276 return REQUIRES_SIGN_IN; 283 return REQUIRES_SIGN_IN;
277 284
278 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) 285 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH))
279 return REQUIRES_PASSIVE_SIGN_IN; 286 return REQUIRES_PASSIVE_SIGN_IN;
280 287
281 return SIGNED_IN; 288 return SIGNED_IN;
282 } 289 }
283 290
284 string16 AutofillDialogControllerImpl::SaveLocallyText() const { 291 bool AutofillDialogControllerImpl::CanPayWithWallet() const {
285 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); 292 return !had_wallet_error_;
286 } 293 }
287 294
288 string16 AutofillDialogControllerImpl::ProgressBarText() const { 295 string16 AutofillDialogControllerImpl::AccountChooserText() const {
289 return l10n_util::GetStringUTF16( 296 if (!CanPayWithWallet())
290 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); 297 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
298
299 // TODO(dbeam): real strings and l10n.
300 DialogSignedInState state = SignedInState();
301 return state != SIGNED_IN ? ASCIIToUTF16("Sign in to use Google Wallet") :
302 ASCIIToUTF16("user@example.com");
303 }
304
305 bool AutofillDialogControllerImpl::AccountChooserEnabled() const {
306 if (!CanPayWithWallet())
307 return false;
308
309 DialogSignedInState state = SignedInState();
310 return state != REQUIRES_RESPONSE && state != SIGNED_IN;
291 } 311 }
292 312
293 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( 313 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
294 DialogSection section) const { 314 DialogSection section) const {
295 switch (section) { 315 switch (section) {
296 case SECTION_EMAIL: 316 case SECTION_EMAIL:
297 return requested_email_fields_; 317 return requested_email_fields_;
298 case SECTION_CC: 318 case SECTION_CC:
299 return requested_cc_fields_; 319 return requested_cc_fields_;
300 case SECTION_BILLING: 320 case SECTION_BILLING:
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); 572 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING));
553 } 573 }
554 574
555 if (!invoked_from_same_origin_) { 575 if (!invoked_from_same_origin_) {
556 return DialogNotification( 576 return DialogNotification(
557 DialogNotification::SECURITY_WARNING, 577 DialogNotification::SECURITY_WARNING,
558 l10n_util::GetStringFUTF16( 578 l10n_util::GetStringFUTF16(
559 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); 579 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host())));
560 } 580 }
561 581
582 if (!CanPayWithWallet()) {
583 // TODO(dbeam): pass along the Wallet error or remove from the translation.
584 return DialogNotification(
585 DialogNotification::WALLET_ERROR,
586 l10n_util::GetStringFUTF16(
587 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
588 ASCIIToUTF16("Oops, [Wallet-Error].")));
589 }
590
562 return DialogNotification(); 591 return DialogNotification();
563 } 592 }
564 593
565 void AutofillDialogControllerImpl::StartSignInFlow() { 594 void AutofillDialogControllerImpl::StartSignInFlow() {
566 DCHECK(registrar_.IsEmpty()); 595 DCHECK(registrar_.IsEmpty());
567 596
568 content::Source<content::NavigationController> source( 597 content::Source<content::NavigationController> source(&view_->ShowSignIn());
569 &view_->ShowSignIn());
570 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); 598 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
571 } 599 }
572 600
573 void AutofillDialogControllerImpl::EndSignInFlow() { 601 void AutofillDialogControllerImpl::EndSignInFlow() {
574 DCHECK(!registrar_.IsEmpty()); 602 DCHECK(!registrar_.IsEmpty());
575 registrar_.RemoveAll(); 603 registrar_.RemoveAll();
576 view_->HideSignIn(); 604 view_->HideSignIn();
577 } 605 }
578 606
579 Profile* AutofillDialogControllerImpl::profile() { 607 Profile* AutofillDialogControllerImpl::profile() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 661
634 void AutofillDialogControllerImpl::Observe( 662 void AutofillDialogControllerImpl::Observe(
635 int type, 663 int type,
636 const content::NotificationSource& source, 664 const content::NotificationSource& source,
637 const content::NotificationDetails& details) { 665 const content::NotificationDetails& details) {
638 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); 666 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED);
639 content::LoadCommittedDetails* load_details = 667 content::LoadCommittedDetails* load_details =
640 content::Details<content::LoadCommittedDetails>(details).ptr(); 668 content::Details<content::LoadCommittedDetails>(details).ptr();
641 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { 669 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
642 EndSignInFlow(); 670 EndSignInFlow();
643 // TODO(dbeam): the fetcher can't handle being called multiple times. 671 if (CanPayWithWallet())
644 // Address this soon as we will be re-fetching wallet items after every 672 ScheduleRefreshWalletItems();
645 // required action is resolved.
646 wallet_client_.GetWalletItems(this);
647 } 673 }
648 } 674 }
649 675
650 //////////////////////////////////////////////////////////////////////////////// 676 ////////////////////////////////////////////////////////////////////////////////
651 // SuggestionsMenuModelDelegate 677 // SuggestionsMenuModelDelegate
652 678
653 void AutofillDialogControllerImpl::SuggestionItemSelected( 679 void AutofillDialogControllerImpl::SuggestionItemSelected(
654 const SuggestionsMenuModel& model) { 680 const SuggestionsMenuModel& model) {
655 DialogSection section = SectionForSuggestionsMenuModel(model); 681 DialogSection section = SectionForSuggestionsMenuModel(model);
656 section_editing_state_[section] = false; 682 section_editing_state_[section] = false;
(...skipping 14 matching lines...) Expand all
671 } 697 }
672 698
673 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation( 699 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation(
674 const std::string& escrow_handle) { 700 const std::string& escrow_handle) {
675 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle; 701 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle;
676 } 702 }
677 703
678 void AutofillDialogControllerImpl::OnDidGetFullWallet( 704 void AutofillDialogControllerImpl::OnDidGetFullWallet(
679 scoped_ptr<wallet::FullWallet> full_wallet) { 705 scoped_ptr<wallet::FullWallet> full_wallet) {
680 NOTIMPLEMENTED(); 706 NOTIMPLEMENTED();
707 WalletRequestCompleted(true);
681 } 708 }
682 709
683 void AutofillDialogControllerImpl::OnDidGetWalletItems( 710 void AutofillDialogControllerImpl::OnDidGetWalletItems(
684 scoped_ptr<wallet::WalletItems> wallet_items) { 711 scoped_ptr<wallet::WalletItems> wallet_items) {
712 bool items_changed = !wallet_items_ || *wallet_items != *wallet_items_;
685 wallet_items_ = wallet_items.Pass(); 713 wallet_items_ = wallet_items.Pass();
686 view_->UpdateAccountChooser(); 714 WalletRequestCompleted(true);
687 view_->UpdateNotificationArea(); 715
716 if (items_changed) {
717 view_->UpdateAccountChooser();
718 view_->UpdateNotificationArea();
719 }
688 } 720 }
689 721
690 void AutofillDialogControllerImpl::OnDidSaveAddress( 722 void AutofillDialogControllerImpl::OnDidSaveAddress(
691 const std::string& address_id) { 723 const std::string& address_id) {
692 NOTIMPLEMENTED() << " address_id=" << address_id; 724 NOTIMPLEMENTED() << " address_id=" << address_id;
725 WalletRequestCompleted(true);
693 } 726 }
694 727
695 void AutofillDialogControllerImpl::OnDidSaveInstrument( 728 void AutofillDialogControllerImpl::OnDidSaveInstrument(
696 const std::string& instrument_id) { 729 const std::string& instrument_id) {
697 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; 730 NOTIMPLEMENTED() << " instrument_id=" << instrument_id;
731 WalletRequestCompleted(true);
698 } 732 }
699 733
700 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( 734 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress(
701 const std::string& instrument_id, const std::string& address_id) { 735 const std::string& instrument_id, const std::string& address_id) {
702 NOTIMPLEMENTED() << " instrument_id=" << instrument_id 736 NOTIMPLEMENTED() << " instrument_id=" << instrument_id
703 << ", address_id=" << address_id; 737 << ", address_id=" << address_id;
738 WalletRequestCompleted(true);
704 } 739 }
705 740
706 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() { 741 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() {
707 NOTIMPLEMENTED(); 742 NOTIMPLEMENTED();
743 WalletRequestCompleted(true);
708 } 744 }
709 745
710 void AutofillDialogControllerImpl::OnDidUpdateInstrument( 746 void AutofillDialogControllerImpl::OnDidUpdateInstrument(
711 const std::string& instrument_id) { 747 const std::string& instrument_id) {
712 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; 748 NOTIMPLEMENTED() << " instrument_id=" << instrument_id;
713 } 749 }
714 750
715 void AutofillDialogControllerImpl::OnWalletError() { 751 void AutofillDialogControllerImpl::OnWalletError() {
716 NOTIMPLEMENTED(); 752 WalletRequestCompleted(false);
717 wallet_items_.reset();
718 } 753 }
719 754
720 void AutofillDialogControllerImpl::OnMalformedResponse() { 755 void AutofillDialogControllerImpl::OnMalformedResponse() {
721 NOTIMPLEMENTED(); 756 WalletRequestCompleted(false);
722 wallet_items_.reset();
723 } 757 }
724 758
725 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { 759 void AutofillDialogControllerImpl::OnNetworkError(int response_code) {
726 NOTIMPLEMENTED() << " response_code=" << response_code; 760 WalletRequestCompleted(false);
727 wallet_items_.reset();
728 } 761 }
729 762
730 //////////////////////////////////////////////////////////////////////////////// 763 ////////////////////////////////////////////////////////////////////////////////
731 764
732 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( 765 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
733 const content::NativeWebKeyboardEvent& event) { 766 const content::NativeWebKeyboardEvent& event) {
734 if (popup_controller_) 767 if (popup_controller_)
735 return popup_controller_->HandleKeyPressEvent(event); 768 return popup_controller_->HandleKeyPressEvent(event);
736 769
737 return false; 770 return false;
(...skipping 21 matching lines...) Expand all
759 bool AutofillDialogControllerImpl::HasRequiredAction( 792 bool AutofillDialogControllerImpl::HasRequiredAction(
760 wallet::RequiredAction action) const { 793 wallet::RequiredAction action) const {
761 if (!wallet_items_) 794 if (!wallet_items_)
762 return false; 795 return false;
763 796
764 const std::vector<wallet::RequiredAction>& actions = 797 const std::vector<wallet::RequiredAction>& actions =
765 wallet_items_->required_actions(); 798 wallet_items_->required_actions();
766 return std::find(actions.begin(), actions.end(), action) != actions.end(); 799 return std::find(actions.begin(), actions.end(), action) != actions.end();
767 } 800 }
768 801
802 void AutofillDialogControllerImpl::ScheduleRefreshWalletItems() {
803 DCHECK(CanPayWithWallet());
804
805 if (wallet_client_.HasRequestInProgress()) {
806 refresh_wallet_items_queued_ = true;
807 return;
808 }
809
810 wallet_client_.GetWalletItems(this);
811 refresh_wallet_items_queued_ = false;
812 }
813
814 void AutofillDialogControllerImpl::WalletRequestCompleted(bool success) {
815 if (!success) {
816 had_wallet_error_ = true;
817 wallet_items_.reset();
818 view_->UpdateAccountChooser();
819 view_->UpdateNotificationArea();
820 return;
821 }
822
823 if (refresh_wallet_items_queued_)
824 ScheduleRefreshWalletItems();
825 }
826
769 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { 827 void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
770 PersonalDataManager* manager = GetManager(); 828 PersonalDataManager* manager = GetManager();
771 const std::vector<CreditCard*>& cards = manager->credit_cards(); 829 const std::vector<CreditCard*>& cards = manager->credit_cards();
772 for (size_t i = 0; i < cards.size(); ++i) { 830 for (size_t i = 0; i < cards.size(); ++i) {
773 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label()); 831 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label());
774 } 832 }
775 // TODO(estade): real strings and i18n. 833 // TODO(estade): real strings and i18n.
776 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card")); 834 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card"));
777 835
778 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); 836 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 DialogSection section) { 1009 DialogSection section) {
952 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 1010 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
953 } 1011 }
954 1012
955 void AutofillDialogControllerImpl::HidePopup() { 1013 void AutofillDialogControllerImpl::HidePopup() {
956 if (popup_controller_) 1014 if (popup_controller_)
957 popup_controller_->Hide(); 1015 popup_controller_->Hide();
958 } 1016 }
959 1017
960 } // namespace autofill 1018 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/views/autofill/autofill_dialog_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698