| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 suggestions); | 547 suggestions); |
| 548 } else { | 548 } else { |
| 549 // Autocomplete is disabled for this field; only pass back Autofill | 549 // Autocomplete is disabled for this field; only pass back Autofill |
| 550 // suggestions. | 550 // suggestions. |
| 551 autocomplete_history_manager_->CancelPendingQuery(); | 551 autocomplete_history_manager_->CancelPendingQuery(); |
| 552 external_delegate_->OnSuggestionsReturned( | 552 external_delegate_->OnSuggestionsReturned( |
| 553 query_id, suggestions); | 553 query_id, suggestions); |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 | 556 |
| 557 bool AutofillManager::WillFillCreditCardNumber(const FormData& form, |
| 558 const FormFieldData& field) { |
| 559 FormStructure* form_structure = nullptr; |
| 560 AutofillField* autofill_field = nullptr; |
| 561 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
| 562 return false; |
| 563 |
| 564 if (autofill_field->Type().GetStorableType() == CREDIT_CARD_NUMBER) |
| 565 return true; |
| 566 |
| 567 // If the relevant section is already autofilled, the new fill operation will |
| 568 // only fill |autofill_field|. |
| 569 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) |
| 570 return false; |
| 571 |
| 572 DCHECK_EQ(form_structure->field_count(), form.fields.size()); |
| 573 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 574 if (form_structure->field(i)->section() == autofill_field->section() && |
| 575 form_structure->field(i)->Type().GetStorableType() == |
| 576 CREDIT_CARD_NUMBER && |
| 577 form.fields[i].value.empty()) { |
| 578 return true; |
| 579 } |
| 580 } |
| 581 |
| 582 return false; |
| 583 } |
| 584 |
| 557 void AutofillManager::FillOrPreviewCreditCardForm( | 585 void AutofillManager::FillOrPreviewCreditCardForm( |
| 558 AutofillDriver::RendererFormDataAction action, | 586 AutofillDriver::RendererFormDataAction action, |
| 559 int query_id, | 587 int query_id, |
| 560 const FormData& form, | 588 const FormData& form, |
| 561 const FormFieldData& field, | 589 const FormFieldData& field, |
| 562 const CreditCard& credit_card, | 590 const CreditCard& credit_card, |
| 563 size_t variant) { | 591 size_t variant) { |
| 564 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) { | 592 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) { |
| 565 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) { | 593 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD && |
| 594 WillFillCreditCardNumber(form, field)) { |
| 566 unmasking_card_ = credit_card; | 595 unmasking_card_ = credit_card; |
| 567 unmasking_query_id_ = query_id; | 596 unmasking_query_id_ = query_id; |
| 568 unmasking_form_ = form; | 597 unmasking_form_ = form; |
| 569 unmasking_field_ = field; | 598 unmasking_field_ = field; |
| 570 real_pan_client_.Prepare(); | 599 real_pan_client_.Prepare(); |
| 571 client()->ShowUnmaskPrompt(unmasking_card_, | 600 client()->ShowUnmaskPrompt(unmasking_card_, |
| 572 weak_ptr_factory_.GetWeakPtr()); | 601 weak_ptr_factory_.GetWeakPtr()); |
| 573 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); | 602 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); |
| 574 return; | 603 return; |
| 575 } | 604 } |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 return false; | 1494 return false; |
| 1466 | 1495 |
| 1467 // Disregard forms that we wouldn't ever autofill in the first place. | 1496 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1468 if (!form.ShouldBeParsed()) | 1497 if (!form.ShouldBeParsed()) |
| 1469 return false; | 1498 return false; |
| 1470 | 1499 |
| 1471 return true; | 1500 return true; |
| 1472 } | 1501 } |
| 1473 | 1502 |
| 1474 } // namespace autofill | 1503 } // namespace autofill |
| OLD | NEW |