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_cache.h" | 5 #include "components/autofill/content/renderer/form_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 FormCache::FormCache(const WebFrame& frame) : frame_(frame) { | 72 FormCache::FormCache(const WebFrame& frame) : frame_(frame) { |
73 } | 73 } |
74 | 74 |
75 FormCache::~FormCache() { | 75 FormCache::~FormCache() { |
76 } | 76 } |
77 | 77 |
78 std::vector<FormData> FormCache::ExtractNewForms() { | 78 std::vector<FormData> FormCache::ExtractNewForms(size_t* unowned_form_index) { |
79 DCHECK(unowned_form_index); | |
80 | |
81 *unowned_form_index = 0; | |
Evan Stade
2015/01/22 23:43:44
I think it's cleaner if fakeness is an attribute o
Lei Zhang
2015/01/22 23:58:13
FormData gets serialized as part of a PasswordForm
Evan Stade
2015/01/23 02:21:46
yea but this is not sustainable either. Next time
| |
79 std::vector<FormData> forms; | 82 std::vector<FormData> forms; |
80 WebDocument document = frame_.document(); | 83 WebDocument document = frame_.document(); |
81 if (document.isNull()) | 84 if (document.isNull()) |
82 return forms; | 85 return forms; |
83 | 86 |
84 WebVector<WebFormElement> web_forms; | 87 WebVector<WebFormElement> web_forms; |
85 document.forms(web_forms); | 88 document.forms(web_forms); |
86 | 89 |
87 // Log an error message for deprecated attributes, but only the first time | 90 // Log an error message for deprecated attributes, but only the first time |
88 // the form is parsed. | 91 // the form is parsed. |
(...skipping 19 matching lines...) Expand all Loading... | |
108 REQUIRE_NONE, extract_mask, &form, nullptr)) { | 111 REQUIRE_NONE, extract_mask, &form, nullptr)) { |
109 continue; | 112 continue; |
110 } | 113 } |
111 | 114 |
112 num_fields_seen += form.fields.size(); | 115 num_fields_seen += form.fields.size(); |
113 if (num_fields_seen > kMaxParseableFields) | 116 if (num_fields_seen > kMaxParseableFields) |
114 return forms; | 117 return forms; |
115 | 118 |
116 if (form.fields.size() >= kRequiredAutofillFields && | 119 if (form.fields.size() >= kRequiredAutofillFields && |
117 !ContainsKey(parsed_forms_, form)) { | 120 !ContainsKey(parsed_forms_, form)) { |
121 ++(*unowned_form_index); | |
118 forms.push_back(form); | 122 forms.push_back(form); |
119 parsed_forms_.insert(form); | 123 parsed_forms_.insert(form); |
120 } | 124 } |
121 } | 125 } |
122 | 126 |
123 // Look for more parseable fields outside of forms. | 127 // Look for more parseable fields outside of forms. |
124 std::vector<WebElement> fieldsets; | 128 std::vector<WebElement> fieldsets; |
125 std::vector<WebFormControlElement> control_elements = | 129 std::vector<WebFormControlElement> control_elements = |
126 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); | 130 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); |
127 | 131 |
(...skipping 10 matching lines...) Expand all Loading... | |
138 &synthetic_form, nullptr)) { | 142 &synthetic_form, nullptr)) { |
139 return forms; | 143 return forms; |
140 } | 144 } |
141 | 145 |
142 num_fields_seen += synthetic_form.fields.size(); | 146 num_fields_seen += synthetic_form.fields.size(); |
143 if (num_fields_seen > kMaxParseableFields) | 147 if (num_fields_seen > kMaxParseableFields) |
144 return forms; | 148 return forms; |
145 | 149 |
146 if (synthetic_form.fields.size() >= kRequiredAutofillFields && | 150 if (synthetic_form.fields.size() >= kRequiredAutofillFields && |
147 !parsed_forms_.count(synthetic_form)) { | 151 !parsed_forms_.count(synthetic_form)) { |
152 // |*unowned_form_index| is already at the right index here. | |
148 forms.push_back(synthetic_form); | 153 forms.push_back(synthetic_form); |
149 parsed_forms_.insert(synthetic_form); | 154 parsed_forms_.insert(synthetic_form); |
150 synthetic_form_ = synthetic_form; | 155 synthetic_form_ = synthetic_form; |
151 } | 156 } |
152 return forms; | 157 return forms; |
153 } | 158 } |
154 | 159 |
155 void FormCache::Reset() { | 160 void FormCache::Reset() { |
156 synthetic_form_ = FormData(); | 161 synthetic_form_ = FormData(); |
157 parsed_forms_.clear(); | 162 parsed_forms_.clear(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 std::make_pair(input_element, input_element.isChecked())); | 323 std::make_pair(input_element, input_element.isChecked())); |
319 } else { | 324 } else { |
320 ++num_editable_elements; | 325 ++num_editable_elements; |
321 } | 326 } |
322 } | 327 } |
323 } | 328 } |
324 return num_editable_elements; | 329 return num_editable_elements; |
325 } | 330 } |
326 | 331 |
327 } // namespace autofill | 332 } // namespace autofill |
OLD | NEW |