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

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

Powered by Google App Engine
This is Rietveld 408576698