| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/card_unmask_prompt_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/autofill/risk_util.h" | 12 #include "chrome/browser/autofill/risk_util.h" |
| 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/autofill/core/browser/autofill_metrics.h" |
| 15 #include "components/autofill/core/common/autofill_pref_names.h" | 16 #include "components/autofill/core/common/autofill_pref_names.h" |
| 16 #include "components/user_prefs/user_prefs.h" | 17 #include "components/user_prefs/user_prefs.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 | 23 |
| 23 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( | 24 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( |
| 24 content::WebContents* web_contents) | 25 content::WebContents* web_contents) |
| 25 : web_contents_(web_contents), | 26 : web_contents_(web_contents), |
| 26 card_unmask_view_(nullptr), | 27 card_unmask_view_(nullptr), |
| 28 unmasking_success_(false), |
| 29 unmasking_initial_should_store_pan_(false), |
| 30 unmasking_number_of_attempts_(0), |
| 27 weak_pointer_factory_(this) { | 31 weak_pointer_factory_(this) { |
| 28 } | 32 } |
| 29 | 33 |
| 30 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { | 34 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { |
| 31 if (card_unmask_view_) | 35 if (card_unmask_view_) |
| 32 card_unmask_view_->ControllerGone(); | 36 card_unmask_view_->ControllerGone(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 void CardUnmaskPromptControllerImpl::ShowPrompt( | 39 void CardUnmaskPromptControllerImpl::ShowPrompt( |
| 36 const CreditCard& card, | 40 const CreditCard& card, |
| 37 base::WeakPtr<CardUnmaskDelegate> delegate) { | 41 base::WeakPtr<CardUnmaskDelegate> delegate) { |
| 38 if (card_unmask_view_) | 42 if (card_unmask_view_) |
| 39 card_unmask_view_->ControllerGone(); | 43 card_unmask_view_->ControllerGone(); |
| 40 | 44 |
| 41 pending_response_ = CardUnmaskDelegate::UnmaskResponse(); | 45 pending_response_ = CardUnmaskDelegate::UnmaskResponse(); |
| 42 LoadRiskFingerprint(); | 46 LoadRiskFingerprint(); |
| 43 card_ = card; | 47 card_ = card; |
| 44 delegate_ = delegate; | 48 delegate_ = delegate; |
| 45 card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); | 49 card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); |
| 50 unmasking_success_ = false; |
| 51 unmasking_number_of_attempts_ = 0; |
| 52 unmasking_initial_should_store_pan_ = GetStoreLocallyStartState(); |
| 53 AutofillMetrics::LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN); |
| 46 } | 54 } |
| 47 | 55 |
| 48 void CardUnmaskPromptControllerImpl::OnVerificationResult( | 56 void CardUnmaskPromptControllerImpl::OnVerificationResult( |
| 49 AutofillClient::GetRealPanResult result) { | 57 AutofillClient::GetRealPanResult result) { |
| 50 if (!card_unmask_view_) | 58 if (!card_unmask_view_) |
| 51 return; | 59 return; |
| 52 | 60 |
| 53 base::string16 error_message; | 61 base::string16 error_message; |
| 54 bool allow_retry = true; | 62 bool allow_retry = true; |
| 55 switch (result) { | 63 switch (result) { |
| 56 case AutofillClient::SUCCESS: | 64 case AutofillClient::SUCCESS: { |
| 65 unmasking_success_ = true; |
| 66 AutofillMetrics::LogUnmaskPromptEvent( |
| 67 AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD); |
| 68 bool final_should_store_pan = |
| 69 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) |
| 70 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); |
| 71 if (final_should_store_pan) { |
| 72 AutofillMetrics::LogUnmaskPromptEvent( |
| 73 AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY); |
| 74 } |
| 57 break; | 75 break; |
| 76 } |
| 58 | 77 |
| 59 case AutofillClient::TRY_AGAIN_FAILURE: { | 78 case AutofillClient::TRY_AGAIN_FAILURE: { |
| 60 error_message = l10n_util::GetStringUTF16( | 79 error_message = l10n_util::GetStringUTF16( |
| 61 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); | 80 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); |
| 62 break; | 81 break; |
| 63 } | 82 } |
| 64 | 83 |
| 65 case AutofillClient::PERMANENT_FAILURE: { | 84 case AutofillClient::PERMANENT_FAILURE: { |
| 66 error_message = l10n_util::GetStringUTF16( | 85 error_message = l10n_util::GetStringUTF16( |
| 67 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); | 86 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); |
| 68 allow_retry = false; | 87 allow_retry = false; |
| 69 break; | 88 break; |
| 70 } | 89 } |
| 71 | 90 |
| 72 case AutofillClient::NETWORK_ERROR: { | 91 case AutofillClient::NETWORK_ERROR: { |
| 73 error_message = l10n_util::GetStringUTF16( | 92 error_message = l10n_util::GetStringUTF16( |
| 74 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); | 93 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); |
| 75 allow_retry = false; | 94 allow_retry = false; |
| 76 break; | 95 break; |
| 77 } | 96 } |
| 78 } | 97 } |
| 79 | 98 |
| 80 card_unmask_view_->GotVerificationResult(error_message, allow_retry); | 99 card_unmask_view_->GotVerificationResult(error_message, allow_retry); |
| 81 } | 100 } |
| 82 | 101 |
| 83 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 102 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { |
| 84 card_unmask_view_ = nullptr; | 103 card_unmask_view_ = nullptr; |
| 104 if (!unmasking_success_) { |
| 105 if (unmasking_number_of_attempts_ > 0) { |
| 106 AutofillMetrics::LogUnmaskPromptEvent( |
| 107 AutofillMetrics::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK); |
| 108 } else { |
| 109 AutofillMetrics::LogUnmaskPromptEvent( |
| 110 AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS); |
| 111 } |
| 112 } |
| 113 if (unmasking_number_of_attempts_ > 0) { |
| 114 bool final_should_store_pan = |
| 115 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) |
| 116 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); |
| 117 if (unmasking_initial_should_store_pan_ && final_should_store_pan) { |
| 118 AutofillMetrics::LogUnmaskPromptEvent( |
| 119 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_KEPT_OPT_IN); |
| 120 } else if (!unmasking_initial_should_store_pan_ |
| 121 && !final_should_store_pan) { |
| 122 AutofillMetrics::LogUnmaskPromptEvent( |
| 123 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_KEPT_OPT_OUT); |
| 124 } else if (unmasking_initial_should_store_pan_ && !final_should_store_pan) { |
| 125 AutofillMetrics::LogUnmaskPromptEvent( |
| 126 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT); |
| 127 } else { |
| 128 AutofillMetrics::LogUnmaskPromptEvent( |
| 129 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN); |
| 130 } |
| 131 } |
| 85 delegate_->OnUnmaskPromptClosed(); | 132 delegate_->OnUnmaskPromptClosed(); |
| 86 } | 133 } |
| 87 | 134 |
| 88 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 135 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( |
| 89 const base::string16& cvc, | 136 const base::string16& cvc, |
| 90 const base::string16& exp_month, | 137 const base::string16& exp_month, |
| 91 const base::string16& exp_year, | 138 const base::string16& exp_year, |
| 92 bool should_store_pan) { | 139 bool should_store_pan) { |
| 140 unmasking_number_of_attempts_++; |
| 93 card_unmask_view_->DisableAndWaitForVerification(); | 141 card_unmask_view_->DisableAndWaitForVerification(); |
| 94 | 142 |
| 95 DCHECK(!cvc.empty()); | 143 DCHECK(!cvc.empty()); |
| 96 pending_response_.cvc = cvc; | 144 pending_response_.cvc = cvc; |
| 97 if (ShouldRequestExpirationDate()) { | 145 if (ShouldRequestExpirationDate()) { |
| 98 pending_response_.exp_month = exp_month; | 146 pending_response_.exp_month = exp_month; |
| 99 pending_response_.exp_year = exp_year; | 147 pending_response_.exp_year = exp_year; |
| 100 } | 148 } |
| 101 pending_response_.should_store_pan = should_store_pan; | 149 pending_response_.should_store_pan = should_store_pan; |
| 102 // Remember the last choice the user made (on this device). | 150 // Remember the last choice the user made (on this device). |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 248 } |
| 201 | 249 |
| 202 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 250 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( |
| 203 const std::string& risk_data) { | 251 const std::string& risk_data) { |
| 204 pending_response_.risk_data = risk_data; | 252 pending_response_.risk_data = risk_data; |
| 205 if (!pending_response_.cvc.empty()) | 253 if (!pending_response_.cvc.empty()) |
| 206 delegate_->OnUnmaskResponse(pending_response_); | 254 delegate_->OnUnmaskResponse(pending_response_); |
| 207 } | 255 } |
| 208 | 256 |
| 209 } // namespace autofill | 257 } // namespace autofill |
| OLD | NEW |