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

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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 const GURL& source_url, 126 const GURL& source_url,
127 const content::SSLStatus& ssl_status, 127 const content::SSLStatus& ssl_status,
128 const base::Callback<void(const FormStructure*)>& callback) 128 const base::Callback<void(const FormStructure*)>& callback)
129 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), 129 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
130 contents_(contents), 130 contents_(contents),
131 form_structure_(form), 131 form_structure_(form),
132 source_url_(source_url), 132 source_url_(source_url),
133 ssl_status_(ssl_status), 133 ssl_status_(ssl_status),
134 callback_(callback), 134 callback_(callback),
135 wallet_client_(profile_->GetRequestContext()), 135 wallet_client_(profile_->GetRequestContext()),
136 refresh_wallet_items_queued_(false),
137 had_wallet_error_(false),
136 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), 138 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)),
137 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), 139 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)),
138 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), 140 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)),
139 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), 141 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)),
140 popup_controller_(NULL), 142 popup_controller_(NULL),
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();
(...skipping 70 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 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
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();
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); 566 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING));
548 } 567 }
549 568
550 if (!invoked_from_same_origin_) { 569 if (!invoked_from_same_origin_) {
551 return DialogNotification( 570 return DialogNotification(
552 DialogNotification::SECURITY_WARNING, 571 DialogNotification::SECURITY_WARNING,
553 l10n_util::GetStringFUTF16( 572 l10n_util::GetStringFUTF16(
554 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); 573 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host())));
555 } 574 }
556 575
576 if (!CanPayWithWallet()) {
577 // TODO(dbeam): pass along the Wallet error or remove from the translation.
578 return DialogNotification(
579 DialogNotification::WALLET_ERROR,
580 l10n_util::GetStringFUTF16(
581 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
582 ASCIIToUTF16("[Wallet-Error].")));
583 }
584
557 return DialogNotification(); 585 return DialogNotification();
558 } 586 }
559 587
560 void AutofillDialogControllerImpl::StartSignInFlow() { 588 void AutofillDialogControllerImpl::StartSignInFlow() {
561 DCHECK(registrar_.IsEmpty()); 589 DCHECK(registrar_.IsEmpty());
562 590
563 content::Source<content::NavigationController> source( 591 content::Source<content::NavigationController> source(&view_->ShowSignIn());
564 &view_->ShowSignIn());
565 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); 592 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
566 } 593 }
567 594
568 void AutofillDialogControllerImpl::EndSignInFlow() { 595 void AutofillDialogControllerImpl::EndSignInFlow() {
569 DCHECK(!registrar_.IsEmpty()); 596 DCHECK(!registrar_.IsEmpty());
570 registrar_.RemoveAll(); 597 registrar_.RemoveAll();
571 view_->HideSignIn(); 598 view_->HideSignIn();
572 } 599 }
573 600
574 Profile* AutofillDialogControllerImpl::profile() { 601 Profile* AutofillDialogControllerImpl::profile() {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 653
627 void AutofillDialogControllerImpl::Observe( 654 void AutofillDialogControllerImpl::Observe(
628 int type, 655 int type,
629 const content::NotificationSource& source, 656 const content::NotificationSource& source,
630 const content::NotificationDetails& details) { 657 const content::NotificationDetails& details) {
631 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); 658 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED);
632 content::LoadCommittedDetails* load_details = 659 content::LoadCommittedDetails* load_details =
633 content::Details<content::LoadCommittedDetails>(details).ptr(); 660 content::Details<content::LoadCommittedDetails>(details).ptr();
634 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { 661 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
635 EndSignInFlow(); 662 EndSignInFlow();
636 // TODO(dbeam): the fetcher can't handle being called multiple times. 663 ScheduleRefreshWalletItems();
637 // Address this soon as we will be re-fetching wallet items after every
638 // required action is resolved.
639 wallet_client_.GetWalletItems(this);
640 } 664 }
641 } 665 }
642 666
643 //////////////////////////////////////////////////////////////////////////////// 667 ////////////////////////////////////////////////////////////////////////////////
644 // SuggestionsMenuModelDelegate 668 // SuggestionsMenuModelDelegate
645 669
646 void AutofillDialogControllerImpl::SuggestionItemSelected( 670 void AutofillDialogControllerImpl::SuggestionItemSelected(
647 const SuggestionsMenuModel& model) { 671 const SuggestionsMenuModel& model) {
648 DialogSection section = SectionForSuggestionsMenuModel(model); 672 DialogSection section = SectionForSuggestionsMenuModel(model);
649 section_editing_state_[section] = false; 673 section_editing_state_[section] = false;
(...skipping 14 matching lines...) Expand all
664 } 688 }
665 689
666 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation( 690 void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation(
667 const std::string& escrow_handle) { 691 const std::string& escrow_handle) {
668 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle; 692 NOTIMPLEMENTED() << " escrow_handle=" << escrow_handle;
669 } 693 }
670 694
671 void AutofillDialogControllerImpl::OnDidGetFullWallet( 695 void AutofillDialogControllerImpl::OnDidGetFullWallet(
672 scoped_ptr<wallet::FullWallet> full_wallet) { 696 scoped_ptr<wallet::FullWallet> full_wallet) {
673 NOTIMPLEMENTED(); 697 NOTIMPLEMENTED();
698 WalletRequestCompleted(true);
674 } 699 }
675 700
676 void AutofillDialogControllerImpl::OnDidGetWalletItems( 701 void AutofillDialogControllerImpl::OnDidGetWalletItems(
677 scoped_ptr<wallet::WalletItems> wallet_items) { 702 scoped_ptr<wallet::WalletItems> wallet_items) {
703 bool items_changed = !wallet_items_ || *wallet_items != *wallet_items_;
678 wallet_items_ = wallet_items.Pass(); 704 wallet_items_ = wallet_items.Pass();
679 view_->UpdateAccountChooser(); 705 WalletRequestCompleted(true);
680 view_->UpdateNotificationArea(); 706
707 if (items_changed) {
708 view_->UpdateAccountChooser();
709 view_->UpdateNotificationArea();
710 }
681 } 711 }
682 712
683 void AutofillDialogControllerImpl::OnDidSaveAddress( 713 void AutofillDialogControllerImpl::OnDidSaveAddress(
684 const std::string& address_id) { 714 const std::string& address_id) {
685 NOTIMPLEMENTED() << " address_id=" << address_id; 715 NOTIMPLEMENTED() << " address_id=" << address_id;
716 WalletRequestCompleted(true);
686 } 717 }
687 718
688 void AutofillDialogControllerImpl::OnDidSaveInstrument( 719 void AutofillDialogControllerImpl::OnDidSaveInstrument(
689 const std::string& instrument_id) { 720 const std::string& instrument_id) {
690 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; 721 NOTIMPLEMENTED() << " instrument_id=" << instrument_id;
722 WalletRequestCompleted(true);
691 } 723 }
692 724
693 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress( 725 void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress(
694 const std::string& instrument_id, const std::string& address_id) { 726 const std::string& instrument_id, const std::string& address_id) {
695 NOTIMPLEMENTED() << " instrument_id=" << instrument_id 727 NOTIMPLEMENTED() << " instrument_id=" << instrument_id
696 << ", address_id=" << address_id; 728 << ", address_id=" << address_id;
729 WalletRequestCompleted(true);
697 } 730 }
698 731
699 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() { 732 void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() {
700 NOTIMPLEMENTED(); 733 NOTIMPLEMENTED();
734 WalletRequestCompleted(true);
701 } 735 }
702 736
703 void AutofillDialogControllerImpl::OnWalletError() { 737 void AutofillDialogControllerImpl::OnWalletError() {
704 NOTIMPLEMENTED(); 738 WalletRequestCompleted(false);
705 wallet_items_.reset();
706 } 739 }
707 740
708 void AutofillDialogControllerImpl::OnMalformedResponse() { 741 void AutofillDialogControllerImpl::OnMalformedResponse() {
709 NOTIMPLEMENTED(); 742 WalletRequestCompleted(false);
710 wallet_items_.reset();
711 } 743 }
712 744
713 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { 745 void AutofillDialogControllerImpl::OnNetworkError(int response_code) {
714 NOTIMPLEMENTED() << " response_code=" << response_code; 746 WalletRequestCompleted(false);
715 wallet_items_.reset();
716 } 747 }
717 748
718 //////////////////////////////////////////////////////////////////////////////// 749 ////////////////////////////////////////////////////////////////////////////////
719 750
720 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( 751 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
721 const content::NativeWebKeyboardEvent& event) { 752 const content::NativeWebKeyboardEvent& event) {
722 if (popup_controller_) 753 if (popup_controller_)
723 return popup_controller_->HandleKeyPressEvent(event); 754 return popup_controller_->HandleKeyPressEvent(event);
724 755
725 return false; 756 return false;
(...skipping 21 matching lines...) Expand all
747 bool AutofillDialogControllerImpl::HasRequiredAction( 778 bool AutofillDialogControllerImpl::HasRequiredAction(
748 wallet::RequiredAction action) const { 779 wallet::RequiredAction action) const {
749 if (!wallet_items_) 780 if (!wallet_items_)
750 return false; 781 return false;
751 782
752 const std::vector<wallet::RequiredAction>& actions = 783 const std::vector<wallet::RequiredAction>& actions =
753 wallet_items_->required_actions(); 784 wallet_items_->required_actions();
754 return std::find(actions.begin(), actions.end(), action) != actions.end(); 785 return std::find(actions.begin(), actions.end(), action) != actions.end();
755 } 786 }
756 787
788 void AutofillDialogControllerImpl::ScheduleRefreshWalletItems() {
789 if (!CanPayWithWallet())
790 return;
791
792 if (wallet_client_.IsRequestInProgress()) {
793 refresh_wallet_items_queued_ = true;
794 return;
795 }
796
797 wallet_client_.GetWalletItems(this);
798 refresh_wallet_items_queued_ = false;
799 }
800
801 void AutofillDialogControllerImpl::WalletRequestCompleted(bool success) {
802 if (!success) {
803 had_wallet_error_ = true;
804 wallet_items_.reset();
805 view_->UpdateAccountChooser();
806 view_->UpdateNotificationArea();
807 return;
808 }
809
810 if (refresh_wallet_items_queued_)
811 ScheduleRefreshWalletItems();
812 }
813
757 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { 814 void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
758 PersonalDataManager* manager = GetManager(); 815 PersonalDataManager* manager = GetManager();
759 const std::vector<CreditCard*>& cards = manager->credit_cards(); 816 const std::vector<CreditCard*>& cards = manager->credit_cards();
760 for (size_t i = 0; i < cards.size(); ++i) { 817 for (size_t i = 0; i < cards.size(); ++i) {
761 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label()); 818 suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label());
762 } 819 }
763 // TODO(estade): real strings and i18n. 820 // TODO(estade): real strings and i18n.
764 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card")); 821 suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card"));
765 822
766 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); 823 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 } 990 }
934 991
935 void AutofillDialogControllerImpl::HidePopup() { 992 void AutofillDialogControllerImpl::HidePopup() {
936 if (popup_controller_) { 993 if (popup_controller_) {
937 popup_controller_->Hide(); 994 popup_controller_->Hide();
938 ControllerDestroyed(); 995 ControllerDestroyed();
939 } 996 }
940 } 997 }
941 998
942 } // namespace autofill 999 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698