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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 base::ContainsOnlyChars(CreditCard::StripSeparators(field.value), | 302 base::ContainsOnlyChars(CreditCard::StripSeparators(field.value), |
| 303 base::ASCIIToUTF16("0123456789")); | 303 base::ASCIIToUTF16("0123456789")); |
| 304 | 304 |
| 305 bool is_scannable_name_on_card_field = | 305 bool is_scannable_name_on_card_field = |
| 306 autofill_field->Type().GetStorableType() == CREDIT_CARD_NAME_FULL && | 306 autofill_field->Type().GetStorableType() == CREDIT_CARD_NAME_FULL && |
| 307 base::FeatureList::IsEnabled(kAutofillScanCardholderName); | 307 base::FeatureList::IsEnabled(kAutofillScanCardholderName); |
| 308 | 308 |
| 309 if (!is_card_number_field && !is_scannable_name_on_card_field) | 309 if (!is_card_number_field && !is_scannable_name_on_card_field) |
| 310 return false; | 310 return false; |
| 311 | 311 |
| 312 if (IsFormNonSecure(form)) | |
| 313 return false; | |
| 314 | |
| 312 static const int kShowScanCreditCardMaxValueLength = 6; | 315 static const int kShowScanCreditCardMaxValueLength = 6; |
| 313 return field.value.size() <= kShowScanCreditCardMaxValueLength; | 316 return field.value.size() <= kShowScanCreditCardMaxValueLength; |
| 314 } | 317 } |
| 315 | 318 |
| 316 bool AutofillManager::IsCreditCardPopup(const FormData& form, | 319 bool AutofillManager::IsCreditCardPopup(const FormData& form, |
| 317 const FormFieldData& field) { | 320 const FormFieldData& field) { |
| 318 AutofillField* autofill_field = GetAutofillField(form, field); | 321 AutofillField* autofill_field = GetAutofillField(form, field); |
| 319 return autofill_field && autofill_field->Type().group() == CREDIT_CARD; | 322 return autofill_field && autofill_field->Type().group() == CREDIT_CARD; |
| 320 } | 323 } |
| 321 | 324 |
| 322 bool AutofillManager::ShouldShowCreditCardSigninPromo( | 325 bool AutofillManager::ShouldShowCreditCardSigninPromo( |
|
Mathieu
2017/02/06 18:21:26
also see if the unit test for this needs to be upd
elawrence
2017/02/07 20:16:48
I added two new tests that check the new restricti
| |
| 323 const FormData& form, | 326 const FormData& form, |
| 324 const FormFieldData& field) { | 327 const FormFieldData& field) { |
| 325 // Check whether we are dealing with a credit card field and whether it's | 328 // Check whether we are dealing with a credit card field and whether it's |
| 326 // appropriate to show the promo (e.g. the platform is supported). | 329 // appropriate to show the promo (e.g. the platform is supported). |
| 327 AutofillField* autofill_field = GetAutofillField(form, field); | 330 AutofillField* autofill_field = GetAutofillField(form, field); |
| 328 if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD || | 331 if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD || |
| 329 !client_->ShouldShowSigninPromo()) | 332 !client_->ShouldShowSigninPromo()) |
| 330 return false; | 333 return false; |
| 331 | 334 |
| 335 if (IsFormNonSecure(form)) | |
| 336 return false; | |
| 337 | |
| 332 // The last step is checking if we are under the limit of impressions. | 338 // The last step is checking if we are under the limit of impressions. |
| 333 int impression_count = client_->GetPrefs()->GetInteger( | 339 int impression_count = client_->GetPrefs()->GetInteger( |
| 334 prefs::kAutofillCreditCardSigninPromoImpressionCount); | 340 prefs::kAutofillCreditCardSigninPromoImpressionCount); |
| 335 if (impression_count < kCreditCardSigninPromoImpressionLimit) { | 341 if (impression_count < kCreditCardSigninPromoImpressionLimit) { |
| 336 // The promo will be shown. Increment the impression count. | 342 // The promo will be shown. Increment the impression count. |
| 337 client_->GetPrefs()->SetInteger( | 343 client_->GetPrefs()->SetInteger( |
| 338 prefs::kAutofillCreditCardSigninPromoImpressionCount, | 344 prefs::kAutofillCreditCardSigninPromoImpressionCount, |
| 339 impression_count + 1); | 345 impression_count + 1); |
| 340 return true; | 346 return true; |
| 341 } | 347 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 if (!user_did_edit_autofilled_field_) { | 526 if (!user_did_edit_autofilled_field_) { |
| 521 user_did_edit_autofilled_field_ = true; | 527 user_did_edit_autofilled_field_ = true; |
| 522 AutofillMetrics::LogUserHappinessMetric( | 528 AutofillMetrics::LogUserHappinessMetric( |
| 523 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); | 529 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); |
| 524 } | 530 } |
| 525 } | 531 } |
| 526 | 532 |
| 527 UpdateInitialInteractionTimestamp(timestamp); | 533 UpdateInitialInteractionTimestamp(timestamp); |
| 528 } | 534 } |
| 529 | 535 |
| 536 bool AutofillManager::IsFormNonSecure(const FormData& form) const { | |
|
Mathieu
2017/02/06 18:16:41
short unit test? AutofillClient functionality will
elawrence
2017/02/07 20:16:47
My new Unit tests exercise the IsFormNonSecure fun
| |
| 537 if (!client_->IsContextSecure(form.origin)) | |
| 538 return true; | |
| 539 if (form.action.is_valid() && form.action.SchemeIs("http")) | |
|
Mathieu
2017/02/06 18:16:41
return !client_->IsContextSecure(form.origin) || (
elawrence
2017/02/07 20:16:47
Done.
| |
| 540 return true; | |
| 541 | |
| 542 return false; | |
| 543 } | |
| 544 | |
| 530 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 545 void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
| 531 const FormData& form, | 546 const FormData& form, |
| 532 const FormFieldData& field, | 547 const FormFieldData& field, |
| 533 const gfx::RectF& bounding_box) { | 548 const gfx::RectF& bounding_box) { |
| 534 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 549 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
| 535 return; | 550 return; |
| 536 | 551 |
| 537 gfx::RectF transformed_box = | 552 gfx::RectF transformed_box = |
| 538 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); | 553 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); |
| 539 | 554 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 556 if (autofill_field->Type().group() == CREDIT_CARD) { | 571 if (autofill_field->Type().group() == CREDIT_CARD) { |
| 557 is_filling_credit_card = true; | 572 is_filling_credit_card = true; |
| 558 driver_->DidInteractWithCreditCardForm(); | 573 driver_->DidInteractWithCreditCardForm(); |
| 559 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); | 574 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 560 } else { | 575 } else { |
| 561 address_form_event_logger_->OnDidInteractWithAutofillableForm(); | 576 address_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 562 } | 577 } |
| 563 } | 578 } |
| 564 | 579 |
| 565 std::vector<Suggestion> suggestions; | 580 std::vector<Suggestion> suggestions; |
| 566 const bool is_context_secure = | 581 const bool is_context_secure = !IsFormNonSecure(form); |
| 567 !form_structure || | 582 |
| 568 (client_->IsContextSecure(form_structure->source_url()) && | |
| 569 (!form_structure->target_url().is_valid() || | |
| 570 !form_structure->target_url().SchemeIs("http"))); | |
| 571 const bool is_http_warning_enabled = | 583 const bool is_http_warning_enabled = |
| 572 security_state::IsHttpWarningInFormEnabled(); | 584 security_state::IsHttpWarningInFormEnabled(); |
| 573 | 585 |
| 574 // TODO(rogerm): Early exit here on !driver_->RendererIsAvailable()? | 586 // TODO(rogerm): Early exit here on !driver_->RendererIsAvailable()? |
| 575 // We skip populating autofill data, but might generate warnings and or | 587 // We skip populating autofill data, but might generate warnings and or |
| 576 // signin promo to show over the unavailable renderer. That seems a mistake. | 588 // signin promo to show over the unavailable renderer. That seems a mistake. |
| 577 | 589 |
| 578 if (is_autofill_possible && | 590 if (is_autofill_possible && |
| 579 driver_->RendererIsAvailable() && | 591 driver_->RendererIsAvailable() && |
| 580 got_autofillable_form) { | 592 got_autofillable_form) { |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2170 if (i > 0) | 2182 if (i > 0) |
| 2171 fputs("Next oldest form:\n", file); | 2183 fputs("Next oldest form:\n", file); |
| 2172 } | 2184 } |
| 2173 fputs("\n", file); | 2185 fputs("\n", file); |
| 2174 | 2186 |
| 2175 fclose(file); | 2187 fclose(file); |
| 2176 } | 2188 } |
| 2177 #endif // ENABLE_FORM_DEBUG_DUMP | 2189 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2178 | 2190 |
| 2179 } // namespace autofill | 2191 } // namespace autofill |
| OLD | NEW |