OLD | NEW |
---|---|
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 return REQUIRES_PASSIVE_SIGN_IN; | 455 return REQUIRES_PASSIVE_SIGN_IN; |
456 | 456 |
457 return SIGNED_IN; | 457 return SIGNED_IN; |
458 } | 458 } |
459 | 459 |
460 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { | 460 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { |
461 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE; | 461 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE; |
462 } | 462 } |
463 | 463 |
464 string16 AutofillDialogControllerImpl::AccountChooserText() const { | 464 string16 AutofillDialogControllerImpl::AccountChooserText() const { |
465 // TODO(aruslan): this should be l10n "Not using Google Wallet". | |
465 if (!IsPayingWithWallet()) | 466 if (!IsPayingWithWallet()) |
466 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); | 467 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); |
467 | 468 |
468 // TODO(dbeam): real strings and l10n. | |
469 if (SignedInState() == SIGNED_IN) | 469 if (SignedInState() == SIGNED_IN) |
470 return ASCIIToUTF16(current_username_); | 470 return ASCIIToUTF16(account_chooser_model_.GetCurrentlySignedInAccount()); |
471 | 471 |
472 // In this case, the account chooser should be showing the signin link. | 472 // In this case, the account chooser should be showing the signin link. |
473 return string16(); | 473 return string16(); |
474 } | 474 } |
475 | 475 |
476 string16 AutofillDialogControllerImpl::SignInLinkText() const { | 476 string16 AutofillDialogControllerImpl::SignInLinkText() const { |
477 // TODO(estade): real strings and l10n. | 477 // TODO(estade): real strings and l10n. |
478 return ASCIIToUTF16("Sign in to use Google Wallet"); | 478 return ASCIIToUTF16("Sign in to use Google Wallet"); |
479 } | 479 } |
480 | 480 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 std::vector<wallet::WalletClient::RiskCapability>()); | 522 std::vector<wallet::WalletClient::RiskCapability>()); |
523 } | 523 } |
524 | 524 |
525 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { | 525 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
526 if (wallet_items_.get()) { | 526 if (wallet_items_.get()) { |
527 DCHECK(IsPayingWithWallet()); | 527 DCHECK(IsPayingWithWallet()); |
528 DCHECK(!signin_helper_.get()); | 528 DCHECK(!signin_helper_.get()); |
529 switch (SignedInState()) { | 529 switch (SignedInState()) { |
530 case SIGNED_IN: | 530 case SIGNED_IN: |
531 // Start fetching the user name if we don't know it yet. | 531 // Start fetching the user name if we don't know it yet. |
532 if (current_username_.empty()) { | 532 if (account_chooser_model_.GetCurrentlySignedInAccount().empty()) { |
533 signin_helper_.reset(new wallet::WalletSigninHelper( | 533 signin_helper_.reset(new wallet::WalletSigninHelper( |
534 this, | 534 this, |
535 profile_->GetRequestContext())); | 535 profile_->GetRequestContext())); |
536 signin_helper_->StartUserNameFetch(); | 536 signin_helper_->StartUserNameFetch(); |
537 } | 537 } |
538 break; | 538 break; |
539 | 539 |
540 case REQUIRES_SIGN_IN: | 540 case REQUIRES_SIGN_IN: |
541 // TODO(aruslan): automatic sign-in? | 541 // Switch to the local account and refresh the dialog. |
542 OnWalletSigninError(); | |
542 break; | 543 break; |
543 | 544 |
544 case REQUIRES_PASSIVE_SIGN_IN: | 545 case REQUIRES_PASSIVE_SIGN_IN: |
545 // Attempt to passively sign in the user. | 546 // Attempt to passively sign in the user. |
546 current_username_.clear(); | 547 account_chooser_model_.ResetCurrentlySignedInAccount(); |
547 signin_helper_.reset(new wallet::WalletSigninHelper( | 548 signin_helper_.reset(new wallet::WalletSigninHelper( |
548 this, | 549 this, |
549 profile_->GetRequestContext())); | 550 profile_->GetRequestContext())); |
550 signin_helper_->StartPassiveSignin(); | 551 signin_helper_->StartPassiveSignin(); |
551 break; | 552 break; |
552 | 553 |
553 case REQUIRES_RESPONSE: | 554 case REQUIRES_RESPONSE: |
554 NOTREACHED(); | 555 NOTREACHED(); |
555 } | 556 } |
556 } | 557 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 return NULL; | 601 return NULL; |
601 } | 602 } |
602 } | 603 } |
603 | 604 |
604 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 605 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
605 DialogSection section) { | 606 DialogSection section) { |
606 return SuggestionsMenuModelForSection(section); | 607 return SuggestionsMenuModelForSection(section); |
607 } | 608 } |
608 | 609 |
609 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { | 610 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { |
610 // When paying with wallet, but not signed in, there is no menu, just a | 611 // If there is no accounts to choose from except the autofill data, |
611 // sign in link. | 612 // there is no menu, just a sign in link. |
Evan Stade
2013/03/29 23:08:45
comment is hard to follow. "Autofill data" is not
aruslan
2013/03/30 00:07:47
Done.
| |
612 if (IsPayingWithWallet() && SignedInState() != SIGNED_IN) | 613 if (!account_chooser_model_.HasAccountsToChoose()) |
613 return NULL; | 614 return NULL; |
614 | 615 |
615 return &account_chooser_model_; | 616 return &account_chooser_model_; |
616 } | 617 } |
617 | 618 |
618 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { | 619 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { |
619 if (!MenuModelForAccountChooser()) { | 620 if (!MenuModelForAccountChooser()) { |
620 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 621 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
621 IDR_WALLET_ICON); | 622 IDR_WALLET_ICON); |
622 } | 623 } |
623 | 624 |
624 gfx::Image icon; | 625 gfx::Image icon; |
625 account_chooser_model_.GetIconAt(account_chooser_model_.checked_item(), | 626 account_chooser_model_.GetIconAt( |
626 &icon); | 627 account_chooser_model_.GetIndexOfCommandId( |
628 account_chooser_model_.checked_item()), | |
Evan Stade
2013/03/29 23:08:45
isn't the checked item already an index? aren't in
aruslan
2013/03/30 00:07:47
Not anymore; do you suggest it should be?
Command-
| |
629 &icon); | |
627 return icon; | 630 return icon; |
628 } | 631 } |
629 | 632 |
630 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) | 633 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) |
631 const { | 634 const { |
632 switch (section) { | 635 switch (section) { |
633 case SECTION_EMAIL: | 636 case SECTION_EMAIL: |
634 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); | 637 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); |
635 case SECTION_CC: | 638 case SECTION_CC: |
636 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); | 639 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 DialogNotification::WALLET_ERROR, | 1036 DialogNotification::WALLET_ERROR, |
1034 l10n_util::GetStringFUTF16( | 1037 l10n_util::GetStringFUTF16( |
1035 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, | 1038 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, |
1036 ASCIIToUTF16("Oops, [Wallet-Error].")))); | 1039 ASCIIToUTF16("Oops, [Wallet-Error].")))); |
1037 } | 1040 } |
1038 | 1041 |
1039 return notifications; | 1042 return notifications; |
1040 } | 1043 } |
1041 | 1044 |
1042 void AutofillDialogControllerImpl::StartSignInFlow() { | 1045 void AutofillDialogControllerImpl::StartSignInFlow() { |
1046 DCHECK(!IsPayingWithWallet()); | |
1043 DCHECK(registrar_.IsEmpty()); | 1047 DCHECK(registrar_.IsEmpty()); |
1044 | 1048 |
1045 content::Source<content::NavigationController> source(view_->ShowSignIn()); | 1049 content::Source<content::NavigationController> source(view_->ShowSignIn()); |
1046 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | 1050 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); |
1047 } | 1051 } |
1048 | 1052 |
1049 void AutofillDialogControllerImpl::EndSignInFlow() { | 1053 void AutofillDialogControllerImpl::EndSignInFlow() { |
1050 DCHECK(!registrar_.IsEmpty()); | 1054 DCHECK(!registrar_.IsEmpty()); |
1051 registrar_.RemoveAll(); | 1055 registrar_.RemoveAll(); |
1052 view_->HideSignIn(); | 1056 view_->HideSignIn(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 | 1155 |
1152 void AutofillDialogControllerImpl::Observe( | 1156 void AutofillDialogControllerImpl::Observe( |
1153 int type, | 1157 int type, |
1154 const content::NotificationSource& source, | 1158 const content::NotificationSource& source, |
1155 const content::NotificationDetails& details) { | 1159 const content::NotificationDetails& details) { |
1156 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 1160 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
1157 content::LoadCommittedDetails* load_details = | 1161 content::LoadCommittedDetails* load_details = |
1158 content::Details<content::LoadCommittedDetails>(details).ptr(); | 1162 content::Details<content::LoadCommittedDetails>(details).ptr(); |
1159 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 1163 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
1160 EndSignInFlow(); | 1164 EndSignInFlow(); |
1161 if (IsPayingWithWallet()) | 1165 // The sign-in flow means that the user implicitly switched the account |
1162 StartFetchingWalletItems(); | 1166 // to the Wallet. This will trigger AccountChoiceChanged. |
1167 DCHECK(!IsPayingWithWallet()); | |
1168 account_chooser_model_.ForceWalletAccountSelected(); | |
1163 } | 1169 } |
1164 } | 1170 } |
1165 | 1171 |
1166 //////////////////////////////////////////////////////////////////////////////// | 1172 //////////////////////////////////////////////////////////////////////////////// |
1167 // SuggestionsMenuModelDelegate implementation. | 1173 // SuggestionsMenuModelDelegate implementation. |
1168 | 1174 |
1169 void AutofillDialogControllerImpl::SuggestionItemSelected( | 1175 void AutofillDialogControllerImpl::SuggestionItemSelected( |
1170 const SuggestionsMenuModel& model) { | 1176 const SuggestionsMenuModel& model) { |
1171 DialogSection section = SectionForSuggestionsMenuModel(model); | 1177 DialogSection section = SectionForSuggestionsMenuModel(model); |
1172 section_editing_state_[section] = false; | 1178 section_editing_state_[section] = false; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 | 1215 |
1210 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) | 1216 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) |
1211 DisableWallet(); | 1217 DisableWallet(); |
1212 else | 1218 else |
1213 FinishSubmit(); | 1219 FinishSubmit(); |
1214 } | 1220 } |
1215 | 1221 |
1216 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( | 1222 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( |
1217 const std::string& username) { | 1223 const std::string& username) { |
1218 DCHECK(IsPayingWithWallet()); | 1224 DCHECK(IsPayingWithWallet()); |
1219 current_username_ = username; | 1225 account_chooser_model_.SetCurrentlySignedInAccount(username); |
1220 signin_helper_.reset(); | 1226 signin_helper_.reset(); |
1221 wallet_items_.reset(); | 1227 wallet_items_.reset(); |
1222 StartFetchingWalletItems(); | 1228 StartFetchingWalletItems(); |
1223 } | 1229 } |
1224 | 1230 |
1225 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( | 1231 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
1226 const std::string& username) { | 1232 const std::string& username) { |
1227 DCHECK(IsPayingWithWallet()); | 1233 DCHECK(IsPayingWithWallet()); |
1228 current_username_ = username; | 1234 account_chooser_model_.SetCurrentlySignedInAccount(username); |
1229 signin_helper_.reset(); | 1235 signin_helper_.reset(); |
1230 OnWalletOrSigninUpdate(); | 1236 OnWalletOrSigninUpdate(); |
1231 } | 1237 } |
1232 | 1238 |
1233 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( | 1239 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( |
1234 const std::string& username) { | 1240 const std::string& username) { |
1235 // TODO(aruslan): automatic sign-in. | 1241 // TODO(aruslan): automatic sign-in. |
1236 NOTIMPLEMENTED(); | 1242 NOTIMPLEMENTED(); |
1237 } | 1243 } |
1238 | 1244 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1326 void AutofillDialogControllerImpl::OnPersonalDataChanged() { | 1332 void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
1327 HidePopup(); | 1333 HidePopup(); |
1328 GenerateSuggestionsModels(); | 1334 GenerateSuggestionsModels(); |
1329 view_->ModelChanged(); | 1335 view_->ModelChanged(); |
1330 } | 1336 } |
1331 | 1337 |
1332 void AutofillDialogControllerImpl::AccountChoiceChanged() { | 1338 void AutofillDialogControllerImpl::AccountChoiceChanged() { |
1333 if (!view_) | 1339 if (!view_) |
1334 return; | 1340 return; |
1335 | 1341 |
1336 // Whenever the user changes the current account, the Wallet data should be | 1342 // The Wallet data should be cleared when the user switches accounts. |
1337 // cleared. If the user has chosen a Wallet account, an attempt to fetch | |
1338 // the Wallet data is made to see if the user is still signed in. | |
1339 // This will trigger a passive sign-in if required. | |
1340 // TODO(aruslan): integrate an automatic sign-in. | |
1341 wallet_items_.reset(); | 1343 wallet_items_.reset(); |
1342 if (IsPayingWithWallet()) | 1344 if (IsPayingWithWallet()) { |
1343 StartFetchingWalletItems(); | 1345 if (account_chooser_model_.IsCurrentlySignedInAccountSelected()) { |
1346 // If the user has chosen a content-area Wallet account, an attempt to | |
1347 // fetch the Wallet data is made to see if the user is still signed in. | |
1348 // This will trigger a passive sign-in if required. | |
1349 StartFetchingWalletItems(); | |
1350 } else { | |
1351 // TODO(aruslan): integrate an automatic sign-in. | |
1352 OnWalletSigninError(); | |
1353 } | |
1354 } | |
1344 | 1355 |
1345 GenerateSuggestionsModels(); | 1356 GenerateSuggestionsModels(); |
1346 view_->ModelChanged(); | 1357 view_->ModelChanged(); |
1347 view_->UpdateAccountChooser(); | 1358 view_->UpdateAccountChooser(); |
1348 view_->UpdateNotificationArea(); | 1359 view_->UpdateNotificationArea(); |
1349 } | 1360 } |
1350 | 1361 |
1351 //////////////////////////////////////////////////////////////////////////////// | 1362 //////////////////////////////////////////////////////////////////////////////// |
1352 | 1363 |
1353 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 1364 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1386 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { | 1397 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { |
1387 return &wallet_client_; | 1398 return &wallet_client_; |
1388 } | 1399 } |
1389 | 1400 |
1390 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 1401 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
1391 return account_chooser_model_.WalletIsSelected(); | 1402 return account_chooser_model_.WalletIsSelected(); |
1392 } | 1403 } |
1393 | 1404 |
1394 void AutofillDialogControllerImpl::DisableWallet() { | 1405 void AutofillDialogControllerImpl::DisableWallet() { |
1395 signin_helper_.reset(); | 1406 signin_helper_.reset(); |
1396 current_username_.clear(); | |
1397 account_chooser_model_.SetHadWalletError(); | 1407 account_chooser_model_.SetHadWalletError(); |
1398 GetWalletClient()->CancelPendingRequests(); | 1408 GetWalletClient()->CancelPendingRequests(); |
1399 } | 1409 } |
1400 | 1410 |
1401 void AutofillDialogControllerImpl::OnWalletSigninError() { | 1411 void AutofillDialogControllerImpl::OnWalletSigninError() { |
1402 signin_helper_.reset(); | 1412 signin_helper_.reset(); |
1403 current_username_.clear(); | |
1404 account_chooser_model_.SetHadWalletSigninError(); | 1413 account_chooser_model_.SetHadWalletSigninError(); |
1405 GetWalletClient()->CancelPendingRequests(); | 1414 GetWalletClient()->CancelPendingRequests(); |
1406 } | 1415 } |
1407 | 1416 |
1408 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1417 bool AutofillDialogControllerImpl::IsFirstRun() const { |
1409 PrefService* prefs = profile_->GetPrefs(); | 1418 PrefService* prefs = profile_->GetPrefs(); |
1410 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); | 1419 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); |
1411 } | 1420 } |
1412 | 1421 |
1413 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { | 1422 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1842 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 1851 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
1843 } | 1852 } |
1844 | 1853 |
1845 // Has Wallet items. | 1854 // Has Wallet items. |
1846 return has_autofill_profiles ? | 1855 return has_autofill_profiles ? |
1847 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 1856 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
1848 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 1857 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
1849 } | 1858 } |
1850 | 1859 |
1851 } // namespace autofill | 1860 } // namespace autofill |
OLD | NEW |