diff options
author | estade <estade@chromium.org> | 2014-12-30 15:35:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-30 23:35:57 +0000 |
commit | 39f60498e6576e5402e67d77990478d31415f337 (patch) | |
tree | 457bbf6a8b36265af0e9db15dd837a984fad785a /components/autofill | |
parent | f3810b62c20630764d4845edd17279ddfaef5633 (diff) | |
download | chromium_src-39f60498e6576e5402e67d77990478d31415f337.zip chromium_src-39f60498e6576e5402e67d77990478d31415f337.tar.gz chromium_src-39f60498e6576e5402e67d77990478d31415f337.tar.bz2 |
Iterate on the card unmasking prompt on Views a little bit more.
Move some code from ChromeAutofillClient into new controller class. Move some potentially shared view code into this class.
Move verification to AutofillExternalDelegate. Add new verification algorithm: assume "1234" is the correct cvc.
BUG=437116
TBR=aruslan@chromium.org,sgurun@chromium.org
Review URL: https://codereview.chromium.org/802933003
Cr-Commit-Position: refs/heads/master@{#309789}
Diffstat (limited to 'components/autofill')
8 files changed, 80 insertions, 5 deletions
diff --git a/components/autofill/core/browser/autofill_client.h b/components/autofill/core/browser/autofill_client.h index 6ffcd70..4e95487 100644 --- a/components/autofill/core/browser/autofill_client.h +++ b/components/autofill/core/browser/autofill_client.h @@ -28,6 +28,7 @@ namespace autofill { class AutofillPopupDelegate; class AutofillWebDataService; +class CardUnmaskDelegate; class CreditCard; class FormStructure; class PersonalDataManager; @@ -78,7 +79,9 @@ class AutofillClient { // A user has attempted to use a masked card. Prompt them for further // information to proceed. - virtual void ShowUnmaskPrompt() = 0; + virtual void ShowUnmaskPrompt(const CreditCard& card, + base::WeakPtr<CardUnmaskDelegate> delegate) = 0; + virtual void OnUnmaskVerificationResult(bool success) = 0; // Run |save_card_callback| if the credit card should be imported as personal // data. |metric_logger| can be used to log user actions. diff --git a/components/autofill/core/browser/autofill_external_delegate.cc b/components/autofill/core/browser/autofill_external_delegate.cc index d058523..54f0d7f 100644 --- a/components/autofill/core/browser/autofill_external_delegate.cc +++ b/components/autofill/core/browser/autofill_external_delegate.cc @@ -9,6 +9,7 @@ #include "base/message_loop/message_loop.h" #include "base/metrics/histogram.h" #include "base/metrics/sparse_histogram.h" +#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "components/autofill/core/browser/autocomplete_history_manager.h" #include "components/autofill/core/browser/autofill_driver.h" @@ -267,7 +268,10 @@ void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, manager_->client()->ScanCreditCard(base::Bind( &AutofillExternalDelegate::OnCreditCardScanned, GetWeakPtr())); } else if (identifier == POPUP_ITEM_ID_FAKE_MASKED_INSTRUMENT) { - manager_->client()->ShowUnmaskPrompt(); + CreditCard fake_masked_card(base::ASCIIToUTF16("8431"), 5, 2016); + fake_masked_card.set_record_type(CreditCard::MASKED_WALLET_CARD); + fake_masked_card.SetTypeForMaskedCard(kAmericanExpressCard); + manager_->client()->ShowUnmaskPrompt(fake_masked_card, GetWeakPtr()); } else { FillAutofillFormData(identifier, false); } @@ -300,6 +304,23 @@ void AutofillExternalDelegate::ClearPreviewedForm() { driver_->RendererShouldClearPreviewedForm(); } +void AutofillExternalDelegate::OnUnmaskResponse(const base::string16& cvc) { + // TODO(estade): fake verification: assume 1234 is the correct cvc. + if (LowerCaseEqualsASCII(cvc, "1234")) { + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&AutofillExternalDelegate::OnUnmaskVerificationResult, + base::Unretained(this), true), + base::TimeDelta::FromSeconds(2)); + } else { + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&AutofillExternalDelegate::OnUnmaskVerificationResult, + base::Unretained(this), false), + base::TimeDelta::FromSeconds(2)); + } +} + void AutofillExternalDelegate::Reset() { manager_->client()->HideAutofillPopup(); } @@ -418,4 +439,13 @@ void AutofillExternalDelegate::PingRenderer() { } #endif // defined(OS_MACOSX) && !defined(OS_IOS) +void AutofillExternalDelegate::OnUnmaskVerificationResult(bool success) { + if (success) { + CreditCard fake_card(base::ASCIIToUTF16("371449635398431"), 5, 2016); + manager_->FillCreditCardForm(query_id_, query_form_, query_field_, + fake_card); + } + manager_->client()->OnUnmaskVerificationResult(success); +} + } // namespace autofill diff --git a/components/autofill/core/browser/autofill_external_delegate.h b/components/autofill/core/browser/autofill_external_delegate.h index c45ea6b..0e7f352 100644 --- a/components/autofill/core/browser/autofill_external_delegate.h +++ b/components/autofill/core/browser/autofill_external_delegate.h @@ -12,6 +12,7 @@ #include "base/memory/weak_ptr.h" #include "base/strings/string16.h" #include "components/autofill/core/browser/autofill_popup_delegate.h" +#include "components/autofill/core/browser/card_unmask_delegate.h" #include "components/autofill/core/browser/suggestion.h" #include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_field_data.h" @@ -27,7 +28,8 @@ class AutofillManager; // this logic. See http://crbug.com/51644 // Delegate for in-browser Autocomplete and Autofill display and selection. -class AutofillExternalDelegate : public AutofillPopupDelegate { +class AutofillExternalDelegate : public AutofillPopupDelegate, + public CardUnmaskDelegate { public: // Creates an AutofillExternalDelegate for the specified AutofillManager and // AutofillDriver. @@ -45,6 +47,9 @@ class AutofillExternalDelegate : public AutofillPopupDelegate { void RemoveSuggestion(const base::string16& value, int identifier) override; void ClearPreviewedForm() override; + // CardUnmaskDelegate implementation. + void OnUnmaskResponse(const base::string16& cvc) override; + // Records and associates a query_id with web form data. Called // when the renderer posts an Autofill query to the browser. |bounds| // is window relative. |display_warning_if_disabled| tells us if we should @@ -115,6 +120,9 @@ class AutofillExternalDelegate : public AutofillPopupDelegate { void PingRenderer(); #endif // defined(OS_MACOSX) && !defined(OS_IOS) + // FIXME + void OnUnmaskVerificationResult(bool success); + AutofillManager* manager_; // weak. // Provides driver-level context to the shared code of the component. Must diff --git a/components/autofill/core/browser/card_unmask_delegate.h b/components/autofill/core/browser/card_unmask_delegate.h new file mode 100644 index 0000000..bf9f5a4 --- /dev/null +++ b/components/autofill/core/browser/card_unmask_delegate.h @@ -0,0 +1,19 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CARD_UNMASK_DELEGATE_H_ +#define COMPONENTS_AUTOFILL_CORE_BROWSER_CARD_UNMASK_DELEGATE_H_ + +#include "base/strings/string16.h" + +namespace autofill { + +class CardUnmaskDelegate { + public: + virtual void OnUnmaskResponse(const base::string16& cvc) = 0; +}; + +} // namespace autofill + +#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CARD_UNMASK_DELEGATE_H_ diff --git a/components/autofill/core/browser/credit_card.cc b/components/autofill/core/browser/credit_card.cc index 5e2cc635..94821b2 100644 --- a/components/autofill/core/browser/credit_card.cc +++ b/components/autofill/core/browser/credit_card.cc @@ -300,6 +300,11 @@ const char* CreditCard::GetCreditCardType(const base::string16& number) { return kGenericCard; } +void CreditCard::SetTypeForMaskedCard(const char* type) { + DCHECK_EQ(MASKED_WALLET_CARD, record_type()); + type_ = type; +} + base::string16 CreditCard::GetRawInfo(ServerFieldType type) const { DCHECK_EQ(CREDIT_CARD, AutofillType(type).group()); switch (type) { diff --git a/components/autofill/core/browser/credit_card.h b/components/autofill/core/browser/credit_card.h index a9dd937..50a1f96 100644 --- a/components/autofill/core/browser/credit_card.h +++ b/components/autofill/core/browser/credit_card.h @@ -68,6 +68,9 @@ class CreditCard : public AutofillDataModel { // the invalid card "4garbage" will be Visa, which has an IIN of 4. static const char* GetCreditCardType(const base::string16& number); + // Type strings are defined at the bottom of this file, e.g. kVisaCard. + void SetTypeForMaskedCard(const char* type); + // FormGroup: void GetMatchingTypes(const base::string16& text, const std::string& app_locale, diff --git a/components/autofill/core/browser/test_autofill_client.cc b/components/autofill/core/browser/test_autofill_client.cc index bb94d05..5361b0f 100644 --- a/components/autofill/core/browser/test_autofill_client.cc +++ b/components/autofill/core/browser/test_autofill_client.cc @@ -31,7 +31,12 @@ void TestAutofillClient::HideRequestAutocompleteDialog() { void TestAutofillClient::ShowAutofillSettings() { } -void TestAutofillClient::ShowUnmaskPrompt() { +void TestAutofillClient::ShowUnmaskPrompt( + const CreditCard& card, + base::WeakPtr<CardUnmaskDelegate> delegate) { +} + +void TestAutofillClient::OnUnmaskVerificationResult(bool success) { } void TestAutofillClient::ConfirmSaveCreditCard( diff --git a/components/autofill/core/browser/test_autofill_client.h b/components/autofill/core/browser/test_autofill_client.h index a809a8c..295669d 100644 --- a/components/autofill/core/browser/test_autofill_client.h +++ b/components/autofill/core/browser/test_autofill_client.h @@ -25,7 +25,9 @@ class TestAutofillClient : public AutofillClient { PrefService* GetPrefs() override; void HideRequestAutocompleteDialog() override; void ShowAutofillSettings() override; - void ShowUnmaskPrompt() override; + void ShowUnmaskPrompt(const CreditCard& card, + base::WeakPtr<CardUnmaskDelegate> delegate) override; + void OnUnmaskVerificationResult(bool success) override; void ConfirmSaveCreditCard(const base::Closure& save_card_callback) override; bool HasCreditCardScanFeature() override; void ScanCreditCard(const CreditCardScanCallback& callback) override; |