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

Side by Side Diff: Source/WebKit/chromium/src/WebPasswordFormUtils.cpp

Issue 17381010: Introduce toHTMLFormControlElement, and use it. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 7 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 | Annotate | Revision Log
OLDNEW
1 /* ***** BEGIN LICENSE BLOCK ***** 1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 * 3 *
4 * The contents of this file are subject to the Mozilla Public License Version 4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with 5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at 6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/ 7 * http://www.mozilla.org/MPL/
8 * 8 *
9 * Software distributed under the License is distributed on an "AS IS" basis, 9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void findPasswordFormFields(HTMLFormElement* form, PasswordFormFields* fields) 58 void findPasswordFormFields(HTMLFormElement* form, PasswordFormFields* fields)
59 { 59 {
60 ASSERT(form); 60 ASSERT(form);
61 ASSERT(fields); 61 ASSERT(fields);
62 62
63 HTMLInputElement* latestInputElement = 0; 63 HTMLInputElement* latestInputElement = 0;
64 const Vector<FormAssociatedElement*>& formElements = form->associatedElement s(); 64 const Vector<FormAssociatedElement*>& formElements = form->associatedElement s();
65 for (size_t i = 0; i < formElements.size(); i++) { 65 for (size_t i = 0; i < formElements.size(); i++) {
66 if (!formElements[i]->isFormControlElement()) 66 if (!formElements[i]->isFormControlElement())
67 continue; 67 continue;
68 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement *>(formElements[i]); 68 HTMLFormControlElement* control = toHTMLFormControlElement(formElements[ i]);
69 if (formElement->isActivatedSubmit()) 69 if (control->isActivatedSubmit())
70 fields->submit = formElement; 70 fields->submit = control;
71 71
72 if (!formElement->hasTagName(HTMLNames::inputTag)) 72 if (!control->hasTagName(HTMLNames::inputTag))
73 continue; 73 continue;
74 74
75 HTMLInputElement* inputElement = toHTMLInputElement(formElement); 75 HTMLInputElement* inputElement = toHTMLInputElement(control);
76 if (inputElement->isDisabledFormControl()) 76 if (inputElement->isDisabledFormControl())
77 continue; 77 continue;
78 78
79 if ((fields->passwords.size() < maxPasswords) 79 if ((fields->passwords.size() < maxPasswords)
80 && inputElement->isPasswordField()) { 80 && inputElement->isPasswordField()) {
81 // We assume that the username is the input element before the 81 // We assume that the username is the input element before the
82 // first password element. 82 // first password element.
83 if (fields->passwords.isEmpty() && latestInputElement) { 83 if (fields->passwords.isEmpty() && latestInputElement) {
84 fields->userName = latestInputElement; 84 fields->userName = latestInputElement;
85 // Remove the selected username from alternateUserNames. 85 // Remove the selected username from alternateUserNames.
86 if (!fields->alternateUserNames.isEmpty() && !latestInputElement ->value().isEmpty()) 86 if (!fields->alternateUserNames.isEmpty() && !latestInputElement ->value().isEmpty())
87 fields->alternateUserNames.removeLast(); 87 fields->alternateUserNames.removeLast();
88 } 88 }
89 fields->passwords.append(inputElement); 89 fields->passwords.append(inputElement);
90 } 90 }
91 91
92 // Various input types such as text, url, email can be a username field. 92 // Various input types such as text, url, email can be a username field.
93 if (inputElement->isTextField() && !inputElement->isPasswordField()) { 93 if (inputElement->isTextField() && !inputElement->isPasswordField()) {
94 latestInputElement = inputElement; 94 latestInputElement = inputElement;
95 // We ignore elements that have no value. Unlike userName, alternate UserNames 95 // We ignore elements that have no value. Unlike userName, alternate UserNames
96 // is used only for autofill, not for form identification, and blank autofill 96 // is used only for autofill, not for form identification, and blank autofill
97 // entries are not useful. 97 // entries are not useful.
98 if (!inputElement->value().isEmpty()) 98 if (!inputElement->value().isEmpty())
99 fields->alternateUserNames.append(inputElement->value()); 99 fields->alternateUserNames.append(inputElement->value());
100 } 100 }
101 } 101 }
102 } 102 }
103 103
104 } // namespace WebKit 104 } // namespace WebKit
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebFormElement.cpp ('k') | Source/WebKit/chromium/src/WebSearchableFormData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698