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/content/renderer/password_form_conversion_utils.h" | 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "components/autofill/content/renderer/form_autofill_util.h" | 8 #include "components/autofill/content/renderer/form_autofill_util.h" |
9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
11 #include "third_party/WebKit/public/web/WebDocument.h" | 11 #include "third_party/WebKit/public/web/WebDocument.h" |
12 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 12 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
13 #include "third_party/WebKit/public/web/WebInputElement.h" | 13 #include "third_party/WebKit/public/web/WebInputElement.h" |
14 | 14 |
15 using blink::WebDocument; | 15 using blink::WebDocument; |
16 using blink::WebFormControlElement; | 16 using blink::WebFormControlElement; |
17 using blink::WebFormElement; | 17 using blink::WebFormElement; |
18 using blink::WebInputElement; | 18 using blink::WebInputElement; |
19 using blink::WebString; | 19 using blink::WebString; |
20 using blink::WebVector; | 20 using blink::WebVector; |
21 | 21 |
22 namespace autofill { | 22 namespace autofill { |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Maximum number of password fields we will observe before throwing our | |
26 // hands in the air and giving up with a given form. | |
27 static const size_t kMaxPasswords = 3; | |
28 | |
29 // Checks in a case-insensitive way if the autocomplete attribute for the given | 25 // Checks in a case-insensitive way if the autocomplete attribute for the given |
30 // |element| is present and has the specified |value_in_lowercase|. | 26 // |element| is present and has the specified |value_in_lowercase|. |
31 bool HasAutocompleteAttributeValue(const WebInputElement& element, | 27 bool HasAutocompleteAttributeValue(const WebInputElement& element, |
32 const char* value_in_lowercase) { | 28 const char* value_in_lowercase) { |
33 return LowerCaseEqualsASCII(element.getAttribute("autocomplete"), | 29 return LowerCaseEqualsASCII(element.getAttribute("autocomplete"), |
34 value_in_lowercase); | 30 value_in_lowercase); |
35 } | 31 } |
36 | 32 |
37 // Helper to determine which password is the main (current) one, and which is | 33 // Helper to determine which password is the main (current) one, and which is |
38 // the new password (e.g., on a sign-up or change password form), if any. | 34 // the new password (e.g., on a sign-up or change password form), if any. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 121 |
126 for (size_t i = 0; i < control_elements.size(); ++i) { | 122 for (size_t i = 0; i < control_elements.size(); ++i) { |
127 WebFormControlElement control_element = control_elements[i]; | 123 WebFormControlElement control_element = control_elements[i]; |
128 if (control_element.isActivatedSubmit()) | 124 if (control_element.isActivatedSubmit()) |
129 password_form->submit_element = control_element.formControlName(); | 125 password_form->submit_element = control_element.formControlName(); |
130 | 126 |
131 WebInputElement* input_element = toWebInputElement(&control_element); | 127 WebInputElement* input_element = toWebInputElement(&control_element); |
132 if (!input_element || !input_element->isEnabled()) | 128 if (!input_element || !input_element->isEnabled()) |
133 continue; | 129 continue; |
134 | 130 |
135 if ((passwords.size() < kMaxPasswords) && | 131 if (input_element->isPasswordField()) { |
136 input_element->isPasswordField()) { | |
137 passwords.push_back(*input_element); | 132 passwords.push_back(*input_element); |
138 // If we have not yet considered any element to be the username so far, | 133 // If we have not yet considered any element to be the username so far, |
139 // provisionally select the input element just before the first password | 134 // provisionally select the input element just before the first password |
140 // element to be the username. This choice will be overruled if we later | 135 // element to be the username. This choice will be overruled if we later |
141 // find an element with autocomplete='username'. | 136 // find an element with autocomplete='username'. |
142 if (username_element.isNull() && !latest_input_element.isNull()) { | 137 if (username_element.isNull() && !latest_input_element.isNull()) { |
143 username_element = latest_input_element; | 138 username_element = latest_input_element; |
144 // Remove the selected username from other_possible_usernames. | 139 // Remove the selected username from other_possible_usernames. |
145 if (!latest_input_element.value().isEmpty()) { | 140 if (!latest_input_element.value().isEmpty()) { |
146 DCHECK(!other_possible_usernames.empty()); | 141 DCHECK(!other_possible_usernames.empty()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 blink::WebFormControlElement(), | 259 blink::WebFormControlElement(), |
265 REQUIRE_NONE, | 260 REQUIRE_NONE, |
266 EXTRACT_NONE, | 261 EXTRACT_NONE, |
267 &password_form->form_data, | 262 &password_form->form_data, |
268 NULL /* FormFieldData */); | 263 NULL /* FormFieldData */); |
269 | 264 |
270 return password_form.Pass(); | 265 return password_form.Pass(); |
271 } | 266 } |
272 | 267 |
273 } // namespace autofill | 268 } // namespace autofill |
OLD | NEW |