Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/autofill/core/browser/autofill_assistant.h" | 5 #include "components/autofill/core/browser/autofill_assistant.h" |
| 6 | 6 |
| 7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "components/autofill/core/browser/autofill_experiments.h" | 9 #include "components/autofill/core/browser/autofill_experiments.h" |
| 10 #include "components/autofill/core/browser/autofill_manager.h" | 10 #include "components/autofill/core/browser/autofill_manager.h" |
| 11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
| 12 #include "components/autofill/core/browser/form_structure.h" | 12 #include "components/autofill/core/browser/form_structure.h" |
| 13 #include "components/autofill/core/common/autofill_constants.h" | 13 #include "components/autofill/core/common/autofill_constants.h" |
| 14 | 14 |
| 15 namespace autofill { | 15 namespace autofill { |
| 16 | 16 |
| 17 AutofillAssistant::AutofillAssistant(AutofillManager* autofill_manager) | 17 AutofillAssistant::AutofillAssistant(AutofillManager* autofill_manager) |
| 18 : credit_card_form_data_(nullptr), | 18 : credit_card_form_data_(nullptr), |
| 19 autofill_manager_(autofill_manager), | 19 autofill_manager_(autofill_manager), |
| 20 weak_ptr_factory_(this) {} | 20 weak_ptr_factory_(this) {} |
| 21 | 21 |
| 22 AutofillAssistant::~AutofillAssistant() {} | 22 AutofillAssistant::~AutofillAssistant() {} |
| 23 | 23 |
| 24 void AutofillAssistant::Reset() { | 24 void AutofillAssistant::Reset() { |
| 25 credit_card_form_data_.reset(); | 25 credit_card_form_data_.reset(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool AutofillAssistant::CanShowCreditCardAssist( | 28 bool AutofillAssistant::CanShowCreditCardAssist( |
| 29 const std::vector<FormStructure*>& form_structures) { | 29 const std::vector<FormStructure*>& form_structures) { |
| 30 if (!IsAutofillCreditCardAssistEnabled() || credit_card_form_data_) | 30 if (form_structures.empty() || // No forms? |
| 31 credit_card_form_data_ != nullptr || // Already done? | |
| 32 !IsAutofillCreditCardAssistEnabled() || // Assist disabled? | |
| 33 !autofill_manager_->client()->IsContextSecure( // Insecure? | |
|
Evan Stade
2016/08/22 15:07:08
nit: I don't think these comments are that helpful
Roger McFarlane (Chromium)
2016/08/23 21:58:44
Done.
| |
| 34 form_structures.front()->source_url())) { | |
| 31 return false; | 35 return false; |
| 36 } | |
| 32 | 37 |
| 33 for (FormStructure* cur_form : base::Reversed(form_structures)) { | 38 for (FormStructure* cur_form : base::Reversed(form_structures)) { |
| 34 if (cur_form->IsCompleteCreditCardForm()) { | 39 if (cur_form->IsCompleteCreditCardForm()) { |
| 35 credit_card_form_data_.reset(new FormData(cur_form->ToFormData())); | 40 credit_card_form_data_.reset(new FormData(cur_form->ToFormData())); |
| 36 break; | 41 break; |
| 37 } | 42 } |
| 38 } | 43 } |
| 39 return !!credit_card_form_data_; | 44 return credit_card_form_data_ != nullptr; |
| 40 } | 45 } |
| 41 | 46 |
| 42 void AutofillAssistant::ShowAssistForCreditCard(const CreditCard& card) { | 47 void AutofillAssistant::ShowAssistForCreditCard(const CreditCard& card) { |
| 43 DCHECK(credit_card_form_data_); | 48 DCHECK(credit_card_form_data_); |
| 44 autofill_manager_->client()->ConfirmCreditCardFillAssist( | 49 autofill_manager_->client()->ConfirmCreditCardFillAssist( |
| 45 card, base::Bind(&AutofillAssistant::OnUserDidAcceptCreditCardFill, | 50 card, base::Bind(&AutofillAssistant::OnUserDidAcceptCreditCardFill, |
| 46 weak_ptr_factory_.GetWeakPtr(), card)); | 51 weak_ptr_factory_.GetWeakPtr(), card)); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void AutofillAssistant::OnUserDidAcceptCreditCardFill(const CreditCard& card) { | 54 void AutofillAssistant::OnUserDidAcceptCreditCardFill(const CreditCard& card) { |
| 50 // TODO(crbug.com/630656): Trigger CVC dialog flow for card filling. | 55 // TODO(crbug.com/630656): Trigger CVC dialog flow for card filling. |
| 51 autofill_manager_->FillCreditCardForm(kNoQueryId, *credit_card_form_data_, | 56 autofill_manager_->FillCreditCardForm(kNoQueryId, *credit_card_form_data_, |
| 52 credit_card_form_data_->fields[0], card, | 57 credit_card_form_data_->fields[0], card, |
| 53 base::string16()); | 58 base::string16()); |
| 54 } | 59 } |
| 55 | 60 |
| 56 } // namespace autofill | 61 } // namespace autofill |
| OLD | NEW |