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

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: 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_
145 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT; 142 && !final_should_store_pan) {
146 } else { 143 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT;
147 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN; 144 } else {
145 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN;
146 }
147 AutofillMetrics::LogUnmaskPromptEvent(event);
148 } 148 }
149 AutofillMetrics::LogUnmaskPromptEvent(event);
150 } 149 }
151 150
152 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( 151 void CardUnmaskPromptControllerImpl::OnUnmaskResponse(
153 const base::string16& cvc, 152 const base::string16& cvc,
154 const base::string16& exp_month, 153 const base::string16& exp_month,
155 const base::string16& exp_year, 154 const base::string16& exp_year,
156 bool should_store_pan) { 155 bool should_store_pan) {
157 unmasking_number_of_attempts_++; 156 unmasking_number_of_attempts_++;
158 card_unmask_view_->DisableAndWaitForVerification(); 157 card_unmask_view_->DisableAndWaitForVerification();
159 158
160 DCHECK(!cvc.empty()); 159 DCHECK(!cvc.empty());
161 pending_response_.cvc = cvc; 160 pending_response_.cvc = cvc;
162 if (ShouldRequestExpirationDate()) { 161 if (ShouldRequestExpirationDate()) {
163 pending_response_.exp_month = exp_month; 162 pending_response_.exp_month = exp_month;
164 pending_response_.exp_year = exp_year; 163 pending_response_.exp_year = exp_year;
165 } 164 }
166 pending_response_.should_store_pan = should_store_pan; 165 if (CanStoreLocally()) {
166 pending_response_.should_store_pan = should_store_pan;
167 } else {
168 DCHECK(!should_store_pan);
169 pending_response_.should_store_pan = false;
170 }
171
167 // Remember the last choice the user made (on this device). 172 // Remember the last choice the user made (on this device).
168 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean( 173 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean(
169 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan); 174 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan);
170 175
171 if (!pending_response_.risk_data.empty()) 176 if (!pending_response_.risk_data.empty())
172 delegate_->OnUnmaskResponse(pending_response_); 177 delegate_->OnUnmaskResponse(pending_response_);
173 } 178 }
174 179
175 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { 180 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() {
176 return web_contents_; 181 return web_contents_;
(...skipping 22 matching lines...) Expand all
199 204
200 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { 205 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const {
201 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX 206 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX
202 : IDR_CREDIT_CARD_CVC_HINT; 207 : IDR_CREDIT_CARD_CVC_HINT;
203 } 208 }
204 209
205 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { 210 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const {
206 return card_.GetServerStatus() == CreditCard::EXPIRED; 211 return card_.GetServerStatus() == CreditCard::EXPIRED;
207 } 212 }
208 213
214 bool CardUnmaskPromptControllerImpl::CanStoreLocally() const {
215 // TODO(estade): Always return false for Linux. See
216 // https://codereview.chromium.org/1012223002/
217 Profile* profile =
218 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
219 return !profile->IsOffTheRecord();
please use gerrit instead 2015/03/23 19:57:58 nit: Technically, you can save 1 line by inlining
Evan Stade 2015/03/23 21:49:56 Done.
220 }
221
209 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const { 222 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 = 223 PrefService* prefs =
213 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()); 224 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext());
214 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); 225 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState);
215 } 226 }
216 227
217 bool CardUnmaskPromptControllerImpl::InputCvcIsValid( 228 bool CardUnmaskPromptControllerImpl::InputCvcIsValid(
218 const base::string16& input_text) const { 229 const base::string16& input_text) const {
219 base::string16 trimmed_text; 230 base::string16 trimmed_text;
220 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); 231 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text);
221 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; 232 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 285 }
275 286
276 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( 287 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint(
277 const std::string& risk_data) { 288 const std::string& risk_data) {
278 pending_response_.risk_data = risk_data; 289 pending_response_.risk_data = risk_data;
279 if (!pending_response_.cvc.empty()) 290 if (!pending_response_.cvc.empty())
280 delegate_->OnUnmaskResponse(pending_response_); 291 delegate_->OnUnmaskResponse(pending_response_);
281 } 292 }
282 293
283 } // namespace autofill 294 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698