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

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

Issue 974613002: Revert of Autofill: Disable autofill for fields outside of forms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 | « components/autofill/content/renderer/form_cache.h ('k') | 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_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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 num_fields_seen += form.fields.size(); 112 num_fields_seen += form.fields.size();
113 if (num_fields_seen > kMaxParseableFields) 113 if (num_fields_seen > kMaxParseableFields)
114 return forms; 114 return forms;
115 115
116 if (form.fields.size() >= kRequiredAutofillFields && 116 if (form.fields.size() >= kRequiredAutofillFields &&
117 !ContainsKey(parsed_forms_, form)) { 117 !ContainsKey(parsed_forms_, form)) {
118 forms.push_back(form); 118 forms.push_back(form);
119 parsed_forms_.insert(form); 119 parsed_forms_.insert(form);
120 } 120 }
121 } 121 }
122
123 // Look for more parseable fields outside of forms.
124 std::vector<WebElement> fieldsets;
125 std::vector<WebFormControlElement> control_elements =
126 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets);
127
128 size_t num_editable_elements =
129 ScanFormControlElements(control_elements, log_deprecation_messages);
130
131 if (ShouldIgnoreForm(num_editable_elements, control_elements.size()))
132 return forms;
133
134 FormData synthetic_form;
135 if (!UnownedFormElementsAndFieldSetsToFormData(fieldsets, control_elements,
136 nullptr, document.url(),
137 REQUIRE_NONE, extract_mask,
138 &synthetic_form, nullptr)) {
139 return forms;
140 }
141
142 num_fields_seen += synthetic_form.fields.size();
143 if (num_fields_seen > kMaxParseableFields)
144 return forms;
145
146 if (synthetic_form.fields.size() >= kRequiredAutofillFields &&
147 !parsed_forms_.count(synthetic_form)) {
148 forms.push_back(synthetic_form);
149 parsed_forms_.insert(synthetic_form);
150 synthetic_form_ = synthetic_form;
151 }
122 return forms; 152 return forms;
123 } 153 }
124 154
125 void FormCache::Reset() { 155 void FormCache::Reset() {
156 synthetic_form_ = FormData();
126 parsed_forms_.clear(); 157 parsed_forms_.clear();
127 initial_select_values_.clear(); 158 initial_select_values_.clear();
128 initial_checked_state_.clear(); 159 initial_checked_state_.clear();
129 } 160 }
130 161
131 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) { 162 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) {
132 WebFormElement form_element = element.form(); 163 WebFormElement form_element = element.form();
133 std::vector<WebFormControlElement> control_elements; 164 std::vector<WebFormControlElement> control_elements;
134 if (form_element.isNull()) { 165 if (form_element.isNull()) {
135 control_elements = GetUnownedAutofillableFormFieldElements( 166 control_elements = GetUnownedAutofillableFormFieldElements(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 215 }
185 216
186 return true; 217 return true;
187 } 218 }
188 219
189 bool FormCache::ShowPredictions(const FormDataPredictions& form) { 220 bool FormCache::ShowPredictions(const FormDataPredictions& form) {
190 DCHECK_EQ(form.data.fields.size(), form.fields.size()); 221 DCHECK_EQ(form.data.fields.size(), form.fields.size());
191 222
192 std::vector<WebFormControlElement> control_elements; 223 std::vector<WebFormControlElement> control_elements;
193 224
225 // First check the synthetic form.
194 bool found_synthetic_form = false; 226 bool found_synthetic_form = false;
227 if (form.data.SameFormAs(synthetic_form_)) {
228 found_synthetic_form = true;
229 WebDocument document = frame_.document();
230 control_elements =
231 GetUnownedAutofillableFormFieldElements(document.all(), nullptr);
232 }
233
195 if (!found_synthetic_form) { 234 if (!found_synthetic_form) {
196 // Find the real form by searching through the WebDocuments. 235 // Find the real form by searching through the WebDocuments.
197 bool found_form = false; 236 bool found_form = false;
198 WebFormElement form_element; 237 WebFormElement form_element;
199 WebVector<WebFormElement> web_forms; 238 WebVector<WebFormElement> web_forms;
200 frame_.document().forms(web_forms); 239 frame_.document().forms(web_forms);
201 240
202 for (size_t i = 0; i < web_forms.size(); ++i) { 241 for (size_t i = 0; i < web_forms.size(); ++i) {
203 form_element = web_forms[i]; 242 form_element = web_forms[i];
204 // Note: matching on the form name here which is not guaranteed to be 243 // Note: matching on the form name here which is not guaranteed to be
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 std::make_pair(input_element, input_element.isChecked())); 318 std::make_pair(input_element, input_element.isChecked()));
280 } else { 319 } else {
281 ++num_editable_elements; 320 ++num_editable_elements;
282 } 321 }
283 } 322 }
284 } 323 }
285 return num_editable_elements; 324 return num_editable_elements;
286 } 325 }
287 326
288 } // namespace autofill 327 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/form_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698