Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
index 470ed592422b101c95b04f39881bd880615ef62e..697d8241c192b18a084603d9a5b6045210e8e803 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
@@ -464,11 +464,12 @@ bool AutofillDialogControllerImpl::ShouldShowSpinner() const { |
} |
string16 AutofillDialogControllerImpl::AccountChooserText() const { |
+ // TODO(aruslan): this should be l10n "Not using Google Wallet". |
if (!account_chooser_model_.WalletIsSelected()) |
return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); |
if (SignedInState() == SIGNED_IN) |
- return UTF8ToUTF16(current_username_); |
+ return account_chooser_model_.GetActiveWalletAccountName(); |
// In this case, the account chooser should be showing the signin link. |
return string16(); |
@@ -535,11 +536,14 @@ void AutofillDialogControllerImpl::GetWalletItems() { |
source_url_, std::vector<wallet::WalletClient::RiskCapability>()); |
} |
-void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
+void AutofillDialogControllerImpl::SignedInStateUpdated() { |
+ if (!account_chooser_model_.WalletIsSelected()) |
+ return; |
+ |
switch (SignedInState()) { |
case SIGNED_IN: |
// Start fetching the user name if we don't know it yet. |
- if (current_username_.empty()) { |
+ if (account_chooser_model_.GetActiveWalletAccountName().empty()) { |
signin_helper_.reset(new wallet::WalletSigninHelper( |
this, profile_->GetRequestContext())); |
signin_helper_->StartUserNameFetch(); |
@@ -547,24 +551,28 @@ void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
break; |
case REQUIRES_SIGN_IN: |
- // TODO(aruslan): automatic sign-in? |
+ // Switch to the local account and refresh the dialog. |
+ OnWalletSigninError(); |
break; |
case REQUIRES_PASSIVE_SIGN_IN: |
// Attempt to passively sign in the user. |
- current_username_.clear(); |
+ account_chooser_model_.ClearActiveWalletAccountName(); |
signin_helper_.reset(new wallet::WalletSigninHelper( |
- this, profile_->GetRequestContext())); |
+ this, |
+ profile_->GetRequestContext())); |
signin_helper_->StartPassiveSignin(); |
break; |
case REQUIRES_RESPONSE: |
break; |
} |
+} |
+void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
+ SignedInStateUpdated(); |
SuggestionsUpdated(); |
- view_->UpdateAccountChooser(); |
- view_->UpdateNotificationArea(); |
+ UpdateAccountChooserView(); |
// On the first successful response, compute the initial user state metric. |
if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) |
@@ -573,7 +581,6 @@ void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
void AutofillDialogControllerImpl::OnWalletSigninError() { |
signin_helper_.reset(); |
- current_username_.clear(); |
account_chooser_model_.SetHadWalletSigninError(); |
GetWalletClient()->CancelRequests(); |
} |
@@ -669,9 +676,9 @@ ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
} |
ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { |
- // When paying with wallet, but not signed in, there is no menu, just a |
- // sign in link. |
- if (account_chooser_model_.WalletIsSelected() && SignedInState() != SIGNED_IN) |
+ // If the only choice is "Pay without the wallet", there is no menu, just |
+ // a sign in link. |
+ if (!account_chooser_model_.HasAccountsToChoose()) |
return NULL; |
return &account_chooser_model_; |
@@ -684,8 +691,10 @@ gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { |
} |
gfx::Image icon; |
- account_chooser_model_.GetIconAt(account_chooser_model_.checked_item(), |
- &icon); |
+ account_chooser_model_.GetIconAt( |
+ account_chooser_model_.GetIndexOfCommandId( |
+ account_chooser_model_.checked_item()), |
+ &icon); |
return icon; |
} |
@@ -1163,6 +1172,7 @@ std::vector<DialogNotification> |
} |
void AutofillDialogControllerImpl::StartSignInFlow() { |
+ DCHECK(!IsPayingWithWallet()); |
DCHECK(registrar_.IsEmpty()); |
content::Source<content::NavigationController> source(view_->ShowSignIn()); |
@@ -1178,7 +1188,7 @@ void AutofillDialogControllerImpl::EndSignInFlow() { |
void AutofillDialogControllerImpl::NotificationCheckboxStateChanged( |
DialogNotification::Type type, bool checked) { |
if (type == DialogNotification::WALLET_USAGE_CONFIRMATION) { |
- int command = checked ? AccountChooserModel::kWalletItemId : |
+ int command = checked ? AccountChooserModel::kActiveWalletItemId : |
AccountChooserModel::kAutofillItemId; |
account_chooser_model_.ExecuteCommand(command, 0); |
} |
@@ -1318,8 +1328,14 @@ void AutofillDialogControllerImpl::Observe( |
content::Details<content::LoadCommittedDetails>(details).ptr(); |
if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
EndSignInFlow(); |
- if (account_chooser_model_.WalletIsSelected()) |
+ |
+ if (account_chooser_model_.WalletIsSelected()) { |
GetWalletItems(); |
+ } else { |
+ // The sign-in flow means that the user implicitly switched the account |
+ // to the Wallet. This will trigger AccountChoiceChanged. |
+ account_chooser_model_.ForceSelectWalletAccount(); |
+ } |
} |
} |
@@ -1381,14 +1397,16 @@ void AutofillDialogControllerImpl::OnDidGetFullWallet( |
void AutofillDialogControllerImpl::OnPassiveSigninSuccess( |
const std::string& username) { |
- current_username_ = username; |
+ account_chooser_model_.SetActiveWalletAccountName( |
+ UTF8ToUTF16(username)); |
signin_helper_.reset(); |
GetWalletItems(); |
} |
void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
const std::string& username) { |
- current_username_ = username; |
+ account_chooser_model_.SetActiveWalletAccountName( |
+ UTF8ToUTF16(username)); |
signin_helper_.reset(); |
OnWalletOrSigninUpdate(); |
} |
@@ -1499,6 +1517,9 @@ void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
SuggestionsUpdated(); |
} |
+//////////////////////////////////////////////////////////////////////////////// |
+// AccountChooserModelDelegate implementation. |
+ |
void AutofillDialogControllerImpl::AccountChoiceChanged() { |
// Whenever the user changes the account, all manual inputs should be reset. |
ResetManualInputForSection(SECTION_EMAIL); |
@@ -1512,11 +1533,15 @@ void AutofillDialogControllerImpl::AccountChoiceChanged() { |
SetIsSubmitting(false); |
+ // TODO(aruslan): integrate an automatic sign-in. |
if (account_chooser_model_.WalletIsSelected() && !wallet_items_) |
GetWalletItems(); |
SuggestionsUpdated(); |
+ UpdateAccountChooserView(); |
+} |
+void AutofillDialogControllerImpl::UpdateAccountChooserView() { |
if (view_) { |
view_->UpdateAccountChooser(); |
view_->UpdateNotificationArea(); |
@@ -1609,7 +1634,6 @@ bool AutofillDialogControllerImpl::IsFirstRun() const { |
void AutofillDialogControllerImpl::DisableWallet() { |
signin_helper_.reset(); |
- current_username_.clear(); |
account_chooser_model_.SetHadWalletError(); |
GetWalletClient()->CancelRequests(); |
wallet_items_.reset(); |
@@ -1627,6 +1651,12 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
if (IsPayingWithWallet()) { |
// TODO(estade): fill in the email address. |
Evan Stade
2013/04/11 19:27:45
you should be able to delete this TODO
aruslan
2013/04/12 00:46:02
Done.
|
+ std::vector<string16> emails(account_chooser_model_.GetAllAccounts()); |
+ std::sort(emails.begin(), emails.end()); |
+ for (size_t i = 0; i < emails.size(); ++i) { |
+ if (!emails[i].empty()) |
+ suggested_email_.AddKeyedItem(base::IntToString(i), emails[i]); |
Evan Stade
2013/04/11 19:27:45
this doesn't make that much sense to me, why sugge
aruslan
2013/04/12 00:46:02
Done; I added your comment to http://crbug.com/223
|
+ } |
const std::vector<wallet::Address*>& addresses = |
wallet_items_->addresses(); |