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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils.cc

Issue 2917933002: [PasswordGeneration] Improve change/confirm password field detection. (Closed)
Patch Set: Address more comments. Created 3 years, 6 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/content/renderer/password_form_conversion_utils.h" 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 field_value_and_properties_map, form_predictions)) 733 field_value_and_properties_map, form_predictions))
734 return std::unique_ptr<PasswordForm>(); 734 return std::unique_ptr<PasswordForm>();
735 735
736 // No actual action on the form, so use the the origin as the action. 736 // No actual action on the form, so use the the origin as the action.
737 password_form->action = password_form->origin; 737 password_form->action = password_form->origin;
738 738
739 return password_form; 739 return password_form;
740 } 740 }
741 741
742 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, 742 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element,
743 const char* value_in_lowercase) { 743 base::StringPiece value_in_lowercase) {
744 std::string autocomplete_value_lowercase = base::ToLowerASCII( 744 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete"));
745 base::UTF16ToUTF8(element.GetAttribute("autocomplete").Utf16())); 745 const std::string autocomplete_value =
746 element.GetAttribute(kAutocomplete)
747 .Utf8(WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
746 748
747 std::vector<base::StringPiece> tokens = base::SplitStringPiece( 749 std::vector<base::StringPiece> tokens =
748 autocomplete_value_lowercase, base::kWhitespaceASCII, 750 base::SplitStringPiece(autocomplete_value, base::kWhitespaceASCII,
749 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 751 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
750 752 return std::find_if(tokens.begin(), tokens.end(),
751 return base::ContainsValue(tokens, value_in_lowercase); 753 [value_in_lowercase](base::StringPiece token) {
dvadym 2017/06/09 11:39:48 Nit: it looks that you can avoid copying value_in_
pkalinnikov 2017/06/09 11:53:23 I assume you mean [value_in_lowercase](base::Strin
dvadym 2017/06/09 11:59:25 Acknowledged
754 return base::LowerCaseEqualsASCII(token,
755 value_in_lowercase);
756 }) != tokens.end();
752 } 757 }
753 758
754 bool HasCreditCardAutocompleteAttributes( 759 bool HasCreditCardAutocompleteAttributes(
755 const blink::WebInputElement& element) { 760 const blink::WebInputElement& element) {
756 std::string autocomplete_value_lowercase = base::ToLowerASCII( 761 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete"));
757 base::UTF16ToUTF8(element.GetAttribute("autocomplete").Utf16())); 762 const std::string autocomplete_value =
763 element.GetAttribute(kAutocomplete)
764 .Utf8(WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
758 765
759 for (const auto& token : base::SplitStringPiece( 766 std::vector<base::StringPiece> tokens =
760 autocomplete_value_lowercase, base::kWhitespaceASCII, 767 base::SplitStringPiece(autocomplete_value, base::kWhitespaceASCII,
761 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { 768 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
762 if (base::StartsWith(token, kAutocompleteCreditCardPrefix, 769 return std::find_if(
763 base::CompareCase::SENSITIVE)) { 770 tokens.begin(), tokens.end(), [](base::StringPiece token) {
dvadym 2017/06/09 11:39:47 Nit: base::StringPiece -> const base::StringPiece&
pkalinnikov 2017/06/09 11:53:23 Same argument as above.
dvadym 2017/06/09 11:59:25 Acknowledged
764 return true; 771 return base::StartsWith(token, kAutocompleteCreditCardPrefix,
765 } 772 base::CompareCase::INSENSITIVE_ASCII);
766 } 773 }) != tokens.end();
767 return false;
768 } 774 }
769 775
770 bool IsCreditCardVerificationPasswordField( 776 bool IsCreditCardVerificationPasswordField(
771 const blink::WebInputElement& field) { 777 const blink::WebInputElement& field) {
772 if (!field.IsPasswordField()) 778 if (!field.IsPasswordField())
773 return false; 779 return false;
774 780
775 static const base::string16 kCardCvcReCached = base::UTF8ToUTF16(kCardCvcRe); 781 static const base::string16 kCardCvcReCached = base::UTF8ToUTF16(kCardCvcRe);
776 782
777 return MatchesPattern(field.GetAttribute("id").Utf16(), kCardCvcReCached) || 783 return MatchesPattern(field.GetAttribute("id").Utf16(), kCardCvcReCached) ||
778 MatchesPattern(field.GetAttribute("name").Utf16(), kCardCvcReCached); 784 MatchesPattern(field.GetAttribute("name").Utf16(), kCardCvcReCached);
779 } 785 }
780 786
781 std::string GetSignOnRealm(const GURL& origin) { 787 std::string GetSignOnRealm(const GURL& origin) {
782 GURL::Replacements rep; 788 GURL::Replacements rep;
783 rep.SetPathStr(""); 789 rep.SetPathStr("");
784 return origin.ReplaceComponents(rep).spec(); 790 return origin.ReplaceComponents(rep).spec();
785 } 791 }
786 792
787 } // namespace autofill 793 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698