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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 #include "ui/gfx/skbitmap_operations.h" | 85 #include "ui/gfx/skbitmap_operations.h" |
86 | 86 |
87 namespace autofill { | 87 namespace autofill { |
88 | 88 |
89 namespace { | 89 namespace { |
90 | 90 |
91 const char kAddNewItemKey[] = "add-new-item"; | 91 const char kAddNewItemKey[] = "add-new-item"; |
92 const char kManageItemsKey[] = "manage-items"; | 92 const char kManageItemsKey[] = "manage-items"; |
93 const char kSameAsBillingKey[] = "same-as-billing"; | 93 const char kSameAsBillingKey[] = "same-as-billing"; |
94 | 94 |
| 95 // URLs for Wallet error messages. |
| 96 const char kBuyerLegalAddressStatusUrl[] = |
| 97 "https://wallet.google.com/manage/settings"; |
| 98 const char kKnowYourCustomerStatusUrl[] = "https://wallet.google.com/kyc"; |
| 99 |
95 // Keys for the kAutofillDialogAutofillDefault pref dictionary (do not change | 100 // Keys for the kAutofillDialogAutofillDefault pref dictionary (do not change |
96 // these values). | 101 // these values). |
97 const char kGuidPrefKey[] = "guid"; | 102 const char kGuidPrefKey[] = "guid"; |
98 const char kVariantPrefKey[] = "variant"; | 103 const char kVariantPrefKey[] = "variant"; |
99 | 104 |
100 // This string is stored along with saved addresses and credit cards in the | 105 // This string is stored along with saved addresses and credit cards in the |
101 // WebDB, and hence should not be modified, so that it remains consistent over | 106 // WebDB, and hence should not be modified, so that it remains consistent over |
102 // time. | 107 // time. |
103 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; | 108 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
104 | 109 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 351 |
347 case wallet::FormFieldError::UNKNOWN_LOCATION: | 352 case wallet::FormFieldError::UNKNOWN_LOCATION: |
348 NOTREACHED(); | 353 NOTREACHED(); |
349 return SECTION_MAX; | 354 return SECTION_MAX; |
350 } | 355 } |
351 | 356 |
352 NOTREACHED(); | 357 NOTREACHED(); |
353 return SECTION_MAX; | 358 return SECTION_MAX; |
354 } | 359 } |
355 | 360 |
356 base::string16 WalletErrorMessage(wallet::WalletClient::ErrorType error_type) { | 361 scoped_ptr<DialogNotification> GetWalletError( |
| 362 wallet::WalletClient::ErrorType error_type) { |
| 363 base::string16 text; |
| 364 GURL url; |
| 365 |
357 switch (error_type) { | 366 switch (error_type) { |
358 case wallet::WalletClient::BUYER_ACCOUNT_ERROR: | 367 case wallet::WalletClient::UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS: |
359 return l10n_util::GetStringUTF16(IDS_AUTOFILL_WALLET_BUYER_ACCOUNT_ERROR); | 368 text = l10n_util::GetStringUTF16( |
| 369 IDS_AUTOFILL_WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS); |
| 370 url = GURL(kKnowYourCustomerStatusUrl); |
| 371 break; |
360 | 372 |
361 case wallet::WalletClient::BUYER_LEGAL_ADDRESS_NOT_SUPPORTED: | 373 case wallet::WalletClient::BUYER_LEGAL_ADDRESS_NOT_SUPPORTED: |
362 return l10n_util::GetStringUTF16( | 374 text = l10n_util::GetStringUTF16( |
363 IDS_AUTOFILL_WALLET_BUYER_COUNTRY_NOT_SUPPORTED); | 375 IDS_AUTOFILL_WALLET_BUYER_COUNTRY_NOT_SUPPORTED); |
| 376 url = GURL(kBuyerLegalAddressStatusUrl); |
| 377 break; |
364 | 378 |
| 379 default: |
| 380 // The notification will not have a link; it's handled in the next |
| 381 // switch statement. |
| 382 break; |
| 383 } |
| 384 |
| 385 if (!text.empty()) { |
| 386 scoped_ptr<DialogNotification> notification(new DialogNotification( |
| 387 DialogNotification::WALLET_ERROR, |
| 388 text)); |
| 389 notification->set_link_url(url); |
| 390 return notification.Pass(); |
| 391 } |
| 392 |
| 393 switch (error_type) { |
365 case wallet::WalletClient::UNSUPPORTED_MERCHANT: | 394 case wallet::WalletClient::UNSUPPORTED_MERCHANT: |
366 return l10n_util::GetStringUTF16( | 395 text = l10n_util::GetStringUTF16( |
367 IDS_AUTOFILL_WALLET_UNSUPPORTED_MERCHANT); | 396 IDS_AUTOFILL_WALLET_UNSUPPORTED_MERCHANT); |
| 397 break; |
368 | 398 |
369 case wallet::WalletClient::BAD_REQUEST: | 399 case wallet::WalletClient::BAD_REQUEST: |
370 return l10n_util::GetStringFUTF16( | 400 text = l10n_util::GetStringFUTF16( |
371 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, | 401 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, |
372 ASCIIToUTF16("71")); | 402 ASCIIToUTF16("71")); |
| 403 break; |
373 | 404 |
374 case wallet::WalletClient::INVALID_PARAMS: | 405 case wallet::WalletClient::INVALID_PARAMS: |
375 return l10n_util::GetStringFUTF16( | 406 text = l10n_util::GetStringFUTF16( |
376 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, | 407 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, |
377 ASCIIToUTF16("42")); | 408 ASCIIToUTF16("42")); |
| 409 break; |
378 | 410 |
379 case wallet::WalletClient::UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS: | 411 case wallet::WalletClient::BUYER_ACCOUNT_ERROR: |
380 return l10n_util::GetStringUTF16( | 412 text = l10n_util::GetStringUTF16(IDS_AUTOFILL_WALLET_BUYER_ACCOUNT_ERROR); |
381 IDS_AUTOFILL_WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS); | 413 break; |
382 | 414 |
383 case wallet::WalletClient::UNSUPPORTED_API_VERSION: | 415 case wallet::WalletClient::UNSUPPORTED_API_VERSION: |
384 return l10n_util::GetStringFUTF16( | 416 text = l10n_util::GetStringFUTF16( |
385 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, | 417 IDS_AUTOFILL_WALLET_UPGRADE_CHROME_ERROR, |
386 ASCIIToUTF16("43")); | 418 ASCIIToUTF16("43")); |
| 419 break; |
387 | 420 |
388 case wallet::WalletClient::SERVICE_UNAVAILABLE: | 421 case wallet::WalletClient::SERVICE_UNAVAILABLE: |
389 return l10n_util::GetStringUTF16( | 422 text = l10n_util::GetStringUTF16( |
390 IDS_AUTOFILL_WALLET_SERVICE_UNAVAILABLE_ERROR); | 423 IDS_AUTOFILL_WALLET_SERVICE_UNAVAILABLE_ERROR); |
| 424 break; |
391 | 425 |
392 case wallet::WalletClient::INTERNAL_ERROR: | 426 case wallet::WalletClient::INTERNAL_ERROR: |
393 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, | 427 text = l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, |
394 ASCIIToUTF16("62")); | 428 ASCIIToUTF16("62")); |
| 429 break; |
395 | 430 |
396 case wallet::WalletClient::MALFORMED_RESPONSE: | 431 case wallet::WalletClient::MALFORMED_RESPONSE: |
397 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, | 432 text = l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, |
398 ASCIIToUTF16("72")); | 433 ASCIIToUTF16("72")); |
| 434 break; |
399 | 435 |
400 case wallet::WalletClient::NETWORK_ERROR: | 436 case wallet::WalletClient::NETWORK_ERROR: |
401 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, | 437 text = l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, |
402 ASCIIToUTF16("73")); | 438 ASCIIToUTF16("73")); |
| 439 break; |
403 | 440 |
404 case wallet::WalletClient::UNKNOWN_ERROR: | 441 case wallet::WalletClient::UNKNOWN_ERROR: |
405 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, | 442 text = l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, |
406 ASCIIToUTF16("74")); | 443 ASCIIToUTF16("74")); |
| 444 break; |
| 445 |
| 446 default: |
| 447 break; |
407 } | 448 } |
408 | 449 |
409 NOTREACHED(); | 450 DCHECK(!text.empty()); |
410 return base::string16(); | 451 |
| 452 // The other error types are strings of the form "XXX. You can pay without |
| 453 // wallet." |
| 454 return make_scoped_ptr(new DialogNotification( |
| 455 DialogNotification::WALLET_ERROR, |
| 456 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, |
| 457 text))); |
411 } | 458 } |
412 | 459 |
413 gfx::Image GetGeneratedCardImage(const string16& card_number) { | 460 gfx::Image GetGeneratedCardImage(const string16& card_number) { |
414 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 461 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
415 const gfx::ImageSkia* card = | 462 const gfx::ImageSkia* card = |
416 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); | 463 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); |
417 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); | 464 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); |
418 canvas.DrawImageInt(*card, 0, 0); | 465 canvas.DrawImageInt(*card, 0, 0); |
419 | 466 |
420 gfx::Rect display_rect(gfx::Point(), card->size()); | 467 gfx::Rect display_rect(gfx::Point(), card->size()); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 757 |
711 string16 AutofillDialogControllerImpl::LegalDocumentsText() { | 758 string16 AutofillDialogControllerImpl::LegalDocumentsText() { |
712 if (!IsPayingWithWallet() || autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED) | 759 if (!IsPayingWithWallet() || autocheckout_state_ != AUTOCHECKOUT_NOT_STARTED) |
713 return string16(); | 760 return string16(); |
714 | 761 |
715 EnsureLegalDocumentsText(); | 762 EnsureLegalDocumentsText(); |
716 return legal_documents_text_; | 763 return legal_documents_text_; |
717 } | 764 } |
718 | 765 |
719 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { | 766 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { |
720 if (account_chooser_model_.HadWalletError()) | 767 if (wallet_error_notification_) |
721 return SIGN_IN_DISABLED; | 768 return SIGN_IN_DISABLED; |
722 | 769 |
723 if (signin_helper_ || !wallet_items_) | 770 if (signin_helper_ || !wallet_items_) |
724 return REQUIRES_RESPONSE; | 771 return REQUIRES_RESPONSE; |
725 | 772 |
726 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) | 773 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) |
727 return REQUIRES_SIGN_IN; | 774 return REQUIRES_SIGN_IN; |
728 | 775 |
729 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 776 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
730 return REQUIRES_PASSIVE_SIGN_IN; | 777 return REQUIRES_PASSIVE_SIGN_IN; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 if (IsASuggestionItemKey(model->GetItemKeyAt(i))) | 1237 if (IsASuggestionItemKey(model->GetItemKeyAt(i))) |
1191 return model; | 1238 return model; |
1192 } | 1239 } |
1193 | 1240 |
1194 return NULL; | 1241 return NULL; |
1195 } | 1242 } |
1196 | 1243 |
1197 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { | 1244 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { |
1198 // If there were unrecoverable Wallet errors, or if there are choices other | 1245 // If there were unrecoverable Wallet errors, or if there are choices other |
1199 // than "Pay without the wallet", show the full menu. | 1246 // than "Pay without the wallet", show the full menu. |
1200 if (account_chooser_model_.HadWalletError() || | 1247 if (wallet_error_notification_ || |
1201 account_chooser_model_.HasAccountsToChoose()) { | 1248 account_chooser_model_.HasAccountsToChoose()) { |
1202 return &account_chooser_model_; | 1249 return &account_chooser_model_; |
1203 } | 1250 } |
1204 | 1251 |
1205 // Otherwise, there is no menu, just a sign in link. | 1252 // Otherwise, there is no menu, just a sign in link. |
1206 return NULL; | 1253 return NULL; |
1207 } | 1254 } |
1208 | 1255 |
1209 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { | 1256 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { |
1210 if (!MenuModelForAccountChooser()) { | 1257 if (!MenuModelForAccountChooser()) { |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING))); | 1872 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING))); |
1826 } | 1873 } |
1827 | 1874 |
1828 if (!invoked_from_same_origin_) { | 1875 if (!invoked_from_same_origin_) { |
1829 notifications.push_back(DialogNotification( | 1876 notifications.push_back(DialogNotification( |
1830 DialogNotification::SECURITY_WARNING, | 1877 DialogNotification::SECURITY_WARNING, |
1831 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING, | 1878 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING, |
1832 UTF8ToUTF16(source_url_.host())))); | 1879 UTF8ToUTF16(source_url_.host())))); |
1833 } | 1880 } |
1834 | 1881 |
1835 if (account_chooser_model_.HadWalletError()) { | 1882 // TODO(dbeam): figure out a way to dismiss this error after a while. |
1836 // TODO(dbeam): figure out a way to dismiss this error after a while. | 1883 if (wallet_error_notification_) |
1837 notifications.push_back(DialogNotification( | 1884 notifications.push_back(*wallet_error_notification_); |
1838 DialogNotification::WALLET_ERROR, | |
1839 l10n_util::GetStringFUTF16( | |
1840 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, | |
1841 account_chooser_model_.wallet_error_message()))); | |
1842 } | |
1843 | 1885 |
1844 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1886 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1845 notifications.push_back(DialogNotification( | 1887 notifications.push_back(DialogNotification( |
1846 DialogNotification::REQUIRED_ACTION, | 1888 DialogNotification::REQUIRED_ACTION, |
1847 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV))); | 1889 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV))); |
1848 } | 1890 } |
1849 | 1891 |
1850 if (autocheckout_state_ == AUTOCHECKOUT_ERROR) { | 1892 if (autocheckout_state_ == AUTOCHECKOUT_ERROR) { |
1851 notifications.push_back(DialogNotification( | 1893 notifications.push_back(DialogNotification( |
1852 DialogNotification::AUTOCHECKOUT_ERROR, | 1894 DialogNotification::AUTOCHECKOUT_ERROR, |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2476 GetWalletClient()->CancelRequests(); | 2518 GetWalletClient()->CancelRequests(); |
2477 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | 2519 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); |
2478 for (std::vector<DialogAutocheckoutStep>::iterator it = steps_.begin(); | 2520 for (std::vector<DialogAutocheckoutStep>::iterator it = steps_.begin(); |
2479 it != steps_.end(); ++it) { | 2521 it != steps_.end(); ++it) { |
2480 if (it->type() == AUTOCHECKOUT_STEP_PROXY_CARD) { | 2522 if (it->type() == AUTOCHECKOUT_STEP_PROXY_CARD) { |
2481 steps_.erase(it); | 2523 steps_.erase(it); |
2482 break; | 2524 break; |
2483 } | 2525 } |
2484 } | 2526 } |
2485 SetIsSubmitting(false); | 2527 SetIsSubmitting(false); |
2486 account_chooser_model_.SetHadWalletError(WalletErrorMessage(error_type)); | 2528 wallet_error_notification_ = GetWalletError(error_type); |
| 2529 account_chooser_model_.SetHadWalletError(); |
2487 } | 2530 } |
2488 | 2531 |
2489 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2532 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
2490 ScopedViewUpdates updates(view_.get()); | 2533 ScopedViewUpdates updates(view_.get()); |
2491 | 2534 |
2492 const DetailOutputMap snapshot = TakeUserInputSnapshot(); | 2535 const DetailOutputMap snapshot = TakeUserInputSnapshot(); |
2493 | 2536 |
2494 suggested_email_.Reset(); | 2537 suggested_email_.Reset(); |
2495 suggested_cc_.Reset(); | 2538 suggested_cc_.Reset(); |
2496 suggested_billing_.Reset(); | 2539 suggested_billing_.Reset(); |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3231 int variant = GetSelectedVariantForModel(*model); | 3274 int variant = GetSelectedVariantForModel(*model); |
3232 PersistAutofillChoice(section, item_key, variant); | 3275 PersistAutofillChoice(section, item_key, variant); |
3233 } | 3276 } |
3234 } | 3277 } |
3235 } | 3278 } |
3236 | 3279 |
3237 // On a successful submit, if the user manually selected "pay without wallet", | 3280 // On a successful submit, if the user manually selected "pay without wallet", |
3238 // stop trying to pay with Wallet on future runs of the dialog. On the other | 3281 // stop trying to pay with Wallet on future runs of the dialog. On the other |
3239 // hand, if there was an error that prevented the user from having the choice | 3282 // hand, if there was an error that prevented the user from having the choice |
3240 // of using Wallet, leave the pref alone. | 3283 // of using Wallet, leave the pref alone. |
3241 if (!account_chooser_model_.HadWalletError() && | 3284 if (!wallet_error_notification_ && |
3242 account_chooser_model_.HasAccountsToChoose()) { | 3285 account_chooser_model_.HasAccountsToChoose()) { |
3243 profile_->GetPrefs()->SetBoolean( | 3286 profile_->GetPrefs()->SetBoolean( |
3244 ::prefs::kAutofillDialogPayWithoutWallet, | 3287 ::prefs::kAutofillDialogPayWithoutWallet, |
3245 !account_chooser_model_.WalletIsSelected()); | 3288 !account_chooser_model_.WalletIsSelected()); |
3246 } | 3289 } |
3247 | 3290 |
3248 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { | 3291 if (GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) { |
3249 // Stop observing PersonalDataManager to avoid the dialog redrawing while | 3292 // Stop observing PersonalDataManager to avoid the dialog redrawing while |
3250 // in an Autocheckout flow. | 3293 // in an Autocheckout flow. |
3251 GetManager()->RemoveObserver(this); | 3294 GetManager()->RemoveObserver(this); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3506 } | 3549 } |
3507 #if !defined(OS_ANDROID) | 3550 #if !defined(OS_ANDROID) |
3508 GeneratedCreditCardBubbleController::Show( | 3551 GeneratedCreditCardBubbleController::Show( |
3509 web_contents(), | 3552 web_contents(), |
3510 full_wallet_->TypeAndLastFourDigits(), | 3553 full_wallet_->TypeAndLastFourDigits(), |
3511 backing_last_four); | 3554 backing_last_four); |
3512 #endif | 3555 #endif |
3513 } | 3556 } |
3514 | 3557 |
3515 } // namespace autofill | 3558 } // namespace autofill |
OLD | NEW |