Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc

Issue 1011503004: Autofill card unmasking - never store locally in incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: inline and format Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/profiles/profile.h"
13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" 14 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "components/autofill/core/browser/autofill_metrics.h" 16 #include "components/autofill/core/browser/autofill_metrics.h"
16 #include "components/autofill/core/common/autofill_pref_names.h" 17 #include "components/autofill/core/common/autofill_pref_names.h"
17 #include "components/user_prefs/user_prefs.h" 18 #include "components/user_prefs/user_prefs.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 22
22 namespace autofill { 23 namespace autofill {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return false; 61 return false;
61 } 62 }
62 return true; 63 return true;
63 } 64 }
64 65
65 void CardUnmaskPromptControllerImpl::OnVerificationResult( 66 void CardUnmaskPromptControllerImpl::OnVerificationResult(
66 AutofillClient::GetRealPanResult result) { 67 AutofillClient::GetRealPanResult result) {
67 if (!card_unmask_view_) 68 if (!card_unmask_view_)
68 return; 69 return;
69 70
71 unmasking_result_ = result;
70 base::string16 error_message; 72 base::string16 error_message;
71 unmasking_result_ = result;
72 switch (result) { 73 switch (result) {
73 case AutofillClient::SUCCESS: 74 case AutofillClient::SUCCESS:
74 break; 75 break;
75 76
76 case AutofillClient::TRY_AGAIN_FAILURE: { 77 case AutofillClient::TRY_AGAIN_FAILURE: {
77 error_message = l10n_util::GetStringUTF16( 78 error_message = l10n_util::GetStringUTF16(
78 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); 79 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN);
79 break; 80 break;
80 } 81 }
81 82
82 case AutofillClient::PERMANENT_FAILURE: { 83 case AutofillClient::PERMANENT_FAILURE: {
83 error_message = l10n_util::GetStringUTF16( 84 error_message = l10n_util::GetStringUTF16(
84 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); 85 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT);
85 break; 86 break;
86 } 87 }
87 88
88 case AutofillClient::NETWORK_ERROR: { 89 case AutofillClient::NETWORK_ERROR: {
89 error_message = l10n_util::GetStringUTF16( 90 error_message = l10n_util::GetStringUTF16(
90 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); 91 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK);
91 break; 92 break;
92 } 93 }
93 } 94 }
94 95
95 AutofillMetrics::LogRealPanResult(result); 96 AutofillMetrics::LogRealPanResult(result);
96 unmasking_allow_retry_ = AllowsRetry(result);
97 card_unmask_view_->GotVerificationResult(error_message, 97 card_unmask_view_->GotVerificationResult(error_message,
98 AllowsRetry(result)); 98 AllowsRetry(result));
99 } 99 }
100 100
101 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { 101 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() {
102 card_unmask_view_ = nullptr; 102 card_unmask_view_ = nullptr;
103 LogOnCloseEvents(); 103 LogOnCloseEvents();
104 delegate_->OnUnmaskPromptClosed(); 104 delegate_->OnUnmaskPromptClosed();
105 } 105 }
106 106
107 void CardUnmaskPromptControllerImpl::LogOnCloseEvents() { 107 void CardUnmaskPromptControllerImpl::LogOnCloseEvents() {
108 if (unmasking_number_of_attempts_ == 0) { 108 if (unmasking_number_of_attempts_ == 0) {
109 AutofillMetrics::LogUnmaskPromptEvent( 109 AutofillMetrics::LogUnmaskPromptEvent(
110 AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS); 110 AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS);
111 return; 111 return;
112 } 112 }
113 113
114 bool final_should_store_pan = 114 bool final_should_store_pan = pending_response_.should_store_pan;
115 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())
116 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState);
117
118 if (unmasking_result_ == AutofillClient::SUCCESS) { 115 if (unmasking_result_ == AutofillClient::SUCCESS) {
119 AutofillMetrics::LogUnmaskPromptEvent( 116 AutofillMetrics::LogUnmaskPromptEvent(
120 unmasking_number_of_attempts_ == 1 117 unmasking_number_of_attempts_ == 1
121 ? AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_FIRST_ATTEMPT 118 ? AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_FIRST_ATTEMPT
122 : AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_AFTER_FAILED_ATTEMPTS); 119 : AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_AFTER_FAILED_ATTEMPTS);
123 if (final_should_store_pan) { 120 if (final_should_store_pan) {
124 AutofillMetrics::LogUnmaskPromptEvent( 121 AutofillMetrics::LogUnmaskPromptEvent(
125 AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY); 122 AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY);
126 } 123 }
127 } else { 124 } else {
128 AutofillMetrics::LogUnmaskPromptEvent( 125 AutofillMetrics::LogUnmaskPromptEvent(
129 AllowsRetry(unmasking_result_) 126 AllowsRetry(unmasking_result_)
130 ? AutofillMetrics 127 ? AutofillMetrics
131 ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_RETRIABLE_FAILURE 128 ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_RETRIABLE_FAILURE
132 : AutofillMetrics 129 : AutofillMetrics
133 ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_NON_RETRIABLE_FAILURE); 130 ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_NON_RETRIABLE_FAILURE);
134 } 131 }
135 132
136 // Tracking changes in local save preference. 133 if (CanStoreLocally()) {
137 AutofillMetrics::UnmaskPromptEvent event; 134 // Tracking changes in local save preference.
138 if (unmasking_initial_should_store_pan_ && final_should_store_pan) { 135 AutofillMetrics::UnmaskPromptEvent event;
139 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT; 136 if (unmasking_initial_should_store_pan_ && final_should_store_pan) {
140 } else if (!unmasking_initial_should_store_pan_ 137 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT;
141 && !final_should_store_pan) { 138 } else if (!unmasking_initial_should_store_pan_ &&
142 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN; 139 !final_should_store_pan) {
143 } else if (unmasking_initial_should_store_pan_ 140 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN;
144 && !final_should_store_pan) { 141 } else if (unmasking_initial_should_store_pan_ && !final_should_store_pan) {
145 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT; 142 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT;
146 } else { 143 } else {
147 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN; 144 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN;
145 }
146 AutofillMetrics::LogUnmaskPromptEvent(event);
148 } 147 }
149 AutofillMetrics::LogUnmaskPromptEvent(event);
150 } 148 }
151 149
152 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( 150 void CardUnmaskPromptControllerImpl::OnUnmaskResponse(
153 const base::string16& cvc, 151 const base::string16& cvc,
154 const base::string16& exp_month, 152 const base::string16& exp_month,
155 const base::string16& exp_year, 153 const base::string16& exp_year,
156 bool should_store_pan) { 154 bool should_store_pan) {
157 unmasking_number_of_attempts_++; 155 unmasking_number_of_attempts_++;
158 card_unmask_view_->DisableAndWaitForVerification(); 156 card_unmask_view_->DisableAndWaitForVerification();
159 157
160 DCHECK(!cvc.empty()); 158 DCHECK(!cvc.empty());
161 pending_response_.cvc = cvc; 159 pending_response_.cvc = cvc;
162 if (ShouldRequestExpirationDate()) { 160 if (ShouldRequestExpirationDate()) {
163 pending_response_.exp_month = exp_month; 161 pending_response_.exp_month = exp_month;
164 pending_response_.exp_year = exp_year; 162 pending_response_.exp_year = exp_year;
165 } 163 }
166 pending_response_.should_store_pan = should_store_pan; 164 if (CanStoreLocally()) {
165 pending_response_.should_store_pan = should_store_pan;
166 } else {
167 DCHECK(!should_store_pan);
168 pending_response_.should_store_pan = false;
169 }
170
167 // Remember the last choice the user made (on this device). 171 // Remember the last choice the user made (on this device).
168 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean( 172 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean(
169 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan); 173 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan);
170 174
171 if (!pending_response_.risk_data.empty()) 175 if (!pending_response_.risk_data.empty())
172 delegate_->OnUnmaskResponse(pending_response_); 176 delegate_->OnUnmaskResponse(pending_response_);
173 } 177 }
174 178
175 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { 179 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() {
176 return web_contents_; 180 return web_contents_;
(...skipping 22 matching lines...) Expand all
199 203
200 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { 204 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const {
201 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX 205 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX
202 : IDR_CREDIT_CARD_CVC_HINT; 206 : IDR_CREDIT_CARD_CVC_HINT;
203 } 207 }
204 208
205 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { 209 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const {
206 return card_.GetServerStatus() == CreditCard::EXPIRED; 210 return card_.GetServerStatus() == CreditCard::EXPIRED;
207 } 211 }
208 212
213 bool CardUnmaskPromptControllerImpl::CanStoreLocally() const {
214 // TODO(estade): Always return false for Linux. See
215 // https://codereview.chromium.org/1012223002/
216 return !Profile::FromBrowserContext(web_contents_->GetBrowserContext())
217 ->IsOffTheRecord();
218 }
219
209 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const { 220 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const {
210 // TODO(estade): Don't even offer to save on Linux? Offer to save but
211 // default to false?
212 PrefService* prefs = 221 PrefService* prefs =
213 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()); 222 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext());
214 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); 223 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState);
215 } 224 }
216 225
217 bool CardUnmaskPromptControllerImpl::InputCvcIsValid( 226 bool CardUnmaskPromptControllerImpl::InputCvcIsValid(
218 const base::string16& input_text) const { 227 const base::string16& input_text) const {
219 base::string16 trimmed_text; 228 base::string16 trimmed_text;
220 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); 229 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text);
221 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; 230 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 283 }
275 284
276 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( 285 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint(
277 const std::string& risk_data) { 286 const std::string& risk_data) {
278 pending_response_.risk_data = risk_data; 287 pending_response_.risk_data = risk_data;
279 if (!pending_response_.cvc.empty()) 288 if (!pending_response_.cvc.empty())
280 delegate_->OnUnmaskResponse(pending_response_); 289 delegate_->OnUnmaskResponse(pending_response_);
281 } 290 }
282 291
283 } // namespace autofill 292 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698