| 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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/risk_util.h" |
| 9 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 11 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
| 10 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/autofill/core/browser/card_unmask_delegate.h" | |
| 12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 | 15 |
| 15 namespace autofill { | 16 namespace autofill { |
| 16 | 17 |
| 17 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( | 18 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( |
| 18 content::WebContents* web_contents) | 19 content::WebContents* web_contents) |
| 19 : web_contents_(web_contents), | 20 : web_contents_(web_contents), |
| 20 card_unmask_view_(nullptr), | 21 card_unmask_view_(nullptr), |
| 21 weak_pointer_factory_(this) { | 22 weak_pointer_factory_(this) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { | 25 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { |
| 25 if (card_unmask_view_) | 26 if (card_unmask_view_) |
| 26 card_unmask_view_->ControllerGone(); | 27 card_unmask_view_->ControllerGone(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void CardUnmaskPromptControllerImpl::ShowPrompt( | 30 void CardUnmaskPromptControllerImpl::ShowPrompt( |
| 30 const CreditCard& card, | 31 const CreditCard& card, |
| 31 base::WeakPtr<CardUnmaskDelegate> delegate) { | 32 base::WeakPtr<CardUnmaskDelegate> delegate) { |
| 32 if (card_unmask_view_) | 33 if (card_unmask_view_) |
| 33 card_unmask_view_->ControllerGone(); | 34 card_unmask_view_->ControllerGone(); |
| 34 | 35 |
| 36 pending_response_ = CardUnmaskDelegate::UnmaskResponse(); |
| 37 LoadRiskFingerprint(); |
| 35 card_ = card; | 38 card_ = card; |
| 36 delegate_ = delegate; | 39 delegate_ = delegate; |
| 37 card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); | 40 card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void CardUnmaskPromptControllerImpl::OnVerificationResult(bool success) { | 43 void CardUnmaskPromptControllerImpl::OnVerificationResult(bool success) { |
| 41 if (card_unmask_view_) | 44 if (card_unmask_view_) |
| 42 card_unmask_view_->GotVerificationResult(success); | 45 card_unmask_view_->GotVerificationResult(success); |
| 43 } | 46 } |
| 44 | 47 |
| 45 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 48 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { |
| 46 card_unmask_view_ = nullptr; | 49 card_unmask_view_ = nullptr; |
| 47 delegate_->OnUnmaskPromptClosed(); | 50 delegate_->OnUnmaskPromptClosed(); |
| 48 } | 51 } |
| 49 | 52 |
| 50 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 53 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( |
| 51 const base::string16& cvc, | 54 const base::string16& cvc, |
| 52 const base::string16& exp_month, | 55 const base::string16& exp_month, |
| 53 const base::string16& exp_year) { | 56 const base::string16& exp_year) { |
| 54 card_unmask_view_->DisableAndWaitForVerification(); | 57 card_unmask_view_->DisableAndWaitForVerification(); |
| 55 delegate_->OnUnmaskResponse(cvc, exp_month, exp_year); | 58 |
| 59 DCHECK(!cvc.empty()); |
| 60 pending_response_.cvc = cvc; |
| 61 pending_response_.exp_month = exp_month; |
| 62 pending_response_.exp_year = exp_year; |
| 63 if (!pending_response_.risk_data.empty()) |
| 64 delegate_->OnUnmaskResponse(pending_response_); |
| 56 } | 65 } |
| 57 | 66 |
| 58 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { | 67 content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { |
| 59 return web_contents_; | 68 return web_contents_; |
| 60 } | 69 } |
| 61 | 70 |
| 62 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { | 71 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { |
| 63 // TODO(estade): i18n. | 72 // TODO(estade): i18n. |
| 64 if (ShouldRequestExpirationDate()) { | 73 if (ShouldRequestExpirationDate()) { |
| 65 return base::ASCIIToUTF16("Update your card ") + | 74 return base::ASCIIToUTF16("Update your card ") + |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 bool CardUnmaskPromptControllerImpl::InputTextIsValid( | 105 bool CardUnmaskPromptControllerImpl::InputTextIsValid( |
| 97 const base::string16& input_text) const { | 106 const base::string16& input_text) const { |
| 98 base::string16 trimmed_text; | 107 base::string16 trimmed_text; |
| 99 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | 108 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
| 100 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; | 109 size_t input_size = card_.type() == kAmericanExpressCard ? 4 : 3; |
| 101 return trimmed_text.size() == input_size && | 110 return trimmed_text.size() == input_size && |
| 102 base::ContainsOnlyChars(trimmed_text, | 111 base::ContainsOnlyChars(trimmed_text, |
| 103 base::ASCIIToUTF16("0123456789")); | 112 base::ASCIIToUTF16("0123456789")); |
| 104 } | 113 } |
| 105 | 114 |
| 115 void CardUnmaskPromptControllerImpl::LoadRiskFingerprint() { |
| 116 LoadRiskData( |
| 117 0, web_contents_, |
| 118 base::Bind(&CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint, |
| 119 weak_pointer_factory_.GetWeakPtr())); |
| 120 } |
| 121 |
| 122 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( |
| 123 const std::string& risk_data) { |
| 124 pending_response_.risk_data = risk_data; |
| 125 if (!pending_response_.cvc.empty()) |
| 126 delegate_->OnUnmaskResponse(pending_response_); |
| 127 } |
| 128 |
| 106 } // namespace autofill | 129 } // namespace autofill |
| OLD | NEW |