summaryrefslogtreecommitdiffstats
path: root/components/autofill/core/browser/autofill_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'components/autofill/core/browser/autofill_manager.cc')
-rw-r--r--components/autofill/core/browser/autofill_manager.cc163
1 files changed, 124 insertions, 39 deletions
diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc
index edc99de..8e05d1f 100644
--- a/components/autofill/core/browser/autofill_manager.cc
+++ b/components/autofill/core/browser/autofill_manager.cc
@@ -52,6 +52,7 @@
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/password_form_fill_data.h"
#include "components/pref_registry/pref_registry_syncable.h"
+#include "google_apis/gaia/identity_provider.h"
#include "grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/rect.h"
@@ -135,7 +136,8 @@ AutofillManager::AutofillManager(
AutofillDownloadManagerState enable_download_manager)
: driver_(driver),
client_(client),
- real_pan_client_(driver->GetURLRequestContext(), this),
+ payments_client_(
+ new payments::PaymentsClient(driver->GetURLRequestContext(), this)),
app_locale_(app_locale),
personal_data_(client->GetPersonalDataManager()),
autocomplete_history_manager_(
@@ -150,6 +152,7 @@ AutofillManager::AutofillManager(
user_did_type_(false),
user_did_autofill_(false),
user_did_edit_autofilled_field_(false),
+ user_did_accept_upload_prompt_(false),
external_delegate_(NULL),
test_delegate_(NULL),
weak_ptr_factory_(this) {
@@ -511,13 +514,15 @@ void AutofillManager::FillOrPreviewCreditCardForm(
if (action == AutofillDriver::FORM_DATA_ACTION_FILL) {
if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD &&
WillFillCreditCardNumber(form, field)) {
- unmasking_card_ = credit_card;
+ unmask_request_.card = credit_card;
unmasking_query_id_ = query_id;
unmasking_form_ = form;
unmasking_field_ = field;
- real_pan_client_.Prepare();
- client()->ShowUnmaskPrompt(unmasking_card_,
- weak_ptr_factory_.GetWeakPtr());
+ payments_client_->Prepare();
+ client_->ShowUnmaskPrompt(unmask_request_.card,
+ weak_ptr_factory_.GetWeakPtr());
+ client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData,
+ weak_ptr_factory_.GetWeakPtr()));
credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion();
return;
}
@@ -714,7 +719,7 @@ void AutofillManager::RemoveAutocompleteEntry(const base::string16& name,
}
bool AutofillManager::IsShowingUnmaskPrompt() {
- return unmasking_card_.Compare(CreditCard()) != 0;
+ return unmask_request_.card.Compare(CreditCard()) != 0;
}
const std::vector<FormStructure*>& AutofillManager::GetFormStructures() {
@@ -750,48 +755,103 @@ void AutofillManager::OnLoadedServerPredictions(
}
void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) {
- unmask_response_ = response;
- real_pan_request_timestamp_ = base::Time::Now();
- real_pan_client_.UnmaskCard(unmasking_card_, response);
+ unmask_request_.user_response = response;
+ if (!unmask_request_.risk_data.empty()) {
+ real_pan_request_timestamp_ = base::Time::Now();
+ payments_client_->UnmaskCard(unmask_request_);
+ }
}
void AutofillManager::OnUnmaskPromptClosed() {
- real_pan_client_.CancelRequest();
+ payments_client_->CancelRequest();
driver_->RendererShouldClearPreviewedForm();
- unmasking_card_ = CreditCard();
- unmask_response_ = UnmaskResponse();
+ unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails();
}
IdentityProvider* AutofillManager::GetIdentityProvider() {
- return client()->GetIdentityProvider();
+ return client_->GetIdentityProvider();
}
-void AutofillManager::OnDidGetRealPan(AutofillClient::GetRealPanResult result,
+void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result,
const std::string& real_pan) {
AutofillMetrics::LogRealPanDuration(
base::Time::Now() - real_pan_request_timestamp_, result);
if (!real_pan.empty()) {
DCHECK_EQ(AutofillClient::SUCCESS, result);
- credit_card_form_event_logger_->OnDidFillSuggestion(unmasking_card_);
- recently_unmasked_cards_.push_back(unmasking_card_);
- unmasking_card_.set_record_type(CreditCard::FULL_SERVER_CARD);
- unmasking_card_.SetNumber(base::UTF8ToUTF16(real_pan));
- if (!unmask_response_.exp_month.empty()) {
- unmasking_card_.SetRawInfo(CREDIT_CARD_EXP_MONTH,
- unmask_response_.exp_month);
+ credit_card_form_event_logger_->OnDidFillSuggestion(unmask_request_.card);
+ recently_unmasked_cards_.push_back(unmask_request_.card);
+ unmask_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD);
+ unmask_request_.card.SetNumber(base::UTF8ToUTF16(real_pan));
+ if (!unmask_request_.user_response.exp_month.empty()) {
+ unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_MONTH,
+ unmask_request_.user_response.exp_month);
}
- if (!unmask_response_.exp_year.empty()) {
- unmasking_card_.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
- unmask_response_.exp_year);
+ if (!unmask_request_.user_response.exp_year.empty()) {
+ unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
+ unmask_request_.user_response.exp_year);
}
- if (unmask_response_.should_store_pan)
- personal_data_->UpdateServerCreditCard(unmasking_card_);
+ if (unmask_request_.user_response.should_store_pan)
+ personal_data_->UpdateServerCreditCard(unmask_request_.card);
FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_,
- unmasking_card_);
+ unmask_request_.card);
+ }
+
+ client_->OnUnmaskVerificationResult(result);
+}
+
+void AutofillManager::OnDidGetUploadDetails(
+ AutofillClient::PaymentsRpcResult result,
+ const base::string16& context_token,
+ scoped_ptr<base::DictionaryValue> legal_message) {
+ // TODO(jdonnelly): Log duration.
+ if (result == AutofillClient::SUCCESS) {
+ // Do *not* call payments_client_->Prepare() here. We shouldn't send
+ // credentials until the user has explicitly accepted a prompt to upload.
+ upload_request_.context_token = context_token;
+ user_did_accept_upload_prompt_ = false;
+ client_->ConfirmSaveCreditCardToCloud(
+ base::Bind(&AutofillManager::OnUserDidAcceptUpload,
+ weak_ptr_factory_.GetWeakPtr()),
+ legal_message.Pass());
+ client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ // Since the upload details request failed, fallback to a local save.
+ client_->ConfirmSaveCreditCardLocally(base::Bind(
+ base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard),
+ base::Unretained(personal_data_), upload_request_.card));
+ }
+}
+
+void AutofillManager::OnDidUploadCard(
+ AutofillClient::PaymentsRpcResult result) {
+ // We don't do anything user-visible if the upload attempt fails.
+ // TODO(jdonnelly): Log duration.
+}
+
+void AutofillManager::OnDidGetUnmaskRiskData(const std::string& risk_data) {
+ unmask_request_.risk_data = risk_data;
+ if (!unmask_request_.user_response.cvc.empty()) {
+ real_pan_request_timestamp_ = base::Time::Now();
+ payments_client_->UnmaskCard(unmask_request_);
+ }
+}
+
+void AutofillManager::OnUserDidAcceptUpload() {
+ user_did_accept_upload_prompt_ = true;
+ if (!upload_request_.risk_data.empty()) {
+ upload_request_.app_locale = app_locale_;
+ payments_client_->UploadCard(upload_request_);
}
+}
- client()->OnUnmaskVerificationResult(result);
+void AutofillManager::OnDidGetUploadRiskData(const std::string& risk_data) {
+ upload_request_.risk_data = risk_data;
+ if (user_did_accept_upload_prompt_) {
+ upload_request_.app_locale = app_locale_;
+ payments_client_->UploadCard(upload_request_);
+ }
}
void AutofillManager::OnDidEndTextFieldEditing() {
@@ -802,6 +862,11 @@ bool AutofillManager::IsAutofillEnabled() const {
return ::autofill::IsAutofillEnabled(client_->GetPrefs());
}
+bool AutofillManager::IsCreditCardUploadEnabled() {
+ return ::autofill::IsCreditCardUploadEnabled(
+ client_->GetPrefs(), GetIdentityProvider()->GetActiveUsername());
+}
+
bool AutofillManager::ShouldUploadForm(const FormStructure& form) {
if (!IsAutofillEnabled())
return false;
@@ -860,11 +925,28 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) {
imported_credit_card->TypeAndLastFourDigits())
return;
}
- client_->ConfirmSaveCreditCard(
- base::Bind(
- base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard),
- base::Unretained(personal_data_),
- *imported_credit_card));
+
+ // Check for a CVC in order to determine whether we can prompt the user to
+ // upload their card.
+ for (const auto& field : submitted_form) {
+ if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE) {
+ upload_request_.cvc = field->value;
+ break;
+ }
+ }
+
+ if (!upload_request_.cvc.empty() && IsCreditCardUploadEnabled()) {
+ // Initiate the upload flow if a CVC was entered into the form and the
+ // feature is enabled.
+ upload_request_ = payments::PaymentsClient::UploadRequestDetails();
+ upload_request_.card = *imported_credit_card;
+ payments_client_->GetUploadDetails(app_locale_);
+ } else {
+ // Otherwise, prompt the user for local save.
+ client_->ConfirmSaveCreditCardLocally(base::Bind(
+ base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard),
+ base::Unretained(personal_data_), *imported_credit_card));
+ }
}
}
@@ -908,6 +990,8 @@ void AutofillManager::UploadFormData(const FormStructure& submitted_form) {
}
void AutofillManager::Reset() {
+ // Note that upload_request_ is not reset here because the prompt to
+ // save a card is shown after page navigation.
form_structures_.clear();
address_form_event_logger_.reset(
new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */));
@@ -919,7 +1003,7 @@ void AutofillManager::Reset() {
user_did_type_ = false;
user_did_autofill_ = false;
user_did_edit_autofilled_field_ = false;
- unmasking_card_ = CreditCard();
+ unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails();
unmasking_query_id_ = -1;
unmasking_form_ = FormData();
unmasking_field_ = FormFieldData();
@@ -933,7 +1017,8 @@ AutofillManager::AutofillManager(AutofillDriver* driver,
PersonalDataManager* personal_data)
: driver_(driver),
client_(client),
- real_pan_client_(driver->GetURLRequestContext(), this),
+ payments_client_(
+ new payments::PaymentsClient(driver->GetURLRequestContext(), this)),
app_locale_("en-US"),
personal_data_(personal_data),
autocomplete_history_manager_(
@@ -1116,10 +1201,10 @@ void AutofillManager::FillOrPreviewDataModelForm(
if (is_credit_card &&
cached_field->Type().GetStorableType() ==
CREDIT_CARD_VERIFICATION_CODE) {
- // If this is |unmasking_card_|, |unmask_response_.cvc| should be
- // non-empty and vice versa.
- value = unmask_response_.cvc;
- DCHECK_EQ(&unmasking_card_ == &data_model, !value.empty());
+ // If this is |unmask_request_.card|, |unmask_request_.user_response.cvc|
+ // should be non-empty and vice versa.
+ value = unmask_request_.user_response.cvc;
+ DCHECK_EQ(&unmask_request_.card == &data_model, !value.empty());
}
// Must match ForEachMatchingFormField() in form_autofill_util.cc.