| 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/form_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/autofill/core/common/autofill_data_validation.h" | 15 #include "components/autofill/core/common/autofill_data_validation.h" |
| 16 #include "components/autofill/core/common/autofill_switches.h" | 16 #include "components/autofill/core/common/autofill_switches.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 17 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/autofill/core/common/form_field_data.h" | 18 #include "components/autofill/core/common/form_field_data.h" |
| 19 #include "components/autofill/core/common/web_element_descriptor.h" | 19 #include "components/autofill/core/common/web_element_descriptor.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 21 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebElement.h" | 23 #include "third_party/WebKit/public/web/WebElement.h" |
| 24 #include "third_party/WebKit/public/web/WebElementCollection.h" |
| 24 #include "third_party/WebKit/public/web/WebExceptionCode.h" | 25 #include "third_party/WebKit/public/web/WebExceptionCode.h" |
| 25 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 26 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 26 #include "third_party/WebKit/public/web/WebFormElement.h" | 27 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 27 #include "third_party/WebKit/public/web/WebFrame.h" | 28 #include "third_party/WebKit/public/web/WebFrame.h" |
| 28 #include "third_party/WebKit/public/web/WebInputElement.h" | 29 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 29 #include "third_party/WebKit/public/web/WebLabelElement.h" | 30 #include "third_party/WebKit/public/web/WebLabelElement.h" |
| 30 #include "third_party/WebKit/public/web/WebNode.h" | 31 #include "third_party/WebKit/public/web/WebNode.h" |
| 31 #include "third_party/WebKit/public/web/WebNodeCollection.h" | |
| 32 #include "third_party/WebKit/public/web/WebNodeList.h" | 32 #include "third_party/WebKit/public/web/WebNodeList.h" |
| 33 #include "third_party/WebKit/public/web/WebOptionElement.h" | 33 #include "third_party/WebKit/public/web/WebOptionElement.h" |
| 34 #include "third_party/WebKit/public/web/WebSelectElement.h" | 34 #include "third_party/WebKit/public/web/WebSelectElement.h" |
| 35 #include "third_party/WebKit/public/web/WebTextAreaElement.h" | 35 #include "third_party/WebKit/public/web/WebTextAreaElement.h" |
| 36 | 36 |
| 37 using blink::WebDocument; | 37 using blink::WebDocument; |
| 38 using blink::WebElement; | 38 using blink::WebElement; |
| 39 using blink::WebElementCollection; |
| 39 using blink::WebExceptionCode; | 40 using blink::WebExceptionCode; |
| 40 using blink::WebFormControlElement; | 41 using blink::WebFormControlElement; |
| 41 using blink::WebFormElement; | 42 using blink::WebFormElement; |
| 42 using blink::WebFrame; | 43 using blink::WebFrame; |
| 43 using blink::WebInputElement; | 44 using blink::WebInputElement; |
| 44 using blink::WebLabelElement; | 45 using blink::WebLabelElement; |
| 45 using blink::WebNode; | 46 using blink::WebNode; |
| 46 using blink::WebNodeCollection; | |
| 47 using blink::WebNodeList; | 47 using blink::WebNodeList; |
| 48 using blink::WebOptionElement; | 48 using blink::WebOptionElement; |
| 49 using blink::WebSelectElement; | 49 using blink::WebSelectElement; |
| 50 using blink::WebTextAreaElement; | 50 using blink::WebTextAreaElement; |
| 51 using blink::WebString; | 51 using blink::WebString; |
| 52 using blink::WebVector; | 52 using blink::WebVector; |
| 53 | 53 |
| 54 namespace autofill { | 54 namespace autofill { |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 // If we failed to extract any fields, give up. Also, to avoid overly | 900 // If we failed to extract any fields, give up. Also, to avoid overly |
| 901 // expensive computation, we impose a maximum number of allowable fields. | 901 // expensive computation, we impose a maximum number of allowable fields. |
| 902 if (form_fields.empty() || form_fields.size() > kMaxParseableFields) | 902 if (form_fields.empty() || form_fields.size() > kMaxParseableFields) |
| 903 return false; | 903 return false; |
| 904 | 904 |
| 905 // Loop through the label elements inside the form element. For each label | 905 // Loop through the label elements inside the form element. For each label |
| 906 // element, get the corresponding form control element, use the form control | 906 // element, get the corresponding form control element, use the form control |
| 907 // element's name as a key into the <name, FormFieldData> map to find the | 907 // element's name as a key into the <name, FormFieldData> map to find the |
| 908 // previously created FormFieldData and set the FormFieldData's label to the | 908 // previously created FormFieldData and set the FormFieldData's label to the |
| 909 // label.firstChild().nodeValue() of the label element. | 909 // label.firstChild().nodeValue() of the label element. |
| 910 WebNodeCollection labels = form_element.getElementsByTagName(kLabel); | 910 WebElementCollection labels = form_element.getElementsByTagName(kLabel); |
| 911 DCHECK(!labels.isNull()); | 911 DCHECK(!labels.isNull()); |
| 912 for (WebNode item = labels.firstItem(); !item.isNull(); | 912 for (WebElement item = labels.firstItem(); !item.isNull(); |
| 913 item = labels.nextItem()) { | 913 item = labels.nextItem()) { |
| 914 WebLabelElement label = item.to<WebLabelElement>(); | 914 WebLabelElement label = item.to<WebLabelElement>(); |
| 915 WebFormControlElement field_element = | 915 WebFormControlElement field_element = |
| 916 label.correspondingControl().to<WebFormControlElement>(); | 916 label.correspondingControl().to<WebFormControlElement>(); |
| 917 | 917 |
| 918 base::string16 element_name; | 918 base::string16 element_name; |
| 919 if (field_element.isNull()) { | 919 if (field_element.isNull()) { |
| 920 // Sometimes site authors will incorrectly specify the corresponding | 920 // Sometimes site authors will incorrectly specify the corresponding |
| 921 // field element's name rather than its id, so we compensate here. | 921 // field element's name rather than its id, so we compensate here. |
| 922 element_name = label.getAttribute(kFor); | 922 element_name = label.getAttribute(kFor); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 | 1181 |
| 1182 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { | 1182 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { |
| 1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1184 return gfx::RectF(bounding_box.x() * scale, | 1184 return gfx::RectF(bounding_box.x() * scale, |
| 1185 bounding_box.y() * scale, | 1185 bounding_box.y() * scale, |
| 1186 bounding_box.width() * scale, | 1186 bounding_box.width() * scale, |
| 1187 bounding_box.height() * scale); | 1187 bounding_box.height() * scale); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 } // namespace autofill | 1190 } // namespace autofill |
| OLD | NEW |