Chromium Code Reviews| 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 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext())->SetBoolean( | |
| 70 prefs::kAutofillWalletImportStorageCheckboxState, should_store_pan); | |
| 71 | |
| 63 if (!pending_response_.risk_data.empty()) | 72 if (!pending_response_.risk_data.empty()) |
| 64 delegate_->OnUnmaskResponse(pending_response_); | 73 delegate_->OnUnmaskResponse(pending_response_); |
| 65 } | 74 } |
| 66 | 75 |
| 67 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { | 76 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { |
| 68 return web_contents_; | 77 return web_contents_; |
| 69 } | 78 } |
| 70 | 79 |
| 71 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { | 80 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { |
| 72 // TODO(estade): i18n. | 81 // TODO(estade): i18n. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 95 | 104 |
| 96 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { | 105 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { |
| 97 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX | 106 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX |
| 98 : IDR_CREDIT_CARD_CVC_HINT; | 107 : IDR_CREDIT_CARD_CVC_HINT; |
| 99 } | 108 } |
| 100 | 109 |
| 101 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { | 110 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { |
| 102 return card_.GetServerStatus() == CreditCard::EXPIRED; | 111 return card_.GetServerStatus() == CreditCard::EXPIRED; |
| 103 } | 112 } |
| 104 | 113 |
| 114 bool CardUnmaskPromptControllerImpl::ShouldOfferToStoreLocally( | |
|
brettw
2015/02/11 23:55:54
Can we make the store locally default to false on
| |
| 115 bool* default_choice) const { | |
| 116 PrefService* prefs = | |
| 117 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()); | |
| 118 *default_choice = | |
| 119 prefs->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); | |
| 120 | |
| 121 // TODO(estade): perhaps we should always show the checkbox, but require | |
| 122 // both prefs to be true for the starting state to be checked. | |
| 123 return prefs->GetBoolean(prefs::kAutofillWalletImportStorageEnabled); | |
| 124 } | |
| 125 | |
| 105 bool CardUnmaskPromptControllerImpl::InputTextIsValid( | 126 bool CardUnmaskPromptControllerImpl::InputTextIsValid( |
| 106 const base::string16& input_text) const { | 127 const base::string16& input_text) const { |
| 107 base::string16 trimmed_text; | 128 base::string16 trimmed_text; |
| 108 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | 129 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
| 109 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; | 130 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; |
| 110 return trimmed_text.size() == input_size && | 131 return trimmed_text.size() == input_size && |
| 111 base::ContainsOnlyChars(trimmed_text, | 132 base::ContainsOnlyChars(trimmed_text, |
| 112 base::ASCIIToUTF16("0123456789")); | 133 base::ASCIIToUTF16("0123456789")); |
| 113 } | 134 } |
| 114 | 135 |
| 115 void CardUnmaskPromptControllerImpl::LoadRiskFingerprint() { | 136 void CardUnmaskPromptControllerImpl::LoadRiskFingerprint() { |
| 116 LoadRiskData( | 137 LoadRiskData( |
| 117 0, web_contents_, | 138 0, web_contents_, |
| 118 base::Bind(&CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint, | 139 base::Bind(&CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint, |
| 119 weak_pointer_factory_.GetWeakPtr())); | 140 weak_pointer_factory_.GetWeakPtr())); |
| 120 } | 141 } |
| 121 | 142 |
| 122 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 143 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( |
| 123 const std::string& risk_data) { | 144 const std::string& risk_data) { |
| 124 pending_response_.risk_data = risk_data; | 145 pending_response_.risk_data = risk_data; |
| 125 if (!pending_response_.cvc.empty()) | 146 if (!pending_response_.cvc.empty()) |
| 126 delegate_->OnUnmaskResponse(pending_response_); | 147 delegate_->OnUnmaskResponse(pending_response_); |
| 127 } | 148 } |
| 128 | 149 |
| 129 } // namespace autofill | 150 } // namespace autofill |
| OLD | NEW |