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

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

Issue 2676653004: Show FormNotSecure warnings on sensitive inputs in non-secure contexts (Closed)
Patch Set: 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // Need to refresh models before using the form_event_loggers. 543 // Need to refresh models before using the form_event_loggers.
544 bool is_autofill_possible = RefreshDataModels(); 544 bool is_autofill_possible = RefreshDataModels();
545 545
546 FormStructure* form_structure = NULL; 546 FormStructure* form_structure = NULL;
547 AutofillField* autofill_field = NULL; 547 AutofillField* autofill_field = NULL;
548 bool got_autofillable_form = 548 bool got_autofillable_form =
549 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && 549 GetCachedFormAndField(form, field, &form_structure, &autofill_field) &&
550 // Don't send suggestions or track forms that should not be parsed. 550 // Don't send suggestions or track forms that should not be parsed.
551 form_structure->ShouldBeParsed(); 551 form_structure->ShouldBeParsed();
552 552
553 // Logging interactions of forms that are autofillable. 553 bool is_filling_credit_card = false;
554
555 // Log interactions of forms that are autofillable.
554 if (got_autofillable_form) { 556 if (got_autofillable_form) {
555 if (autofill_field->Type().group() == CREDIT_CARD) { 557 if (autofill_field->Type().group() == CREDIT_CARD) {
558 is_filling_credit_card = true;
556 driver_->DidInteractWithCreditCardForm(); 559 driver_->DidInteractWithCreditCardForm();
557 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); 560 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm();
558 } else { 561 } else {
559 address_form_event_logger_->OnDidInteractWithAutofillableForm(); 562 address_form_event_logger_->OnDidInteractWithAutofillableForm();
560 } 563 }
561 } 564 }
562 565
563 std::vector<Suggestion> suggestions; 566 std::vector<Suggestion> suggestions;
567 const bool is_context_secure =
568 !form_structure ||
569 (client_->IsContextSecure(form_structure->source_url()) &&
570 (!form_structure->target_url().is_valid() ||
571 !form_structure->target_url().SchemeIs("http")));
572 const bool is_http_warning_enabled =
573 security_state::IsHttpWarningInFormEnabled();
564 574
565 if (is_autofill_possible && 575 if (is_autofill_possible &&
566 driver_->RendererIsAvailable() && 576 driver_->RendererIsAvailable() &&
567 got_autofillable_form) { 577 got_autofillable_form) {
568 AutofillType type = autofill_field->Type();
569 bool is_filling_credit_card = (type.group() == CREDIT_CARD);
570 // On desktop, don't return non credit card related suggestions for forms or 578 // On desktop, don't return non credit card related suggestions for forms or
571 // fields that have the "autocomplete" attribute set to off. 579 // fields that have the "autocomplete" attribute set to off.
572 if (IsDesktopPlatform() && !is_filling_credit_card && 580 if (IsDesktopPlatform() && !is_filling_credit_card &&
573 !field.should_autocomplete) { 581 !field.should_autocomplete) {
574 return; 582 return;
575 } 583 }
576 if (is_filling_credit_card) { 584 if (is_filling_credit_card) {
577 suggestions = GetCreditCardSuggestions(field, type); 585 suggestions = GetCreditCardSuggestions(field, autofill_field->Type());
578 } else { 586 } else {
579 suggestions = 587 suggestions =
580 GetProfileSuggestions(*form_structure, field, *autofill_field); 588 GetProfileSuggestions(*form_structure, field, *autofill_field);
581 } 589 }
590
582 if (!suggestions.empty()) { 591 if (!suggestions.empty()) {
583 bool is_context_secure =
584 client_->IsContextSecure(form_structure->source_url()) &&
585 (!form_structure->target_url().is_valid() ||
586 !form_structure->target_url().SchemeIs("http"));
587 if (is_filling_credit_card) 592 if (is_filling_credit_card)
588 AutofillMetrics::LogIsQueriedCreditCardFormSecure(is_context_secure); 593 AutofillMetrics::LogIsQueriedCreditCardFormSecure(is_context_secure);
589 594
590 // Don't provide credit card suggestions for non-secure pages, but do 595 // Don't provide credit card suggestions for non-secure pages, but do
591 // provide them for secure pages with passive mixed content (see impl. of 596 // provide them for secure pages with passive mixed content (see impl. of
592 // IsContextSecure). 597 // IsContextSecure).
593 if (is_filling_credit_card && !is_context_secure) { 598 if (is_filling_credit_card && !is_context_secure) {
594 bool is_http_warning_enabled =
595 security_state::IsHttpWarningInFormEnabled();
596 // Replace the suggestion content with a warning message explaining why 599 // Replace the suggestion content with a warning message explaining why
597 // Autofill is disabled for a website. The string is different if the 600 // Autofill is disabled for a website. The string is different if the
598 // credit card autofill HTTP warning experiment is enabled. 601 // credit card autofill HTTP warning experiment is enabled.
599 Suggestion warning_suggestion(l10n_util::GetStringUTF16( 602 Suggestion warning_suggestion(l10n_util::GetStringUTF16(
600 is_http_warning_enabled 603 is_http_warning_enabled
601 ? IDS_AUTOFILL_WARNING_PAYMENT_DISABLED 604 ? IDS_AUTOFILL_WARNING_PAYMENT_DISABLED
602 : IDS_AUTOFILL_WARNING_INSECURE_CONNECTION)); 605 : IDS_AUTOFILL_WARNING_INSECURE_CONNECTION));
603 warning_suggestion.frontend_id = 606 warning_suggestion.frontend_id =
604 POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE; 607 POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE;
605 suggestions.assign(1, warning_suggestion); 608 suggestions.assign(1, warning_suggestion);
606
607 // On top of the explanation message, first show a "Payment not secure"
608 // message.
609 if (is_http_warning_enabled) {
610 #if !defined(OS_ANDROID)
611 suggestions.insert(suggestions.begin(), Suggestion());
612 suggestions.front().frontend_id = POPUP_ITEM_ID_SEPARATOR;
613 #endif
614 suggestions.insert(suggestions.begin(),
615 CreateHttpWarningMessageSuggestionItem(
616 form_structure->source_url()));
617 }
618 } else { 609 } else {
619 bool section_is_autofilled = 610 bool section_is_autofilled = SectionIsAutofilled(
620 SectionIsAutofilled(*form_structure, form, 611 *form_structure, form, autofill_field->section());
621 autofill_field->section());
622 if (section_is_autofilled) { 612 if (section_is_autofilled) {
623 // If the relevant section is auto-filled and the renderer is querying 613 // If the relevant section is auto-filled and the renderer is querying
624 // for suggestions, then the user is editing the value of a field. 614 // for suggestions, then the user is editing the value of a field.
625 // In this case, mimic autocomplete: don't display labels or icons, 615 // In this case, mimic autocomplete: don't display labels or icons,
626 // as that information is redundant. Moreover, filter out duplicate 616 // as that information is redundant. Moreover, filter out duplicate
627 // suggestions. 617 // suggestions.
628 std::set<base::string16> seen_values; 618 std::set<base::string16> seen_values;
629 for (auto iter = suggestions.begin(); iter != suggestions.end();) { 619 for (auto iter = suggestions.begin(); iter != suggestions.end();) {
630 if (!seen_values.insert(iter->value).second) { 620 if (!seen_values.insert(iter->value).second) {
631 // If we've seen this suggestion value before, remove it. 621 // If we've seen this suggestion value before, remove it.
(...skipping 11 matching lines...) Expand all
643 // TODO(mathp): Differentiate between number of suggestions available 633 // TODO(mathp): Differentiate between number of suggestions available
644 // (current metric) and number shown to the user. 634 // (current metric) and number shown to the user.
645 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) { 635 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) {
646 AutofillMetrics::LogAddressSuggestionsCount(suggestions.size()); 636 AutofillMetrics::LogAddressSuggestionsCount(suggestions.size());
647 has_logged_address_suggestions_count_ = true; 637 has_logged_address_suggestions_count_ = true;
648 } 638 }
649 } 639 }
650 } 640 }
651 } 641 }
652 642
643 // Show a "Payment not secure" message.
644 if (!is_context_secure && is_http_warning_enabled) {
645 #if !defined(OS_ANDROID)
646 if (!suggestions.empty()) {
647 suggestions.insert(suggestions.begin(), Suggestion());
648 suggestions.front().frontend_id = POPUP_ITEM_ID_SEPARATOR;
649 }
650 #endif
651
652 suggestions.insert(
653 suggestions.begin(),
654 CreateHttpWarningMessageSuggestionItem(
655 form_structure ? form_structure->source_url() : GURL::EmptyGURL()));
656 }
657
653 // If there are no Autofill suggestions, consider showing Autocomplete 658 // If there are no Autofill suggestions, consider showing Autocomplete
654 // suggestions. We will not show Autocomplete suggestions for a field that 659 // suggestions. We will not show Autocomplete suggestions for a field that
655 // specifies autocomplete=off (or an unrecognized type), a field for which we 660 // specifies autocomplete=off (or an unrecognized type), a field for which we
656 // will show the credit card signin promo, or a field that we think is a 661 // will show the credit card signin promo, or a field that we think is a
657 // credit card expiration, cvc or number. 662 // credit card expiration, cvc or number.
658 if (suggestions.empty() && !ShouldShowCreditCardSigninPromo(form, field) && 663 if (suggestions.empty() && !ShouldShowCreditCardSigninPromo(form, field) &&
659 field.should_autocomplete && 664 field.should_autocomplete &&
660 !(autofill_field && 665 !(autofill_field &&
661 (IsCreditCardExpirationType(autofill_field->Type().GetStorableType()) || 666 (IsCreditCardExpirationType(autofill_field->Type().GetStorableType()) ||
662 autofill_field->Type().html_type() == HTML_TYPE_UNRECOGNIZED || 667 autofill_field->Type().html_type() == HTML_TYPE_UNRECOGNIZED ||
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 if (i > 0) 2143 if (i > 0)
2139 fputs("Next oldest form:\n", file); 2144 fputs("Next oldest form:\n", file);
2140 } 2145 }
2141 fputs("\n", file); 2146 fputs("\n", file);
2142 2147
2143 fclose(file); 2148 fclose(file);
2144 } 2149 }
2145 #endif // ENABLE_FORM_DEBUG_DUMP 2150 #endif // ENABLE_FORM_DEBUG_DUMP
2146 2151
2147 } // namespace autofill 2152 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698