Chromium Code Reviews| 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 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 autofill_field->Type().GetStorableType() == CREDIT_CARD_NAME_FULL && | 283 autofill_field->Type().GetStorableType() == CREDIT_CARD_NAME_FULL && |
| 284 base::FeatureList::IsEnabled(kAutofillScanCardholderName); | 284 base::FeatureList::IsEnabled(kAutofillScanCardholderName); |
| 285 | 285 |
| 286 if (!is_card_number_field && !is_scannable_name_on_card_field) | 286 if (!is_card_number_field && !is_scannable_name_on_card_field) |
| 287 return false; | 287 return false; |
| 288 | 288 |
| 289 static const int kShowScanCreditCardMaxValueLength = 6; | 289 static const int kShowScanCreditCardMaxValueLength = 6; |
| 290 return field.value.size() <= kShowScanCreditCardMaxValueLength; | 290 return field.value.size() <= kShowScanCreditCardMaxValueLength; |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool AutofillManager::IsCreditCardField(const FormData& form, | |
| 294 const FormFieldData& field) { | |
| 295 AutofillField* autofill_field = GetAutofillField(form, field); | |
| 296 // TODO(csashi): Should we check GetStorableType()? | |
|
Mathieu
2016/11/30 21:27:35
I believe this is fine as is.
csashi
2016/12/01 01:13:43
Done.
| |
| 297 return autofill_field && autofill_field->Type().group() == CREDIT_CARD; | |
| 298 } | |
| 299 | |
| 293 bool AutofillManager::ShouldShowCreditCardSigninPromo( | 300 bool AutofillManager::ShouldShowCreditCardSigninPromo( |
| 294 const FormData& form, | 301 const FormData& form, |
| 295 const FormFieldData& field) { | 302 const FormFieldData& field) { |
| 296 if (!IsAutofillCreditCardSigninPromoEnabled()) | 303 if (!IsAutofillCreditCardSigninPromoEnabled()) |
| 297 return false; | 304 return false; |
| 298 | 305 |
| 299 // Check whether we are dealing with a credit card field and whether it's | 306 // Check whether we are dealing with a credit card field and whether it's |
| 300 // appropriate to show the promo (e.g. the platform is supported). | 307 // appropriate to show the promo (e.g. the platform is supported). |
| 301 AutofillField* autofill_field = GetAutofillField(form, field); | 308 AutofillField* autofill_field = GetAutofillField(form, field); |
| 302 if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD || | 309 if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD || |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 UpdateInitialInteractionTimestamp(timestamp); | 510 UpdateInitialInteractionTimestamp(timestamp); |
| 504 } | 511 } |
| 505 | 512 |
| 506 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 513 void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
| 507 const FormData& form, | 514 const FormData& form, |
| 508 const FormFieldData& field, | 515 const FormFieldData& field, |
| 509 const gfx::RectF& bounding_box) { | 516 const gfx::RectF& bounding_box) { |
| 510 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 517 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
| 511 return; | 518 return; |
| 512 | 519 |
| 513 std::vector<Suggestion> suggestions; | |
| 514 | |
| 515 gfx::RectF transformed_box = | 520 gfx::RectF transformed_box = |
| 516 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); | 521 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); |
| 517 external_delegate_->OnQuery(query_id, form, field, transformed_box); | 522 external_delegate_->OnQuery(query_id, form, field, transformed_box); |
| 518 | 523 |
| 519 // Need to refresh models before using the form_event_loggers. | 524 // Need to refresh models before using the form_event_loggers. |
| 520 bool is_autofill_possible = RefreshDataModels(); | 525 bool is_autofill_possible = RefreshDataModels(); |
| 521 | 526 |
| 522 FormStructure* form_structure = NULL; | 527 FormStructure* form_structure = NULL; |
| 523 AutofillField* autofill_field = NULL; | 528 AutofillField* autofill_field = NULL; |
| 524 bool got_autofillable_form = | 529 bool got_autofillable_form = |
| 525 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 530 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 526 // Don't send suggestions or track forms that should not be parsed. | 531 // Don't send suggestions or track forms that should not be parsed. |
| 527 form_structure->ShouldBeParsed(); | 532 form_structure->ShouldBeParsed(); |
| 528 | 533 |
| 529 // Logging interactions of forms that are autofillable. | 534 // Logging interactions of forms that are autofillable. |
| 530 if (got_autofillable_form) { | 535 if (got_autofillable_form) { |
| 531 if (autofill_field->Type().group() == CREDIT_CARD) { | 536 if (autofill_field->Type().group() == CREDIT_CARD) { |
| 532 driver_->DidInteractWithCreditCardForm(); | 537 driver_->DidInteractWithCreditCardForm(); |
| 533 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); | 538 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 534 } else { | 539 } else { |
| 535 address_form_event_logger_->OnDidInteractWithAutofillableForm(); | 540 address_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 536 } | 541 } |
| 537 } | 542 } |
| 538 | 543 |
| 544 std::vector<Suggestion> suggestions; | |
| 545 | |
| 539 if (is_autofill_possible && | 546 if (is_autofill_possible && |
| 540 driver_->RendererIsAvailable() && | 547 driver_->RendererIsAvailable() && |
| 541 got_autofillable_form) { | 548 got_autofillable_form) { |
| 542 AutofillType type = autofill_field->Type(); | 549 AutofillType type = autofill_field->Type(); |
| 543 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 550 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| 544 // On desktop, don't return non credit card related suggestions for forms or | 551 // On desktop, don't return non credit card related suggestions for forms or |
| 545 // fields that have the "autocomplete" attribute set to off. | 552 // fields that have the "autocomplete" attribute set to off. |
| 546 if (IsDesktopPlatform() && !is_filling_credit_card && | 553 if (IsDesktopPlatform() && !is_filling_credit_card && |
| 547 !field.should_autocomplete) { | 554 !field.should_autocomplete) { |
| 548 return; | 555 return; |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 credit_card_form_event_logger_->OnDidPollSuggestions(field); | 1770 credit_card_form_event_logger_->OnDidPollSuggestions(field); |
| 1764 | 1771 |
| 1765 // The field value is sanitized before attempting to match it to the user's | 1772 // The field value is sanitized before attempting to match it to the user's |
| 1766 // data. | 1773 // data. |
| 1767 std::vector<Suggestion> suggestions = | 1774 std::vector<Suggestion> suggestions = |
| 1768 personal_data_->GetCreditCardSuggestions( | 1775 personal_data_->GetCreditCardSuggestions( |
| 1769 type, SanitizeCreditCardFieldValue(field.value)); | 1776 type, SanitizeCreditCardFieldValue(field.value)); |
| 1770 for (size_t i = 0; i < suggestions.size(); i++) { | 1777 for (size_t i = 0; i < suggestions.size(); i++) { |
| 1771 suggestions[i].frontend_id = | 1778 suggestions[i].frontend_id = |
| 1772 MakeFrontendID(suggestions[i].backend_id, std::string()); | 1779 MakeFrontendID(suggestions[i].backend_id, std::string()); |
| 1780 suggestions[i].is_value_bold = IsCreditCardPopupValueBold(); | |
| 1773 } | 1781 } |
| 1774 return suggestions; | 1782 return suggestions; |
| 1775 } | 1783 } |
| 1776 | 1784 |
| 1777 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1785 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
| 1778 if (forms.empty()) | 1786 if (forms.empty()) |
| 1779 return; | 1787 return; |
| 1780 | 1788 |
| 1781 std::vector<FormStructure*> non_queryable_forms; | 1789 std::vector<FormStructure*> non_queryable_forms; |
| 1782 std::vector<FormStructure*> queryable_forms; | 1790 std::vector<FormStructure*> queryable_forms; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2104 if (i > 0) | 2112 if (i > 0) |
| 2105 fputs("Next oldest form:\n", file); | 2113 fputs("Next oldest form:\n", file); |
| 2106 } | 2114 } |
| 2107 fputs("\n", file); | 2115 fputs("\n", file); |
| 2108 | 2116 |
| 2109 fclose(file); | 2117 fclose(file); |
| 2110 } | 2118 } |
| 2111 #endif // ENABLE_FORM_DEBUG_DUMP | 2119 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2112 | 2120 |
| 2113 } // namespace autofill | 2121 } // namespace autofill |
| OLD | NEW |