| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/risk_util.h" | 11 #include "chrome/browser/autofill/risk_util.h" |
| 11 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 12 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
| 12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/autofill/core/common/autofill_pref_names.h" |
| 15 #include "components/user_prefs/user_prefs.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 15 | 19 |
| 16 namespace autofill { | 20 namespace autofill { |
| 17 | 21 |
| 18 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( | 22 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( |
| 19 content::WebContents* web_contents) | 23 content::WebContents* web_contents) |
| 20 : web_contents_(web_contents), | 24 : web_contents_(web_contents), |
| 21 card_unmask_view_(nullptr), | 25 card_unmask_view_(nullptr), |
| 22 weak_pointer_factory_(this) { | 26 weak_pointer_factory_(this) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 } | 50 } |
| 47 | 51 |
| 48 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 52 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { |
| 49 card_unmask_view_ = nullptr; | 53 card_unmask_view_ = nullptr; |
| 50 delegate_->OnUnmaskPromptClosed(); | 54 delegate_->OnUnmaskPromptClosed(); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 57 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( |
| 54 const base::string16& cvc, | 58 const base::string16& cvc, |
| 55 const base::string16& exp_month, | 59 const base::string16& exp_month, |
| 56 const base::string16& exp_year) { | 60 const base::string16& exp_year, |
| 61 bool should_store_pan) { |
| 57 card_unmask_view_->DisableAndWaitForVerification(); | 62 card_unmask_view_->DisableAndWaitForVerification(); |
| 58 | 63 |
| 59 DCHECK(!cvc.empty()); | 64 DCHECK(!cvc.empty()); |
| 60 pending_response_.cvc = cvc; | 65 pending_response_.cvc = cvc; |
| 61 pending_response_.exp_month = exp_month; | 66 pending_response_.exp_month = exp_month; |
| 62 pending_response_.exp_year = exp_year; | 67 pending_response_.exp_year = exp_year; |
| 68 pending_response_.should_store_pan = should_store_pan; |
| 69 // Remember the last choice the user made (on this device). |
| 70 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean( |
| 71 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan); |
| 72 |
| 63 if (!pending_response_.risk_data.empty()) | 73 if (!pending_response_.risk_data.empty()) |
| 64 delegate_->OnUnmaskResponse(pending_response_); | 74 delegate_->OnUnmaskResponse(pending_response_); |
| 65 } | 75 } |
| 66 | 76 |
| 67 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { | 77 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { |
| 68 return web_contents_; | 78 return web_contents_; |
| 69 } | 79 } |
| 70 | 80 |
| 71 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { | 81 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { |
| 72 // TODO(estade): i18n. | 82 // TODO(estade): i18n. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 95 | 105 |
| 96 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { | 106 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { |
| 97 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX | 107 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX |
| 98 : IDR_CREDIT_CARD_CVC_HINT; | 108 : IDR_CREDIT_CARD_CVC_HINT; |
| 99 } | 109 } |
| 100 | 110 |
| 101 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { | 111 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { |
| 102 return card_.GetServerStatus() == CreditCard::EXPIRED; | 112 return card_.GetServerStatus() == CreditCard::EXPIRED; |
| 103 } | 113 } |
| 104 | 114 |
| 115 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const { |
| 116 // TODO(estade): Don't even offer to save on Linux? Offer to save but |
| 117 // default to false? |
| 118 PrefService* prefs = |
| 119 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()); |
| 120 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); |
| 121 } |
| 122 |
| 105 bool CardUnmaskPromptControllerImpl::InputTextIsValid( | 123 bool CardUnmaskPromptControllerImpl::InputTextIsValid( |
| 106 const base::string16& input_text) const { | 124 const base::string16& input_text) const { |
| 107 base::string16 trimmed_text; | 125 base::string16 trimmed_text; |
| 108 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | 126 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
| 109 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; | 127 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; |
| 110 return trimmed_text.size() == input_size && | 128 return trimmed_text.size() == input_size && |
| 111 base::ContainsOnlyChars(trimmed_text, | 129 base::ContainsOnlyChars(trimmed_text, |
| 112 base::ASCIIToUTF16("0123456789")); | 130 base::ASCIIToUTF16("0123456789")); |
| 113 } | 131 } |
| 114 | 132 |
| 115 void CardUnmaskPromptControllerImpl::LoadRiskFingerprint() { | 133 void CardUnmaskPromptControllerImpl::LoadRiskFingerprint() { |
| 116 LoadRiskData( | 134 LoadRiskData( |
| 117 0, web_contents_, | 135 0, web_contents_, |
| 118 base::Bind(&CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint, | 136 base::Bind(&CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint, |
| 119 weak_pointer_factory_.GetWeakPtr())); | 137 weak_pointer_factory_.GetWeakPtr())); |
| 120 } | 138 } |
| 121 | 139 |
| 122 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 140 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( |
| 123 const std::string& risk_data) { | 141 const std::string& risk_data) { |
| 124 pending_response_.risk_data = risk_data; | 142 pending_response_.risk_data = risk_data; |
| 125 if (!pending_response_.cvc.empty()) | 143 if (!pending_response_.cvc.empty()) |
| 126 delegate_->OnUnmaskResponse(pending_response_); | 144 delegate_->OnUnmaskResponse(pending_response_); |
| 127 } | 145 } |
| 128 | 146 |
| 129 } // namespace autofill | 147 } // namespace autofill |
| OLD | NEW |