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

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

Issue 13625002: Change the behavior of the [X] Save details to Wallet checkbox notification to: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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 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 <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // fields. First we must figure out what the "right" fields are. 382 // fields. First we must figure out what the "right" fields are.
383 view_.reset(CreateView()); 383 view_.reset(CreateView());
384 view_->Show(); 384 view_->Show();
385 GetManager()->AddObserver(this); 385 GetManager()->AddObserver(this);
386 386
387 // Try to see if the user is already signed-in. 387 // Try to see if the user is already signed-in.
388 // If signed-in, fetch the user's Wallet data. 388 // If signed-in, fetch the user's Wallet data.
389 // Otherwise, see if the user could be signed in passively. 389 // Otherwise, see if the user could be signed in passively.
390 // TODO(aruslan): UMA metrics for sign-in. 390 // TODO(aruslan): UMA metrics for sign-in.
391 if (account_chooser_model_.WalletIsSelected()) 391 if (account_chooser_model_.WalletIsSelected())
392 StartFetchingWalletItems(); 392 GetWalletItems();
393 } 393 }
394 394
395 void AutofillDialogControllerImpl::Hide() { 395 void AutofillDialogControllerImpl::Hide() {
396 if (view_) 396 if (view_)
397 view_->Hide(); 397 view_->Hide();
398 } 398 }
399 399
400 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { 400 void AutofillDialogControllerImpl::UpdateProgressBar(double value) {
401 view_->UpdateProgressBar(value); 401 view_->UpdateProgressBar(value);
402 } 402 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 return wallet_items_.get() != NULL && 533 return wallet_items_.get() != NULL &&
534 !wallet_items_->instruments().empty() && 534 !wallet_items_->instruments().empty() &&
535 !wallet_items_->addresses().empty(); 535 !wallet_items_->addresses().empty();
536 } 536 }
537 537
538 bool AutofillDialogControllerImpl::IsSubmitPausedOn( 538 bool AutofillDialogControllerImpl::IsSubmitPausedOn(
539 wallet::RequiredAction required_action) const { 539 wallet::RequiredAction required_action) const {
540 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); 540 return full_wallet_ && full_wallet_->HasRequiredAction(required_action);
541 } 541 }
542 542
543 void AutofillDialogControllerImpl::StartFetchingWalletItems() { 543 void AutofillDialogControllerImpl::GetWalletItems() {
544 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges. 544 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges.
545 GetWalletClient()->GetWalletItems( 545 GetWalletClient()->GetWalletItems(
546 source_url_, 546 source_url_, std::vector<wallet::WalletClient::RiskCapability>());
547 std::vector<wallet::WalletClient::RiskCapability>());
548 } 547 }
549 548
550 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { 549 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() {
551 if (wallet_items_.get()) { 550 switch (SignedInState()) {
552 DCHECK(!signin_helper_.get()); 551 case SIGNED_IN:
553 switch (SignedInState()) { 552 // Start fetching the user name if we don't know it yet.
554 case SIGNED_IN: 553 if (current_username_.empty()) {
555 // Start fetching the user name if we don't know it yet. 554 signin_helper_.reset(new wallet::WalletSigninHelper(
556 if (current_username_.empty()) { 555 this, profile_->GetRequestContext()));
557 signin_helper_.reset(new wallet::WalletSigninHelper( 556 signin_helper_->StartUserNameFetch();
558 this, 557 }
559 profile_->GetRequestContext())); 558 break;
560 signin_helper_->StartUserNameFetch();
561 }
562 break;
563 559
564 case REQUIRES_SIGN_IN: 560 case REQUIRES_SIGN_IN:
565 // TODO(aruslan): automatic sign-in? 561 // TODO(aruslan): automatic sign-in?
566 break; 562 break;
567 563
568 case REQUIRES_PASSIVE_SIGN_IN: 564 case REQUIRES_PASSIVE_SIGN_IN:
569 // Attempt to passively sign in the user. 565 // Attempt to passively sign in the user.
570 current_username_.clear(); 566 current_username_.clear();
571 signin_helper_.reset(new wallet::WalletSigninHelper( 567 signin_helper_.reset(new wallet::WalletSigninHelper(
572 this, 568 this, profile_->GetRequestContext()));
573 profile_->GetRequestContext())); 569 signin_helper_->StartPassiveSignin();
574 signin_helper_->StartPassiveSignin(); 570 break;
575 break;
576 571
577 case REQUIRES_RESPONSE: 572 case REQUIRES_RESPONSE:
578 NOTREACHED(); 573 NOTREACHED();
579 }
580 } 574 }
581 575
582 SuggestionsUpdated(); 576 SuggestionsUpdated();
583 view_->UpdateAccountChooser(); 577 view_->UpdateAccountChooser();
584 view_->UpdateNotificationArea(); 578 view_->UpdateNotificationArea();
585 579
586 // On the first successful response, compute the initial user state metric. 580 // On the first successful response, compute the initial user state metric.
587 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) 581 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN)
588 initial_user_state_ = GetInitialUserState(); 582 initial_user_state_ = GetInitialUserState();
589 } 583 }
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 popup_labels, 1061 popup_labels,
1068 popup_icons, 1062 popup_icons,
1069 popup_ids); 1063 popup_ids);
1070 section_showing_popup_ = section; 1064 section_showing_popup_ = section;
1071 } 1065 }
1072 1066
1073 void AutofillDialogControllerImpl::FocusMoved() { 1067 void AutofillDialogControllerImpl::FocusMoved() {
1074 HidePopup(); 1068 HidePopup();
1075 } 1069 }
1076 1070
1071 void AutofillDialogControllerImpl::CheckboxStateChanged(
1072 DialogNotification::Type type, bool checked) {
1073 if (type == DialogNotification::WALLET_USAGE_CONFIRMATION) {
1074 int command = checked ? AccountChooserModel::kWalletItemId :
1075 AccountChooserModel::kAutofillItemId;
1076 account_chooser_model_.ExecuteCommand(command, 0);
1077 }
1078 }
1079
1077 void AutofillDialogControllerImpl::ViewClosed() { 1080 void AutofillDialogControllerImpl::ViewClosed() {
1078 GetManager()->RemoveObserver(this); 1081 GetManager()->RemoveObserver(this);
1079 1082
1080 if (autocheckout_is_running_ || had_autocheckout_error_) { 1083 if (autocheckout_is_running_ || had_autocheckout_error_) {
1081 AutofillMetrics::AutocheckoutCompletionStatus metric = 1084 AutofillMetrics::AutocheckoutCompletionStatus metric =
1082 autocheckout_is_running_ ? 1085 autocheckout_is_running_ ?
1083 AutofillMetrics::AUTOCHECKOUT_SUCCEEDED : 1086 AutofillMetrics::AUTOCHECKOUT_SUCCEEDED :
1084 AutofillMetrics::AUTOCHECKOUT_FAILED; 1087 AutofillMetrics::AUTOCHECKOUT_FAILED;
1085 metric_logger_.LogAutocheckoutDuration( 1088 metric_logger_.LogAutocheckoutDuration(
1086 base::Time::Now() - autocheckout_started_timestamp_, 1089 base::Time::Now() - autocheckout_started_timestamp_,
1087 metric); 1090 metric);
1088 } 1091 }
1089 1092
1090 // Reset the view so that updates to the pref aren't processed.
1091 view_.reset();
1092 // On a successful submit, if the user manually selected "pay without wallet",
1093 // stop trying to pay with Wallet on future runs of the dialog.
1094 bool manually_selected_pay_without_wallet =
1095 !account_chooser_model_.WalletIsSelected() &&
1096 !account_chooser_model_.had_wallet_error();
1097 profile_->GetPrefs()->SetBoolean(prefs::kAutofillDialogPayWithoutWallet,
1098 manually_selected_pay_without_wallet);
1099
1100 delete this; 1093 delete this;
1101 } 1094 }
1102 1095
1103 std::vector<DialogNotification> 1096 std::vector<DialogNotification>
1104 AutofillDialogControllerImpl::CurrentNotifications() const { 1097 AutofillDialogControllerImpl::CurrentNotifications() const {
1105 std::vector<DialogNotification> notifications; 1098 std::vector<DialogNotification> notifications;
1106 1099
1107 if (account_chooser_model_.WalletIsSelected()) { 1100 if (account_chooser_model_.had_wallet_error()) {
1108 if (SignedInState() == SIGNED_IN) { 1101 // TODO(dbeam): pass along the Wallet error or remove from the translation.
1109 // On first run with a complete wallet profile, show a notification 1102 // TODO(dbeam): figure out a way to dismiss this error after a while.
1110 // explaining where this data came from. 1103 notifications.push_back(DialogNotification(
1111 if (IsFirstRun() && HasCompleteWallet()) { 1104 DialogNotification::WALLET_ERROR,
1105 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
1106 ASCIIToUTF16("Oops, [Wallet-Error]."))));
1107 } else {
1108 if (is_first_run_) {
1109 if (SignedInState() == SIGNED_IN) {
1110 if (HasCompleteWallet()) {
1111 // First run, signed in, has a complete Google Wallet.
1112 notifications.push_back(DialogNotification(
1113 DialogNotification::EXPLANATORY_MESSAGE,
1114 l10n_util::GetStringUTF16(
1115 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET)));
1116 } else {
1117 // First run, signed in, has an incomplete (or no) Google Wallet.
1118 DialogNotification notification(
1119 DialogNotification::WALLET_USAGE_CONFIRMATION,
1120 l10n_util::GetStringUTF16(
1121 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET));
1122 notification.set_checked(account_chooser_model_.WalletIsSelected());
1123 notification.set_interactive(!is_submitting_);
1124 notifications.push_back(notification);
1125 }
1126 } else {
1127 // First run, not signed in, wallet promo.
1112 notifications.push_back(DialogNotification( 1128 notifications.push_back(DialogNotification(
1113 DialogNotification::EXPLANATORY_MESSAGE, 1129 DialogNotification::WALLET_SIGNIN_PROMO,
1114 l10n_util::GetStringUTF16( 1130 l10n_util::GetStringUTF16(
1115 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET))); 1131 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS)));
1116 } else {
1117 notifications.push_back(DialogNotification(
1118 DialogNotification::WALLET_USAGE_CONFIRMATION,
1119 l10n_util::GetStringUTF16(
1120 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET)));
1121 notifications.back().set_interactive(!is_submitting_);
1122 } 1132 }
1123 } else if (IsFirstRun()) { 1133 } else if (SignedInState() == SIGNED_IN && !HasCompleteWallet()) {
1124 // If the user is not signed in, show an upsell notification on first run. 1134 // After first run, signed in.
1125 notifications.push_back(DialogNotification( 1135 DialogNotification notification(
1126 DialogNotification::WALLET_SIGNIN_PROMO, 1136 DialogNotification::WALLET_USAGE_CONFIRMATION,
1127 l10n_util::GetStringUTF16( 1137 l10n_util::GetStringUTF16(
1128 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS))); 1138 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET));
1139 notification.set_checked(account_chooser_model_.WalletIsSelected());
1140 notification.set_interactive(!is_submitting_);
1141 notifications.push_back(notification);
1142 } else {
1143 // If the user isn't signed in and it's after the first run, no promo.
1129 } 1144 }
1130 } 1145 }
1131 1146
1132 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { 1147 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
1133 notifications.push_back(DialogNotification( 1148 notifications.push_back(DialogNotification(
1134 DialogNotification::SECURITY_WARNING, 1149 DialogNotification::SECURITY_WARNING,
1135 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING))); 1150 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)));
1136 } 1151 }
1137 1152
1138 if (!invoked_from_same_origin_) { 1153 if (!invoked_from_same_origin_) {
1139 notifications.push_back(DialogNotification( 1154 notifications.push_back(DialogNotification(
1140 DialogNotification::SECURITY_WARNING, 1155 DialogNotification::SECURITY_WARNING,
1141 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING, 1156 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING,
1142 UTF8ToUTF16(source_url_.host())))); 1157 UTF8ToUTF16(source_url_.host()))));
1143 } 1158 }
1144 1159
1145 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { 1160 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1146 notifications.push_back(DialogNotification( 1161 notifications.push_back(DialogNotification(
1147 DialogNotification::REQUIRED_ACTION, 1162 DialogNotification::REQUIRED_ACTION,
1148 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV))); 1163 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)));
1149 } 1164 }
1150 1165
1151 if (had_autocheckout_error_) { 1166 if (had_autocheckout_error_) {
1152 notifications.push_back(DialogNotification( 1167 notifications.push_back(DialogNotification(
1153 DialogNotification::AUTOCHECKOUT_ERROR, 1168 DialogNotification::AUTOCHECKOUT_ERROR,
1154 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); 1169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR)));
1155 } 1170 }
1156 1171
1157 if (account_chooser_model_.had_wallet_error()) {
1158 // TODO(dbeam): pass along the Wallet error or remove from the translation.
1159 // TODO(dbeam): figure out a way to dismiss this error after a while.
1160 notifications.push_back(DialogNotification(
1161 DialogNotification::WALLET_ERROR,
1162 l10n_util::GetStringFUTF16(
1163 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
1164 ASCIIToUTF16("Oops, [Wallet-Error]."))));
1165 }
1166
1167 return notifications; 1172 return notifications;
1168 } 1173 }
1169 1174
1170 void AutofillDialogControllerImpl::StartSignInFlow() { 1175 void AutofillDialogControllerImpl::StartSignInFlow() {
1171 DCHECK(registrar_.IsEmpty()); 1176 DCHECK(registrar_.IsEmpty());
1172 1177
1173 content::Source<content::NavigationController> source(view_->ShowSignIn()); 1178 content::Source<content::NavigationController> source(view_->ShowSignIn());
1174 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); 1179 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
1175 } 1180 }
1176 1181
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 void AutofillDialogControllerImpl::Observe( 1300 void AutofillDialogControllerImpl::Observe(
1296 int type, 1301 int type,
1297 const content::NotificationSource& source, 1302 const content::NotificationSource& source,
1298 const content::NotificationDetails& details) { 1303 const content::NotificationDetails& details) {
1299 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); 1304 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED);
1300 content::LoadCommittedDetails* load_details = 1305 content::LoadCommittedDetails* load_details =
1301 content::Details<content::LoadCommittedDetails>(details).ptr(); 1306 content::Details<content::LoadCommittedDetails>(details).ptr();
1302 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { 1307 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
1303 EndSignInFlow(); 1308 EndSignInFlow();
1304 if (account_chooser_model_.WalletIsSelected()) 1309 if (account_chooser_model_.WalletIsSelected())
1305 StartFetchingWalletItems(); 1310 GetWalletItems();
1306 } 1311 }
1307 } 1312 }
1308 1313
1309 //////////////////////////////////////////////////////////////////////////////// 1314 ////////////////////////////////////////////////////////////////////////////////
1310 // SuggestionsMenuModelDelegate implementation. 1315 // SuggestionsMenuModelDelegate implementation.
1311 1316
1312 void AutofillDialogControllerImpl::SuggestionItemSelected( 1317 void AutofillDialogControllerImpl::SuggestionItemSelected(
1313 const SuggestionsMenuModel& model) { 1318 const SuggestionsMenuModel& model) {
1314 const DialogSection section = SectionForSuggestionsMenuModel(model); 1319 const DialogSection section = SectionForSuggestionsMenuModel(model);
1315 EditCancelledForSection(section); 1320 EditCancelledForSection(section);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1364
1360 SuggestionsUpdated(); 1365 SuggestionsUpdated();
1361 view_->UpdateNotificationArea(); 1366 view_->UpdateNotificationArea();
1362 view_->UpdateButtonStrip(); 1367 view_->UpdateButtonStrip();
1363 } 1368 }
1364 1369
1365 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( 1370 void AutofillDialogControllerImpl::OnPassiveSigninSuccess(
1366 const std::string& username) { 1371 const std::string& username) {
1367 current_username_ = username; 1372 current_username_ = username;
1368 signin_helper_.reset(); 1373 signin_helper_.reset();
1369 wallet_items_.reset(); 1374 GetWalletItems();
1370 StartFetchingWalletItems();
1371 } 1375 }
1372 1376
1373 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( 1377 void AutofillDialogControllerImpl::OnUserNameFetchSuccess(
1374 const std::string& username) { 1378 const std::string& username) {
1375 current_username_ = username; 1379 current_username_ = username;
1376 signin_helper_.reset(); 1380 signin_helper_.reset();
1377 OnWalletOrSigninUpdate(); 1381 OnWalletOrSigninUpdate();
1378 } 1382 }
1379 1383
1380 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( 1384 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 // PersonalDataManagerObserver implementation. 1484 // PersonalDataManagerObserver implementation.
1481 1485
1482 void AutofillDialogControllerImpl::OnPersonalDataChanged() { 1486 void AutofillDialogControllerImpl::OnPersonalDataChanged() {
1483 SuggestionsUpdated(); 1487 SuggestionsUpdated();
1484 } 1488 }
1485 1489
1486 void AutofillDialogControllerImpl::AccountChoiceChanged() { 1490 void AutofillDialogControllerImpl::AccountChoiceChanged() {
1487 if (!view_) 1491 if (!view_)
1488 return; 1492 return;
1489 1493
1490 // Whenever the user changes the current account, the Wallet data should be 1494 if (account_chooser_model_.WalletIsSelected() && !wallet_items_)
1491 // cleared. If the user has chosen a Wallet account, an attempt to fetch 1495 GetWalletItems();
1492 // the Wallet data is made to see if the user is still signed in.
1493 // This will trigger a passive sign-in if required.
1494 // TODO(aruslan): integrate an automatic sign-in.
1495 wallet_items_.reset();
1496 full_wallet_.reset();
1497 GetWalletClient()->CancelRequests();
1498
1499 SetIsSubmitting(false);
1500
1501 if (account_chooser_model_.WalletIsSelected())
1502 StartFetchingWalletItems();
1503 1496
1504 SuggestionsUpdated(); 1497 SuggestionsUpdated();
1505 view_->UpdateAccountChooser(); 1498 view_->UpdateAccountChooser();
1506 view_->UpdateNotificationArea(); 1499 view_->UpdateNotificationArea();
1507 } 1500 }
1508 1501
1509 //////////////////////////////////////////////////////////////////////////////// 1502 ////////////////////////////////////////////////////////////////////////////////
1510 1503
1511 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( 1504 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
1512 const content::NativeWebKeyboardEvent& event) { 1505 const content::NativeWebKeyboardEvent& event) {
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2071 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2079 } 2072 }
2080 2073
2081 // Has Wallet items. 2074 // Has Wallet items.
2082 return has_autofill_profiles ? 2075 return has_autofill_profiles ?
2083 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2076 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2084 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2077 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2085 } 2078 }
2086 2079
2087 } // namespace autofill 2080 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698