| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/form_classifier.h" | 5 #include "components/autofill/content/renderer/form_classifier.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Finds <img>'s inside |form| and checks if <img>'s attributes contains captcha | 84 // Finds <img>'s inside |form| and checks if <img>'s attributes contains captcha |
| 85 // text features. Returns true, if at least one occurrence was found. | 85 // text features. Returns true, if at least one occurrence was found. |
| 86 bool FindCaptchaInImgElements(const blink::WebElement& form, | 86 bool FindCaptchaInImgElements(const blink::WebElement& form, |
| 87 bool ingnore_invisible) { | 87 bool ingnore_invisible) { |
| 88 CR_DEFINE_STATIC_LOCAL(WebString, kImageTag, ("img")); | 88 CR_DEFINE_STATIC_LOCAL(WebString, kImageTag, ("img")); |
| 89 | 89 |
| 90 blink::WebElementCollection img_elements = | 90 blink::WebElementCollection img_elements = |
| 91 form.getElementsByHTMLTagName(kImageTag); | 91 form.getElementsByHTMLTagName(kImageTag); |
| 92 for (blink::WebElement element = img_elements.firstItem(); !element.isNull(); | 92 for (blink::WebElement element = img_elements.firstItem(); !element.isNull(); |
| 93 element = img_elements.nextItem()) { | 93 element = img_elements.nextItem()) { |
| 94 if (ingnore_invisible && !form_util::IsWebNodeVisible(element)) | 94 if (ingnore_invisible && !form_util::IsWebElementVisible(element)) |
| 95 continue; | 95 continue; |
| 96 if (FindTextFeaturesForClass(element, kCaptchaFeatures, | 96 if (FindTextFeaturesForClass(element, kCaptchaFeatures, |
| 97 kNumberOfCaptchaFeatures)) { | 97 kNumberOfCaptchaFeatures)) { |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Finds signin and signup features in |element|'s attribute values. Sets to | 104 // Finds signin and signup features in |element|'s attribute values. Sets to |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // Return true if |form| contains at least one visible password element. | 155 // Return true if |form| contains at least one visible password element. |
| 156 bool FormContainsVisiblePasswordFields(const blink::WebFormElement& form) { | 156 bool FormContainsVisiblePasswordFields(const blink::WebFormElement& form) { |
| 157 WebVector<WebFormControlElement> control_elements; | 157 WebVector<WebFormControlElement> control_elements; |
| 158 form.getFormControlElements(control_elements); | 158 form.getFormControlElements(control_elements); |
| 159 for (auto& control_element : control_elements) { | 159 for (auto& control_element : control_elements) { |
| 160 const WebInputElement* input_element = toWebInputElement(&control_element); | 160 const WebInputElement* input_element = toWebInputElement(&control_element); |
| 161 if (!input_element) | 161 if (!input_element) |
| 162 continue; | 162 continue; |
| 163 if (input_element->isPasswordField() && | 163 if (input_element->isPasswordField() && |
| 164 form_util::IsWebNodeVisible(*input_element)) { | 164 form_util::IsWebElementVisible(*input_element)) { |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace | 171 } // namespace |
| 172 | 172 |
| 173 bool ClassifyFormAndFindGenerationField(const blink::WebFormElement& form, | 173 bool ClassifyFormAndFindGenerationField(const blink::WebFormElement& form, |
| 174 base::string16* generation_field) { | 174 base::string16* generation_field) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 192 &found_signup_text_features); | 192 &found_signup_text_features); |
| 193 | 193 |
| 194 std::vector<WebInputElement> passwords; | 194 std::vector<WebInputElement> passwords; |
| 195 WebVector<WebFormControlElement> control_elements; | 195 WebVector<WebFormControlElement> control_elements; |
| 196 form.getFormControlElements(control_elements); | 196 form.getFormControlElements(control_elements); |
| 197 | 197 |
| 198 for (const WebFormControlElement& control_element : control_elements) { | 198 for (const WebFormControlElement& control_element : control_elements) { |
| 199 if (IsHiddenElement(control_element)) | 199 if (IsHiddenElement(control_element)) |
| 200 continue; | 200 continue; |
| 201 if (ignore_invisible_elements) { | 201 if (ignore_invisible_elements) { |
| 202 if (!form_util::IsWebNodeVisible(control_element)) | 202 if (!form_util::IsWebElementVisible(control_element)) |
| 203 continue; | 203 continue; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // If type="button" or "image", skip them, because it might be a link | 206 // If type="button" or "image", skip them, because it might be a link |
| 207 // to another form. | 207 // to another form. |
| 208 if (IsButtonOrImageElement(control_element)) | 208 if (IsButtonOrImageElement(control_element)) |
| 209 continue; | 209 continue; |
| 210 | 210 |
| 211 FindTextFeaturesInElement(control_element, &found_signin_text_features, | 211 FindTextFeaturesInElement(control_element, &found_signin_text_features, |
| 212 &found_signup_text_features); | 212 &found_signup_text_features); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 password_creation_field = passwords[1]; | 256 password_creation_field = passwords[1]; |
| 257 else | 257 else |
| 258 password_creation_field = passwords[0]; | 258 password_creation_field = passwords[0]; |
| 259 | 259 |
| 260 *generation_field = password_creation_field.nameForAutofill().utf16(); | 260 *generation_field = password_creation_field.nameForAutofill().utf16(); |
| 261 return true; | 261 return true; |
| 262 } | 262 } |
| 263 return false; | 263 return false; |
| 264 } | 264 } |
| 265 } | 265 } |
| OLD | NEW |