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

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

Issue 1130153005: Autofill: Document ExtractFieldsFromControlElements(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/form_autofill_util.h" 5 #include "components/autofill/content/renderer/form_autofill_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 const_cast<blink::WebNode&>(node).childNodes(); 891 const_cast<blink::WebNode&>(node).childNodes();
892 size_t length = children.length(); 892 size_t length = children.length();
893 for (size_t i = 0; i < length; ++i) { 893 for (size_t i = 0; i < length; ++i) {
894 const blink::WebNode& item = children.item(i); 894 const blink::WebNode& item = children.item(i);
895 if (IsWebNodeVisibleImpl(item, depth - 1)) 895 if (IsWebNodeVisibleImpl(item, depth - 1))
896 return true; 896 return true;
897 } 897 }
898 return false; 898 return false;
899 } 899 }
900 900
901 // Extracts the fields from |control_elements| with |extract_mask| to
902 // |form_fields|. The extracted fields are also placed in |element_map|.
903 // |form_fields| and |element_map| should start out empty.
904 // |fields_extracted| should have as many elements as |control_elements|,
905 // initialized to false.
906 // Returns true if the number of fields extracted is within
907 // [1, kMaxParseableFields].
901 bool ExtractFieldsFromControlElements( 908 bool ExtractFieldsFromControlElements(
902 const WebVector<WebFormControlElement>& control_elements, 909 const WebVector<WebFormControlElement>& control_elements,
903 ExtractMask extract_mask, 910 ExtractMask extract_mask,
904 ScopedVector<FormFieldData>* form_fields, 911 ScopedVector<FormFieldData>* form_fields,
905 std::vector<bool>* fields_extracted, 912 std::vector<bool>* fields_extracted,
906 std::map<WebFormControlElement, FormFieldData*>* element_map) { 913 std::map<WebFormControlElement, FormFieldData*>* element_map) {
914 DCHECK(form_fields->empty());
915 DCHECK(element_map->empty());
916 DCHECK_EQ(control_elements.size(), fields_extracted->size());
917
907 for (size_t i = 0; i < control_elements.size(); ++i) { 918 for (size_t i = 0; i < control_elements.size(); ++i) {
908 const WebFormControlElement& control_element = control_elements[i]; 919 const WebFormControlElement& control_element = control_elements[i];
909 920
910 if (!IsAutofillableElement(control_element)) 921 if (!IsAutofillableElement(control_element))
911 continue; 922 continue;
912 923
913 // Create a new FormFieldData, fill it out and map it to the field's name. 924 // Create a new FormFieldData, fill it out and map it to the field's name.
914 FormFieldData* form_field = new FormFieldData; 925 FormFieldData* form_field = new FormFieldData;
915 WebFormControlElementToFormField(control_element, extract_mask, form_field); 926 WebFormControlElementToFormField(control_element, extract_mask, form_field);
916 form_fields->push_back(form_field); 927 form_fields->push_back(form_field);
917 (*element_map)[control_element] = form_field; 928 (*element_map)[control_element] = form_field;
918 (*fields_extracted)[i] = true; 929 (*fields_extracted)[i] = true;
930
931 // To avoid overly expensive computation, we impose a maximum number of
932 // allowable fields.
933 if (form_fields->size() > kMaxParseableFields)
934 return false;
919 } 935 }
920 936
921 // If we failed to extract any fields, give up. Also, to avoid overly 937 // Succeeded if fields were extracted.
922 // expensive computation, we impose a maximum number of allowable fields. 938 return !form_fields->empty();
923 if (form_fields->empty() || form_fields->size() > kMaxParseableFields)
924 return false;
925 return true;
926 } 939 }
927 940
928 // For each label element, get the corresponding form control element, use the 941 // For each label element, get the corresponding form control element, use the
929 // form control element's name as a key into the 942 // form control element's name as a key into the
930 // <WebFormControlElement, FormFieldData> map to find the previously created 943 // <WebFormControlElement, FormFieldData> map to find the previously created
931 // FormFieldData and set the FormFieldData's label to the 944 // FormFieldData and set the FormFieldData's label to the
932 // label.firstChild().nodeValue() of the label element. 945 // label.firstChild().nodeValue() of the label element.
933 void MatchLabelsAndFields( 946 void MatchLabelsAndFields(
934 const WebElementCollection& labels, 947 const WebElementCollection& labels,
935 std::map<WebFormControlElement, FormFieldData*>* element_map) { 948 std::map<WebFormControlElement, FormFieldData*>* element_map) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 1528
1516 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { 1529 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) {
1517 gfx::Rect bounding_box(element->boundsInViewportSpace()); 1530 gfx::Rect bounding_box(element->boundsInViewportSpace());
1518 return gfx::RectF(bounding_box.x() * scale, 1531 return gfx::RectF(bounding_box.x() * scale,
1519 bounding_box.y() * scale, 1532 bounding_box.y() * scale,
1520 bounding_box.width() * scale, 1533 bounding_box.width() * scale,
1521 bounding_box.height() * scale); 1534 bounding_box.height() * scale);
1522 } 1535 }
1523 1536
1524 } // namespace autofill 1537 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698