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/command_line.h" | |
Ilya Sherman
2014/10/21 01:19:11
nit: Duplicate #include.
Evan Stade
2014/10/21 19:12:47
Done.
| |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "components/autofill/core/common/autofill_data_validation.h" | 16 #include "components/autofill/core/common/autofill_data_validation.h" |
16 #include "components/autofill/core/common/autofill_switches.h" | 17 #include "components/autofill/core/common/autofill_switches.h" |
18 #include "components/autofill/core/common/autofill_switches.h" | |
Ilya Sherman
2014/10/21 01:19:11
Here too.
Evan Stade
2014/10/21 19:12:47
Done.
| |
17 #include "components/autofill/core/common/form_data.h" | 19 #include "components/autofill/core/common/form_data.h" |
18 #include "components/autofill/core/common/form_field_data.h" | 20 #include "components/autofill/core/common/form_field_data.h" |
19 #include "components/autofill/core/common/web_element_descriptor.h" | 21 #include "components/autofill/core/common/web_element_descriptor.h" |
20 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
21 #include "third_party/WebKit/public/platform/WebVector.h" | 23 #include "third_party/WebKit/public/platform/WebVector.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebElement.h" | 25 #include "third_party/WebKit/public/web/WebElement.h" |
24 #include "third_party/WebKit/public/web/WebElementCollection.h" | 26 #include "third_party/WebKit/public/web/WebElementCollection.h" |
25 #include "third_party/WebKit/public/web/WebExceptionCode.h" | 27 #include "third_party/WebKit/public/web/WebExceptionCode.h" |
26 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 28 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 enum FieldFilterMask { | 60 enum FieldFilterMask { |
59 FILTER_NONE = 0, | 61 FILTER_NONE = 0, |
60 FILTER_DISABLED_ELEMENTS = 1 << 0, | 62 FILTER_DISABLED_ELEMENTS = 1 << 0, |
61 FILTER_READONLY_ELEMENTS = 1 << 1, | 63 FILTER_READONLY_ELEMENTS = 1 << 1, |
62 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, | 64 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, |
63 FILTER_ALL_NON_EDITIABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | | 65 FILTER_ALL_NON_EDITIABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | |
64 FILTER_READONLY_ELEMENTS | | 66 FILTER_READONLY_ELEMENTS | |
65 FILTER_NON_FOCUSABLE_ELEMENTS, | 67 FILTER_NON_FOCUSABLE_ELEMENTS, |
66 }; | 68 }; |
67 | 69 |
70 RequirementsMask ExtractionRequirements() { | |
71 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
72 switches::kIgnoreAutocompleteOffForAutofill) | |
73 ? REQUIRE_NONE | |
74 : REQUIRE_AUTOCOMPLETE; | |
75 } | |
76 | |
68 bool IsOptionElement(const WebElement& element) { | 77 bool IsOptionElement(const WebElement& element) { |
69 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); | 78 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); |
70 return element.hasHTMLTagName(kOption); | 79 return element.hasHTMLTagName(kOption); |
71 } | 80 } |
72 | 81 |
73 bool IsScriptElement(const WebElement& element) { | 82 bool IsScriptElement(const WebElement& element) { |
74 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); | 83 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); |
75 return element.hasHTMLTagName(kScript); | 84 return element.hasHTMLTagName(kScript); |
76 } | 85 } |
77 | 86 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 | 482 |
474 // For each autofillable field in |data| that matches a field in the |form|, | 483 // For each autofillable field in |data| that matches a field in the |form|, |
475 // the |callback| is invoked with the corresponding |form| field data. | 484 // the |callback| is invoked with the corresponding |form| field data. |
476 void ForEachMatchingFormField(const WebFormElement& form_element, | 485 void ForEachMatchingFormField(const WebFormElement& form_element, |
477 const WebElement& initiating_element, | 486 const WebElement& initiating_element, |
478 const FormData& data, | 487 const FormData& data, |
479 FieldFilterMask filters, | 488 FieldFilterMask filters, |
480 bool force_override, | 489 bool force_override, |
481 Callback callback) { | 490 Callback callback) { |
482 std::vector<WebFormControlElement> control_elements; | 491 std::vector<WebFormControlElement> control_elements; |
483 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 492 ExtractAutofillableElements( |
484 &control_elements); | 493 form_element, ExtractionRequirements(), &control_elements); |
485 | 494 |
486 if (control_elements.size() != data.fields.size()) { | 495 if (control_elements.size() != data.fields.size()) { |
Ilya Sherman
2014/10/21 01:19:11
Hmm, did you also change which fields are extracte
Evan Stade
2014/10/21 19:12:47
good question. I think if there was a mismatch, it
Ilya Sherman
2014/10/21 23:58:18
Hmm, that's odd. Could you please do a bit of deb
| |
487 // This case should be reachable only for pathological websites and tests, | 496 // 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 | 497 // which add or remove form fields while the user is interacting with the |
489 // Autofill popup. | 498 // Autofill popup. |
490 return; | 499 return; |
491 } | 500 } |
492 | 501 |
493 // It's possible that the site has injected fields into the form after the | 502 // 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 | 503 // page has loaded, so we can't assert that the size of the cached control |
495 // elements is equal to the size of the fields in |form|. Fortunately, the | 504 // elements is equal to the size of the fields in |form|. Fortunately, the |
496 // one case in the wild where this happens, paypal.com signup form, the fields | 505 // one case in the wild where this happens, paypal.com signup form, the fields |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1047 &PreviewFormField); | 1056 &PreviewFormField); |
1048 } | 1057 } |
1049 | 1058 |
1050 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, | 1059 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
1051 bool was_autofilled) { | 1060 bool was_autofilled) { |
1052 WebFormElement form_element = element.form(); | 1061 WebFormElement form_element = element.form(); |
1053 if (form_element.isNull()) | 1062 if (form_element.isNull()) |
1054 return false; | 1063 return false; |
1055 | 1064 |
1056 std::vector<WebFormControlElement> control_elements; | 1065 std::vector<WebFormControlElement> control_elements; |
1057 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1066 ExtractAutofillableElements( |
1058 &control_elements); | 1067 form_element, ExtractionRequirements(), &control_elements); |
Ilya Sherman
2014/10/21 01:19:11
We could probably just always pass REQUIRE_NONE he
Evan Stade
2014/10/21 19:12:47
ditto
| |
1059 for (size_t i = 0; i < control_elements.size(); ++i) { | 1068 for (size_t i = 0; i < control_elements.size(); ++i) { |
1060 // There might be unrelated elements in this form which have already been | 1069 // 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 | 1070 // 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 | 1071 // 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. | 1072 // want to reset the auto-filled status for fields that were previewed. |
1064 WebFormControlElement control_element = control_elements[i]; | 1073 WebFormControlElement control_element = control_elements[i]; |
1065 | 1074 |
1066 // Only text input, textarea and select elements can be previewed. | 1075 // Only text input, textarea and select elements can be previewed. |
1067 WebInputElement* input_element = toWebInputElement(&control_element); | 1076 WebInputElement* input_element = toWebInputElement(&control_element); |
1068 if (!IsTextInput(input_element) && | 1077 if (!IsTextInput(input_element) && |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 | 1116 |
1108 return true; | 1117 return true; |
1109 } | 1118 } |
1110 | 1119 |
1111 bool FormWithElementIsAutofilled(const WebInputElement& element) { | 1120 bool FormWithElementIsAutofilled(const WebInputElement& element) { |
1112 WebFormElement form_element = element.form(); | 1121 WebFormElement form_element = element.form(); |
1113 if (form_element.isNull()) | 1122 if (form_element.isNull()) |
1114 return false; | 1123 return false; |
1115 | 1124 |
1116 std::vector<WebFormControlElement> control_elements; | 1125 std::vector<WebFormControlElement> control_elements; |
1117 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1126 ExtractAutofillableElements( |
1118 &control_elements); | 1127 form_element, ExtractionRequirements(), &control_elements); |
Ilya Sherman
2014/10/21 01:19:11
We could probably just always pass REQUIRE_NONE he
Evan Stade
2014/10/21 19:12:47
ditto
| |
1119 for (size_t i = 0; i < control_elements.size(); ++i) { | 1128 for (size_t i = 0; i < control_elements.size(); ++i) { |
1120 WebInputElement* input_element = toWebInputElement(&control_elements[i]); | 1129 WebInputElement* input_element = toWebInputElement(&control_elements[i]); |
1121 if (!IsAutofillableInputElement(input_element)) | 1130 if (!IsAutofillableInputElement(input_element)) |
1122 continue; | 1131 continue; |
1123 | 1132 |
1124 if (input_element->isAutofilled()) | 1133 if (input_element->isAutofilled()) |
1125 return true; | 1134 return true; |
1126 } | 1135 } |
1127 | 1136 |
1128 return false; | 1137 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1181 | 1190 |
1182 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { | 1191 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1192 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
1184 return gfx::RectF(bounding_box.x() * scale, | 1193 return gfx::RectF(bounding_box.x() * scale, |
1185 bounding_box.y() * scale, | 1194 bounding_box.y() * scale, |
1186 bounding_box.width() * scale, | 1195 bounding_box.width() * scale, |
1187 bounding_box.height() * scale); | 1196 bounding_box.height() * scale); |
1188 } | 1197 } |
1189 | 1198 |
1190 } // namespace autofill | 1199 } // namespace autofill |
OLD | NEW |