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

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

Issue 964453004: Autofill: Disable autofill for fields outside of forms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minimize diff 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 }
152 return forms; 122 return forms;
153 } 123 }
154 124
155 void FormCache::Reset() { 125 void FormCache::Reset() {
156 synthetic_form_ = FormData();
157 parsed_forms_.clear(); 126 parsed_forms_.clear();
158 initial_select_values_.clear(); 127 initial_select_values_.clear();
159 initial_checked_state_.clear(); 128 initial_checked_state_.clear();
160 } 129 }
161 130
162 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) { 131 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) {
163 WebFormElement form_element = element.form(); 132 WebFormElement form_element = element.form();
164 std::vector<WebFormControlElement> control_elements; 133 std::vector<WebFormControlElement> control_elements;
165 if (form_element.isNull()) { 134 if (form_element.isNull()) {
166 control_elements = GetUnownedAutofillableFormFieldElements( 135 control_elements = GetUnownedAutofillableFormFieldElements(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 184 }
216 185
217 return true; 186 return true;
218 } 187 }
219 188
220 bool FormCache::ShowPredictions(const FormDataPredictions& form) { 189 bool FormCache::ShowPredictions(const FormDataPredictions& form) {
221 DCHECK_EQ(form.data.fields.size(), form.fields.size()); 190 DCHECK_EQ(form.data.fields.size(), form.fields.size());
222 191
223 std::vector<WebFormControlElement> control_elements; 192 std::vector<WebFormControlElement> control_elements;
224 193
225 // First check the synthetic form.
226 bool found_synthetic_form = false; 194 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
234 if (!found_synthetic_form) { 195 if (!found_synthetic_form) {
235 // Find the real form by searching through the WebDocuments. 196 // Find the real form by searching through the WebDocuments.
236 bool found_form = false; 197 bool found_form = false;
237 WebFormElement form_element; 198 WebFormElement form_element;
238 WebVector<WebFormElement> web_forms; 199 WebVector<WebFormElement> web_forms;
239 frame_.document().forms(web_forms); 200 frame_.document().forms(web_forms);
240 201
241 for (size_t i = 0; i < web_forms.size(); ++i) { 202 for (size_t i = 0; i < web_forms.size(); ++i) {
242 form_element = web_forms[i]; 203 form_element = web_forms[i];
243 // Note: matching on the form name here which is not guaranteed to be 204 // 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
318 std::make_pair(input_element, input_element.isChecked())); 279 std::make_pair(input_element, input_element.isChecked()));
319 } else { 280 } else {
320 ++num_editable_elements; 281 ++num_editable_elements;
321 } 282 }
322 } 283 }
323 } 284 }
324 return num_editable_elements; 285 return num_editable_elements;
325 } 286 }
326 287
327 } // namespace autofill 288 } // 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