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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (IsCreditCardType(it->first->type)) { | 185 if (IsCreditCardType(it->first->type)) { |
186 if (card) | 186 if (card) |
187 card->SetRawInfo(it->first->type, trimmed); | 187 card->SetRawInfo(it->first->type, trimmed); |
188 } else if (profile) { | 188 } else if (profile) { |
189 profile->SetRawInfo(it->first->type, trimmed); | 189 profile->SetRawInfo(it->first->type, trimmed); |
190 } | 190 } |
191 } | 191 } |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 // Returns the containing window for the given |web_contents|. The containing | 195 // Returns the containing window for the given |web_contents|. The containing |
196 // window might be a browser window for a Chrome tab, or it might be a shell | 196 // window might be a browser window for a Chrome tab, or it might be a shell |
197 // window for a platform app. | 197 // window for a platform app. |
198 BaseWindow* GetBaseWindowForWebContents( | 198 BaseWindow* GetBaseWindowForWebContents( |
199 const content::WebContents* web_contents) { | 199 const content::WebContents* web_contents) { |
200 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 200 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
201 if (browser) | 201 if (browser) |
202 return browser->window(); | 202 return browser->window(); |
203 | 203 |
204 gfx::NativeWindow native_window = | 204 gfx::NativeWindow native_window = |
205 web_contents->GetView()->GetTopLevelNativeWindow(); | 205 web_contents->GetView()->GetTopLevelNativeWindow(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 459 |
460 return SIGNED_IN; | 460 return SIGNED_IN; |
461 } | 461 } |
462 | 462 |
463 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { | 463 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { |
464 return account_chooser_model_.WalletIsSelected() && | 464 return account_chooser_model_.WalletIsSelected() && |
465 SignedInState() == REQUIRES_RESPONSE; | 465 SignedInState() == REQUIRES_RESPONSE; |
466 } | 466 } |
467 | 467 |
468 string16 AutofillDialogControllerImpl::AccountChooserText() const { | 468 string16 AutofillDialogControllerImpl::AccountChooserText() const { |
| 469 // TODO(aruslan): this should be l10n "Not using Google Wallet". |
469 if (!account_chooser_model_.WalletIsSelected()) | 470 if (!account_chooser_model_.WalletIsSelected()) |
470 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); | 471 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); |
471 | 472 |
472 if (SignedInState() == SIGNED_IN) | 473 if (SignedInState() == SIGNED_IN) |
473 return UTF8ToUTF16(current_username_); | 474 return account_chooser_model_.active_wallet_account_name(); |
474 | 475 |
475 // In this case, the account chooser should be showing the signin link. | 476 // In this case, the account chooser should be showing the signin link. |
476 return string16(); | 477 return string16(); |
477 } | 478 } |
478 | 479 |
479 string16 AutofillDialogControllerImpl::SignInLinkText() const { | 480 string16 AutofillDialogControllerImpl::SignInLinkText() const { |
480 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SIGN_IN); | 481 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SIGN_IN); |
481 } | 482 } |
482 | 483 |
483 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const { | 484 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 529 |
529 bool AutofillDialogControllerImpl::IsSubmitPausedOn( | 530 bool AutofillDialogControllerImpl::IsSubmitPausedOn( |
530 wallet::RequiredAction required_action) const { | 531 wallet::RequiredAction required_action) const { |
531 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); | 532 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); |
532 } | 533 } |
533 | 534 |
534 void AutofillDialogControllerImpl::GetWalletItems() { | 535 void AutofillDialogControllerImpl::GetWalletItems() { |
535 GetWalletClient()->GetWalletItems(source_url_); | 536 GetWalletClient()->GetWalletItems(source_url_); |
536 } | 537 } |
537 | 538 |
538 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { | 539 void AutofillDialogControllerImpl::SignedInStateUpdated() { |
| 540 if (!account_chooser_model_.WalletIsSelected()) |
| 541 return; |
| 542 |
539 switch (SignedInState()) { | 543 switch (SignedInState()) { |
540 case SIGNED_IN: | 544 case SIGNED_IN: |
541 // Start fetching the user name if we don't know it yet. | 545 // Start fetching the user name if we don't know it yet. |
542 if (current_username_.empty()) { | 546 if (account_chooser_model_.active_wallet_account_name().empty()) { |
543 signin_helper_.reset(new wallet::WalletSigninHelper( | 547 signin_helper_.reset(new wallet::WalletSigninHelper( |
544 this, profile_->GetRequestContext())); | 548 this, profile_->GetRequestContext())); |
545 signin_helper_->StartUserNameFetch(); | 549 signin_helper_->StartUserNameFetch(); |
546 } | 550 } |
547 break; | 551 break; |
548 | 552 |
549 case REQUIRES_SIGN_IN: | 553 case REQUIRES_SIGN_IN: |
550 // TODO(aruslan): automatic sign-in? | 554 // Switch to the local account and refresh the dialog. |
| 555 OnWalletSigninError(); |
551 break; | 556 break; |
552 | 557 |
553 case REQUIRES_PASSIVE_SIGN_IN: | 558 case REQUIRES_PASSIVE_SIGN_IN: |
554 // Attempt to passively sign in the user. | 559 // Attempt to passively sign in the user. |
555 current_username_.clear(); | 560 DCHECK(!signin_helper_); |
| 561 account_chooser_model_.ClearActiveWalletAccountName(); |
556 signin_helper_.reset(new wallet::WalletSigninHelper( | 562 signin_helper_.reset(new wallet::WalletSigninHelper( |
557 this, profile_->GetRequestContext())); | 563 this, |
| 564 profile_->GetRequestContext())); |
558 signin_helper_->StartPassiveSignin(); | 565 signin_helper_->StartPassiveSignin(); |
559 break; | 566 break; |
560 | 567 |
561 case REQUIRES_RESPONSE: | 568 case REQUIRES_RESPONSE: |
562 break; | 569 break; |
563 } | 570 } |
| 571 } |
564 | 572 |
| 573 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { |
| 574 SignedInStateUpdated(); |
565 SuggestionsUpdated(); | 575 SuggestionsUpdated(); |
566 view_->UpdateAccountChooser(); | 576 UpdateAccountChooserView(); |
567 view_->UpdateNotificationArea(); | |
568 | 577 |
569 // On the first successful response, compute the initial user state metric. | 578 // On the first successful response, compute the initial user state metric. |
570 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) | 579 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) |
571 initial_user_state_ = GetInitialUserState(); | 580 initial_user_state_ = GetInitialUserState(); |
572 } | 581 } |
573 | 582 |
574 void AutofillDialogControllerImpl::OnWalletSigninError() { | 583 void AutofillDialogControllerImpl::OnWalletSigninError() { |
575 signin_helper_.reset(); | 584 signin_helper_.reset(); |
576 current_username_.clear(); | |
577 account_chooser_model_.SetHadWalletSigninError(); | 585 account_chooser_model_.SetHadWalletSigninError(); |
578 GetWalletClient()->CancelRequests(); | 586 GetWalletClient()->CancelRequests(); |
579 } | 587 } |
580 | 588 |
581 void AutofillDialogControllerImpl::EnsureLegalDocumentsText() { | 589 void AutofillDialogControllerImpl::EnsureLegalDocumentsText() { |
582 if (!wallet_items_ || wallet_items_->legal_documents().empty()) | 590 if (!wallet_items_ || wallet_items_->legal_documents().empty()) |
583 return; | 591 return; |
584 | 592 |
585 // The text has already been constructed, no need to recompute. | 593 // The text has already been constructed, no need to recompute. |
586 if (!legal_documents_text_.empty()) | 594 if (!legal_documents_text_.empty()) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 return NULL; | 670 return NULL; |
663 } | 671 } |
664 } | 672 } |
665 | 673 |
666 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 674 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
667 DialogSection section) { | 675 DialogSection section) { |
668 return SuggestionsMenuModelForSection(section); | 676 return SuggestionsMenuModelForSection(section); |
669 } | 677 } |
670 | 678 |
671 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { | 679 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { |
672 // When paying with wallet, but not signed in, there is no menu, just a | 680 // If there were unrecoverable Wallet errors, or if there are choices other |
673 // sign in link. | 681 // than "Pay without the wallet", show the full menu. |
674 if (account_chooser_model_.WalletIsSelected() && SignedInState() != SIGNED_IN) | 682 if (account_chooser_model_.had_wallet_error() || |
675 return NULL; | 683 account_chooser_model_.HasAccountsToChoose()) { |
| 684 return &account_chooser_model_; |
| 685 } |
676 | 686 |
677 return &account_chooser_model_; | 687 // Otherwise, there is no menu, just a sign in link. |
| 688 return NULL; |
678 } | 689 } |
679 | 690 |
680 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { | 691 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { |
681 if (!MenuModelForAccountChooser()) { | 692 if (!MenuModelForAccountChooser()) { |
682 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 693 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
683 IDR_WALLET_ICON); | 694 IDR_WALLET_ICON); |
684 } | 695 } |
685 | 696 |
686 gfx::Image icon; | 697 gfx::Image icon; |
687 account_chooser_model_.GetIconAt(account_chooser_model_.checked_item(), | 698 account_chooser_model_.GetIconAt( |
688 &icon); | 699 account_chooser_model_.GetIndexOfCommandId( |
| 700 account_chooser_model_.checked_item()), |
| 701 &icon); |
689 return icon; | 702 return icon; |
690 } | 703 } |
691 | 704 |
692 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) | 705 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) |
693 const { | 706 const { |
694 switch (section) { | 707 switch (section) { |
695 case SECTION_EMAIL: | 708 case SECTION_EMAIL: |
696 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); | 709 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); |
697 case SECTION_CC: | 710 case SECTION_CC: |
698 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); | 711 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 803 |
791 if (IsPayingWithWallet()) { | 804 if (IsPayingWithWallet()) { |
792 int index; | 805 int index; |
793 bool success = base::StringToInt(item_key, &index); | 806 bool success = base::StringToInt(item_key, &index); |
794 DCHECK(success); | 807 DCHECK(success); |
795 | 808 |
796 if (section == SECTION_CC_BILLING) { | 809 if (section == SECTION_CC_BILLING) { |
797 return scoped_ptr<DataModelWrapper>( | 810 return scoped_ptr<DataModelWrapper>( |
798 new WalletInstrumentWrapper(wallet_items_->instruments()[index])); | 811 new WalletInstrumentWrapper(wallet_items_->instruments()[index])); |
799 } | 812 } |
| 813 |
| 814 if (section == SECTION_SHIPPING) { |
| 815 return scoped_ptr<DataModelWrapper>( |
| 816 new WalletAddressWrapper(wallet_items_->addresses()[index])); |
| 817 } |
| 818 |
800 // TODO(dbeam): should SECTION_EMAIL get here? http://crbug.com/223923 | 819 // TODO(dbeam): should SECTION_EMAIL get here? http://crbug.com/223923 |
801 return scoped_ptr<DataModelWrapper>( | 820 return scoped_ptr<DataModelWrapper>(); |
802 new WalletAddressWrapper(wallet_items_->addresses()[index])); | |
803 } | 821 } |
804 | 822 |
805 if (section == SECTION_CC) { | 823 if (section == SECTION_CC) { |
806 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); | 824 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
807 DCHECK(card); | 825 DCHECK(card); |
808 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); | 826 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); |
809 } | 827 } |
810 | 828 |
811 // Calculate the variant by looking at how many items come from the same | 829 // Calculate the variant by looking at how many items come from the same |
812 // FormGroup. | 830 // FormGroup. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 if (had_autocheckout_error_) { | 1177 if (had_autocheckout_error_) { |
1160 notifications.push_back(DialogNotification( | 1178 notifications.push_back(DialogNotification( |
1161 DialogNotification::AUTOCHECKOUT_ERROR, | 1179 DialogNotification::AUTOCHECKOUT_ERROR, |
1162 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); | 1180 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); |
1163 } | 1181 } |
1164 | 1182 |
1165 return notifications; | 1183 return notifications; |
1166 } | 1184 } |
1167 | 1185 |
1168 void AutofillDialogControllerImpl::StartSignInFlow() { | 1186 void AutofillDialogControllerImpl::StartSignInFlow() { |
| 1187 DCHECK(!IsPayingWithWallet()); |
1169 DCHECK(registrar_.IsEmpty()); | 1188 DCHECK(registrar_.IsEmpty()); |
1170 | 1189 |
1171 content::Source<content::NavigationController> source(view_->ShowSignIn()); | 1190 content::Source<content::NavigationController> source(view_->ShowSignIn()); |
1172 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | 1191 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); |
1173 | 1192 |
1174 GetMetricLogger().LogDialogUiEvent( | 1193 GetMetricLogger().LogDialogUiEvent( |
1175 dialog_type_, AutofillMetrics::DIALOG_UI_SIGNIN_SHOWN); | 1194 dialog_type_, AutofillMetrics::DIALOG_UI_SIGNIN_SHOWN); |
1176 } | 1195 } |
1177 | 1196 |
1178 void AutofillDialogControllerImpl::EndSignInFlow() { | 1197 void AutofillDialogControllerImpl::EndSignInFlow() { |
1179 DCHECK(!registrar_.IsEmpty()); | 1198 DCHECK(!registrar_.IsEmpty()); |
1180 registrar_.RemoveAll(); | 1199 registrar_.RemoveAll(); |
1181 view_->HideSignIn(); | 1200 view_->HideSignIn(); |
1182 } | 1201 } |
1183 | 1202 |
1184 void AutofillDialogControllerImpl::NotificationCheckboxStateChanged( | 1203 void AutofillDialogControllerImpl::NotificationCheckboxStateChanged( |
1185 DialogNotification::Type type, bool checked) { | 1204 DialogNotification::Type type, bool checked) { |
1186 if (type == DialogNotification::WALLET_USAGE_CONFIRMATION) { | 1205 if (type == DialogNotification::WALLET_USAGE_CONFIRMATION) { |
1187 int command = checked ? AccountChooserModel::kWalletItemId : | 1206 if (checked) |
1188 AccountChooserModel::kAutofillItemId; | 1207 account_chooser_model_.SelectActiveWalletAccount(); |
1189 account_chooser_model_.ExecuteCommand(command, 0); | 1208 else |
| 1209 account_chooser_model_.SelectUseAutofill(); |
1190 } | 1210 } |
1191 } | 1211 } |
1192 | 1212 |
1193 void AutofillDialogControllerImpl::LegalDocumentLinkClicked( | 1213 void AutofillDialogControllerImpl::LegalDocumentLinkClicked( |
1194 const ui::Range& range) { | 1214 const ui::Range& range) { |
1195 #if !defined(OS_ANDROID) | 1215 #if !defined(OS_ANDROID) |
1196 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { | 1216 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { |
1197 if (legal_document_link_ranges_[i] == range) { | 1217 if (legal_document_link_ranges_[i] == range) { |
1198 chrome::NavigateParams params( | 1218 chrome::NavigateParams params( |
1199 chrome::FindBrowserWithWebContents(web_contents()), | 1219 chrome::FindBrowserWithWebContents(web_contents()), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 | 1334 |
1315 void AutofillDialogControllerImpl::Observe( | 1335 void AutofillDialogControllerImpl::Observe( |
1316 int type, | 1336 int type, |
1317 const content::NotificationSource& source, | 1337 const content::NotificationSource& source, |
1318 const content::NotificationDetails& details) { | 1338 const content::NotificationDetails& details) { |
1319 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 1339 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
1320 content::LoadCommittedDetails* load_details = | 1340 content::LoadCommittedDetails* load_details = |
1321 content::Details<content::LoadCommittedDetails>(details).ptr(); | 1341 content::Details<content::LoadCommittedDetails>(details).ptr(); |
1322 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 1342 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
1323 EndSignInFlow(); | 1343 EndSignInFlow(); |
1324 if (account_chooser_model_.WalletIsSelected()) | 1344 |
| 1345 if (account_chooser_model_.WalletIsSelected()) { |
1325 GetWalletItems(); | 1346 GetWalletItems(); |
| 1347 } else { |
| 1348 // The sign-in flow means that the user implicitly switched the account |
| 1349 // to the Wallet. This will trigger AccountChoiceChanged. |
| 1350 account_chooser_model_.SelectActiveWalletAccount(); |
| 1351 } |
1326 } | 1352 } |
1327 } | 1353 } |
1328 | 1354 |
1329 //////////////////////////////////////////////////////////////////////////////// | 1355 //////////////////////////////////////////////////////////////////////////////// |
1330 // SuggestionsMenuModelDelegate implementation. | 1356 // SuggestionsMenuModelDelegate implementation. |
1331 | 1357 |
1332 void AutofillDialogControllerImpl::SuggestionItemSelected( | 1358 void AutofillDialogControllerImpl::SuggestionItemSelected( |
1333 const SuggestionsMenuModel& model) { | 1359 const SuggestionsMenuModel& model) { |
1334 const DialogSection section = SectionForSuggestionsMenuModel(model); | 1360 const DialogSection section = SectionForSuggestionsMenuModel(model); |
1335 EditCancelledForSection(section); | 1361 EditCancelledForSection(section); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 return; | 1405 return; |
1380 } | 1406 } |
1381 | 1407 |
1382 SuggestionsUpdated(); | 1408 SuggestionsUpdated(); |
1383 view_->UpdateNotificationArea(); | 1409 view_->UpdateNotificationArea(); |
1384 view_->UpdateButtonStrip(); | 1410 view_->UpdateButtonStrip(); |
1385 } | 1411 } |
1386 | 1412 |
1387 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( | 1413 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( |
1388 const std::string& username) { | 1414 const std::string& username) { |
1389 current_username_ = username; | 1415 const string16 username16 = UTF8ToUTF16(username); |
1390 signin_helper_.reset(); | 1416 signin_helper_.reset(); |
| 1417 account_chooser_model_.SetActiveWalletAccountName(username16); |
1391 GetWalletItems(); | 1418 GetWalletItems(); |
1392 } | 1419 } |
1393 | 1420 |
1394 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( | 1421 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
1395 const std::string& username) { | 1422 const std::string& username) { |
1396 current_username_ = username; | 1423 const string16 username16 = UTF8ToUTF16(username); |
1397 signin_helper_.reset(); | 1424 signin_helper_.reset(); |
| 1425 account_chooser_model_.SetActiveWalletAccountName(username16); |
1398 OnWalletOrSigninUpdate(); | 1426 OnWalletOrSigninUpdate(); |
1399 } | 1427 } |
1400 | 1428 |
1401 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( | 1429 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( |
1402 const std::string& username) { | 1430 const std::string& username) { |
1403 // TODO(aruslan): automatic sign-in. | |
1404 NOTIMPLEMENTED(); | 1431 NOTIMPLEMENTED(); |
1405 } | 1432 } |
1406 | 1433 |
1407 void AutofillDialogControllerImpl::OnPassiveSigninFailure( | 1434 void AutofillDialogControllerImpl::OnPassiveSigninFailure( |
1408 const GoogleServiceAuthError& error) { | 1435 const GoogleServiceAuthError& error) { |
1409 // TODO(aruslan): report an error. | 1436 // TODO(aruslan): report an error. |
1410 LOG(ERROR) << "failed to passively sign-in: " << error.ToString(); | 1437 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); |
1411 OnWalletSigninError(); | 1438 OnWalletSigninError(); |
1412 } | 1439 } |
1413 | 1440 |
1414 void AutofillDialogControllerImpl::OnUserNameFetchFailure( | 1441 void AutofillDialogControllerImpl::OnUserNameFetchFailure( |
1415 const GoogleServiceAuthError& error) { | 1442 const GoogleServiceAuthError& error) { |
1416 // TODO(aruslan): report an error. | 1443 // TODO(aruslan): report an error. |
1417 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); | 1444 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); |
1418 OnWalletSigninError(); | 1445 OnWalletSigninError(); |
1419 } | 1446 } |
1420 | 1447 |
1421 void AutofillDialogControllerImpl::OnAutomaticSigninFailure( | 1448 void AutofillDialogControllerImpl::OnAutomaticSigninFailure( |
1422 const GoogleServiceAuthError& error) { | 1449 const GoogleServiceAuthError& error) { |
1423 // TODO(aruslan): automatic sign-in failure. | 1450 // TODO(aruslan): report an error. |
1424 NOTIMPLEMENTED(); | 1451 LOG(ERROR) << "failed to automatically sign in: " << error.ToString(); |
| 1452 OnWalletSigninError(); |
1425 } | 1453 } |
1426 | 1454 |
1427 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 1455 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
1428 scoped_ptr<wallet::WalletItems> wallet_items) { | 1456 scoped_ptr<wallet::WalletItems> wallet_items) { |
1429 DCHECK(account_chooser_model_.WalletIsSelected()); | 1457 DCHECK(account_chooser_model_.WalletIsSelected()); |
1430 | |
1431 legal_documents_text_.clear(); | 1458 legal_documents_text_.clear(); |
1432 legal_document_link_ranges_.clear(); | 1459 legal_document_link_ranges_.clear(); |
1433 | 1460 |
1434 // TODO(dbeam): verify items support kCartCurrency? http://crbug.com/232952 | 1461 // TODO(dbeam): verify items support kCartCurrency? http://crbug.com/232952 |
1435 wallet_items_ = wallet_items.Pass(); | 1462 wallet_items_ = wallet_items.Pass(); |
1436 OnWalletOrSigninUpdate(); | 1463 OnWalletOrSigninUpdate(); |
1437 } | 1464 } |
1438 | 1465 |
1439 void AutofillDialogControllerImpl::OnDidSaveAddress( | 1466 void AutofillDialogControllerImpl::OnDidSaveAddress( |
1440 const std::string& address_id, | 1467 const std::string& address_id, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 DisableWallet(); | 1524 DisableWallet(); |
1498 } | 1525 } |
1499 | 1526 |
1500 //////////////////////////////////////////////////////////////////////////////// | 1527 //////////////////////////////////////////////////////////////////////////////// |
1501 // PersonalDataManagerObserver implementation. | 1528 // PersonalDataManagerObserver implementation. |
1502 | 1529 |
1503 void AutofillDialogControllerImpl::OnPersonalDataChanged() { | 1530 void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
1504 SuggestionsUpdated(); | 1531 SuggestionsUpdated(); |
1505 } | 1532 } |
1506 | 1533 |
| 1534 //////////////////////////////////////////////////////////////////////////////// |
| 1535 // AccountChooserModelDelegate implementation. |
| 1536 |
1507 void AutofillDialogControllerImpl::AccountChoiceChanged() { | 1537 void AutofillDialogControllerImpl::AccountChoiceChanged() { |
1508 // Whenever the user changes the account, all manual inputs should be reset. | 1538 // Whenever the user changes the account, all manual inputs should be reset. |
1509 ResetManualInputForSection(SECTION_EMAIL); | 1539 ResetManualInputForSection(SECTION_EMAIL); |
1510 ResetManualInputForSection(SECTION_CC); | 1540 ResetManualInputForSection(SECTION_CC); |
1511 ResetManualInputForSection(SECTION_BILLING); | 1541 ResetManualInputForSection(SECTION_BILLING); |
1512 ResetManualInputForSection(SECTION_CC_BILLING); | 1542 ResetManualInputForSection(SECTION_CC_BILLING); |
1513 ResetManualInputForSection(SECTION_SHIPPING); | 1543 ResetManualInputForSection(SECTION_SHIPPING); |
1514 | 1544 |
1515 if (is_submitting_) | 1545 if (is_submitting_) |
1516 GetWalletClient()->CancelRequests(); | 1546 GetWalletClient()->CancelRequests(); |
1517 | 1547 |
1518 SetIsSubmitting(false); | 1548 SetIsSubmitting(false); |
1519 | 1549 |
1520 if (account_chooser_model_.WalletIsSelected() && !wallet_items_) | 1550 if (!signin_helper_ && account_chooser_model_.WalletIsSelected()) { |
1521 GetWalletItems(); | 1551 if (account_chooser_model_.IsActiveWalletAccountSelected()) { |
| 1552 // If the user has chosen an already active Wallet account, and we don't |
| 1553 // have the Wallet items, an attempt to fetch the Wallet data is made to |
| 1554 // see if the user is still signed in. This will trigger a passive sign-in |
| 1555 // if required. |
| 1556 if (!wallet_items_) |
| 1557 GetWalletItems(); |
| 1558 else |
| 1559 SignedInStateUpdated(); |
| 1560 } else { |
| 1561 // TODO(aruslan): trigger the automatic sign-in process. |
| 1562 LOG(ERROR) << "failed to initiate an automatic sign-in"; |
| 1563 OnWalletSigninError(); |
| 1564 } |
| 1565 } |
1522 | 1566 |
1523 SuggestionsUpdated(); | 1567 SuggestionsUpdated(); |
| 1568 UpdateAccountChooserView(); |
| 1569 } |
1524 | 1570 |
| 1571 void AutofillDialogControllerImpl::UpdateAccountChooserView() { |
1525 if (view_) { | 1572 if (view_) { |
1526 view_->UpdateAccountChooser(); | 1573 view_->UpdateAccountChooser(); |
1527 view_->UpdateNotificationArea(); | 1574 view_->UpdateNotificationArea(); |
1528 } | 1575 } |
1529 } | 1576 } |
1530 | 1577 |
1531 //////////////////////////////////////////////////////////////////////////////// | 1578 //////////////////////////////////////////////////////////////////////////////// |
1532 | 1579 |
1533 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 1580 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
1534 const content::NativeWebKeyboardEvent& event) { | 1581 const content::NativeWebKeyboardEvent& event) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 return account_chooser_model_.WalletIsSelected() && | 1655 return account_chooser_model_.WalletIsSelected() && |
1609 SignedInState() == SIGNED_IN; | 1656 SignedInState() == SIGNED_IN; |
1610 } | 1657 } |
1611 | 1658 |
1612 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1659 bool AutofillDialogControllerImpl::IsFirstRun() const { |
1613 return is_first_run_; | 1660 return is_first_run_; |
1614 } | 1661 } |
1615 | 1662 |
1616 void AutofillDialogControllerImpl::DisableWallet() { | 1663 void AutofillDialogControllerImpl::DisableWallet() { |
1617 signin_helper_.reset(); | 1664 signin_helper_.reset(); |
1618 current_username_.clear(); | |
1619 account_chooser_model_.SetHadWalletError(); | 1665 account_chooser_model_.SetHadWalletError(); |
1620 GetWalletClient()->CancelRequests(); | 1666 GetWalletClient()->CancelRequests(); |
1621 wallet_items_.reset(); | 1667 wallet_items_.reset(); |
1622 full_wallet_.reset(); | 1668 full_wallet_.reset(); |
1623 SetIsSubmitting(false); | 1669 SetIsSubmitting(false); |
1624 } | 1670 } |
1625 | 1671 |
1626 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 1672 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
1627 suggested_email_.Reset(); | 1673 suggested_email_.Reset(); |
1628 suggested_cc_.Reset(); | 1674 suggested_cc_.Reset(); |
1629 suggested_billing_.Reset(); | 1675 suggested_billing_.Reset(); |
1630 suggested_cc_billing_.Reset(); | 1676 suggested_cc_billing_.Reset(); |
1631 suggested_shipping_.Reset(); | 1677 suggested_shipping_.Reset(); |
1632 HidePopup(); | 1678 HidePopup(); |
1633 | 1679 |
1634 if (IsPayingWithWallet()) { | 1680 if (IsPayingWithWallet()) { |
1635 // TODO(estade): fill in the email address. | 1681 if (!account_chooser_model_.active_wallet_account_name().empty()) { |
| 1682 suggested_email_.AddKeyedItem( |
| 1683 base::IntToString(0), |
| 1684 account_chooser_model_.active_wallet_account_name()); |
| 1685 } |
1636 | 1686 |
1637 const std::vector<wallet::Address*>& addresses = | 1687 const std::vector<wallet::Address*>& addresses = |
1638 wallet_items_->addresses(); | 1688 wallet_items_->addresses(); |
1639 for (size_t i = 0; i < addresses.size(); ++i) { | 1689 for (size_t i = 0; i < addresses.size(); ++i) { |
1640 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954 | 1690 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954 |
1641 suggested_shipping_.AddKeyedItemWithSublabel( | 1691 suggested_shipping_.AddKeyedItemWithSublabel( |
1642 base::IntToString(i), | 1692 base::IntToString(i), |
1643 addresses[i]->DisplayName(), | 1693 addresses[i]->DisplayName(), |
1644 addresses[i]->DisplayNameDetail()); | 1694 addresses[i]->DisplayNameDetail()); |
1645 } | 1695 } |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 DCHECK(!section_editing_state_[section]); | 2209 DCHECK(!section_editing_state_[section]); |
2160 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); | 2210 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); |
2161 } | 2211 } |
2162 | 2212 |
2163 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); | 2213 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); |
2164 } | 2214 } |
2165 | 2215 |
2166 AutofillMetrics::DialogInitialUserStateMetric | 2216 AutofillMetrics::DialogInitialUserStateMetric |
2167 AutofillDialogControllerImpl::GetInitialUserState() const { | 2217 AutofillDialogControllerImpl::GetInitialUserState() const { |
2168 // Consider a user to be an Autofill user if the user has any credit cards | 2218 // Consider a user to be an Autofill user if the user has any credit cards |
2169 // or addresses saved. Check that the item count is greater than 1 because | 2219 // or addresses saved. Check that the item count is greater than 1 because |
2170 // an "empty" menu still has the "add new" menu item. | 2220 // an "empty" menu still has the "add new" menu item. |
2171 const bool has_autofill_profiles = | 2221 const bool has_autofill_profiles = |
2172 suggested_cc_.GetItemCount() > 1 || | 2222 suggested_cc_.GetItemCount() > 1 || |
2173 suggested_billing_.GetItemCount() > 1; | 2223 suggested_billing_.GetItemCount() > 1; |
2174 | 2224 |
2175 if (SignedInState() != SIGNED_IN) { | 2225 if (SignedInState() != SIGNED_IN) { |
2176 // Not signed in. | 2226 // Not signed in. |
2177 return has_autofill_profiles ? | 2227 return has_autofill_profiles ? |
2178 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL : | 2228 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL : |
2179 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL; | 2229 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL; |
2180 } | 2230 } |
2181 | 2231 |
2182 // Signed in. | 2232 // Signed in. |
2183 if (wallet_items_->instruments().empty()) { | 2233 if (wallet_items_->instruments().empty()) { |
2184 // No Wallet items. | 2234 // No Wallet items. |
2185 return has_autofill_profiles ? | 2235 return has_autofill_profiles ? |
2186 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL : | 2236 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL : |
2187 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2237 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
2188 } | 2238 } |
2189 | 2239 |
2190 // Has Wallet items. | 2240 // Has Wallet items. |
2191 return has_autofill_profiles ? | 2241 return has_autofill_profiles ? |
2192 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2242 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
2193 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2243 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
2194 } | 2244 } |
2195 | 2245 |
2196 } // namespace autofill | 2246 } // namespace autofill |
OLD | NEW |