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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
57 // A bit field mask for FillForm functions to not fill some fields. | 57 // A bit field mask for FillForm functions to not fill some fields. |
58 enum FieldFilterMask { | 58 enum FieldFilterMask { |
59 FILTER_NONE = 0, | 59 FILTER_NONE = 0, |
60 FILTER_DISABLED_ELEMENTS = 1 << 0, | 60 FILTER_DISABLED_ELEMENTS = 1 << 0, |
61 FILTER_READONLY_ELEMENTS = 1 << 1, | 61 FILTER_READONLY_ELEMENTS = 1 << 1, |
62 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, | 62 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, |
63 FILTER_ALL_NON_EDITIABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | | 63 FILTER_ALL_NON_EDITABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | |
64 FILTER_READONLY_ELEMENTS | | 64 FILTER_READONLY_ELEMENTS | |
65 FILTER_NON_FOCUSABLE_ELEMENTS, | 65 FILTER_NON_FOCUSABLE_ELEMENTS, |
66 }; | 66 }; |
67 | 67 |
| 68 RequirementsMask ExtractionRequirements() { |
| 69 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 70 switches::kIgnoreAutocompleteOffForAutofill) |
| 71 ? REQUIRE_NONE |
| 72 : REQUIRE_AUTOCOMPLETE; |
| 73 } |
| 74 |
68 bool IsOptionElement(const WebElement& element) { | 75 bool IsOptionElement(const WebElement& element) { |
69 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); | 76 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); |
70 return element.hasHTMLTagName(kOption); | 77 return element.hasHTMLTagName(kOption); |
71 } | 78 } |
72 | 79 |
73 bool IsScriptElement(const WebElement& element) { | 80 bool IsScriptElement(const WebElement& element) { |
74 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); | 81 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); |
75 return element.hasHTMLTagName(kScript); | 82 return element.hasHTMLTagName(kScript); |
76 } | 83 } |
77 | 84 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 480 |
474 // For each autofillable field in |data| that matches a field in the |form|, | 481 // For each autofillable field in |data| that matches a field in the |form|, |
475 // the |callback| is invoked with the corresponding |form| field data. | 482 // the |callback| is invoked with the corresponding |form| field data. |
476 void ForEachMatchingFormField(const WebFormElement& form_element, | 483 void ForEachMatchingFormField(const WebFormElement& form_element, |
477 const WebElement& initiating_element, | 484 const WebElement& initiating_element, |
478 const FormData& data, | 485 const FormData& data, |
479 FieldFilterMask filters, | 486 FieldFilterMask filters, |
480 bool force_override, | 487 bool force_override, |
481 Callback callback) { | 488 Callback callback) { |
482 std::vector<WebFormControlElement> control_elements; | 489 std::vector<WebFormControlElement> control_elements; |
483 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 490 ExtractAutofillableElements( |
484 &control_elements); | 491 form_element, ExtractionRequirements(), &control_elements); |
485 | 492 |
486 if (control_elements.size() != data.fields.size()) { | 493 if (control_elements.size() != data.fields.size()) { |
487 // This case should be reachable only for pathological websites and tests, | 494 // This case should be reachable only for pathological websites and tests, |
488 // which add or remove form fields while the user is interacting with the | 495 // which add or remove form fields while the user is interacting with the |
489 // Autofill popup. | 496 // Autofill popup. |
490 return; | 497 return; |
491 } | 498 } |
492 | 499 |
493 // It's possible that the site has injected fields into the form after the | 500 // It's possible that the site has injected fields into the form after the |
494 // page has loaded, so we can't assert that the size of the cached control | 501 // page has loaded, so we can't assert that the size of the cached control |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 } | 1001 } |
995 | 1002 |
996 void FillForm(const FormData& form, const WebFormControlElement& element) { | 1003 void FillForm(const FormData& form, const WebFormControlElement& element) { |
997 WebFormElement form_element = element.form(); | 1004 WebFormElement form_element = element.form(); |
998 if (form_element.isNull()) | 1005 if (form_element.isNull()) |
999 return; | 1006 return; |
1000 | 1007 |
1001 ForEachMatchingFormField(form_element, | 1008 ForEachMatchingFormField(form_element, |
1002 element, | 1009 element, |
1003 form, | 1010 form, |
1004 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1011 FILTER_ALL_NON_EDITABLE_ELEMENTS, |
1005 false, /* dont force override */ | 1012 false, /* dont force override */ |
1006 &FillFormField); | 1013 &FillFormField); |
1007 } | 1014 } |
1008 | 1015 |
1009 void FillFormIncludingNonFocusableElements(const FormData& form_data, | 1016 void FillFormIncludingNonFocusableElements(const FormData& form_data, |
1010 const WebFormElement& form_element) { | 1017 const WebFormElement& form_element) { |
1011 if (form_element.isNull()) | 1018 if (form_element.isNull()) |
1012 return; | 1019 return; |
1013 | 1020 |
1014 FieldFilterMask filter_mask = static_cast<FieldFilterMask>( | 1021 FieldFilterMask filter_mask = static_cast<FieldFilterMask>( |
(...skipping 20 matching lines...) Expand all Loading... |
1035 } | 1042 } |
1036 | 1043 |
1037 void PreviewForm(const FormData& form, const WebFormControlElement& element) { | 1044 void PreviewForm(const FormData& form, const WebFormControlElement& element) { |
1038 WebFormElement form_element = element.form(); | 1045 WebFormElement form_element = element.form(); |
1039 if (form_element.isNull()) | 1046 if (form_element.isNull()) |
1040 return; | 1047 return; |
1041 | 1048 |
1042 ForEachMatchingFormField(form_element, | 1049 ForEachMatchingFormField(form_element, |
1043 element, | 1050 element, |
1044 form, | 1051 form, |
1045 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1052 FILTER_ALL_NON_EDITABLE_ELEMENTS, |
1046 false, /* dont force override */ | 1053 false, /* dont force override */ |
1047 &PreviewFormField); | 1054 &PreviewFormField); |
1048 } | 1055 } |
1049 | 1056 |
1050 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, | 1057 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
1051 bool was_autofilled) { | 1058 bool was_autofilled) { |
1052 WebFormElement form_element = element.form(); | 1059 WebFormElement form_element = element.form(); |
1053 if (form_element.isNull()) | 1060 if (form_element.isNull()) |
1054 return false; | 1061 return false; |
1055 | 1062 |
1056 std::vector<WebFormControlElement> control_elements; | 1063 std::vector<WebFormControlElement> control_elements; |
1057 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1064 ExtractAutofillableElements( |
1058 &control_elements); | 1065 form_element, ExtractionRequirements(), &control_elements); |
1059 for (size_t i = 0; i < control_elements.size(); ++i) { | 1066 for (size_t i = 0; i < control_elements.size(); ++i) { |
1060 // There might be unrelated elements in this form which have already been | 1067 // There might be unrelated elements in this form which have already been |
1061 // auto-filled. For example, the user might have already filled the address | 1068 // auto-filled. For example, the user might have already filled the address |
1062 // part of a form and now be dealing with the credit card section. We only | 1069 // part of a form and now be dealing with the credit card section. We only |
1063 // want to reset the auto-filled status for fields that were previewed. | 1070 // want to reset the auto-filled status for fields that were previewed. |
1064 WebFormControlElement control_element = control_elements[i]; | 1071 WebFormControlElement control_element = control_elements[i]; |
1065 | 1072 |
1066 // Only text input, textarea and select elements can be previewed. | 1073 // Only text input, textarea and select elements can be previewed. |
1067 WebInputElement* input_element = toWebInputElement(&control_element); | 1074 WebInputElement* input_element = toWebInputElement(&control_element); |
1068 if (!IsTextInput(input_element) && | 1075 if (!IsTextInput(input_element) && |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 | 1114 |
1108 return true; | 1115 return true; |
1109 } | 1116 } |
1110 | 1117 |
1111 bool FormWithElementIsAutofilled(const WebInputElement& element) { | 1118 bool FormWithElementIsAutofilled(const WebInputElement& element) { |
1112 WebFormElement form_element = element.form(); | 1119 WebFormElement form_element = element.form(); |
1113 if (form_element.isNull()) | 1120 if (form_element.isNull()) |
1114 return false; | 1121 return false; |
1115 | 1122 |
1116 std::vector<WebFormControlElement> control_elements; | 1123 std::vector<WebFormControlElement> control_elements; |
1117 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1124 ExtractAutofillableElements( |
1118 &control_elements); | 1125 form_element, ExtractionRequirements(), &control_elements); |
1119 for (size_t i = 0; i < control_elements.size(); ++i) { | 1126 for (size_t i = 0; i < control_elements.size(); ++i) { |
1120 WebInputElement* input_element = toWebInputElement(&control_elements[i]); | 1127 WebInputElement* input_element = toWebInputElement(&control_elements[i]); |
1121 if (!IsAutofillableInputElement(input_element)) | 1128 if (!IsAutofillableInputElement(input_element)) |
1122 continue; | 1129 continue; |
1123 | 1130 |
1124 if (input_element->isAutofilled()) | 1131 if (input_element->isAutofilled()) |
1125 return true; | 1132 return true; |
1126 } | 1133 } |
1127 | 1134 |
1128 return false; | 1135 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 | 1188 |
1182 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { | 1189 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1190 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
1184 return gfx::RectF(bounding_box.x() * scale, | 1191 return gfx::RectF(bounding_box.x() * scale, |
1185 bounding_box.y() * scale, | 1192 bounding_box.y() * scale, |
1186 bounding_box.width() * scale, | 1193 bounding_box.width() * scale, |
1187 bounding_box.height() * scale); | 1194 bounding_box.height() * scale); |
1188 } | 1195 } |
1189 | 1196 |
1190 } // namespace autofill | 1197 } // namespace autofill |
OLD | NEW |