Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 2676513007: Do not show Scan or Sign In options when credit card form is non-secure (Closed)
Patch Set: Add unit tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
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
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 {
537 return !client_->IsContextSecure(form.origin) ||
538 (form.action.is_valid() && form.action.SchemeIs("http"));
539 }
540
530 void AutofillManager::OnQueryFormFieldAutofill(int query_id, 541 void AutofillManager::OnQueryFormFieldAutofill(int query_id,
531 const FormData& form, 542 const FormData& form,
532 const FormFieldData& field, 543 const FormFieldData& field,
533 const gfx::RectF& bounding_box) { 544 const gfx::RectF& bounding_box) {
534 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) 545 if (!IsValidFormData(form) || !IsValidFormFieldData(field))
535 return; 546 return;
536 547
537 gfx::RectF transformed_box = 548 gfx::RectF transformed_box =
538 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); 549 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box);
539 550
(...skipping 16 matching lines...) Expand all
556 if (autofill_field->Type().group() == CREDIT_CARD) { 567 if (autofill_field->Type().group() == CREDIT_CARD) {
557 is_filling_credit_card = true; 568 is_filling_credit_card = true;
558 driver_->DidInteractWithCreditCardForm(); 569 driver_->DidInteractWithCreditCardForm();
559 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); 570 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm();
560 } else { 571 } else {
561 address_form_event_logger_->OnDidInteractWithAutofillableForm(); 572 address_form_event_logger_->OnDidInteractWithAutofillableForm();
562 } 573 }
563 } 574 }
564 575
565 std::vector<Suggestion> suggestions; 576 std::vector<Suggestion> suggestions;
566 const bool is_context_secure = 577 const bool is_context_secure = !IsFormNonSecure(form);
567 !form_structure || 578
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 = 579 const bool is_http_warning_enabled =
572 security_state::IsHttpWarningInFormEnabled(); 580 security_state::IsHttpWarningInFormEnabled();
573 581
574 // TODO(rogerm): Early exit here on !driver_->RendererIsAvailable()? 582 // TODO(rogerm): Early exit here on !driver_->RendererIsAvailable()?
575 // We skip populating autofill data, but might generate warnings and or 583 // We skip populating autofill data, but might generate warnings and or
576 // signin promo to show over the unavailable renderer. That seems a mistake. 584 // signin promo to show over the unavailable renderer. That seems a mistake.
577 585
578 if (is_autofill_possible && 586 if (is_autofill_possible &&
579 driver_->RendererIsAvailable() && 587 driver_->RendererIsAvailable() &&
580 got_autofillable_form) { 588 got_autofillable_form) {
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 if (i > 0) 2178 if (i > 0)
2171 fputs("Next oldest form:\n", file); 2179 fputs("Next oldest form:\n", file);
2172 } 2180 }
2173 fputs("\n", file); 2181 fputs("\n", file);
2174 2182
2175 fclose(file); 2183 fclose(file);
2176 } 2184 }
2177 #endif // ENABLE_FORM_DEBUG_DUMP 2185 #endif // ENABLE_FORM_DEBUG_DUMP
2178 2186
2179 } // namespace autofill 2187 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698